]> git.donarmstrong.com Git - lilypond.git/blob - lily/tempo-performer.cc
*** empty log message ***
[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--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9
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);
22   virtual void stop_translation_timestep ();
23   virtual void create_audio_elements ();
24
25 private:
26 Music* tempo_req_;
27   Audio_tempo* audio_;
28 };
29
30 Tempo_performer::Tempo_performer ()
31 {
32   tempo_req_ = 0;
33   audio_ = 0;
34 }
35
36 Tempo_performer::~Tempo_performer ()
37 {
38 }
39
40
41 void
42 Tempo_performer::create_audio_elements ()
43 {
44   if (tempo_req_)
45     {
46
47       SCM met = tempo_req_->get_mus_property ("metronome-count");
48       Duration *d = unsmob_duration (tempo_req_->get_mus_property ("tempo-unit"));
49       
50       Rational r =  (d->get_length () / Moment (Rational (1, 4)) * Moment (gh_scm2int (met))).main_part_;
51       
52       audio_ = new Audio_tempo (int (r));
53
54       Audio_element_info info (audio_, tempo_req_);
55       announce_element (info);
56       tempo_req_ = 0;
57     }
58 }
59
60 void
61 Tempo_performer::stop_translation_timestep ()
62 {
63   if (audio_)
64     {
65       play_element (audio_);
66       audio_ = 0;
67     }
68 }
69
70 bool
71 Tempo_performer::try_music (Music* req)
72 {
73   if (tempo_req_)
74     return false;
75
76       tempo_req_ = req;
77       return true;
78 }
79
80
81
82
83 ENTER_DESCRIPTION (Tempo_performer, "","",
84                    "tempo-event",
85                    "","","" );