2 piano-pedal-performer.cc -- implement Piano_pedal_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2007 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"
18 typedef enum Pedal_type {SOSTENUTO, SUSTAIN, UNA_CORDA, NUM_PEDAL_TYPES};
23 class Piano_pedal_performer : public Performer
27 Stream_event *start_event_;
28 Drul_array<Stream_event *> event_drul_;
32 TRANSLATOR_DECLARATIONS (Piano_pedal_performer);
35 virtual void initialize ();
36 static const char *pedal_type_str (int t);
37 void process_music ();
38 void stop_translation_timestep ();
39 void start_translation_timestep ();
40 DECLARE_TRANSLATOR_LISTENER (sustain);
41 DECLARE_TRANSLATOR_LISTENER (una_corda);
42 DECLARE_TRANSLATOR_LISTENER (sostenuto);
44 vector<Audio_piano_pedal*> audios_;
45 Pedal_info info_alist_[NUM_PEDAL_TYPES];
48 Piano_pedal_performer::Piano_pedal_performer ()
53 Piano_pedal_performer::pedal_type_str (int t)
64 programming_error ("Unknown pedal type");
70 Piano_pedal_performer::initialize ()
72 Pedal_info *p = info_alist_;
74 for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++)
76 p->event_drul_[START] = 0;
77 p->event_drul_[STOP] = 0;
83 Piano_pedal_performer::process_music ()
85 Pedal_info *p = info_alist_;
87 for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++)
89 string pedal_type = pedal_type_str (i);
90 if (p->event_drul_[STOP])
93 p->event_drul_[STOP]->origin ()->warning (_f ("cannot find start of piano pedal: `%s'", pedal_type));
96 Audio_piano_pedal *a = new Audio_piano_pedal;
97 a->type_string_ = pedal_type;
99 audios_.push_back (a);
100 Audio_element_info info (a, p->event_drul_[STOP]);
101 announce_element (info);
106 if (p->event_drul_[START])
108 p->start_event_ = p->event_drul_[START];
109 Audio_piano_pedal *a = new Audio_piano_pedal;
110 a->type_string_ = pedal_type;
112 audios_.push_back (a);
113 Audio_element_info info (a, p->event_drul_[START]);
114 announce_element (info);
116 p->event_drul_[START] = 0;
117 p->event_drul_[STOP] = 0;
122 Piano_pedal_performer::stop_translation_timestep ()
128 Piano_pedal_performer::start_translation_timestep ()
130 Pedal_info *p = info_alist_;
131 for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++)
133 p->event_drul_[STOP] = 0;
134 p->event_drul_[START] = 0;
138 IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_performer, sostenuto);
140 Piano_pedal_performer::listen_sostenuto (Stream_event *r)
142 Direction d = to_dir (r->get_property ("span-direction"));
143 info_alist_[SOSTENUTO].event_drul_[d] = r;
146 IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_performer, sustain);
148 Piano_pedal_performer::listen_sustain (Stream_event *r)
150 Direction d = to_dir (r->get_property ("span-direction"));
151 info_alist_[SUSTAIN].event_drul_[d] = r;
154 IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_performer, una_corda);
156 Piano_pedal_performer::listen_una_corda (Stream_event *r)
158 Direction d = to_dir (r->get_property ("span-direction"));
159 info_alist_[UNA_CORDA].event_drul_[d] = r;
162 ADD_TRANSLATOR (Piano_pedal_performer,