]> git.donarmstrong.com Git - lilypond.git/blob - lily/piano-pedal-performer.cc
patch::: 1.3.44.jcn2
[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     Span_req* start_req_l_;
24     Drul_array<Span_req*> req_l_drul_;
25   };
26
27 public:
28   VIRTUAL_COPY_CONS (Translator);
29   
30   Piano_pedal_performer ();
31
32 protected:
33   virtual bool do_try_music (Music*);
34   virtual void do_process_music ();
35   virtual void do_pre_move_processing ();
36   virtual void do_post_move_processing ();
37
38 private:
39   Link_array<Audio_piano_pedal> audio_p_arr_;
40   Dictionary<Pedal_info> info_dict_;
41 };
42
43 ADD_THIS_TRANSLATOR (Piano_pedal_performer);
44
45 Piano_pedal_performer::Piano_pedal_performer ()
46 {
47   (void)info_dict_["Sostenuto"];
48   (void)info_dict_["Sustain"];
49   (void)info_dict_["UnaChorda"];
50   for (Dictionary_iter <Pedal_info> i (info_dict_); i.ok (); i++)
51     {
52       Pedal_info& p = i.val_ref ();
53       p.req_l_drul_[START] = 0;
54       p.req_l_drul_[STOP] = 0;
55       p.start_req_l_ = 0;
56     }
57 }
58
59 void
60 Piano_pedal_performer::do_process_music ()
61 {
62   for (Dictionary_iter <Pedal_info> i (info_dict_); i.ok (); i++)
63     {
64       Pedal_info& p = i.val_ref ();
65       if (p.req_l_drul_[STOP])
66         {
67           if (!p.start_req_l_)
68             {
69               p.req_l_drul_[STOP]->warning (_f ("can't find start of piano pedal: %s", i.key ()));
70             }
71           else
72             {
73               Audio_piano_pedal* a = new Audio_piano_pedal;
74               a->type_str_ = i.key ();
75               a->dir_ = STOP;
76               audio_p_arr_.push (a);
77             }
78           p.start_req_l_ = 0;
79         }
80
81       if (p.req_l_drul_[START])
82         {
83           p.start_req_l_ = p.req_l_drul_[START];
84           Audio_piano_pedal* a = new Audio_piano_pedal;
85           a->type_str_ = i.key ();
86           a->dir_ = START;
87           audio_p_arr_.push (a);
88         }
89     }
90 }
91
92 void
93 Piano_pedal_performer::do_pre_move_processing ()
94 {
95   for (int i=0; i < audio_p_arr_.size (); i++)
96     play_element (audio_p_arr_[i]);
97   audio_p_arr_.clear ();
98 }
99
100 void
101 Piano_pedal_performer::do_post_move_processing ()
102 {
103   for (Dictionary_iter <Pedal_info> i (info_dict_); i.ok (); i++)
104     {
105       Pedal_info& p = i.val_ref ();
106       p.req_l_drul_[STOP] = 0;
107       p.req_l_drul_[START] = 0;
108     }
109 }
110
111 bool
112 Piano_pedal_performer::do_try_music (Music* r)
113 {
114   for (Dictionary_iter <Pedal_info> i (info_dict_); i.ok (); i++)
115     {
116       Pedal_info& p = i.val_ref ();
117       if (Span_req * s = dynamic_cast<Span_req*>(r))
118         {
119           if (s->span_type_str_ == i.key ())
120             {
121               p.req_l_drul_[s->span_dir_] = s;
122               return true;
123             }
124         }
125     }
126   return false;
127 }