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