]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-engraver.cc
release: 1.3.93
[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 || early_stop)
76     {
77       end_volta_span_p_ = volta_span_p_;
78       volta_span_p_ =0;
79
80       /*
81         maybe do typeset_element () directly?
82       */
83
84       if (!gh_string_p (str))
85         end_volta_span_p_->set_elt_property ("last-volta", SCM_BOOL_T);
86     }
87
88   if (gh_string_p (str))
89     {
90       started_mom_ = now;
91       if (volta_span_p_)
92         {
93           warning (_ ("Already have a volta spanner. Stopping that one prematurely."));
94
95           if (end_volta_span_p_)
96             {
97               warning (_("Also have a stopped spanner. Giving up."));
98
99               return ;
100
101             }
102
103                      
104           end_volta_span_p_ = volta_span_p_;
105           volta_span_p_ = 0;
106         }
107
108       volta_span_p_ = new Spanner (get_property ("basicVoltaBracketProperties"));
109       Volta_spanner::set_interface (volta_span_p_);
110       announce_element (volta_span_p_,0);
111       volta_span_p_->set_elt_property ("text", str);
112     }
113 }
114
115 void
116 Volta_engraver::acknowledge_element (Score_element_info i)
117 {
118   if (Item* item = dynamic_cast<Item*> (i.elem_l_))
119     {
120       if (Note_column::has_interface (item))
121         {
122           if (volta_span_p_)
123             Volta_spanner::add_column (volta_span_p_,item);
124           if (end_volta_span_p_)
125             Volta_spanner::add_column (end_volta_span_p_,item);      
126         }
127       if (Bar::has_interface (item))
128         {
129           if (volta_span_p_)
130             Volta_spanner::add_bar (volta_span_p_, item);
131           if (end_volta_span_p_)
132             Volta_spanner::add_bar(end_volta_span_p_ , item);
133         }
134     }
135 }
136
137 void
138 Volta_engraver::do_removal_processing ()
139 {
140   if (volta_span_p_)
141     {
142       typeset_element(volta_span_p_);
143     }
144   if (end_volta_span_p_)
145     {
146       typeset_element (end_volta_span_p_);
147     }
148 }
149
150 void 
151 Volta_engraver::do_pre_move_processing ()
152 {
153   if (end_volta_span_p_)
154     {
155       Side_position::add_staff_support (end_volta_span_p_);
156       
157       typeset_element (end_volta_span_p_ );
158       end_volta_span_p_ =0;
159     }
160 }