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