lilypond-1.4.4
[lilypond.git] / lily / change-iterator.cc
blob96e7affd0741d01717ed08479ca35315fe43f278
1 /*
2 change-iterator.cc -- implement Change_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "change-iterator.hh"
10 #include "translator-group.hh"
11 #include "music.hh"
12 #include "debug.hh"
15 void
16 Change_iterator::error (String reason)
18 String to_type = ly_scm2string (music_l_->get_mus_property ("change-to-type"));
19 String to_id = ly_scm2string (music_l_->get_mus_property ("change-to-id"));
21 String warn1 = _f ("can't change `%s' to `%s'", to_type, to_id)
22 + ": " + reason;
24 GUHG!
26 String warn2= "Change_iterator::process (): "
27 + report_to_l ()->type_str_ + " = `"
28 + report_to_l ()->id_str_ + "': ";
29 warning (warn2);
30 music_l_->origin ()->warning (warn1);
34 move to construct_children ?
36 void
37 Change_iterator::process (Moment m)
39 Translator_group * current = report_to_l ();
40 Translator_group * last = 0;
42 String to_type = ly_scm2string (music_l_->get_mus_property ("change-to-type"));
43 String to_id = ly_scm2string (music_l_->get_mus_property ("change-to-id"));
46 /* find the type of translator that we're changing.
48 If \translator Staff = bass, then look for Staff = *
50 while (current && current->type_str_ != to_type)
52 last = current;
53 current = current->daddy_trans_l_;
56 if (current && current->id_str_ == to_id)
58 String msg;
59 msg += _ ("Can't switch translators, I'm there already");
62 if (current)
63 if (last)
65 Translator_group * dest =
66 report_to_l ()->find_create_translator_l (to_type, to_id);
67 current->remove_translator_p (last);
68 dest->add_group_translator (last);
70 else
73 We could change the current translator's id, but that would make
74 errors hard to catch
76 last->translator_id_str_ = change_l ()->change_to_id_str_;
78 error (_ ("I'm one myself"));
80 else
81 error (_ ("none of these in my family"));
82 Simple_music_iterator::process (m);
87 IMPLEMENT_CTOR_CALLBACK (Change_iterator);