]> git.donarmstrong.com Git - lilypond.git/blob - lily/dynamic-performer.cc
release: 1.3.93
[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   VIRTUAL_COPY_CONS (Translator);
26   
27   Dynamic_performer ();
28   ~Dynamic_performer ();
29
30 protected:
31   virtual bool do_try_music (Music* req_l);
32   virtual void do_process_music ();
33   virtual void do_pre_move_processing ();
34
35 private:
36   Text_script_req* text_script_req_l_;
37   Audio_dynamic* audio_p_;
38 };
39
40 ADD_THIS_TRANSLATOR (Dynamic_performer);
41
42 Dynamic_performer::Dynamic_performer ()
43 {
44   text_script_req_l_ = 0;
45   audio_p_ = 0;
46 }
47
48 Dynamic_performer::~Dynamic_performer ()
49 {
50 }
51
52
53 void
54 Dynamic_performer::do_process_music ()
55 {
56   if (text_script_req_l_)
57     {
58       SCM proc = get_property ("dynamicAbsoluteVolumeFunction");
59
60       SCM svolume  = SCM_EOL;
61       if (gh_procedure_p (proc))
62         {
63           svolume = gh_call1 (proc, ly_str02scm (text_script_req_l_->text_str_.ch_C ())); 
64         }
65
66       Real volume = 0.5; 
67       if (gh_number_p (svolume))
68         volume = gh_scm2double (svolume);
69
70       /*
71         properties override default equaliser setting
72        */
73       SCM min = get_property ("midiMinimumVolume");
74       SCM max = get_property ("midiMaximumVolume");
75       if (gh_number_p (min) || gh_number_p (max))
76         {
77           Interval iv (0, 1);
78           if (gh_number_p (min))
79             iv[MIN] = gh_scm2double (min);
80           if (gh_number_p (max))
81             iv[MAX] = gh_scm2double (max);
82           volume = iv[MIN] + iv.length () * volume;
83         }
84       else
85         {
86           /*
87             urg, code duplication:: staff_performer
88           */
89           SCM s = get_property ("midiInstrument");
90           
91           if (!gh_string_p(s))
92             s = get_property ("instrument");
93           
94           if (!gh_string_p(s))
95             s = ly_str02scm ("piano");
96           
97           
98           SCM eq = get_property ("instrumentEqualizer");
99           if (gh_procedure_p (eq))
100             {
101               s = gh_call1 (eq, s);
102             }
103
104           if (gh_pair_p (s))
105             {
106               Interval iv;
107               iv[MIN] = gh_scm2double (gh_car (s));
108               iv[MAX] = gh_scm2double (gh_cdr (s));
109               volume = iv[MIN] + iv.length () * volume;
110             }
111         }
112       
113       audio_p_ = new Audio_dynamic (volume);
114       Audio_element_info info (audio_p_, text_script_req_l_);
115       announce_element (info);
116       text_script_req_l_ = 0;
117     }
118 }
119
120 void
121 Dynamic_performer::do_pre_move_processing ()
122 {
123   if (audio_p_)
124     {
125       play_element (audio_p_);
126       audio_p_ = 0;
127     }
128 }
129
130 bool
131 Dynamic_performer::do_try_music (Music* r)
132 {
133   if (!text_script_req_l_)
134     {
135       // urg, text script, style `dynamic' is how absolute dynamics appear
136       if(Text_script_req* t = dynamic_cast <Text_script_req*> (r))
137         {
138           if (t->style_str_ == "dynamic")
139             {
140               text_script_req_l_ = t;
141               return true;
142             }
143         }
144     }
145   return false;
146 }
147