]> git.donarmstrong.com Git - lilypond.git/blob - lily/tempo-performer.cc
release: 1.5.29
[lilypond.git] / lily / tempo-performer.cc
1 /*
2   tempo-performer.cc -- implement Tempo_performer
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2002 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "command-request.hh"
10 #include "audio-item.hh"
11 #include "performer.hh"
12
13 class Tempo_performer : public Performer
14 {
15 public:
16   TRANSLATOR_DECLARATIONS(Tempo_performer);
17   ~Tempo_performer ();
18
19 protected:
20
21   virtual bool try_music (Music* req_l);
22   virtual void stop_translation_timestep ();
23   virtual void create_audio_elements ();
24
25 private:
26   Tempo_req* tempo_req_l_;
27   Audio_tempo* audio_p_;
28 };
29
30 ENTER_DESCRIPTION (Tempo_performer, "","","","","" );
31
32
33 Tempo_performer::Tempo_performer ()
34 {
35   tempo_req_l_ = 0;
36   audio_p_ = 0;
37 }
38
39 Tempo_performer::~Tempo_performer ()
40 {
41 }
42
43
44 void
45 Tempo_performer::create_audio_elements ()
46 {
47   if (tempo_req_l_)
48     {
49
50       SCM met = tempo_req_l_->get_mus_property ("metronome-count");
51       Duration *d = unsmob_duration (tempo_req_l_->get_mus_property ("duration"));
52       
53       Rational r =  (d->length_mom () / Moment (Rational (1, 4)) * Moment (gh_scm2int (met))).main_part_;
54       
55       audio_p_ = new Audio_tempo (int (r));
56
57       Audio_element_info info (audio_p_, tempo_req_l_);
58       announce_element (info);
59       tempo_req_l_ = 0;
60     }
61 }
62
63 void
64 Tempo_performer::stop_translation_timestep ()
65 {
66   if (audio_p_)
67     {
68       play_element (audio_p_);
69       audio_p_ = 0;
70     }
71 }
72
73 bool
74 Tempo_performer::try_music (Music* req_l)
75 {
76   if (tempo_req_l_)
77     return false;
78
79   if (Tempo_req *t =
80       dynamic_cast <Tempo_req *> (req_l))
81     {
82       tempo_req_l_ = t;
83       return true;
84     }
85
86   return false;
87 }
88