]> git.donarmstrong.com Git - lilypond.git/blob - lily/piano-pedal-performer.cc
36f91d131d412a888c938a87a28a7d43121f8ece
[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 #include "dictionary.hh"
14 #include "dictionary-iter.hh"
15
16 /**
17    perform Piano pedals
18  */
19 class Piano_pedal_performer : public Performer
20 {
21   struct Pedal_info
22   {
23     char const *name_;
24     Span_req* start_req_l_;
25     Drul_array<Span_req*> req_l_drul_;
26   };
27
28 public:
29   VIRTUAL_COPY_CONS (Translator);
30   Piano_pedal_performer ();
31   ~Piano_pedal_performer ();
32   
33 protected:
34   virtual void initialize ();
35   virtual bool try_music (Music*);
36   virtual void create_audio_elements ();
37   virtual void stop_translation_timestep ();
38   virtual void start_translation_timestep ();
39
40 private:
41   Link_array<Audio_piano_pedal> audio_p_arr_;
42   Pedal_info * info_alist_;
43 };
44
45 ADD_THIS_TRANSLATOR (Piano_pedal_performer);
46
47 Piano_pedal_performer::Piano_pedal_performer ()
48 {
49   info_alist_ = 0;
50 }
51
52 Piano_pedal_performer::~Piano_pedal_performer ()
53 {
54   delete[] info_alist_;
55 }
56
57 void
58 Piano_pedal_performer::initialize ()
59 {
60   info_alist_ = new Pedal_info[4];
61   Pedal_info *p = info_alist_;
62
63   char * names [] = { "Sostenuto", "Sustain", "UnaChorda", 0  };
64   char **np = names ;
65   do
66     {
67       p->name_ = *np;
68       p->req_l_drul_[START] = 0;
69       p->req_l_drul_[STOP] = 0;
70       p->start_req_l_ = 0;
71
72       p++;
73     }
74   while (* (np ++));
75 }
76
77 void
78 Piano_pedal_performer::create_audio_elements ()
79 {
80   for (Pedal_info*p = info_alist_; p && p->name_; p ++)
81  
82     {
83       if (p->req_l_drul_[STOP])
84         {
85           if (!p->start_req_l_)
86             {
87               p->req_l_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: %s", String (p->name_)));
88             }
89           else
90             {
91               Audio_piano_pedal* a = new Audio_piano_pedal;
92               a->type_str_ = String (p->name_);
93               a->dir_ = STOP;
94               audio_p_arr_.push (a);
95             }
96           p->start_req_l_ = 0;
97         }
98
99       if (p->req_l_drul_[START])
100         {
101           p->start_req_l_ = p->req_l_drul_[START];
102           Audio_piano_pedal* a = new Audio_piano_pedal;
103           a->type_str_ = String (p->name_);
104           a->dir_ = START;
105           audio_p_arr_.push (a);
106         }
107       p->req_l_drul_[START] = 0;
108       p->req_l_drul_[STOP] = 0;
109     }
110 }
111
112 void
113 Piano_pedal_performer::stop_translation_timestep ()
114 {
115   for (int i=0; i< audio_p_arr_.size (); i++)
116     play_element (audio_p_arr_[i]);
117   audio_p_arr_.clear ();
118 }
119
120 void
121 Piano_pedal_performer::start_translation_timestep ()
122 {
123   for (Pedal_info*p = info_alist_; p && p->name_; p ++)
124     {
125       p->req_l_drul_[STOP] = 0;
126       p->req_l_drul_[START] = 0;
127     }
128 }
129
130 bool
131 Piano_pedal_performer::try_music (Music* r)
132 {
133   if (Span_req * s = dynamic_cast<Span_req*> (r))
134     {
135       for (Pedal_info*p = info_alist_; p->name_; p ++)
136         {
137           if (scm_equal_p (s->get_mus_property ("span-type"),
138                            ly_str02scm (p->name_)) == SCM_BOOL_T)
139             {
140               p->req_l_drul_[s->get_span_dir ()] = s;
141               return true;
142             }
143         }
144     }
145   return false;
146 }