2 dynamic-performer.cc -- implement New_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"
18 handle multiple events
20 perform absolute (text) dynamics
22 class New_dynamic_performer : public Performer
25 TRANSLATOR_DECLARATIONS (New_dynamic_performer);
27 void stop_translation_timestep ();
28 void process_music ();
29 Real equalize_volume (Real);
31 DECLARE_TRANSLATOR_LISTENER (decrescendo);
32 DECLARE_TRANSLATOR_LISTENER (crescendo);
33 DECLARE_TRANSLATOR_LISTENER (absolute_dynamic);
35 Stream_event *script_event_;
36 Drul_array<Stream_event*> span_events_;
37 Drul_array<Direction> grow_dir_;
39 Audio_dynamic *absolute_;
40 Audio_span_dynamic *span_dynamic_;
41 Audio_span_dynamic *finished_span_dynamic_;
44 New_dynamic_performer::New_dynamic_performer ()
50 span_events_[RIGHT] = 0;
52 finished_span_dynamic_ = 0;
56 New_dynamic_performer::equalize_volume (Real volume)
59 properties override default equaliser setting
61 SCM min = get_property ("midiMinimumVolume");
62 SCM max = get_property ("midiMaximumVolume");
63 if (scm_is_number (min) || scm_is_number (max))
66 if (scm_is_number (min))
67 iv[MIN] = scm_to_double (min);
68 if (scm_is_number (max))
69 iv[MAX] = scm_to_double (max);
70 volume = iv[MIN] + iv.length () * volume;
75 urg, code duplication:: staff_performer
77 SCM s = get_property ("midiInstrument");
79 if (!scm_is_string (s))
80 s = get_property ("instrumentName");
82 if (!scm_is_string (s))
83 s = scm_from_locale_string ("piano");
85 SCM eq = get_property ("instrumentEqualizer");
86 if (ly_is_procedure (eq))
87 s = scm_call_1 (eq, s);
89 if (is_number_pair (s))
91 Interval iv = ly_scm2interval (s);
92 volume = iv[MIN] + iv.length () * volume;
100 New_dynamic_performer::process_music ()
102 if (span_events_[STOP] || script_event_)
104 finished_span_dynamic_ = span_dynamic_;
108 if (span_events_[START])
110 span_dynamic_ = new Audio_span_dynamic();
111 announce_element (Audio_element_info (span_dynamic_, span_events_[START]));
113 span_dynamic_->grow_dir_ = grow_dir_[START];
118 || finished_span_dynamic_)
120 absolute_ = new Audio_dynamic ();
124 SCM proc = get_property ("dynamicAbsoluteVolumeFunction");
126 SCM svolume = SCM_EOL;
127 if (ly_is_procedure (proc))
130 svolume = scm_call_1 (proc, script_event_->get_property ("text"));
133 Real volume = robust_scm2double (svolume, 0.5);
136 = absolute_->volume_ = equalize_volume (volume);
139 Audio_element_info info (absolute_, script_event_);
140 announce_element (info);
145 span_dynamic_->add_absolute (absolute_);
147 if (finished_span_dynamic_)
148 finished_span_dynamic_->add_absolute (absolute_);
152 New_dynamic_performer::stop_translation_timestep ()
154 if (finished_span_dynamic_)
156 finished_span_dynamic_->render ();
157 finished_span_dynamic_ = 0;
161 if (absolute_ && absolute_->volume_ < 0)
163 absolute_->volume_ = last_volume_;
167 last_volume_ = absolute_->volume_;
173 span_events_[RIGHT] = 0;
176 IMPLEMENT_TRANSLATOR_LISTENER (New_dynamic_performer, decrescendo);
178 New_dynamic_performer::listen_decrescendo (Stream_event *r)
180 Direction d = to_dir (r->get_property ("span-direction"));
182 grow_dir_[d] = SMALLER;
185 IMPLEMENT_TRANSLATOR_LISTENER (New_dynamic_performer, crescendo);
187 New_dynamic_performer::listen_crescendo (Stream_event *r)
189 Direction d = to_dir (r->get_property ("span-direction"));
191 grow_dir_[d] = BIGGER;
194 IMPLEMENT_TRANSLATOR_LISTENER (New_dynamic_performer, absolute_dynamic);
196 New_dynamic_performer::listen_absolute_dynamic (Stream_event *r)
202 ADD_TRANSLATOR (New_dynamic_performer,
207 "dynamicAbsoluteVolumeFunction "
208 "instrumentEqualizer "