]> git.donarmstrong.com Git - lilypond.git/blob - lily/piano-pedal-performer.cc
patch::: 1.3.42.jcn3
[lilypond.git] / lily / piano-pedal-performer.cc
1 /*
2  piano-pedal-performer.cc -- implement Piano_pedal_performer
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "performer.hh"
10 #include "command-request.hh"
11 #include "musical-request.hh"
12 #include "audio-item.hh"
13
14
15 /*
16   TODO:
17     sostenuto
18     una-chorda ?
19  */
20
21 /**
22    perform Piano pedals
23  */
24 class Piano_pedal_performer : public Performer
25 {
26 public:
27   VIRTUAL_COPY_CONS (Translator);
28   
29   Piano_pedal_performer ();
30
31 protected:
32   virtual bool do_try_music (Music*);
33   virtual void do_process_music ();
34   virtual void do_pre_move_processing ();
35   virtual void do_post_move_processing ();
36
37 private:
38   Link_array<Audio_piano_pedal> audio_p_arr_;
39   Span_req* span_start_req_l_;
40   Drul_array<Span_req*> span_req_l_drul_;
41 };
42
43 ADD_THIS_TRANSLATOR (Piano_pedal_performer);
44
45 Piano_pedal_performer::Piano_pedal_performer ()
46 {
47   span_req_l_drul_[START] = 0;
48   span_req_l_drul_[STOP] = 0;
49   span_start_req_l_ = 0;
50 }
51
52 void
53 Piano_pedal_performer::do_process_music ()
54 {
55   if (span_req_l_drul_[STOP])
56     {
57       if (!span_start_req_l_)
58         {
59           span_req_l_drul_[STOP]->warning (_ ("can't find start of piano_pedal"));
60         }
61       else
62         {
63           Audio_piano_pedal* p = new Audio_piano_pedal;
64           p->type_b_ = false;
65           audio_p_arr_.push (p);
66         }
67       span_start_req_l_ = 0;
68     }
69
70   if (span_req_l_drul_[START])
71     {
72       span_start_req_l_ = span_req_l_drul_[START];
73       Audio_piano_pedal* p = new Audio_piano_pedal;
74       p->type_b_ = true;
75       audio_p_arr_.push (p);
76     }
77 }
78
79 void
80 Piano_pedal_performer::do_pre_move_processing ()
81 {
82   for (int i=0; i < audio_p_arr_.size (); i++)
83     play_element (audio_p_arr_[i]);
84   audio_p_arr_.clear ();
85 }
86
87 void
88 Piano_pedal_performer::do_post_move_processing ()
89 {
90   span_req_l_drul_[STOP] = 0;
91   span_req_l_drul_[START] = 0;
92 }
93
94 bool
95 Piano_pedal_performer::do_try_music (Music* r)
96 {
97   if (Span_req * s = dynamic_cast<Span_req*>(r))
98     {
99       if (s-> span_type_str_ == "sustain")
100         {
101           span_req_l_drul_[s->span_dir_] = s;
102           return true;
103         }
104     }
105   return false;
106 }