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