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