(staff_eligible): new function.
[lilypond.git] / lily / piano-pedal-performer.cc
blob84f540f323b01b37b85cec059be1ae3da28be043
1 /*
2 piano-pedal-performer.cc -- implement Piano_pedal_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include "performer.hh"
11 #include "event.hh"
12 #include "audio-item.hh"
14 /**
15 perform Piano pedals
17 class Piano_pedal_performer : public Performer
19 struct Pedal_info
21 char const *name_;
22 Music* start_req_;
23 Drul_array<Music*> req_l_drul_;
26 public:
27 TRANSLATOR_DECLARATIONS(Piano_pedal_performer);
28 ~Piano_pedal_performer ();
30 protected:
31 virtual void initialize ();
32 virtual bool try_music (Music*);
33 virtual void create_audio_elements ();
34 virtual void stop_translation_timestep ();
35 virtual void start_translation_timestep ();
37 private:
38 Link_array<Audio_piano_pedal> audios_;
39 Pedal_info * info_alist_;
42 Piano_pedal_performer::Piano_pedal_performer ()
44 info_alist_ = 0;
47 Piano_pedal_performer::~Piano_pedal_performer ()
49 delete[] info_alist_;
52 void
53 Piano_pedal_performer::initialize ()
55 info_alist_ = new Pedal_info[4];
56 Pedal_info *p = info_alist_;
58 char * names [] = { "Sostenuto", "Sustain", "UnaCorda", 0 };
59 char **np = names ;
62 p->name_ = *np;
63 p->req_l_drul_[START] = 0;
64 p->req_l_drul_[STOP] = 0;
65 p->start_req_ = 0;
67 p++;
69 while (* (np ++));
72 void
73 Piano_pedal_performer::create_audio_elements ()
75 for (Pedal_info*p = info_alist_; p && p->name_; p ++)
78 if (p->req_l_drul_[STOP])
80 if (!p->start_req_)
82 p->req_l_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", String (p->name_)));
84 else
86 Audio_piano_pedal* a = new Audio_piano_pedal;
87 a->type_string_ = String (p->name_);
88 a->dir_ = STOP;
89 audios_.push (a);
91 p->start_req_ = 0;
94 if (p->req_l_drul_[START])
96 p->start_req_ = p->req_l_drul_[START];
97 Audio_piano_pedal* a = new Audio_piano_pedal;
98 a->type_string_ = String (p->name_);
99 a->dir_ = START;
100 audios_.push (a);
102 p->req_l_drul_[START] = 0;
103 p->req_l_drul_[STOP] = 0;
107 void
108 Piano_pedal_performer::stop_translation_timestep ()
110 for (int i=0; i< audios_.size (); i++)
111 play_element (audios_[i]);
112 audios_.clear ();
115 void
116 Piano_pedal_performer::start_translation_timestep ()
118 for (Pedal_info*p = info_alist_; p && p->name_; p ++)
120 p->req_l_drul_[STOP] = 0;
121 p->req_l_drul_[START] = 0;
125 bool
126 Piano_pedal_performer::try_music (Music* r)
128 if (r->is_mus_type ("pedal-event"))
130 for (Pedal_info*p = info_alist_; p->name_; p ++)
132 String nm = p->name_ + String ("Event");
133 if (gh_equal_p (r->get_mus_property ("name") ,
134 scm_makfrom0str (nm.to_str0())))
136 Direction d = to_dir (r->get_mus_property ("span-direction"));
137 p->req_l_drul_[d] = r;
138 return true;
142 return false;
145 ENTER_DESCRIPTION (Piano_pedal_performer, "","",
146 "pedal-event",
147 "","","" );