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