]> git.donarmstrong.com Git - lilypond.git/blob - lily/change-iterator.cc
96e7affd0741d01717ed08479ca35315fe43f278
[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--2001 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 "debug.hh"
13
14
15 void
16 Change_iterator::error (String reason)
17 {
18   String to_type = ly_scm2string (music_l_->get_mus_property ("change-to-type"));
19   String to_id =  ly_scm2string (music_l_->get_mus_property ("change-to-id"));
20
21   String warn1 = _f ("can't change `%s' to `%s'", to_type, to_id) 
22     + ": " + reason;
23   /*
24     GUHG!
25    */
26   String warn2= "Change_iterator::process (): " 
27     + report_to_l ()->type_str_ + " = `"
28     + report_to_l ()->id_str_ + "': ";
29   warning (warn2);
30   music_l_->origin ()->warning (warn1);
31 }
32
33 /*
34   move to construct_children ?
35  */
36 void
37 Change_iterator::process (Moment m)
38 {
39   Translator_group * current = report_to_l ();
40   Translator_group * last = 0;
41
42   String to_type = ly_scm2string (music_l_->get_mus_property ("change-to-type"));
43   String to_id =  ly_scm2string (music_l_->get_mus_property ("change-to-id"));
44
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   if (current && current->id_str_ == to_id)
57     {
58       String msg;
59       msg += _ ("Can't switch translators, I'm there already");
60     }
61   
62   if (current) 
63     if (last)
64       {
65         Translator_group * dest = 
66           report_to_l ()->find_create_translator_l (to_type, to_id);
67         current->remove_translator_p (last);
68         dest->add_group_translator (last);
69       }
70     else
71       {
72         /*
73           We could change the current translator's id, but that would make 
74           errors hard to catch
75           
76            last->translator_id_str_  = change_l ()->change_to_id_str_;
77         */
78         error (_ ("I'm one myself"));
79       }
80   else
81     error (_ ("none of these in my family"));
82   Simple_music_iterator::process (m);
83 }
84
85
86
87 IMPLEMENT_CTOR_CALLBACK (Change_iterator);