]> git.donarmstrong.com Git - lilypond.git/blob - lily/metronome-engraver.cc
Run `make grand-replace'.
[lilypond.git] / lily / metronome-engraver.cc
1 /*
2   metronome-engraver.cc -- implement Metronome_mark_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2008 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <cctype>
10 using namespace std;
11
12 #include "engraver.hh"
13
14 #include "context.hh"
15 #include "duration.hh"
16 #include "grob-array.hh"
17 #include "item.hh"
18 #include "stream-event.hh"
19 #include "text-interface.hh"
20
21 #include "translator.icc"
22
23 class Metronome_mark_engraver : public Engraver
24 {
25 public:
26   TRANSLATOR_DECLARATIONS (Metronome_mark_engraver);
27 protected:
28   Item *text_;
29   Grob *bar_line_;
30
31   SCM last_duration_;
32   SCM last_count_;
33   SCM last_text_;
34   
35 protected:
36   virtual void derived_mark () const;
37   void stop_translation_timestep ();
38   void process_music ();
39 };
40
41 Metronome_mark_engraver::Metronome_mark_engraver ()
42 {
43   text_ = 0;
44   last_duration_ = SCM_EOL;
45   last_count_ = SCM_EOL;
46   last_text_ = SCM_EOL;
47 }
48
49 void
50 Metronome_mark_engraver::derived_mark () const
51 {
52   scm_gc_mark (last_count_);
53   scm_gc_mark (last_duration_);
54   scm_gc_mark (last_text_);
55 }
56
57 void
58 Metronome_mark_engraver::stop_translation_timestep ()
59 {
60   if (text_)
61     {
62       Grob *mc = unsmob_grob (get_property ("currentMusicalColumn"));
63       text_->set_parent (mc, X_AXIS);
64       text_->set_object ("side-support-elements",
65                          grob_list_to_grob_array (get_property ("stavesFound")));
66       text_ = 0;
67     }
68 }
69
70 void
71 Metronome_mark_engraver::process_music ()
72 {
73   SCM count = get_property ("tempoUnitCount");
74   SCM duration = get_property ("tempoUnitDuration");
75   SCM text = get_property ("tempoText");
76
77   if ( ( (unsmob_duration (duration) && scm_is_number (count))
78         || Text_interface::is_markup (text) )
79       && !(ly_is_equal (count, last_count_)
80            && ly_is_equal (duration, last_duration_)
81            && ly_is_equal (text, last_text_)))
82     {
83       text_ = make_item ("MetronomeMark", SCM_EOL);
84
85       SCM proc = get_property ("metronomeMarkFormatter");
86       SCM result = scm_call_4 (proc,
87                                text,
88                                duration,
89                                count,
90                                context ()->self_scm ());
91
92       text_->set_property ("text", result);
93     }
94
95   last_duration_ = duration;
96   last_count_ = count;
97   last_text_ = text;
98 }
99
100 ADD_TRANSLATOR (Metronome_mark_engraver,
101                 /* doc */
102                 "Engrave metronome marking.  This delegates the formatting"
103                 " work to the function in the @code{metronomeMarkFormatter}"
104                 " property.  The mark is put over all staves.  The staves are"
105                 " taken from the @code{stavesFound} property, which is"
106                 " maintained by @ref{Staff_collecting_engraver}.",
107
108                 /* create */
109                 "MetronomeMark ",
110
111                 /* read */
112                 "stavesFound "
113                 "metronomeMarkFormatter "
114                 "tempoUnitDuration "
115                 "tempoUnitCount "
116                 "tempoText "
117                 "tempoHideNote ",
118
119                 /* write */
120                 ""
121                 );