2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2015 Jan Nieuwenhuizen <janneke@gnu.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "performer.hh"
22 #include "audio-item.hh"
23 #include "international.hh"
24 #include "stream-event.hh"
27 #include "translator.icc"
32 enum Pedal_type {SOSTENUTO, SUSTAIN, UNA_CORDA, NUM_PEDAL_TYPES};
37 class Piano_pedal_performer : public Performer
41 Stream_event *start_event_;
42 Drul_array<Stream_event *> event_drul_;
46 TRANSLATOR_DECLARATIONS (Piano_pedal_performer);
49 virtual void initialize ();
50 static const char *pedal_type_str (int t);
51 void process_music ();
52 void stop_translation_timestep ();
53 void start_translation_timestep ();
54 DECLARE_TRANSLATOR_LISTENER (sustain);
55 DECLARE_TRANSLATOR_LISTENER (una_corda);
56 DECLARE_TRANSLATOR_LISTENER (sostenuto);
58 vector<Audio_piano_pedal *> audios_;
59 Pedal_info info_alist_[NUM_PEDAL_TYPES];
62 Piano_pedal_performer::Piano_pedal_performer ()
67 Piano_pedal_performer::pedal_type_str (int t)
78 programming_error ("Unknown pedal type");
84 Piano_pedal_performer::initialize ()
86 Pedal_info *p = info_alist_;
88 for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++)
90 p->event_drul_[START] = 0;
91 p->event_drul_[STOP] = 0;
97 Piano_pedal_performer::process_music ()
99 Pedal_info *p = info_alist_;
101 for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++)
103 string pedal_type = pedal_type_str (i);
104 if (p->event_drul_[STOP])
106 if (!p->start_event_)
107 p->event_drul_[STOP]->origin ()->warning (_f ("cannot find start of piano pedal: `%s'", pedal_type));
110 Audio_piano_pedal *a = new Audio_piano_pedal;
111 a->type_string_ = pedal_type;
113 audios_.push_back (a);
114 Audio_element_info info (a, p->event_drul_[STOP]);
115 announce_element (info);
120 if (p->event_drul_[START])
122 p->start_event_ = p->event_drul_[START];
123 Audio_piano_pedal *a = new Audio_piano_pedal;
124 a->type_string_ = pedal_type;
126 audios_.push_back (a);
127 Audio_element_info info (a, p->event_drul_[START]);
128 announce_element (info);
130 p->event_drul_[START] = 0;
131 p->event_drul_[STOP] = 0;
136 Piano_pedal_performer::stop_translation_timestep ()
142 Piano_pedal_performer::start_translation_timestep ()
144 Pedal_info *p = info_alist_;
145 for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++)
147 p->event_drul_[STOP] = 0;
148 p->event_drul_[START] = 0;
152 IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_performer, sostenuto);
154 Piano_pedal_performer::listen_sostenuto (Stream_event *r)
156 Direction d = to_dir (r->get_property ("span-direction"));
157 info_alist_[SOSTENUTO].event_drul_[d] = r;
160 IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_performer, sustain);
162 Piano_pedal_performer::listen_sustain (Stream_event *r)
164 Direction d = to_dir (r->get_property ("span-direction"));
165 info_alist_[SUSTAIN].event_drul_[d] = r;
168 IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_performer, una_corda);
170 Piano_pedal_performer::listen_una_corda (Stream_event *r)
172 Direction d = to_dir (r->get_property ("span-direction"));
173 info_alist_[UNA_CORDA].event_drul_[d] = r;
176 ADD_TRANSLATOR (Piano_pedal_performer,