]> git.donarmstrong.com Git - lilypond.git/blob - lily/auto-change-iterator.cc
patch::: 1.3.86.jcn2
[lilypond.git] / lily / auto-change-iterator.cc
1 /*   
2   auto-change-iterator.cc -- implement  Auto_change_iterator
3
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "auto-change-music.hh"
11 #include "auto-change-iterator.hh"
12 #include "translator-group.hh"
13 #include "musical-request.hh"
14
15
16
17 void
18 Auto_change_iterator::change_to (Music_iterator *it, String to_type,
19                                  String to_id)
20 {
21   Translator_group * current = it->report_to_l ();
22   Translator_group * last = 0;
23
24   /*
25     Cut & Paste from Change_iterator (ugh).
26
27     TODO: abstract this function 
28    */
29   
30   /* find the type  of translator that we're changing.
31      
32      If \translator Staff = bass, then look for Staff = *
33    */
34   while  (current && current->type_str_ != to_type)
35     {
36       last = current;
37       current = current->daddy_trans_l_;
38     }
39
40   if (current && current->id_str_ == to_id)
41     {
42       String msg;
43       msg += _ ("Can't switch translators, I'm there already");
44     }
45   
46   if (current) 
47     if (last)
48       {
49         Translator_group * dest = 
50           it->report_to_l ()->find_create_translator_l (to_type, to_id);
51         current->remove_translator_p (last);
52         dest->add_group_translator (last);
53       }
54     else
55       {
56         /*
57           We could change the current translator's id, but that would make 
58           errors hard to catch
59           
60            last->translator_id_str_  = change_l ()->change_to_id_str_;
61         */
62         //      error (_ ("I'm one myself"));
63       }
64   else
65     ; //    error (_ ("none of these in my family"));
66
67 }
68
69 Pitch_interrogate_req* spanish_inquisition; // nobody expects it
70
71 void
72 Auto_change_iterator::do_process (Moment m)
73 {
74   Music_wrapper_iterator::do_process (m);
75
76   if (!spanish_inquisition)
77     spanish_inquisition = new Pitch_interrogate_req;
78
79   Music_iterator *it = try_music (spanish_inquisition);
80
81   if (it && spanish_inquisition->pitch_arr_.size ())
82     {
83       Musical_pitch p = spanish_inquisition->pitch_arr_[0];
84       Direction s = Direction (sign(p.steps ()));
85       if (s != where_dir_)
86         {
87           where_dir_ = s;
88           String to_id =  (s >= 0) ?  "up" : "down";
89           Auto_change_music const * auto_mus = dynamic_cast<Auto_change_music const* > (music_l_);
90
91           change_to (it, auto_mus->what_str_, to_id);     
92         }
93     }
94
95   spanish_inquisition->pitch_arr_.clear ();
96 }
97
98 Auto_change_iterator::Auto_change_iterator( )
99 {
100   where_dir_ = CENTER;
101 }