]> git.donarmstrong.com Git - lilypond.git/blob - lily/dynamic-performer.cc
patch::: 1.3.96.jcn7
[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   Dynamic_script_req* script_req_l_;
37   Audio_dynamic* audio_p_;
38 };
39
40 ADD_THIS_TRANSLATOR (Dynamic_performer);
41
42 Dynamic_performer::Dynamic_performer ()
43 {
44   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 (script_req_l_)
57     {
58       SCM proc = get_property ("dynamicAbsoluteVolumeFunction");
59
60       SCM svolume  = SCM_EOL;
61       if (gh_procedure_p (proc))
62         {
63           // urg
64           svolume = gh_call1 (proc, script_req_l_->text_); 
65         }
66
67       Real volume = 0.5; 
68       if (gh_number_p (svolume))
69         volume = gh_scm2double (svolume);
70
71       /*
72         properties override default equaliser setting
73        */
74       SCM min = get_property ("midiMinimumVolume");
75       SCM max = get_property ("midiMaximumVolume");
76       if (gh_number_p (min) || gh_number_p (max))
77         {
78           Interval iv (0, 1);
79           if (gh_number_p (min))
80             iv[MIN] = gh_scm2double (min);
81           if (gh_number_p (max))
82             iv[MAX] = gh_scm2double (max);
83           volume = iv[MIN] + iv.length () * volume;
84         }
85       else
86         {
87           /*
88             urg, code duplication:: staff_performer
89           */
90           SCM s = get_property ("midiInstrument");
91           
92           if (!gh_string_p(s))
93             s = get_property ("instrument");
94           
95           if (!gh_string_p(s))
96             s = ly_str02scm ("piano");
97           
98           
99           SCM eq = get_property ("instrumentEqualizer");
100           if (gh_procedure_p (eq))
101             {
102               s = gh_call1 (eq, s);
103             }
104
105           if (gh_pair_p (s))
106             {
107               Interval iv;
108               iv[MIN] = gh_scm2double (gh_car (s));
109               iv[MAX] = gh_scm2double (gh_cdr (s));
110               volume = iv[MIN] + iv.length () * volume;
111             }
112         }
113       
114       audio_p_ = new Audio_dynamic (volume);
115       Audio_element_info info (audio_p_, script_req_l_);
116       announce_element (info);
117       script_req_l_ = 0;
118     }
119 }
120
121 void
122 Dynamic_performer::do_pre_move_processing ()
123 {
124   if (audio_p_)
125     {
126       play_element (audio_p_);
127       audio_p_ = 0;
128     }
129 }
130
131 bool
132 Dynamic_performer::do_try_music (Music* r)
133 {
134   if (!script_req_l_)
135     {
136       if(Dynamic_script_req* d = dynamic_cast <Dynamic_script_req*> (r))
137         {
138           script_req_l_ = d;
139           return true;
140         }
141     }
142   return false;
143 }
144