]> git.donarmstrong.com Git - lilypond.git/blob - lily/change-iterator.cc
*** empty log message ***
[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--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "change-iterator.hh"
10 #include "translator-group.hh"
11 #include "music.hh"
12 #include "warn.hh"
13
14
15
16 void
17 Change_iterator::error (String reason)
18 {
19   String to_type = ly_scm2string (get_music ()->get_mus_property ("change-to-type"));
20   String to_id =  ly_scm2string (get_music ()->get_mus_property ("change-to-id"));
21
22   String warn1 = _f ("can't change `%s' to `%s'", to_type, to_id) 
23     + ": " + reason;
24   /*
25     GUHG!
26    */
27   String warn2= "Change_iterator::process (): " 
28     + report_to ()->type_string_ + " = `"
29     + report_to ()->id_string_ + "': ";
30   warning (warn2);
31   get_music ()->origin ()->warning (warn1);
32 }
33
34 /*
35   move to construct_children ?
36  */
37 void
38 Change_iterator::process (Moment m)
39 {
40   Translator_group * current = report_to ();
41   Translator_group * last = 0;
42
43   String to_type = ly_scm2string (get_music ()->get_mus_property ("change-to-type"));
44   String to_id =  ly_scm2string (get_music ()->get_mus_property ("change-to-id"));
45
46
47   /* find the type  of translator that we're changing.
48      
49      If \translator Staff = bass, then look for Staff = *
50    */
51   while (current && current->type_string_ != to_type)
52     {
53       last = current;
54       current = current->daddy_trans_;
55     }
56
57   if (current && current->id_string_ == to_id)
58     {
59       String msg;
60       msg += _ ("Can't switch translators, I'm there already");
61     }
62   
63   if (current) 
64     if (last)
65       {
66         Translator_group * dest = 
67           report_to ()->find_create_translator (to_type, to_id);
68         current->remove_translator (last);
69         dest->add_used_group_translator (last);
70       }
71     else
72       {
73         /*
74           We could change the current translator's id, but that would make 
75           errors hard to catch
76           
77            last->translator_id_string_  = get_change ()->change_to_id_string_;
78         */
79         error (_ ("I'm one myself"));
80       }
81   else
82     error (_ ("none of these in my family"));
83   Simple_music_iterator::process (m);
84 }
85
86
87
88 IMPLEMENT_CTOR_CALLBACK (Change_iterator);