lilypond-1.3.7
[lilypond.git] / lily / change-iterator.cc
blob4fa7c519e460611ca8e108c4c7a2a0eef13c9a66
1 /*
2 change-iterator.cc -- implement Change_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "change-iterator.hh"
10 #include "translator-group.hh"
11 #include "change-translator.hh"
12 #include "debug.hh"
15 void
16 Change_iterator::error (String reason)
18 Change_translator const * t = dynamic_cast<Change_translator const*> (music_l_);
19 String to_type = t->change_to_type_str_;
20 String to_id = t->change_to_id_str_;
22 String warn1 = _f ("Can't change `%s' to `%s'", to_type, to_id)
23 + ": " + reason;
25 GUHG!
27 String warn2= "Change_iterator::do_process_and_next (): "
28 + report_to_l ()->type_str_ + " = `"
29 + report_to_l ()->id_str_ + "': ";
30 warning (warn2);
31 t->warning (warn1);
35 move to construct_children ?
37 void
38 Change_iterator::do_process_and_next (Moment m)
40 Translator_group * current = report_to_l ();
41 Translator_group * last = 0;
43 Change_translator const * t = dynamic_cast<Change_translator const*> (music_l_);
44 String to_type = t->change_to_type_str_;
45 String to_id = t->change_to_id_str_;
47 /* find the type of translator that we're changing.
49 If \translator Staff = bass, then look for Staff = *
51 while (current && current->type_str_ != to_type)
53 last = current;
54 current = current->daddy_trans_l_;
57 if (current && current->id_str_ == to_id)
59 String msg;
60 msg += _ ("Can't switch translators, I'm there already");
63 if (current)
64 if (last)
66 Translator_group * dest =
67 report_to_l ()->find_create_translator_l (to_type, to_id);
68 current->remove_translator_p (last);
69 dest->add_translator (last);
71 else
74 We could change the current translator's id, but that would make
75 errors hard to catch
77 last->translator_id_str_ = change_l ()->change_to_id_str_;
79 error (_ ("I'm one myself"));
81 else
82 error (_ ("none of these in my family"));
83 Music_iterator::do_process_and_next (m);