]> git.donarmstrong.com Git - lilypond.git/blob - lily/piano-pedal-performer.cc
release: 1.5.13
[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 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "performer.hh"
10 #include "command-request.hh"
11 #include "musical-request.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     Span_req* start_req_l_;
23     Drul_array<Span_req*> 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> audio_p_arr_;
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", "UnaChorda", 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_l_ = 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_l_)
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_str_ = String (p->name_);
88               a->dir_ = STOP;
89               audio_p_arr_.push (a);
90             }
91           p->start_req_l_ = 0;
92         }
93
94       if (p->req_l_drul_[START])
95         {
96           p->start_req_l_ = p->req_l_drul_[START];
97           Audio_piano_pedal* a = new Audio_piano_pedal;
98           a->type_str_ = String (p->name_);
99           a->dir_ = START;
100           audio_p_arr_.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< audio_p_arr_.size (); i++)
111     play_element (audio_p_arr_[i]);
112   audio_p_arr_.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 (Span_req * s = dynamic_cast<Span_req*> (r))
129     {
130       for (Pedal_info*p = info_alist_; p->name_; p ++)
131         {
132           if (scm_equal_p (s->get_mus_property ("span-type"),
133                            ly_str02scm (p->name_)) == SCM_BOOL_T)
134             {
135               p->req_l_drul_[s->get_span_dir ()] = s;
136               return true;
137             }
138         }
139     }
140   return false;
141 }
142 ENTER_DESCRIPTION (Piano_pedal_performer, "","","","","" );