]> git.donarmstrong.com Git - lilypond.git/blob - lily/piano-pedal-performer.cc
Fix some bugs in the dynamic engraver and PostScript backend
[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--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "performer.hh"
10
11 #include "audio-item.hh"
12 #include "international.hh"
13 #include "music.hh"
14
15 /**
16    perform Piano pedals
17 */
18 class Piano_pedal_performer : public Performer
19 {
20   struct Pedal_info
21   {
22     char const *name_;
23     Music *start_event_;
24     Drul_array<Music *> event_drul_;
25   };
26
27 public:
28   TRANSLATOR_DECLARATIONS (Piano_pedal_performer);
29   ~Piano_pedal_performer ();
30
31 protected:
32   virtual void initialize ();
33   virtual bool try_music (Music *);
34   void process_music ();
35   void stop_translation_timestep ();
36   void start_translation_timestep ();
37
38 private:
39   vector<Audio_piano_pedal*> audios_;
40   Pedal_info *info_alist_;
41 };
42
43 Piano_pedal_performer::Piano_pedal_performer ()
44 {
45   info_alist_ = 0;
46 }
47
48 Piano_pedal_performer::~Piano_pedal_performer ()
49 {
50   delete[] info_alist_;
51 }
52
53 void
54 Piano_pedal_performer::initialize ()
55 {
56   info_alist_ = new Pedal_info[4];
57   Pedal_info *p = info_alist_;
58
59   char *names [] = { "Sostenuto", "Sustain", "UnaCorda", 0 };
60   char **np = names;
61   do
62     {
63       p->name_ = *np;
64       p->event_drul_[START] = 0;
65       p->event_drul_[STOP] = 0;
66       p->start_event_ = 0;
67
68       p++;
69     }
70   while (* (np++));
71 }
72
73 void
74 Piano_pedal_performer::process_music ()
75 {
76   for (Pedal_info *p = info_alist_; p && p->name_; p++)
77
78     {
79       if (p->event_drul_[STOP])
80         {
81           if (!p->start_event_)
82             p->event_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", string (p->name_)));
83           else
84             {
85               Audio_piano_pedal *a = new Audio_piano_pedal;
86               a->type_string_ = string (p->name_);
87               a->dir_ = STOP;
88               audios_.push_back (a);
89               Audio_element_info info(a, p->event_drul_[STOP]);
90               announce_element (info);
91             }
92           p->start_event_ = 0;
93         }
94
95       if (p->event_drul_[START])
96         {
97           p->start_event_ = p->event_drul_[START];
98           Audio_piano_pedal *a = new Audio_piano_pedal;
99           a->type_string_ = string (p->name_);
100           a->dir_ = START;
101           audios_.push_back (a);
102           Audio_element_info info(a, p->event_drul_[START]);
103           announce_element (info);
104         }
105       p->event_drul_[START] = 0;
106       p->event_drul_[STOP] = 0;
107     }
108 }
109
110 void
111 Piano_pedal_performer::stop_translation_timestep ()
112 {
113   for (vsize i = 0; i < audios_.size (); i++)
114     play_element (audios_[i]);
115   audios_.clear ();
116 }
117
118 void
119 Piano_pedal_performer::start_translation_timestep ()
120 {
121   for (Pedal_info *p = info_alist_; p && p->name_; p++)
122     {
123       p->event_drul_[STOP] = 0;
124       p->event_drul_[START] = 0;
125     }
126 }
127
128 bool
129 Piano_pedal_performer::try_music (Music *r)
130 {
131   if (r->is_mus_type ("pedal-event"))
132     {
133       for (Pedal_info *p = info_alist_; p->name_; p++)
134         {
135           string nm = p->name_ + string ("Event");
136           if (ly_is_equal (r->get_property ("name"),
137                            scm_str2symbol (nm.c_str ())))
138             {
139               Direction d = to_dir (r->get_property ("span-direction"));
140               p->event_drul_[d] = r;
141               return true;
142             }
143         }
144     }
145   return false;
146 }
147
148 #include "translator.icc"
149
150 ADD_TRANSLATOR (Piano_pedal_performer, "", "",
151                 "pedal-event",
152                 "", "");