]> git.donarmstrong.com Git - lilypond.git/blob - lily/dynamic-performer.cc
release: 1.5.13
[lilypond.git] / lily / dynamic-performer.cc
1 /*
2   dynamic-performer.cc -- implement Dynamic_performer
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "performer.hh"
10 #include "command-request.hh"
11 #include "musical-request.hh"
12 #include "audio-item.hh"
13
14 /*
15   TODO:
16     handle multiple requests
17  */
18
19 /**
20    perform absolute (text) dynamics
21  */
22 class Dynamic_performer : public Performer
23 {
24 public:
25   TRANSLATOR_DECLARATIONS(Dynamic_performer);
26 protected:
27   virtual bool try_music (Music* req_l);
28   virtual void stop_translation_timestep ();
29   virtual void create_audio_elements ();
30
31 private:
32   Music* script_req_l_;
33   Audio_dynamic* audio_p_;
34 };
35
36
37
38 Dynamic_performer::Dynamic_performer ()
39 {
40   script_req_l_ = 0;
41   audio_p_ = 0;
42 }
43
44 void
45 Dynamic_performer::create_audio_elements ()
46 {
47   if (script_req_l_)
48     {
49       SCM proc = get_property ("dynamicAbsoluteVolumeFunction");
50
51       SCM svolume  = SCM_EOL;
52       if (gh_procedure_p (proc))
53         {
54           // urg
55           svolume = gh_call1 (proc, script_req_l_->get_mus_property ("text"));
56         }
57
58       Real volume = 0.5; 
59       if (gh_number_p (svolume))
60         volume = gh_scm2double (svolume);
61
62       /*
63         properties override default equaliser setting
64        */
65       SCM min = get_property ("midiMinimumVolume");
66       SCM max = get_property ("midiMaximumVolume");
67       if (gh_number_p (min) || gh_number_p (max))
68         {
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;
75         }
76       else
77         {
78           /*
79             urg, code duplication:: staff_performer
80           */
81           SCM s = get_property ("midiInstrument");
82           
83           if (!gh_string_p (s))
84             s = get_property ("instrument");
85           
86           if (!gh_string_p (s))
87             s = ly_str02scm ("piano");
88           
89           
90           SCM eq = get_property ("instrumentEqualizer");
91           if (gh_procedure_p (eq))
92             {
93               s = gh_call1 (eq, s);
94             }
95
96           if (gh_pair_p (s))
97             {
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;
102             }
103         }
104       
105       audio_p_ = new Audio_dynamic (volume);
106       Audio_element_info info (audio_p_, script_req_l_);
107       announce_element (info);
108       script_req_l_ = 0;
109     }
110 }
111
112 void
113 Dynamic_performer::stop_translation_timestep ()
114 {
115   if (audio_p_)
116     {
117       play_element (audio_p_);
118       audio_p_ = 0;
119     }
120 }
121
122 bool
123 Dynamic_performer::try_music (Music* r)
124 {
125   if (!script_req_l_)
126     {
127       if (dynamic_cast <Text_script_req*> (r)
128           && r->get_mus_property ("text-type") == ly_symbol2scm ("dynamic"))
129         {
130           script_req_l_ = r;
131           return true;
132         }
133     }
134   return false;
135 }
136
137 ENTER_DESCRIPTION(Dynamic_performer,
138                   "","","","","");