]> git.donarmstrong.com Git - lilypond.git/blob - lily/dynamic-performer.cc
* lily/include/lily-guile.hh: compatibility glue for 1.6
[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--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "performer.hh"
10
11 #include "event.hh"
12 #include "audio-item.hh"
13
14 /*
15   TODO:
16   
17     handle multiple events
18
19     perform absolute (text) dynamics
20  */
21 class Dynamic_performer : public Performer
22 {
23 public:
24   TRANSLATOR_DECLARATIONS (Dynamic_performer);
25 protected:
26   virtual bool try_music (Music* req);
27   virtual void stop_translation_timestep ();
28   virtual void create_audio_elements ();
29
30 private:
31   Music* script_req_;
32   Audio_dynamic* audio_;
33 };
34
35 Dynamic_performer::Dynamic_performer ()
36 {
37   script_req_ = 0;
38   audio_ = 0;
39 }
40
41 void
42 Dynamic_performer::create_audio_elements ()
43 {
44   if (script_req_)
45     {
46       SCM proc = get_property ("dynamicAbsoluteVolumeFunction");
47
48       SCM svolume  = SCM_EOL;
49       if (ly_c_procedure_p (proc))
50         {
51           // urg
52           svolume = scm_call_1 (proc, script_req_->get_property ("text"));
53         }
54
55       Real volume = robust_scm2double (svolume, 0.5); 
56
57       /*
58         properties override default equaliser setting
59        */
60       SCM min = get_property ("midiMinimumVolume");
61       SCM max = get_property ("midiMaximumVolume");
62       if (ly_c_number_p (min) || ly_c_number_p (max))
63         {
64           Interval iv (0, 1);
65           if (ly_c_number_p (min))
66             iv[MIN] = ly_scm2double (min);
67           if (ly_c_number_p (max))
68             iv[MAX] = ly_scm2double (max);
69           volume = iv[MIN] + iv.length () * volume;
70         }
71       else
72         {
73           /*
74             urg, code duplication:: staff_performer
75           */
76           SCM s = get_property ("midiInstrument");
77           
78           if (!scm_is_string (s))
79             s = get_property ("instrument");
80           
81           if (!scm_is_string (s))
82             s = scm_makfrom0str ("piano");
83           
84           
85           SCM eq = get_property ("instrumentEqualizer");
86           if (ly_c_procedure_p (eq))
87             {
88               s = scm_call_1 (eq, s);
89             }
90
91           if (is_number_pair (s))
92             {
93               Interval iv = ly_scm2interval (s);
94               volume = iv[MIN] + iv.length () * volume;
95             }
96         }
97       
98       audio_ = new Audio_dynamic (volume);
99       Audio_element_info info (audio_, script_req_);
100       announce_element (info);
101       script_req_ = 0;
102     }
103 }
104
105 void
106 Dynamic_performer::stop_translation_timestep ()
107 {
108   if (audio_)
109     {
110       play_element (audio_);
111       audio_ = 0;
112     }
113 }
114
115 bool
116 Dynamic_performer::try_music (Music* r)
117 {
118   if (!script_req_)
119     {
120       if (r->is_mus_type ("absolute-dynamic-event")) // fixme.
121         {
122           script_req_ = r;
123           return true;
124         }
125     }
126   return false;
127 }
128
129 ENTER_DESCRIPTION (Dynamic_performer,
130                   /*descr*/               "",
131                   /* creats*/ "",
132                   /* accepts */     "absolute-dynamic-event",
133                   /* acks */ "",
134                   /*reads */"dynamicAbsoluteVolumeFunction midiMaximumVolume midiMinimumVolume midiInstrument instrumentEqualizer",
135                   /*writes*/"");