]> git.donarmstrong.com Git - lilypond.git/blob - lily/metronome-engraver.cc
* lily/include/translator.hh (class Translator): remove
[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--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <cctype>
10
11 #include "note-column.hh"
12 #include "bar-line.hh"
13 #include "time-signature.hh"
14 #include "engraver-group-engraver.hh"
15 #include "context.hh"
16
17 /**
18    put stuff over or next to  bars.  Examples: bar numbers, marginal notes,
19    rehearsal marks.
20 */
21 class Metronome_mark_engraver : public Engraver
22 {
23 public:
24   TRANSLATOR_DECLARATIONS (Metronome_mark_engraver);
25 protected:
26   Item *text_;
27   Grob *bar_line_;
28   Music *mark_ev_;
29
30   void create_items (Music *);
31 protected:
32   void stop_translation_timestep ();
33   virtual bool try_music (Music *ev);
34   void process_music ();
35 };
36
37 Metronome_mark_engraver::Metronome_mark_engraver ()
38 {
39   text_ = 0;
40   mark_ev_ = 0;
41 }
42
43 void
44 Metronome_mark_engraver::stop_translation_timestep ()
45 {
46   if (text_)
47     {
48       Grob *mc = unsmob_grob (get_property ("currentMusicalColumn"));
49       text_->set_parent (mc, X_AXIS);
50       text_->set_object ("side-support-elements", get_property ("stavesFound"));
51
52       text_ = 0;
53     }
54   mark_ev_ = 0;
55 }
56
57 void
58 Metronome_mark_engraver::create_items (Music *rq)
59 {
60   if (text_)
61     return;
62
63   text_ = make_item ("MetronomeMark", rq->self_scm ());
64 }
65
66 bool
67 Metronome_mark_engraver::try_music (Music *r)
68 {
69   mark_ev_ = r;
70   return true;
71 }
72
73 void
74 Metronome_mark_engraver::process_music ()
75 {
76   if (mark_ev_)
77     {
78       create_items (mark_ev_);
79
80       SCM proc = get_property ("metronomeMarkFormatter");
81       SCM result = scm_call_2 (proc, mark_ev_->self_scm (),
82                                context ()->self_scm ());
83
84       text_->set_property ("text", result);
85     }
86 }
87
88 #include "translator.icc"
89
90 ADD_TRANSLATOR (Metronome_mark_engraver,
91                 /* descr */ "Engrave metro nome marking. This delegates the formatting work "
92                 "to the function in the metronomeMarkFormatter property. "
93                 "The mark is put over all staves. "
94                 "The staves are taken from the @code{stavesFound} property, "
95                 "which is maintained by @code{@ref{Staff_collecting_engraver}}. ",
96                 /* creats*/ "MetronomeMark",
97                 /* accepts */ "metronome-change-event",
98                 /* reads */ "stavesFound metronomeMarkFormatter",
99                 /* write */ "");