2 auto-change-iterator.cc -- implement Auto_change_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
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_group_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 Look ahead to find first pitches to determine staff position.
71 WARNING: this means that
73 \autochange Staff \notes { .... \context Staff = otherstaff { .. } .. }
75 will confuse the autochanger, since it will not notice that the
76 music for OTHERSTAFF is not his.
78 PRECONDITION: this->ok () holds.
81 Auto_change_iterator::pending_pitch (Moment m) const
83 Music_iterator * iter = child_iter_p_ ->clone ();
87 SCM muses = iter->get_music (m);
88 for (SCM s = muses; gh_pair_p (s); s=ly_cdr (s))
89 if (Note_req* nr = dynamic_cast<Note_req*> (unsmob_music (ly_car (s))))
91 ps.push (*unsmob_pitch (nr->get_mus_property ("pitch")));
101 m = iter->pending_moment ();
109 Auto_change_iterator::process (Moment m)
112 first we get the pitches, then we do the real work.
113 Music_wrapper_iterator::process () might process (and throw away)
115 Array<Pitch> ps = pending_pitch (m);
117 Music_wrapper_iterator::process (m);
121 Direction s = Direction (sign (p.steps ()));
125 String to_id = (s >= 0) ? "up" : "down";
126 String wh = ly_scm2string (music_l ()->get_mus_property ("what"));
127 change_to (child_iter_p_, wh, to_id);
132 Auto_change_iterator::Auto_change_iterator ()
137 IMPLEMENT_CTOR_CALLBACK (Auto_change_iterator);