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