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