]> git.donarmstrong.com Git - lilypond.git/blob - lily/metronome-engraver.cc
Merge branch 'lilypond/translation' of ssh://jomand@git.sv.gnu.org/srv/git/lilypond...
[lilypond.git] / lily / metronome-engraver.cc
1 /*
2   mark-engraver.cc -- implement Metronome_mark_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2007 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
20 #include "translator.icc"
21
22 /**
23    put stuff over or next to  bars.  Examples: bar numbers, marginal notes,
24    rehearsal marks.
25 */
26 class Metronome_mark_engraver : public Engraver
27 {
28 public:
29   TRANSLATOR_DECLARATIONS (Metronome_mark_engraver);
30 protected:
31   Item *text_;
32   Grob *bar_line_;
33
34   SCM last_duration_;
35   SCM last_count_;
36   
37 protected:
38   virtual void derived_mark () const;
39   void stop_translation_timestep ();
40   void process_music ();
41 };
42
43 Metronome_mark_engraver::Metronome_mark_engraver ()
44 {
45   text_ = 0;
46   last_duration_ = SCM_EOL;
47   last_count_ = SCM_EOL;
48 }
49
50 void
51 Metronome_mark_engraver::derived_mark () const
52 {
53   scm_gc_mark (last_count_);
54   scm_gc_mark (last_duration_);
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   
76   if (unsmob_duration (duration)
77       && scm_is_number (count)
78       && !(ly_is_equal (count, last_count_)
79            && ly_is_equal (duration, last_duration_)))
80     {
81       text_ = make_item ("MetronomeMark", SCM_EOL);
82
83       SCM proc = get_property ("metronomeMarkFormatter");
84       SCM result = scm_call_3 (proc,
85                                duration,
86                                count,
87                                context ()->self_scm ());
88
89       text_->set_property ("text", result);
90     }
91
92   last_duration_ = duration;
93   last_count_ = count;
94 }
95
96 ADD_TRANSLATOR (Metronome_mark_engraver,
97                 /* doc */
98                 "Engrave metronome marking.  This delegates the formatting"
99                 " work to the function in the @code{metronomeMarkFormatter}"
100                 " property.  The mark is put over all staves.  The staves are"
101                 " taken from the @code{stavesFound} property, which is"
102                 " maintained by @ref{Staff_collecting_engraver}.",
103
104                 /* create */
105                 "MetronomeMark ",
106
107                 /* read */
108                 "stavesFound "
109                 "metronomeMarkFormatter "
110                 "tempoUnitDuration "
111                 "tempoUnitCount ",
112
113                 /* write */
114                 ""
115                 );