]> git.donarmstrong.com Git - lilypond.git/blob - lily/tempo-performer.cc
release: 1.3.109
[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--2000 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   VIRTUAL_COPY_CONS(Translator);
17   
18   Tempo_performer();
19   ~Tempo_performer();
20
21 protected:
22
23   virtual bool try_music (Music* req_l);
24   virtual void stop_translation_timestep ();
25   virtual void create_grobs ();
26
27 private:
28   Tempo_req* tempo_req_l_;
29   Audio_tempo* audio_p_;
30 };
31
32 ADD_THIS_TRANSLATOR (Tempo_performer);
33
34 Tempo_performer::Tempo_performer ()
35 {
36   tempo_req_l_ = 0;
37   audio_p_ = 0;
38 }
39
40 Tempo_performer::~Tempo_performer ()
41 {
42 }
43
44
45 void
46 Tempo_performer::create_grobs ()
47 {
48   if (tempo_req_l_)
49     {
50
51       SCM met = tempo_req_l_->get_mus_property ("metronome-count");
52       audio_p_ = new Audio_tempo (tempo_req_l_->dur_.length_mom () /
53                                   Moment (1, 4) 
54                                   * Moment(gh_scm2int (met)));
55
56       Audio_element_info info (audio_p_, tempo_req_l_);
57       announce_element (info);
58       tempo_req_l_ = 0;
59     }
60 }
61
62 void
63 Tempo_performer::stop_translation_timestep ()
64 {
65   if (audio_p_)
66     {
67       play_element (audio_p_);
68       audio_p_ = 0;
69     }
70 }
71
72 bool
73 Tempo_performer::try_music (Music* req_l)
74 {
75   if (tempo_req_l_)
76     return false;
77
78   if (Tempo_req *t =
79       dynamic_cast <Tempo_req *> (req_l))
80     {
81       tempo_req_l_ = t;
82       return true;
83     }
84
85   return false;
86 }
87