2 dynamic-performer.cc -- implement Dynamic_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2007 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "performer.hh"
10 #include "audio-item.hh"
11 #include "stream-event.hh"
13 #include "translator.icc"
15 class Dynamic_performer : public Performer
18 TRANSLATOR_DECLARATIONS (Dynamic_performer);
20 void stop_translation_timestep ();
21 void process_music ();
22 Real equalize_volume (Real);
24 DECLARE_TRANSLATOR_LISTENER (decrescendo);
25 DECLARE_TRANSLATOR_LISTENER (crescendo);
26 DECLARE_TRANSLATOR_LISTENER (absolute_dynamic);
28 Stream_event *script_event_;
29 Drul_array<Stream_event*> span_events_;
30 Drul_array<Direction> grow_dir_;
32 Audio_dynamic *absolute_;
33 Audio_span_dynamic *span_dynamic_;
34 Audio_span_dynamic *finished_span_dynamic_;
37 Dynamic_performer::Dynamic_performer ()
43 span_events_[RIGHT] = 0;
45 finished_span_dynamic_ = 0;
49 Dynamic_performer::equalize_volume (Real volume)
52 properties override default equaliser setting
54 SCM min = get_property ("midiMinimumVolume");
55 SCM max = get_property ("midiMaximumVolume");
56 if (scm_is_number (min) || scm_is_number (max))
59 if (scm_is_number (min))
60 iv[MIN] = scm_to_double (min);
61 if (scm_is_number (max))
62 iv[MAX] = scm_to_double (max);
63 volume = iv[MIN] + iv.length () * volume;
68 urg, code duplication:: staff_performer
70 SCM s = get_property ("midiInstrument");
72 if (!scm_is_string (s))
73 s = get_property ("instrumentName");
75 if (!scm_is_string (s))
76 s = scm_from_locale_string ("piano");
78 SCM eq = get_property ("instrumentEqualizer");
79 if (ly_is_procedure (eq))
80 s = scm_call_1 (eq, s);
82 if (is_number_pair (s))
84 Interval iv = ly_scm2interval (s);
85 volume = iv[MIN] + iv.length () * volume;
93 Dynamic_performer::process_music ()
95 if (span_events_[STOP] || script_event_)
97 finished_span_dynamic_ = span_dynamic_;
101 if (span_events_[START])
103 span_dynamic_ = new Audio_span_dynamic ();
104 announce_element (Audio_element_info (span_dynamic_, span_events_[START]));
106 span_dynamic_->grow_dir_ = grow_dir_[START];
111 || finished_span_dynamic_)
113 absolute_ = new Audio_dynamic ();
117 SCM proc = get_property ("dynamicAbsoluteVolumeFunction");
119 SCM svolume = SCM_EOL;
120 if (ly_is_procedure (proc))
123 svolume = scm_call_1 (proc, script_event_->get_property ("text"));
126 Real volume = robust_scm2double (svolume, 0.5);
129 = absolute_->volume_ = equalize_volume (volume);
132 Audio_element_info info (absolute_, script_event_);
133 announce_element (info);
138 span_dynamic_->add_absolute (absolute_);
140 if (finished_span_dynamic_)
141 finished_span_dynamic_->add_absolute (absolute_);
145 Dynamic_performer::stop_translation_timestep ()
147 if (finished_span_dynamic_)
149 finished_span_dynamic_->render ();
150 finished_span_dynamic_ = 0;
153 if (absolute_ && absolute_->volume_ < 0)
155 absolute_->volume_ = last_volume_;
159 last_volume_ = absolute_->volume_;
165 span_events_[RIGHT] = 0;
168 IMPLEMENT_TRANSLATOR_LISTENER (Dynamic_performer, decrescendo);
170 Dynamic_performer::listen_decrescendo (Stream_event *r)
172 Direction d = to_dir (r->get_property ("span-direction"));
174 grow_dir_[d] = SMALLER;
177 IMPLEMENT_TRANSLATOR_LISTENER (Dynamic_performer, crescendo);
179 Dynamic_performer::listen_crescendo (Stream_event *r)
181 Direction d = to_dir (r->get_property ("span-direction"));
183 grow_dir_[d] = BIGGER;
186 IMPLEMENT_TRANSLATOR_LISTENER (Dynamic_performer, absolute_dynamic);
188 Dynamic_performer::listen_absolute_dynamic (Stream_event *r)
194 ADD_TRANSLATOR (Dynamic_performer,
202 "dynamicAbsoluteVolumeFunction "
203 "instrumentEqualizer "