]> git.donarmstrong.com Git - lilypond.git/blob - lily/piano-pedal-performer.cc
patch::: 1.3.108.jcn3
[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 #include "dictionary.hh"
14 #include "dictionary-iter.hh"
15
16 /**
17    perform Piano pedals
18  */
19 class Piano_pedal_performer : public Performer
20 {
21   struct Pedal_info
22   {
23     char const *name_;
24     Span_req* start_req_l_;
25     Drul_array<Span_req*> req_l_drul_;
26   };
27
28 public:
29   VIRTUAL_COPY_CONS (Translator);
30   Piano_pedal_performer ();
31   ~Piano_pedal_performer ();
32   
33 protected:
34   virtual void do_creation_processing ();
35   virtual bool do_try_music (Music*);
36   void deprecated_process_music ();
37   virtual void do_pre_move_processing ();
38   virtual void do_post_move_processing ();
39
40 private:
41   Link_array<Audio_piano_pedal> audio_p_arr_;
42   Pedal_info * info_alist_;
43 };
44
45 ADD_THIS_TRANSLATOR (Piano_pedal_performer);
46
47 Piano_pedal_performer::Piano_pedal_performer ()
48 {
49   info_alist_ = 0;
50 }
51
52 Piano_pedal_performer::~Piano_pedal_performer()
53 {
54   delete[] info_alist_;
55 }
56
57 void
58 Piano_pedal_performer::do_creation_processing ()
59 {
60   info_alist_ = new Pedal_info[4];
61   Pedal_info *p = info_alist_;
62
63   char * names [] = { "Sostenuto", "Sustain", "UnaChorda", 0  };
64   char **np = names ;
65   do
66     {
67       p->name_ = *np;
68       p->req_l_drul_[START] = 0;
69       p->req_l_drul_[STOP] = 0;
70       p->start_req_l_ = 0;
71
72       p++;
73     }
74   while (*(np ++));
75 }
76
77 void
78 Piano_pedal_performer::deprecated_process_music ()
79 {
80   for (Pedal_info*p = info_alist_; p && p->name_; p ++)
81  
82     {
83       if (p->req_l_drul_[STOP])
84         {
85           if (!p->start_req_l_)
86             {
87               p->req_l_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: %s", String (p->name_)));
88             }
89           else
90             {
91               Audio_piano_pedal* a = new Audio_piano_pedal;
92               a->type_str_ = String (p->name_);
93               a->dir_ = STOP;
94               audio_p_arr_.push (a);
95             }
96           p->start_req_l_ = 0;
97         }
98
99       if (p->req_l_drul_[START])
100         {
101           p->start_req_l_ = p->req_l_drul_[START];
102           Audio_piano_pedal* a = new Audio_piano_pedal;
103           a->type_str_ = String (p->name_);
104           a->dir_ = START;
105           audio_p_arr_.push (a);
106         }
107     }
108 }
109
110 void
111 Piano_pedal_performer::do_pre_move_processing ()
112 {
113   for (int i=0; i< audio_p_arr_.size (); i++)
114     play_element (audio_p_arr_[i]);
115   audio_p_arr_.clear ();
116 }
117
118 void
119 Piano_pedal_performer::do_post_move_processing ()
120 {
121   for (Pedal_info*p = info_alist_; p && p->name_; p ++)
122     {
123       p->req_l_drul_[STOP] = 0;
124       p->req_l_drul_[START] = 0;
125     }
126 }
127
128 bool
129 Piano_pedal_performer::do_try_music (Music* r)
130 {
131   if (Span_req * s = dynamic_cast<Span_req*>(r))
132     {
133       for (Pedal_info*p = info_alist_; p->name_; p ++)
134         {
135           if (scm_equal_p (s->get_mus_property ("span-type"),
136                            ly_str02scm (p->name_)) == SCM_BOOL_T)
137             {
138               p->req_l_drul_[s->get_span_dir()] = s;
139               return true;
140             }
141         }
142     }
143   return false;
144 }