2 piano-pedal-performer.cc -- implement Piano_pedal_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2006 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "performer.hh"
11 #include "audio-item.hh"
12 #include "international.hh"
13 #include "stream-event.hh"
16 #include "translator.icc"
21 #define NUM_PEDAL_TYPES 3
26 class Piano_pedal_performer : public Performer
30 Stream_event *start_event_;
31 Drul_array<Stream_event *> event_drul_;
35 TRANSLATOR_DECLARATIONS (Piano_pedal_performer);
38 virtual void initialize ();
39 static const char *pedal_type_str (int t);
40 void process_music ();
41 void stop_translation_timestep ();
42 void start_translation_timestep ();
43 DECLARE_TRANSLATOR_LISTENER (sustain);
44 DECLARE_TRANSLATOR_LISTENER (una_corda);
45 DECLARE_TRANSLATOR_LISTENER (sostenuto);
47 vector<Audio_piano_pedal*> audios_;
48 Pedal_info info_alist_[NUM_PEDAL_TYPES];
51 Piano_pedal_performer::Piano_pedal_performer ()
56 Piano_pedal_performer::pedal_type_str (int t)
67 programming_error ("Unknown pedal type");
73 Piano_pedal_performer::initialize ()
75 Pedal_info *p = info_alist_;
77 for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++)
79 p->event_drul_[START] = 0;
80 p->event_drul_[STOP] = 0;
86 Piano_pedal_performer::process_music ()
88 Pedal_info *p = info_alist_;
90 for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++)
92 if (p->event_drul_[STOP])
95 p->event_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", pedal_type_str (i)));
98 Audio_piano_pedal *a = new Audio_piano_pedal;
99 a->type_string_ = string (pedal_type_str (i));
101 audios_.push_back (a);
102 Audio_element_info info(a, p->event_drul_[STOP]);
103 announce_element (info);
108 if (p->event_drul_[START])
110 p->start_event_ = p->event_drul_[START];
111 Audio_piano_pedal *a = new Audio_piano_pedal;
112 a->type_string_ = string (pedal_type_str (i));
114 audios_.push_back (a);
115 Audio_element_info info(a, p->event_drul_[START]);
116 announce_element (info);
118 p->event_drul_[START] = 0;
119 p->event_drul_[STOP] = 0;
124 Piano_pedal_performer::stop_translation_timestep ()
126 for (vsize i = 0; i < audios_.size (); i++)
127 play_element (audios_[i]);
132 Piano_pedal_performer::start_translation_timestep ()
134 Pedal_info *p = info_alist_;
135 for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++)
137 p->event_drul_[STOP] = 0;
138 p->event_drul_[START] = 0;
142 IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_performer, sostenuto);
144 Piano_pedal_performer::listen_sostenuto (Stream_event *r)
146 Direction d = to_dir (r->get_property ("span-direction"));
147 info_alist_[SOSTENUTO].event_drul_[d] = r;
150 IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_performer, sustain);
152 Piano_pedal_performer::listen_sustain (Stream_event *r)
154 Direction d = to_dir (r->get_property ("span-direction"));
155 info_alist_[SUSTAIN].event_drul_[d] = r;
158 IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_performer, una_corda);
160 Piano_pedal_performer::listen_una_corda (Stream_event *r)
162 Direction d = to_dir (r->get_property ("span-direction"));
163 info_alist_[UNA_CORDA].event_drul_[d] = r;
166 ADD_TRANSLATOR (Piano_pedal_performer, "", "",