]> git.donarmstrong.com Git - lilypond.git/blob - lily/metronome-engraver.cc
* lily/smobs.cc (protect_smob): switch off fancy smob protection
[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--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <cctype>
10 using namespace std;
11
12 #include "engraver.hh"
13
14 #include "item.hh"
15 #include "context.hh"
16 #include "grob-array.hh"
17 #include "duration.hh"
18
19 /**
20    put stuff over or next to  bars.  Examples: bar numbers, marginal notes,
21    rehearsal marks.
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   
34 protected:
35   virtual void derived_mark () const;
36   void stop_translation_timestep ();
37   void process_music ();
38 };
39
40 Metronome_mark_engraver::Metronome_mark_engraver ()
41 {
42   text_ = 0;
43   last_duration_ = SCM_EOL;
44   last_count_ = SCM_EOL;
45 }
46
47 void
48 Metronome_mark_engraver::derived_mark () const
49 {
50   scm_gc_mark (last_count_);
51   scm_gc_mark (last_duration_);
52 }
53
54 void
55 Metronome_mark_engraver::stop_translation_timestep ()
56 {
57   if (text_)
58     {
59       Grob *mc = unsmob_grob (get_property ("currentMusicalColumn"));
60       text_->set_parent (mc, X_AXIS);
61       text_->set_object ("side-support-elements",
62                          grob_list_to_grob_array (get_property ("stavesFound")));
63
64       text_ = 0;
65     }
66 }
67
68 void
69 Metronome_mark_engraver::process_music ()
70 {
71   SCM count = get_property ("tempoUnitCount");
72   SCM duration = get_property ("tempoUnitDuration");
73   
74   if (unsmob_duration (duration)
75       && scm_is_number (count)
76       && !(ly_is_equal (count, last_count_)
77            && ly_is_equal (duration, last_duration_)))
78     {
79       text_ = make_item ("MetronomeMark", SCM_EOL);
80
81       SCM proc = get_property ("metronomeMarkFormatter");
82       SCM result = scm_call_3 (proc,
83                                duration,
84                                count,
85                                context ()->self_scm ());
86
87       text_->set_property ("text", result);
88     }
89
90   last_duration_ = duration;
91   last_count_ = count;
92 }
93
94 #include "translator.icc"
95
96 ADD_TRANSLATOR (Metronome_mark_engraver,
97                 /* doc */ "Engrave metro nome marking. This delegates the formatting work "
98                 "to the function in the metronomeMarkFormatter property. "
99                 "The mark is put over all staves. "
100                 "The staves are taken from the @code{stavesFound} property, "
101                 "which is maintained by @code{@ref{Staff_collecting_engraver}}. ",
102                 /* create */ "MetronomeMark",
103                 /* accept */ "",
104
105                 /* read */
106                 "stavesFound "
107                 "metronomeMarkFormatter "
108                 "tempoUnitDuration "
109                 "tempoUnitCount "
110                 ,
111
112                 /* write */ "");