* lily/include/lily-guile.hh: many new ly_ functions. Thanks to
[lilypond.git] / lily / auto-change-iterator.cc
blob000e0417d07f901d34024172111429adf0d7b020
1 /*
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>
8 */
10 #include "music.hh"
11 #include "context.hh"
12 #include "event.hh"
13 #include "music-wrapper-iterator.hh"
14 #include "direction.hh"
16 class Auto_change_iterator : public Music_wrapper_iterator
18 public:
19 DECLARE_SCHEME_CALLBACK (constructor, ());
21 Auto_change_iterator ();
23 protected:
24 virtual void construct_children ();
25 virtual void process (Moment);
26 Array<Pitch> pending_pitch (Moment)const;
27 private:
28 SCM split_list_;
29 Direction where_dir_;
30 void change_to (Music_iterator* , SCM, String);
31 Moment start_moment_;
36 void
37 Auto_change_iterator::change_to (Music_iterator *it, SCM to_type_sym,
38 String to_id)
40 Context * current = it->get_outlet ();
41 Context * last = 0;
44 Cut & Paste from Change_iterator (ugh).
46 TODO: abstract this function
49 /* find the type of translator that we're changing.
51 If \translator Staff = bass, then look for Staff = *
53 while (current && !current->is_alias (to_type_sym))
55 last = current;
56 current = current->daddy_context_;
59 if (current && current->id_string_ == to_id)
61 String msg;
62 msg += _ ("Can't switch translators, I'm there already");
65 if (current)
66 if (last)
68 Context * dest =
69 it->get_outlet ()->find_create_context (to_type_sym, to_id, SCM_EOL);
70 current->remove_context (last);
71 dest->add_context (last);
73 else
76 We could change the current translator's id, but that would make
77 errors hard to catch
81 else
86 void
87 Auto_change_iterator::process (Moment m)
89 Music_wrapper_iterator::process (m);
91 Moment now = get_outlet ()->now_mom ();
92 Moment *splitm = 0;
94 for (; ly_pair_p (split_list_); split_list_ = ly_cdr (split_list_))
96 splitm = unsmob_moment (ly_caar (split_list_));
97 if ((*splitm + start_moment_) > now)
98 break ;
100 SCM tag = ly_cdar (split_list_);
101 Direction d = to_dir (tag);
103 if (d && d != where_dir_)
105 where_dir_ = d;
106 String to_id = (d >= 0) ? "up" : "down";
107 change_to (child_iter_,
108 ly_symbol2scm ("Staff"),
109 to_id);
114 Auto_change_iterator::Auto_change_iterator ()
116 where_dir_ = CENTER;
117 split_list_ = SCM_EOL;
120 void
121 Auto_change_iterator::construct_children ()
123 Music_wrapper_iterator::construct_children ();
124 split_list_ = get_music ()->get_property ("split-list");
125 start_moment_ = get_outlet ()->now_mom ();
128 IMPLEMENT_CTOR_CALLBACK (Auto_change_iterator);