2 piano-pedal-performer.cc -- implement Piano_pedal_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
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"
19 class Piano_pedal_performer
: public Performer
24 Span_req
* start_req_l_
;
25 Drul_array
<Span_req
*> req_l_drul_
;
29 VIRTUAL_COPY_CONS (Translator
);
30 Piano_pedal_performer ();
31 ~Piano_pedal_performer ();
34 virtual void initialize ();
35 virtual bool try_music (Music
*);
36 virtual void create_audio_elements ();
37 virtual void stop_translation_timestep ();
38 virtual void start_translation_timestep ();
41 Link_array
<Audio_piano_pedal
> audio_p_arr_
;
42 Pedal_info
* info_alist_
;
45 ADD_THIS_TRANSLATOR (Piano_pedal_performer
);
47 Piano_pedal_performer::Piano_pedal_performer ()
52 Piano_pedal_performer::~Piano_pedal_performer ()
58 Piano_pedal_performer::initialize ()
60 info_alist_
= new Pedal_info
[4];
61 Pedal_info
*p
= info_alist_
;
63 char * names
[] = { "Sostenuto", "Sustain", "UnaChorda", 0 };
68 p
->req_l_drul_
[START
] = 0;
69 p
->req_l_drul_
[STOP
] = 0;
78 Piano_pedal_performer::create_audio_elements ()
80 for (Pedal_info
*p
= info_alist_
; p
&& p
->name_
; p
++)
83 if (p
->req_l_drul_
[STOP
])
87 p
->req_l_drul_
[STOP
]->origin ()->warning (_f ("can't find start of piano pedal: %s", String (p
->name_
)));
91 Audio_piano_pedal
* a
= new Audio_piano_pedal
;
92 a
->type_str_
= String (p
->name_
);
94 audio_p_arr_
.push (a
);
99 if (p
->req_l_drul_
[START
])
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_
);
105 audio_p_arr_
.push (a
);
107 p
->req_l_drul_
[START
] = 0;
108 p
->req_l_drul_
[STOP
] = 0;
113 Piano_pedal_performer::stop_translation_timestep ()
115 for (int i
=0; i
< audio_p_arr_
.size (); i
++)
116 play_element (audio_p_arr_
[i
]);
117 audio_p_arr_
.clear ();
121 Piano_pedal_performer::start_translation_timestep ()
123 for (Pedal_info
*p
= info_alist_
; p
&& p
->name_
; p
++)
125 p
->req_l_drul_
[STOP
] = 0;
126 p
->req_l_drul_
[START
] = 0;
131 Piano_pedal_performer::try_music (Music
* r
)
133 if (Span_req
* s
= dynamic_cast<Span_req
*> (r
))
135 for (Pedal_info
*p
= info_alist_
; p
->name_
; p
++)
137 if (scm_equal_p (s
->get_mus_property ("span-type"),
138 ly_str02scm (p
->name_
)) == SCM_BOOL_T
)
140 p
->req_l_drul_
[s
->get_span_dir ()] = s
;