]> git.donarmstrong.com Git - lilypond.git/blob - lily/tempo-performer.cc
* flower
[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--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "audio-item.hh"
10 #include "performer.hh"
11
12 class Tempo_performer : public Performer
13 {
14 public:
15   TRANSLATOR_DECLARATIONS (Tempo_performer);
16   ~Tempo_performer ();
17
18 protected:
19
20   virtual bool try_music (Music *req);
21   virtual void stop_translation_timestep ();
22   virtual void create_audio_elements ();
23
24 private:
25   Music *tempo_req_;
26   Audio_tempo *audio_;
27 };
28
29 Tempo_performer::Tempo_performer ()
30 {
31   tempo_req_ = 0;
32   audio_ = 0;
33 }
34
35 Tempo_performer::~Tempo_performer ()
36 {
37 }
38
39 void
40 Tempo_performer::create_audio_elements ()
41 {
42   if (tempo_req_)
43     {
44
45       SCM met = tempo_req_->get_property ("metronome-count");
46       Duration *d = unsmob_duration (tempo_req_->get_property ("tempo-unit"));
47
48       Rational r = (d->get_length () / Moment (Rational (1, 4)) * Moment (scm_to_int (met))).main_part_;
49
50       audio_ = new Audio_tempo (int (r));
51
52       Audio_element_info info (audio_, tempo_req_);
53       announce_element (info);
54       tempo_req_ = 0;
55     }
56 }
57
58 void
59 Tempo_performer::stop_translation_timestep ()
60 {
61   if (audio_)
62     {
63       play_element (audio_);
64       audio_ = 0;
65     }
66 }
67
68 bool
69 Tempo_performer::try_music (Music *req)
70 {
71   if (tempo_req_)
72     return false;
73
74   tempo_req_ = req;
75   return true;
76 }
77
78
79 ADD_TRANSLATOR (Tempo_performer, "", "",
80                 "metronome-change-event",
81                 "", "", "");