2 part-combine-music-iterator.cc -- implement Part_combine_music_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "part-combine-music.hh"
10 #include "part-combine-music-iterator.hh"
11 #include "translator-group.hh"
12 #include "musical-request.hh"
15 Part_combine_music_iterator::Part_combine_music_iterator ()
23 Part_combine_music_iterator::~Part_combine_music_iterator ()
25 delete second_iter_p_;
30 Part_combine_music_iterator::next_moment () const
32 Moment first_next = first_iter_p_->next_moment ();
33 Moment second_next = second_iter_p_->next_moment ();
34 return first_next <? second_next;
38 Part_combine_music_iterator::ok () const
41 return first_iter_p_->ok ();
45 Part_combine_music_iterator::do_print () const
47 first_iter_p_->print ();
48 second_iter_p_->print ();
52 Part_combine_music_iterator::construct_children ()
54 Part_combine_music const * m = dynamic_cast<Part_combine_music const*> (music_l_);
56 first_iter_p_ = get_iterator_p (m->first_l ());
57 second_iter_p_ = get_iterator_p (m->second_l ());
61 Part_combine_music_iterator::change_to (Music_iterator *it, String to_type,
64 Translator_group * current = it->report_to_l ();
65 Translator_group * last = 0;
68 Cut & Paste from from Auto_change_iterator from Change_iterator (ugh).
70 TODO: abstract this function
73 /* find the type of translator that we're changing.
75 If \translator Staff = bass, then look for Staff = *
77 while (current && current->type_str_ != to_type)
80 current = current->daddy_trans_l_;
83 if (current && current->id_str_ == to_id)
86 msg += _ ("Can't switch translators, I'm there already");
92 Translator_group * dest =
93 it->report_to_l ()->find_create_translator_l (to_type, to_id);
94 current->remove_translator_p (last);
95 dest->add_translator (last);
100 We could change the current translator's id, but that would make
103 last->translator_id_str_ = change_l ()->change_to_id_str_;
105 error (_f ("I'm one myself: `%s'", to_type.ch_C ()));
108 error (_f ("none of these in my family: `%s'", to_id.ch_C ()));
111 Pitch_interrogate_req* first_spanish_inquisition; // nobody expects it
112 Pitch_interrogate_req* second_spanish_inquisition; // won't strike twice
115 Part_combine_music_iterator::do_process_and_next (Moment m)
117 Moment first_next = first_iter_p_->next_moment ();
118 Moment second_next = second_iter_p_->next_moment ();
120 Part_combine_music const * p = dynamic_cast<Part_combine_music const* > (music_l_);
123 first_iter_p_->process_and_next (m);
125 if (second_next <= m)
126 second_iter_p_->process_and_next (m);
128 Music_iterator::do_process_and_next (m);
135 * check setting/resetting of properties
137 Later (because currently, we only handle thread switching, really):
139 Maybe different modes exist?
141 * Wind instruments (Flute I/II)
145 Rules for Hymnals/SATB (John Henckel <henckel@iname.com>):
147 1. if S and A differ by less than a third, the stems should be up/down.
148 2. else if S and A have different values, the stems should be up/down.
149 3. else if A sings "la" or higher, both S and A stems should be down.
150 4. else both stems should be up
152 * This may get really tricky: combining voices/staffs: string instruments
156 if (!first_spanish_inquisition)
157 first_spanish_inquisition = new Pitch_interrogate_req;
158 Music_iterator* fit = first_iter_p_->try_music (first_spanish_inquisition);
160 if (!second_spanish_inquisition)
161 second_spanish_inquisition = new Pitch_interrogate_req;
162 Music_iterator* sit = second_iter_p_->try_music (second_spanish_inquisition);
164 Array<Musical_pitch>* first_arr_l = &first_spanish_inquisition->pitch_arr_;
165 Array<Musical_pitch>* second_arr_l = &second_spanish_inquisition->pitch_arr_;
167 SCM interval = SCM_BOOL_F;
168 if (first_arr_l->size () && second_arr_l->size ())
170 first_arr_l->sort (Musical_pitch::compare);
171 second_arr_l->sort (Musical_pitch::compare);
172 interval = gh_int2scm (first_arr_l->top ().steps ()
173 - (*second_arr_l)[0].steps ());
176 Translator_group * fir = first_iter_p_->report_to_l ();
177 Translator_group * sir = second_iter_p_->report_to_l ();
179 bool solo_b = (first_arr_l->empty () != second_arr_l->empty ());
182 Urg, this doesn't work at all. Do we need to send out another inquisition?
184 bool unirhythm_b = (first_next == second_next) && !solo_b;
186 Translator_group * fd = fir->find_create_translator_l (p->what_str_, "one");
187 Translator_group * sd = sir->find_create_translator_l (p->what_str_, "two");
189 bool split_interval_b = false;
190 if (gh_number_p (interval))
192 SCM s = fd->get_property (ly_symbol2scm ("splitInterval"));
193 int i = gh_scm2int (interval);
195 && gh_number_p (gh_car (s))
196 && gh_number_p (gh_cdr (s))
197 && i >= gh_scm2int (gh_car (s))
198 && i <= gh_scm2int (gh_cdr (s)))
199 split_interval_b = true;
203 Hmm, maybe we should set/check combined_b_ against
205 first_iter_p_->report_to_l () == second_iter_p_->report_to_l ()
210 String to_id = combined_b_ ? "one" : "two";
211 if ((!unirhythm_b && combined_b_)
212 || (split_interval_b && combined_b_)
213 || (solo_b && combined_b_)
214 || (unirhythm_b && !combined_b_ && !split_interval_b && !solo_b))
216 combined_b_ = !combined_b_;
217 to_id = combined_b_ ? "one" : "two";
218 change_to (second_iter_p_, p->what_str_, to_id);
222 sir = second_iter_p_->report_to_l ();
224 SCM b = unirhythm_b ? SCM_BOOL_T : SCM_BOOL_F;
225 fd->set_property ("unirhythm", b);
226 sd->set_property ("unirhythm", b);
228 b = split_interval_b ? SCM_BOOL_T : SCM_BOOL_F;
229 fd->set_property ("split-interval", b);
230 sd->set_property ("split-interval", b);
232 b = gh_bool2scm (unirhythm_b && !compare (first_arr_l, second_arr_l));
233 fd->set_property ("unison", b);
234 sd->set_property ("unison", b);
236 b = solo_b ? SCM_BOOL_T : SCM_BOOL_F;
237 if (first_arr_l->size ())
239 fd->set_property ("solo", b);
240 sd->set_property ("solo", SCM_BOOL_F);
243 if (second_arr_l->size ())
245 fd->set_property ("solo", SCM_BOOL_F);
246 sd->set_property ("solo", b);
249 first_arr_l->clear ();
250 second_arr_l->clear ();
254 Part_combine_music_iterator::try_music_in_children (Music *m) const
256 Music_iterator * i = first_iter_p_->try_music (m);
260 return second_iter_p_->try_music (m);