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