2 auto-change-iterator.cc -- implement Auto_change_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "translator-group.hh"
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 construct_children ();
25 virtual void process (Moment);
26 Array<Pitch> pending_pitch (Moment)const;
30 void change_to (Music_iterator* , SCM, String);
36 Auto_change_iterator::change_to (Music_iterator *it, SCM to_type_sym,
39 Translator_group * current = it->get_outlet ();
40 Translator_group * last = 0;
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->daddy_trans_;
58 if (current && current->id_string_ == to_id)
61 msg += _ ("Can't switch translators, I'm there already");
67 Translator_group * dest =
68 it->get_outlet ()->find_create_translator (to_type_sym, to_id, SCM_EOL);
69 current->remove_translator (last);
70 dest->add_used_group_translator (last);
75 We could change the current translator's id, but that would make
86 Auto_change_iterator::process (Moment m)
88 Music_wrapper_iterator::process (m);
91 Moment now = get_outlet ()->now_mom ();
94 for (; gh_pair_p (split_list_); split_list_ = gh_cdr (split_list_))
96 splitm = unsmob_moment (gh_caar (split_list_));
100 SCM tag = gh_cdar (split_list_);
101 Direction d = to_dir (tag);
103 if (d && d != where_dir_)
106 String to_id = (d >= 0) ? "up" : "down";
107 change_to (child_iter_,
108 ly_symbol2scm ("Staff"),
114 Auto_change_iterator::Auto_change_iterator ()
117 split_list_ = SCM_EOL;
121 Auto_change_iterator::construct_children ()
123 Music_wrapper_iterator::construct_children ();
124 split_list_ = get_music ()->get_mus_property ("split-list");
127 IMPLEMENT_CTOR_CALLBACK (Auto_change_iterator);