]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-engraver.cc
d80304ad9b1ea1ee3a941c4e3f4257e18e2fee22
[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 acknowledge_element (Score_element_info);
30   virtual void do_removal_processing ();
31   virtual void do_pre_move_processing ();
32   virtual void do_process_music ();
33
34   Moment started_mom_;
35   Spanner * volta_span_p_;
36   Spanner* end_volta_span_p_;
37 };
38
39 ADD_THIS_TRANSLATOR(Volta_engraver);
40
41 Volta_engraver::Volta_engraver ()
42 {
43   volta_span_p_ = 0;
44   end_volta_span_p_ = 0;
45 }
46
47 void
48 Volta_engraver::do_process_music ()
49 {
50   SCM cs = get_property ("repeatCommands");
51
52   SCM str = SCM_EOL; 
53   bool end = false;
54   while (gh_pair_p (cs))
55     {
56       SCM c = gh_car (cs);
57
58       if (gh_pair_p (c) && gh_car (c) == ly_symbol2scm ("volta"))
59         {
60           if (gh_cadr (c) ==  SCM_BOOL_F)
61             end = true;
62           else
63             str = gh_cadr (c);
64         }
65       
66       cs = gh_cdr (cs);
67     }
68
69   SCM l (get_property ("voltaSpannerDuration"));
70   Moment now = now_mom ();
71   
72   bool early_stop = volta_span_p_ &&    unsmob_moment (l)
73     &&*unsmob_moment (l) <= now - started_mom_;
74
75   if (end && !volta_span_p_)
76     {
77       warning (_("No volta spanner to end")); // fixme: be more verbose.
78     }
79   else if (end || early_stop)
80     {
81       end_volta_span_p_ = volta_span_p_;
82       volta_span_p_ =0;
83
84       /*
85         maybe do typeset_element () directly?
86       */
87
88       if (!gh_string_p (str))
89         end_volta_span_p_->set_elt_property ("last-volta", SCM_BOOL_T);
90     }
91
92   if (gh_string_p (str))
93     {
94       started_mom_ = now;
95       if (volta_span_p_)
96         {
97           warning (_ ("Already have a volta spanner. Stopping that one prematurely."));
98
99           if (end_volta_span_p_)
100             {
101               warning (_("Also have a stopped spanner. Giving up."));
102
103               return ;
104
105             }
106
107                      
108           end_volta_span_p_ = volta_span_p_;
109           volta_span_p_ = 0;
110         }
111
112       volta_span_p_ = new Spanner (get_property ("VoltaBracket"));
113       Volta_spanner::set_interface (volta_span_p_);
114       announce_element (volta_span_p_,0);
115       volta_span_p_->set_elt_property ("text", str);
116     }
117 }
118
119 void
120 Volta_engraver::acknowledge_element (Score_element_info i)
121 {
122   if (Item* item = dynamic_cast<Item*> (i.elem_l_))
123     {
124       if (Note_column::has_interface (item))
125         {
126           if (volta_span_p_)
127             Volta_spanner::add_column (volta_span_p_,item);
128           if (end_volta_span_p_)
129             Volta_spanner::add_column (end_volta_span_p_,item);      
130         }
131       if (Bar::has_interface (item))
132         {
133           if (volta_span_p_)
134             Volta_spanner::add_bar (volta_span_p_, item);
135           if (end_volta_span_p_)
136             Volta_spanner::add_bar(end_volta_span_p_ , item);
137         }
138     }
139 }
140
141 void
142 Volta_engraver::do_removal_processing ()
143 {
144   if (volta_span_p_)
145     {
146       typeset_element(volta_span_p_);
147     }
148   if (end_volta_span_p_)
149     {
150       typeset_element (end_volta_span_p_);
151     }
152 }
153
154 void 
155 Volta_engraver::do_pre_move_processing ()
156 {
157   if (end_volta_span_p_)
158     {
159       Side_position::add_staff_support (end_volta_span_p_);
160       
161       typeset_element (end_volta_span_p_ );
162       end_volta_span_p_ =0;
163     }
164 }