lilypond-1.5.10
[lilypond.git] / lily / dynamic-performer.cc
blobf805428f0c8e6ed9bc87566d84be7029e376ac0d
1 /*
2 dynamic-performer.cc -- implement Dynamic_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include "performer.hh"
10 #include "command-request.hh"
11 #include "musical-request.hh"
12 #include "audio-item.hh"
15 TODO:
16 handle multiple requests
19 /**
20 perform absolute (text) dynamics
22 class Dynamic_performer : public Performer
24 public:
25 VIRTUAL_COPY_CONS (Translator);
27 Dynamic_performer ();
29 protected:
30 virtual bool try_music (Music* req_l);
31 virtual void stop_translation_timestep ();
32 virtual void create_audio_elements ();
34 private:
35 Music* script_req_l_;
36 Audio_dynamic* audio_p_;
39 ADD_THIS_TRANSLATOR (Dynamic_performer);
41 Dynamic_performer::Dynamic_performer ()
43 script_req_l_ = 0;
44 audio_p_ = 0;
47 void
48 Dynamic_performer::create_audio_elements ()
50 if (script_req_l_)
52 SCM proc = get_property ("dynamicAbsoluteVolumeFunction");
54 SCM svolume = SCM_EOL;
55 if (gh_procedure_p (proc))
57 // urg
58 svolume = gh_call1 (proc, script_req_l_->get_mus_property ("text"));
61 Real volume = 0.5;
62 if (gh_number_p (svolume))
63 volume = gh_scm2double (svolume);
66 properties override default equaliser setting
68 SCM min = get_property ("midiMinimumVolume");
69 SCM max = get_property ("midiMaximumVolume");
70 if (gh_number_p (min) || gh_number_p (max))
72 Interval iv (0, 1);
73 if (gh_number_p (min))
74 iv[MIN] = gh_scm2double (min);
75 if (gh_number_p (max))
76 iv[MAX] = gh_scm2double (max);
77 volume = iv[MIN] + iv.length () * volume;
79 else
82 urg, code duplication:: staff_performer
84 SCM s = get_property ("midiInstrument");
86 if (!gh_string_p (s))
87 s = get_property ("instrument");
89 if (!gh_string_p (s))
90 s = ly_str02scm ("piano");
93 SCM eq = get_property ("instrumentEqualizer");
94 if (gh_procedure_p (eq))
96 s = gh_call1 (eq, s);
99 if (gh_pair_p (s))
101 Interval iv;
102 iv[MIN] = gh_scm2double (gh_car (s));
103 iv[MAX] = gh_scm2double (gh_cdr (s));
104 volume = iv[MIN] + iv.length () * volume;
108 audio_p_ = new Audio_dynamic (volume);
109 Audio_element_info info (audio_p_, script_req_l_);
110 announce_element (info);
111 script_req_l_ = 0;
115 void
116 Dynamic_performer::stop_translation_timestep ()
118 if (audio_p_)
120 play_element (audio_p_);
121 audio_p_ = 0;
125 bool
126 Dynamic_performer::try_music (Music* r)
128 if (!script_req_l_)
130 if (dynamic_cast <Text_script_req*> (r)
131 && r->get_mus_property ("text-type") == ly_symbol2scm ("dynamic"))
133 script_req_l_ = r;
134 return true;
137 return false;