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>
13 #include "music-wrapper-iterator.hh"
14 #include "direction.hh"
16 class Auto_change_iterator : public Music_wrapper_iterator
19 DECLARE_SCHEME_CALLBACK (constructor, ());
21 Auto_change_iterator ();
24 virtual void do_quit ();
25 virtual void construct_children ();
26 virtual void process (Moment);
27 Array<Pitch> pending_pitch (Moment)const;
31 void change_to (Music_iterator* , SCM, String);
34 Interpretation_context_handle up_;
35 Interpretation_context_handle down_;
42 Auto_change_iterator::change_to (Music_iterator *it, SCM to_type_sym,
45 Context * current = it->get_outlet ();
49 Cut & Paste from Change_iterator (ugh).
51 TODO: abstract this function
54 /* find the type of translator that we're changing.
56 If \translator Staff = bass, then look for Staff = *
58 while (current && !current->is_alias (to_type_sym))
61 current = current->get_parent_context ();
64 if (current && current->id_string () == to_id)
67 msg += _ ("Can't switch translators, I'm there already");
74 it->get_outlet ()->find_create_context (to_type_sym, to_id, SCM_EOL);
75 current->remove_context (last);
76 dest->add_context (last);
81 We could change the current translator's id, but that would make
92 Auto_change_iterator::process (Moment m)
94 Music_wrapper_iterator::process (m);
96 Moment now = get_outlet ()->now_mom ();
99 for (; scm_is_pair (split_list_); split_list_ = scm_cdr (split_list_))
101 splitm = unsmob_moment (scm_caar (split_list_));
102 if ((*splitm + start_moment_) > now)
105 SCM tag = scm_cdar (split_list_);
106 Direction d = to_dir (tag);
108 if (d && d != where_dir_)
111 String to_id = (d >= 0) ? "up" : "down";
112 change_to (child_iter_,
113 ly_symbol2scm ("Staff"),
119 Auto_change_iterator::Auto_change_iterator ()
122 split_list_ = SCM_EOL;
126 Auto_change_iterator::construct_children ()
128 split_list_ = get_music ()->get_property ("split-list");
129 start_moment_ = get_outlet ()->now_mom ();
131 SCM props = get_outlet()->get_property ("trebleStaffProperties");
132 Context *up = get_outlet()->find_create_context (ly_symbol2scm ("Staff"),
135 props = get_outlet()->get_property ("bassStaffProperties");
136 Context *down = get_outlet()->find_create_context (ly_symbol2scm ("Staff"),
139 up_.set_translator (up);
140 down_.set_translator (down);
142 Context *voice = up->find_create_context (ly_symbol2scm ("Voice"),
144 set_translator (voice);
145 Music_wrapper_iterator::construct_children ();
150 Auto_change_iterator::do_quit()
152 up_.set_translator (0);
153 down_.set_translator (0);
156 IMPLEMENT_CTOR_CALLBACK (Auto_change_iterator);