]> git.donarmstrong.com Git - lilypond.git/blob - lily/tempo-performer.cc
patch::: 1.3.136.jcn3
[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--2001 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_audio_elements ();
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_audio_elements ()
47 {
48   if (tempo_req_l_)
49     {
50
51       SCM met = tempo_req_l_->get_mus_property ("metronome-count");
52       Duration *d = unsmob_duration (tempo_req_l_->get_mus_property ("duration"));
53       
54       audio_p_ = new Audio_tempo (d->length_mom () /
55                                   Moment (1, 4) 
56                                   * Moment (gh_scm2int (met)));
57
58       Audio_element_info info (audio_p_, tempo_req_l_);
59       announce_element (info);
60       tempo_req_l_ = 0;
61     }
62 }
63
64 void
65 Tempo_performer::stop_translation_timestep ()
66 {
67   if (audio_p_)
68     {
69       play_element (audio_p_);
70       audio_p_ = 0;
71     }
72 }
73
74 bool
75 Tempo_performer::try_music (Music* req_l)
76 {
77   if (tempo_req_l_)
78     return false;
79
80   if (Tempo_req *t =
81       dynamic_cast <Tempo_req *> (req_l))
82     {
83       tempo_req_l_ = t;
84       return true;
85     }
86
87   return false;
88 }
89