]> git.donarmstrong.com Git - lilypond.git/blob - lily/tempo-performer.cc
* python/midi.c (midi_parse_track): robustness: don't read past
[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   virtual void derived_mark () const; 
26   void stop_translation_timestep ();
27   void process_music ();
28 private:
29   Audio_tempo *audio_;
30   SCM last_tempo_; 
31 };
32
33 void
34 Tempo_performer::derived_mark () const
35 {
36   scm_gc_mark (last_tempo_);
37 }
38
39 Tempo_performer::Tempo_performer ()
40 {
41   audio_ = 0;
42 }
43
44 Tempo_performer::~Tempo_performer ()
45 {
46 }
47
48 void
49 Tempo_performer::process_music ()
50 {
51   SCM w = get_property ("tempoWholesPerMinute");
52   if (unsmob_moment (w)
53       && !ly_is_equal (w, last_tempo_))
54     {
55       Rational r = unsmob_moment (w)->main_part_;
56       r *= Rational (4, 1);
57
58       audio_ = new Audio_tempo (r.to_int ());
59
60       Audio_element_info info (audio_, 0);
61       announce_element (info);
62
63       last_tempo_ = w;
64     }
65 }
66
67 void
68 Tempo_performer::stop_translation_timestep ()
69 {
70   if (audio_)
71     {
72       audio_ = 0;
73     }
74 }
75
76 ADD_TRANSLATOR (Tempo_performer, "", "",
77                 "",
78                 "tempoWholesPerMinute ",
79                 "");