Update from Andrew: tweaks for cross-staff chords snippet.
[lilypond.git] / lily / piano-pedal-performer.cc
blob323ee40cd372b450724c466498e0b12a8f0ef80a
1 /*
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>
7 */
9 #include "performer.hh"
11 #include "audio-item.hh"
12 #include "international.hh"
13 #include "stream-event.hh"
14 #include "warn.hh"
16 #include "translator.icc"
18 typedef enum Pedal_type {SOSTENUTO, SUSTAIN, UNA_CORDA, NUM_PEDAL_TYPES};
20 /**
21 perform Piano pedals
23 class Piano_pedal_performer : public Performer
25 struct Pedal_info
27 Stream_event *start_event_;
28 Drul_array<Stream_event *> event_drul_;
31 public:
32 TRANSLATOR_DECLARATIONS (Piano_pedal_performer);
34 protected:
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);
43 private:
44 vector<Audio_piano_pedal*> audios_;
45 Pedal_info info_alist_[NUM_PEDAL_TYPES];
48 Piano_pedal_performer::Piano_pedal_performer ()
52 const char *
53 Piano_pedal_performer::pedal_type_str (int t)
55 switch (t)
57 case SOSTENUTO:
58 return "Sostenuto";
59 case SUSTAIN:
60 return "Sustain";
61 case UNA_CORDA:
62 return "UnaCorda";
63 default:
64 programming_error ("Unknown pedal type");
65 return 0;
69 void
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;
78 p->start_event_ = 0;
82 void
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])
92 if (!p->start_event_)
93 p->event_drul_[STOP]->origin ()->warning (_f ("cannot find start of piano pedal: `%s'", pedal_type));
94 else
96 Audio_piano_pedal *a = new Audio_piano_pedal;
97 a->type_string_ = pedal_type;
98 a->dir_ = STOP;
99 audios_.push_back (a);
100 Audio_element_info info (a, p->event_drul_[STOP]);
101 announce_element (info);
103 p->start_event_ = 0;
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;
111 a->dir_ = START;
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;
121 void
122 Piano_pedal_performer::stop_translation_timestep ()
124 audios_.clear ();
127 void
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);
139 void
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);
147 void
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);
155 void
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,
163 /* doc */
166 /* create */
169 /* read */
172 /* write */