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