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