(readPostTable): ugh. Kludge: nglyphs in maxp
[lilypond.git] / lily / auto-change-iterator.cc
blob1d07d6a7de8c076b6b09bc992f4269466f461c52
1 /*
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>
7 */
9 #include "context.hh"
10 #include "event.hh"
11 #include "music-wrapper-iterator.hh"
12 #include "direction.hh"
14 class Auto_change_iterator : public Music_wrapper_iterator
16 public:
17 DECLARE_SCHEME_CALLBACK (constructor, ());
19 Auto_change_iterator ();
21 protected:
22 virtual void do_quit ();
23 virtual void construct_children ();
24 virtual void process (Moment);
25 Array<Pitch> pending_pitch (Moment) const;
26 private:
27 SCM split_list_;
28 Direction where_dir_;
29 void change_to (Music_iterator *, SCM, String);
30 Moment start_moment_;
32 Context_handle up_;
33 Context_handle down_;
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->get_parent_context ();
59 if (current && current->id_string () == to_id)
61 String msg;
62 msg += _f ("can't change, already in translator: %s", to_id);
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;
84 void
85 Auto_change_iterator::process (Moment m)
87 Music_wrapper_iterator::process (m);
89 Moment now = get_outlet ()->now_mom ();
90 Moment *splitm = 0;
92 for (; scm_is_pair (split_list_); split_list_ = scm_cdr (split_list_))
94 splitm = unsmob_moment (scm_caar (split_list_));
95 if ((*splitm + start_moment_) > now)
96 break;
98 SCM tag = scm_cdar (split_list_);
99 Direction d = to_dir (tag);
101 if (d && d != where_dir_)
103 where_dir_ = d;
104 String to_id = (d >= 0) ? "up" : "down";
105 change_to (child_iter_,
106 ly_symbol2scm ("Staff"),
107 to_id);
112 Auto_change_iterator::Auto_change_iterator ()
114 where_dir_ = CENTER;
115 split_list_ = SCM_EOL;
118 void
119 Auto_change_iterator::construct_children ()
121 split_list_ = get_music ()->get_property ("split-list");
122 start_moment_ = get_outlet ()->now_mom ();
124 SCM props = get_outlet ()->get_property ("trebleStaffProperties");
125 Context *up = get_outlet ()->find_create_context (ly_symbol2scm ("Staff"),
126 "up", props);
128 props = get_outlet ()->get_property ("bassStaffProperties");
129 Context *down = get_outlet ()->find_create_context (ly_symbol2scm ("Staff"),
130 "down", props);
132 up_.set_context (up);
133 down_.set_context (down);
135 Context *voice = up->find_create_context (ly_symbol2scm ("Voice"),
136 "", SCM_EOL);
137 set_context (voice);
138 Music_wrapper_iterator::construct_children ();
141 void
142 Auto_change_iterator::do_quit ()
144 up_.set_context (0);
145 down_.set_context (0);
148 IMPLEMENT_CTOR_CALLBACK (Auto_change_iterator);