*** empty log message ***
[lilypond.git] / lily / change-iterator.cc
blobb8ccb356b1cf904fa1129be1b3055db7bde53c94
1 /*
2 change-iterator.cc -- implement Change_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "change-iterator.hh"
10 #include "translator-group.hh"
11 #include "music.hh"
12 #include "warn.hh"
16 void
17 Change_iterator::error (String reason)
19 String to_type = ly_scm2string (get_music ()->get_mus_property ("change-to-type"));
20 String to_id = ly_scm2string (get_music ()->get_mus_property ("change-to-id"));
22 String warn1 = _f ("can't change `%s' to `%s'", to_type, to_id)
23 + ": " + reason;
26 GUHG!
28 String warn2= "Change_iterator::process (): "
29 + report_to ()->context_name () + " = `"
30 + report_to ()->id_string_ + "': ";
31 warning (warn2);
32 get_music ()->origin ()->warning (warn1);
36 move to construct_children ?
38 void
39 Change_iterator::process (Moment m)
41 Translator_group * current = report_to ();
42 Translator_group * last = 0;
44 SCM to_type = get_music ()->get_mus_property ("change-to-type");
45 String to_id = ly_scm2string (get_music ()->get_mus_property ("change-to-id"));
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_b (to_type))
54 last = current;
55 current = current->daddy_trans_;
58 if (current && current->id_string_ == to_id)
60 String msg;
61 msg += _ ("Can't switch translators, I'm there already");
64 if (current)
65 if (last)
67 Translator_group * dest =
68 report_to ()->find_create_translator (to_type, to_id);
69 current->remove_translator (last);
70 dest->add_used_group_translator (last);
72 else
75 We could change the current translator's id, but that would make
76 errors hard to catch
78 last->translator_id_string_ = get_change ()->change_to_id_string_;
80 error (_ ("I'm one myself"));
82 else
83 error (_ ("none of these in my family"));
84 Simple_music_iterator::process (m);
89 IMPLEMENT_CTOR_CALLBACK (Change_iterator);