2 auto-change-iterator.cc -- implement Auto_change_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "auto-change-music.hh"
11 #include "auto-change-iterator.hh"
12 #include "translator-group.hh"
13 #include "musical-request.hh"
18 Auto_change_iterator::change_to (Music_iterator
*it
, String to_type
,
21 Translator_group
* current
= it
->report_to_l ();
22 Translator_group
* last
= 0;
25 Cut & Paste from Change_iterator (ugh).
27 TODO: abstract this function
30 /* find the type of translator that we're changing.
32 If \translator Staff = bass, then look for Staff = *
34 while (current
&& current
->type_str_
!= to_type
)
37 current
= current
->daddy_trans_l_
;
40 if (current
&& current
->id_str_
== to_id
)
43 msg
+= _ ("Can't switch translators, I'm there already");
49 Translator_group
* dest
=
50 it
->report_to_l ()->find_create_translator_l (to_type
, to_id
);
51 current
->remove_translator_p (last
);
52 dest
->add_translator (last
);
57 We could change the current translator's id, but that would make
60 last->translator_id_str_ = change_l ()->change_to_id_str_;
62 // error (_ ("I'm one myself"));
65 ; // error (_ ("none of these in my family"));
70 Auto_change_iterator::do_process_and_next (Moment m
)
72 Music_wrapper_iterator::do_process_and_next (m
);
73 Pitch_interrogate_req spanish_inquisition
; // nobody expects it
75 Music_iterator
*it
= try_music (&spanish_inquisition
);
77 if (it
&& spanish_inquisition
.pitch_arr_
.size ())
79 Musical_pitch p
= spanish_inquisition
.pitch_arr_
[0];
80 Direction s
= Direction (sign(p
.steps ()));
84 String to_id
= (s
>= 0) ? "up" : "down";
85 Auto_change_music
const * auto_mus
= dynamic_cast<Auto_change_music
const* > (music_l_
);
87 change_to (it
, auto_mus
->what_str_
, to_id
);
92 Auto_change_iterator::Auto_change_iterator( )