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