* stepmake/stepmake/metafont-rules.make: backport 1.7 fixes.
[lilypond.git] / lily / dynamic-performer.cc
blobe76f07cd62fb66641ad919d00db4699f456a8e16
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 TRANSLATOR_DECLARATIONS(Dynamic_performer);
26 protected:
27 virtual bool try_music (Music* req);
28 virtual void stop_translation_timestep ();
29 virtual void create_audio_elements ();
31 private:
32 Music* script_req_;
33 Audio_dynamic* audio_;
38 Dynamic_performer::Dynamic_performer ()
40 script_req_ = 0;
41 audio_ = 0;
44 void
45 Dynamic_performer::create_audio_elements ()
47 if (script_req_)
49 SCM proc = get_property ("dynamicAbsoluteVolumeFunction");
51 SCM svolume = SCM_EOL;
52 if (gh_procedure_p (proc))
54 // urg
55 svolume = gh_call1 (proc, script_req_->get_mus_property ("text"));
58 Real volume = 0.5;
59 if (gh_number_p (svolume))
60 volume = gh_scm2double (svolume);
63 properties override default equaliser setting
65 SCM min = get_property ("midiMinimumVolume");
66 SCM max = get_property ("midiMaximumVolume");
67 if (gh_number_p (min) || gh_number_p (max))
69 Interval iv (0, 1);
70 if (gh_number_p (min))
71 iv[MIN] = gh_scm2double (min);
72 if (gh_number_p (max))
73 iv[MAX] = gh_scm2double (max);
74 volume = iv[MIN] + iv.length () * volume;
76 else
79 urg, code duplication:: staff_performer
81 SCM s = get_property ("midiInstrument");
83 if (!gh_string_p (s))
84 s = get_property ("instrument");
86 if (!gh_string_p (s))
87 s = scm_makfrom0str ("piano");
90 SCM eq = get_property ("instrumentEqualizer");
91 if (gh_procedure_p (eq))
93 s = gh_call1 (eq, s);
96 if (gh_pair_p (s))
98 Interval iv;
99 iv[MIN] = gh_scm2double (ly_car (s));
100 iv[MAX] = gh_scm2double (ly_cdr (s));
101 volume = iv[MIN] + iv.length () * volume;
105 audio_ = new Audio_dynamic (volume);
106 Audio_element_info info (audio_, script_req_);
107 announce_element (info);
108 script_req_ = 0;
112 void
113 Dynamic_performer::stop_translation_timestep ()
115 if (audio_)
117 play_element (audio_);
118 audio_ = 0;
122 bool
123 Dynamic_performer::try_music (Music* r)
125 if (!script_req_)
127 if (dynamic_cast <Text_script_req*> (r)
128 && r->get_mus_property ("text-type") == ly_symbol2scm ("dynamic"))
130 script_req_ = r;
131 return true;
134 return false;
137 ENTER_DESCRIPTION(Dynamic_performer,
138 "","","","dynamicAbsoluteVolumeFunction midiMaximumVolume midiMinimumVolume midiInstrument instrumentEqualizer","");