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