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