2 auto-change-iterator.cc -- implement Auto_change_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "music-wrapper-iterator.hh"
11 #include "direction.hh"
13 class Auto_change_iterator : public Music_wrapper_iterator
16 DECLARE_SCHEME_CALLBACK (constructor, ());
18 Auto_change_iterator ();
21 virtual void do_quit ();
22 virtual void construct_children ();
23 virtual void process (Moment);
24 Array<Pitch> pending_pitch (Moment) const;
28 void change_to (Music_iterator *, SCM, String);
36 Auto_change_iterator::change_to (Music_iterator *it, SCM to_type_sym,
39 Context *current = it->get_outlet ();
43 Cut & Paste from Change_iterator (ugh).
45 TODO: abstract this function
48 /* find the type of translator that we're changing.
50 If \translator Staff = bass, then look for Staff = *
52 while (current && !current->is_alias (to_type_sym))
55 current = current->get_parent_context ();
58 if (current && current->id_string () == to_id)
61 msg += _f ("can't change, already in translator: %s", to_id);
68 = it->get_outlet ()->find_create_context (to_type_sym, to_id, SCM_EOL);
69 current->remove_context (last);
70 dest->add_context (last);
75 We could change the current translator's id, but that would make
84 Auto_change_iterator::process (Moment m)
86 Music_wrapper_iterator::process (m);
88 Moment now = get_outlet ()->now_mom ();
91 for (; scm_is_pair (split_list_); split_list_ = scm_cdr (split_list_))
93 splitm = unsmob_moment (scm_caar (split_list_));
94 if ((*splitm + start_moment_) > now)
97 SCM tag = scm_cdar (split_list_);
98 Direction d = to_dir (tag);
100 if (d && d != where_dir_)
103 String to_id = (d >= 0) ? "up" : "down";
104 change_to (child_iter_,
105 ly_symbol2scm ("Staff"),
111 Auto_change_iterator::Auto_change_iterator ()
114 split_list_ = SCM_EOL;
118 Auto_change_iterator::construct_children ()
120 split_list_ = get_music ()->get_property ("split-list");
121 start_moment_ = get_outlet ()->now_mom ();
123 SCM props = get_outlet ()->get_property ("trebleStaffProperties");
124 Context *up = get_outlet ()->find_create_context (ly_symbol2scm ("Staff"),
127 props = get_outlet ()->get_property ("bassStaffProperties");
128 Context *down = get_outlet ()->find_create_context (ly_symbol2scm ("Staff"),
131 up_.set_context (up);
132 down_.set_context (down);
134 Context *voice = up->find_create_context (ly_symbol2scm ("Voice"),
137 Music_wrapper_iterator::construct_children ();
141 Auto_change_iterator::do_quit ()
144 down_.set_context (0);
147 IMPLEMENT_CTOR_CALLBACK (Auto_change_iterator);