]> git.donarmstrong.com Git - lilypond.git/blob - lily/piano-pedal-performer.cc
LSR: update.
[lilypond.git] / lily / piano-pedal-performer.cc
1 /*
2   piano-pedal-performer.cc -- implement Piano_pedal_performer
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2007 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "performer.hh"
10
11 #include "audio-item.hh"
12 #include "international.hh"
13 #include "stream-event.hh"
14 #include "warn.hh"
15
16 #include "translator.icc"
17
18 typedef enum Pedal_type {SOSTENUTO, SUSTAIN, UNA_CORDA, NUM_PEDAL_TYPES};
19
20 /**
21    perform Piano pedals
22 */
23 class Piano_pedal_performer : public Performer
24 {
25   struct Pedal_info
26   {
27     Stream_event *start_event_;
28     Drul_array<Stream_event *> event_drul_;
29   };
30
31 public:
32   TRANSLATOR_DECLARATIONS (Piano_pedal_performer);
33
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];
46 };
47
48 Piano_pedal_performer::Piano_pedal_performer ()
49 {
50 }
51
52 const char *
53 Piano_pedal_performer::pedal_type_str (int t)
54 {
55   switch (t)
56     {
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;
66     }
67 }
68
69 void
70 Piano_pedal_performer::initialize ()
71 {
72   Pedal_info *p = info_alist_;
73
74   for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++)
75     {
76       p->event_drul_[START] = 0;
77       p->event_drul_[STOP] = 0;
78       p->start_event_ = 0;
79     }
80 }
81
82 void
83 Piano_pedal_performer::process_music ()
84 {
85   Pedal_info *p = info_alist_;
86
87   for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++)
88     {
89       string pedal_type = pedal_type_str (i);
90       if (p->event_drul_[STOP])
91         {
92           if (!p->start_event_)
93             p->event_drul_[STOP]->origin ()->warning (_f ("cannot find start of piano pedal: `%s'", pedal_type));
94           else
95             {
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);
102             }
103           p->start_event_ = 0;
104         }
105
106       if (p->event_drul_[START])
107         {
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);
115         }
116       p->event_drul_[START] = 0;
117       p->event_drul_[STOP] = 0;
118     }
119 }
120
121 void
122 Piano_pedal_performer::stop_translation_timestep ()
123 {
124   audios_.clear ();
125 }
126
127 void
128 Piano_pedal_performer::start_translation_timestep ()
129 {
130   Pedal_info *p = info_alist_;
131   for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++)
132     {
133       p->event_drul_[STOP] = 0;
134       p->event_drul_[START] = 0;
135     }
136 }
137
138 IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_performer, sostenuto);
139 void
140 Piano_pedal_performer::listen_sostenuto (Stream_event *r)
141 {
142   Direction d = to_dir (r->get_property ("span-direction"));
143   info_alist_[SOSTENUTO].event_drul_[d] = r;
144 }
145
146 IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_performer, sustain);
147 void
148 Piano_pedal_performer::listen_sustain (Stream_event *r)
149 {
150   Direction d = to_dir (r->get_property ("span-direction"));
151   info_alist_[SUSTAIN].event_drul_[d] = r;
152 }
153
154 IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_performer, una_corda);
155 void
156 Piano_pedal_performer::listen_una_corda (Stream_event *r)
157 {
158   Direction d = to_dir (r->get_property ("span-direction"));
159   info_alist_[UNA_CORDA].event_drul_[d] = r;
160 }
161
162 ADD_TRANSLATOR (Piano_pedal_performer,
163                 /* doc */
164                 "",
165
166                 /* create */
167                 "",
168
169                 /* read */
170                 "",
171
172                 /* write */
173                 ""
174                 );