]> git.donarmstrong.com Git - lilypond.git/blob - lily/change-iterator.cc
release: 1.1.65
[lilypond.git] / lily / change-iterator.cc
1 /*
2   change-iterator.cc -- implement Change_iterator
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "change-iterator.hh"
10 #include "translator-group.hh"
11 #include "change-translator.hh"
12 #include "debug.hh"
13
14
15 void
16 Change_iterator::error (String reason)
17 {
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_;
21
22   String warn1 = _f ("can't change `%s\' to `%s\'", to_type, to_id) 
23     + ": " + reason;
24   String warn2= "Change_iterator::do_process_and_next (): " 
25     + report_to_l ()->type_str_ + " = `"
26     + report_to_l ()->id_str_ + "\': ";
27   warning (warn2);
28   t->warning (warn1);
29 }
30
31 /*
32   move to construct_children ?
33  */
34 void
35 Change_iterator::do_process_and_next (Moment m)
36 {
37   Translator_group * current = report_to_l ();
38   Translator_group * last = 0;
39
40   Change_translator const * t = dynamic_cast<Change_translator const*> (music_l_); 
41   String to_type = t->change_to_type_str_;
42   String to_id =  t->change_to_id_str_;
43
44   /* find the type  of translator that we're changing.
45      
46      If \translator Staff = bass, then look for Staff = *
47    */
48   while  (current && current->type_str_ != to_type)
49     {
50       last = current;
51       current = current->daddy_trans_l_;
52     }
53
54   if (current && current->id_str_ == to_id)
55     {
56       String msg;
57       msg += "Cannot switch  translators, I'm there already.";
58     }
59   
60   if (current) 
61     if (last)
62       {
63         Translator_group * dest = 
64           report_to_l ()->find_create_translator_l (to_type, to_id);
65         current->remove_translator_p (last);
66         dest->add_translator (last);
67       }
68     else
69       {
70         /*
71           We could change the current translator's id, but that would make 
72           errors hard to catch
73           
74            last->translator_id_str_  = change_l ()->change_to_id_str_;
75         */
76         error ("I'm one myself");
77       }
78   else
79     error ("None of these in my family.");
80   Music_iterator::do_process_and_next (m);
81 }
82
83