2 auto-change-iterator.cc -- implement Auto_change_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "music-wrapper-iterator.hh"
13 #include "direction.hh"
15 class Auto_change_iterator : public Music_wrapper_iterator
18 DECLARE_SCHEME_CALLBACK (constructor, ());
20 Auto_change_iterator ();
23 virtual void do_quit ();
24 virtual void construct_children ();
25 virtual void process (Moment);
26 Array<Pitch> pending_pitch (Moment)const;
30 void change_to (Music_iterator* , SCM, String);
33 Interpretation_context_handle up_;
34 Interpretation_context_handle down_;
41 Auto_change_iterator::change_to (Music_iterator *it, SCM to_type_sym,
44 Context * current = it->get_outlet ();
48 Cut & Paste from Change_iterator (ugh).
50 TODO: abstract this function
53 /* find the type of translator that we're changing.
55 If \translator Staff = bass, then look for Staff = *
57 while (current && !current->is_alias (to_type_sym))
60 current = current->get_parent_context ();
63 if (current && current->id_string () == to_id)
66 msg += _ ("Can't switch translators, I'm there already");
73 it->get_outlet ()->find_create_context (to_type_sym, to_id, SCM_EOL);
74 current->remove_context (last);
75 dest->add_context (last);
80 We could change the current translator's id, but that would make
91 Auto_change_iterator::process (Moment m)
93 Music_wrapper_iterator::process (m);
95 Moment now = get_outlet ()->now_mom ();
98 for (; scm_is_pair (split_list_); split_list_ = scm_cdr (split_list_))
100 splitm = unsmob_moment (scm_caar (split_list_));
101 if ((*splitm + start_moment_) > now)
104 SCM tag = scm_cdar (split_list_);
105 Direction d = to_dir (tag);
107 if (d && d != where_dir_)
110 String to_id = (d >= 0) ? "up" : "down";
111 change_to (child_iter_,
112 ly_symbol2scm ("Staff"),
118 Auto_change_iterator::Auto_change_iterator ()
121 split_list_ = SCM_EOL;
125 Auto_change_iterator::construct_children ()
127 split_list_ = get_music ()->get_property ("split-list");
128 start_moment_ = get_outlet ()->now_mom ();
130 SCM props = get_outlet()->get_property ("trebleStaffProperties");
131 Context *up = get_outlet()->find_create_context (ly_symbol2scm ("Staff"),
134 props = get_outlet()->get_property ("bassStaffProperties");
135 Context *down = get_outlet()->find_create_context (ly_symbol2scm ("Staff"),
138 up_.set_context (up);
139 down_.set_context (down);
141 Context *voice = up->find_create_context (ly_symbol2scm ("Voice"),
144 Music_wrapper_iterator::construct_children ();
149 Auto_change_iterator::do_quit()
152 down_.set_context (0);
155 IMPLEMENT_CTOR_CALLBACK (Auto_change_iterator);