]> git.donarmstrong.com Git - lilypond.git/blob - lily/metronome-engraver.cc
Merge branch 'master' of git://git.sv.gnu.org/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 #include "text-interface.hh"
20
21 #include "translator.icc"
22
23 /**
24    put stuff over or next to  bars.  Examples: bar numbers, marginal notes,
25    rehearsal marks.
26 */
27 class Metronome_mark_engraver : public Engraver
28 {
29 public:
30   TRANSLATOR_DECLARATIONS (Metronome_mark_engraver);
31 protected:
32   Item *text_;
33   Grob *bar_line_;
34
35   SCM last_duration_;
36   SCM last_count_;
37   SCM last_text_;
38   
39 protected:
40   virtual void derived_mark () const;
41   void stop_translation_timestep ();
42   void process_music ();
43 };
44
45 Metronome_mark_engraver::Metronome_mark_engraver ()
46 {
47   text_ = 0;
48   last_duration_ = SCM_EOL;
49   last_count_ = SCM_EOL;
50   last_text_ = SCM_EOL;
51 }
52
53 void
54 Metronome_mark_engraver::derived_mark () const
55 {
56   scm_gc_mark (last_count_);
57   scm_gc_mark (last_duration_);
58   scm_gc_mark (last_text_);
59 }
60
61 void
62 Metronome_mark_engraver::stop_translation_timestep ()
63 {
64   if (text_)
65     {
66       Grob *mc = unsmob_grob (get_property ("currentMusicalColumn"));
67       text_->set_parent (mc, X_AXIS);
68       text_->set_object ("side-support-elements",
69                          grob_list_to_grob_array (get_property ("stavesFound")));
70       text_ = 0;
71     }
72 }
73
74 void
75 Metronome_mark_engraver::process_music ()
76 {
77   SCM count = get_property ("tempoUnitCount");
78   SCM duration = get_property ("tempoUnitDuration");
79   SCM text = get_property ("tempoText");
80
81   if ( ( (unsmob_duration (duration) && scm_is_number (count))
82         || Text_interface::is_markup (text) )
83       && !(ly_is_equal (count, last_count_)
84            && ly_is_equal (duration, last_duration_)
85            && ly_is_equal (text, last_text_)))
86     {
87       text_ = make_item ("MetronomeMark", SCM_EOL);
88
89       SCM proc = get_property ("metronomeMarkFormatter");
90       SCM result = scm_call_4 (proc,
91                                text,
92                                duration,
93                                count,
94                                context ()->self_scm ());
95
96       text_->set_property ("text", result);
97     }
98
99   last_duration_ = duration;
100   last_count_ = count;
101   last_text_ = text;
102 }
103
104 ADD_TRANSLATOR (Metronome_mark_engraver,
105                 /* doc */
106                 "Engrave metronome marking.  This delegates the formatting"
107                 " work to the function in the @code{metronomeMarkFormatter}"
108                 " property.  The mark is put over all staves.  The staves are"
109                 " taken from the @code{stavesFound} property, which is"
110                 " maintained by @ref{Staff_collecting_engraver}.",
111
112                 /* create */
113                 "MetronomeMark ",
114
115                 /* read */
116                 "stavesFound "
117                 "metronomeMarkFormatter "
118                 "tempoUnitDuration "
119                 "tempoUnitCount "
120                 "tempoText "
121                 "tempoHideNote ",
122
123                 /* write */
124                 ""
125                 );