lilypond-1.3.31
[lilypond.git] / lily / dynamic-performer.cc
blobb7472eaf515b87a241343f5e5644437a64ca2efd
1 /*
2 dynamic-performer.cc -- implement Dynamic_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include "performer.hh"
10 #include "command-request.hh"
11 #include "musical-request.hh"
12 #include "audio-item.hh"
15 TODO:
16 handle multiple requests
17 handle span requests (crescendo/decrescendo)
20 /**
21 perform absolute (text) dynamics
23 class Dynamic_performer : public Performer
25 public:
26 VIRTUAL_COPY_CONS (Translator);
28 Dynamic_performer ();
29 ~Dynamic_performer ();
31 protected:
32 void do_print () const;
33 virtual bool do_try_music (Music* req_l);
34 virtual void do_process_requests ();
35 virtual void do_pre_move_processing ();
37 private:
38 Text_script_req* text_script_req_l_;
39 Audio_dynamic* audio_p_;
42 ADD_THIS_TRANSLATOR (Dynamic_performer);
44 Dynamic_performer::Dynamic_performer ()
46 text_script_req_l_ = 0;
47 audio_p_ = 0;
50 Dynamic_performer::~Dynamic_performer ()
54 void
55 Dynamic_performer::do_print () const
57 #ifndef NPRINT
58 if (text_script_req_l_)
59 text_script_req_l_->print ();
60 #endif
63 void
64 Dynamic_performer::do_process_requests ()
66 if (text_script_req_l_)
69 SCM s = scm_eval
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 int volume = gh_scm2int (ly_eval_str ("dynamic-default-volume"));
75 if (gh_number_p (s))
76 volume = gh_scm2int (s);
78 audio_p_ = new Audio_dynamic (volume);
79 Audio_element_info info (audio_p_, text_script_req_l_);
80 announce_element (info);
81 text_script_req_l_ = 0;
85 void
86 Dynamic_performer::do_pre_move_processing ()
88 if (audio_p_)
90 play_element (audio_p_);
91 audio_p_ = 0;
95 bool
96 Dynamic_performer::do_try_music (Music* r)
98 if (!text_script_req_l_)
100 // urg, text script, style `dynamic' is how absolute dynamics appear
101 if(Text_script_req* t = dynamic_cast <Text_script_req*> (r))
103 if (t->style_str_ == "dynamic")
105 text_script_req_l_ = t;
106 return true;
110 return false;