]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-engraver.cc
release: 1.3.109
[lilypond.git] / lily / volta-engraver.cc
1 /*   
2   volta-engraver.cc --  implement Volta_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "translator-group.hh"
12 #include "volta-spanner.hh"
13 #include "item.hh"
14 #include "note-column.hh"
15 #include "bar.hh"
16 #include "side-position-interface.hh"
17
18 /*
19   Create Volta spanners, by reading repeatCommands  property, usually
20   set by Unfolded_repeat_iterator.
21  */
22 class Volta_engraver : public Engraver
23 {
24 public:
25   Volta_engraver();
26   VIRTUAL_COPY_CONS(Translator);
27 protected:
28
29   virtual void start_translation_timestep ();
30   virtual void acknowledge_grob (Grob_info);
31   virtual void do_removal_processing ();
32   virtual void stop_translation_timestep ();
33   void deprecated_process_music ();
34   virtual void create_grobs ();
35   
36   Moment started_mom_;
37   Spanner *volta_span_p_;
38   Spanner *end_volta_span_p_;
39
40   bool first_b_;
41 };
42
43 ADD_THIS_TRANSLATOR(Volta_engraver);
44
45 Volta_engraver::Volta_engraver ()
46 {
47   first_b_ = true;
48   volta_span_p_ = 0;
49   end_volta_span_p_ = 0;
50 }
51
52 void
53 Volta_engraver::create_grobs ()
54 {
55   if (first_b_)
56     {
57       deprecated_process_music ();
58       first_b_ = false;
59     }
60 }
61   
62 void
63 Volta_engraver::deprecated_process_music ()
64 {
65   if (volta_span_p_)
66     return;
67   SCM cs = get_property ("repeatCommands");
68
69   SCM str = SCM_EOL; 
70   bool end = false;
71   while (gh_pair_p (cs))
72     {
73       SCM c = gh_car (cs);
74
75       if (gh_pair_p (c) && gh_car (c) == ly_symbol2scm ("volta"))
76         {
77           if (gh_cadr (c) ==  SCM_BOOL_F)
78             end = true;
79           else
80             str = gh_cadr (c);
81         }
82       
83       cs = gh_cdr (cs);
84     }
85
86   SCM l (get_property ("voltaSpannerDuration"));
87   Moment now = now_mom ();
88   
89   bool early_stop = volta_span_p_ &&    unsmob_moment (l)
90     &&*unsmob_moment (l) <= now - started_mom_;
91
92   if (end && !volta_span_p_)
93     {
94       warning (_("No volta spanner to end")); // fixme: be more verbose.
95     }
96   else if (end || early_stop)
97     {
98       end_volta_span_p_ = volta_span_p_;
99       volta_span_p_ =0;
100
101       /*
102         maybe do typeset_grob () directly?
103       */
104
105       if (!gh_string_p (str))
106         end_volta_span_p_->set_grob_property ("last-volta", SCM_BOOL_T);
107     }
108
109   if (gh_string_p (str))
110     {
111       started_mom_ = now;
112       if (volta_span_p_)
113         {
114           warning (_ ("Already have a volta spanner. Stopping that one prematurely."));
115
116           if (end_volta_span_p_)
117             {
118               warning (_("Also have a stopped spanner. Giving up."));
119
120               return ;
121
122             }
123
124           end_volta_span_p_ = volta_span_p_;
125           volta_span_p_ = 0;
126         }
127
128       volta_span_p_ = new Spanner (get_property ("VoltaBracket"));
129       Volta_spanner::set_interface (volta_span_p_);
130       announce_grob (volta_span_p_,0);
131       volta_span_p_->set_grob_property ("text", str);
132     }
133 }
134
135 void
136 Volta_engraver::acknowledge_grob (Grob_info i)
137 {
138   if (Item* item = dynamic_cast<Item*> (i.elem_l_))
139     {
140       if (Note_column::has_interface (item))
141         {
142           if (volta_span_p_)
143             Volta_spanner::add_column (volta_span_p_,item);
144           if (end_volta_span_p_)
145             Volta_spanner::add_column (end_volta_span_p_,item);      
146         }
147       if (Bar::has_interface (item))
148         {
149           if (volta_span_p_)
150             Volta_spanner::add_bar (volta_span_p_, item);
151           if (end_volta_span_p_)
152             Volta_spanner::add_bar(end_volta_span_p_ , item);
153         }
154     }
155 }
156
157 void
158 Volta_engraver::do_removal_processing ()
159 {
160   if (volta_span_p_)
161     {
162       typeset_grob(volta_span_p_);
163     }
164   if (end_volta_span_p_)
165     {
166       typeset_grob (end_volta_span_p_);
167     }
168 }
169
170 void
171 Volta_engraver::start_translation_timestep ()
172 {
173   first_b_ = true;
174 }
175
176 void 
177 Volta_engraver::stop_translation_timestep ()
178 {
179   if (end_volta_span_p_)
180     {
181       Side_position::add_staff_support (end_volta_span_p_);
182       
183       typeset_grob (end_volta_span_p_ );
184       end_volta_span_p_ =0;
185     }
186 }
187
188 /*
189   TODO: should attach volta to paper-column if no bar is found.
190  */