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"
29 enum Pedal_type {SOSTENUTO, SUSTAIN, UNA_CORDA, NUM_PEDAL_TYPES};
34 class Piano_pedal_performer : public Performer
38 Stream_event *start_event_;
39 Drul_array<Stream_event *> event_drul_;
43 TRANSLATOR_DECLARATIONS (Piano_pedal_performer);
46 virtual void initialize ();
47 static const char *pedal_type_str (int t);
48 void process_music ();
49 void stop_translation_timestep ();
50 void start_translation_timestep ();
51 DECLARE_TRANSLATOR_LISTENER (sustain);
52 DECLARE_TRANSLATOR_LISTENER (una_corda);
53 DECLARE_TRANSLATOR_LISTENER (sostenuto);
55 vector<Audio_piano_pedal *> audios_;
56 Pedal_info info_alist_[NUM_PEDAL_TYPES];
59 Piano_pedal_performer::Piano_pedal_performer ()
64 Piano_pedal_performer::pedal_type_str (int t)
75 programming_error ("Unknown pedal type");
81 Piano_pedal_performer::initialize ()
83 Pedal_info *p = info_alist_;
85 for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++)
87 p->event_drul_[START] = 0;
88 p->event_drul_[STOP] = 0;
94 Piano_pedal_performer::process_music ()
96 Pedal_info *p = info_alist_;
98 for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++)
100 string pedal_type = pedal_type_str (i);
101 if (p->event_drul_[STOP])
103 if (!p->start_event_)
104 p->event_drul_[STOP]->origin ()->warning (_f ("cannot find start of piano pedal: `%s'", pedal_type));
107 Audio_piano_pedal *a = new Audio_piano_pedal;
108 a->type_string_ = pedal_type;
110 audios_.push_back (a);
111 Audio_element_info info (a, p->event_drul_[STOP]);
112 announce_element (info);
117 if (p->event_drul_[START])
119 p->start_event_ = p->event_drul_[START];
120 Audio_piano_pedal *a = new Audio_piano_pedal;
121 a->type_string_ = pedal_type;
123 audios_.push_back (a);
124 Audio_element_info info (a, p->event_drul_[START]);
125 announce_element (info);
127 p->event_drul_[START] = 0;
128 p->event_drul_[STOP] = 0;
133 Piano_pedal_performer::stop_translation_timestep ()
139 Piano_pedal_performer::start_translation_timestep ()
141 Pedal_info *p = info_alist_;
142 for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++)
144 p->event_drul_[STOP] = 0;
145 p->event_drul_[START] = 0;
149 IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_performer, sostenuto);
151 Piano_pedal_performer::listen_sostenuto (Stream_event *r)
153 Direction d = to_dir (r->get_property ("span-direction"));
154 info_alist_[SOSTENUTO].event_drul_[d] = r;
157 IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_performer, sustain);
159 Piano_pedal_performer::listen_sustain (Stream_event *r)
161 Direction d = to_dir (r->get_property ("span-direction"));
162 info_alist_[SUSTAIN].event_drul_[d] = r;
165 IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_performer, una_corda);
167 Piano_pedal_performer::listen_una_corda (Stream_event *r)
169 Direction d = to_dir (r->get_property ("span-direction"));
170 info_alist_[UNA_CORDA].event_drul_[d] = r;
173 ADD_TRANSLATOR (Piano_pedal_performer,