]> git.donarmstrong.com Git - lilypond.git/blob - lily/metronome-engraver.cc
* lily/include/context.hh (class Context): make members protected.
[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--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <ctype.h>
10
11 #include "bar-line.hh"
12 #include "time-signature.hh"
13 #include "engraver.hh"
14 #include "engraver-group-engraver.hh"
15 #include "item.hh"
16 #include "context.hh"
17
18 /**
19   put stuff over or next to  bars.  Examples: bar numbers, marginal notes,
20   rehearsal marks.
21  */
22 class Metronome_mark_engraver : public Engraver
23 {
24 public:
25   TRANSLATOR_DECLARATIONS (Metronome_mark_engraver);
26 protected:
27   Item *text_;
28   Grob *bar_line_;
29   
30 protected:
31   virtual void stop_translation_timestep ();
32   virtual void acknowledge_grob (Grob_info);
33   void create_items (Music*);
34   virtual bool try_music (Music *ev);
35   virtual void process_music ();
36   
37 private:
38   Music *mark_ev_;
39 };
40
41 Metronome_mark_engraver::Metronome_mark_engraver ()
42 {
43   text_ =0;
44   mark_ev_ = 0;
45 }
46
47 void
48 Metronome_mark_engraver::acknowledge_grob (Grob_info inf)
49 {
50   if (Bar_line::has_interface (inf.grob_))
51     {
52       bar_line_ = inf.grob_;
53     }
54   else if (text_ && Time_signature::has_interface (inf.grob_))
55     {
56       text_->set_parent (inf.grob_, X_AXIS);
57     }
58 }
59
60 void 
61 Metronome_mark_engraver::stop_translation_timestep ()
62 {
63   if (text_)
64     {
65       if (bar_line_ && !text_->get_parent (X_AXIS))
66         text_->set_parent (bar_line_, X_AXIS);
67       
68       text_->set_property ("side-support-elements" , get_property ("stavesFound"));
69       typeset_grob (text_);
70       text_ =0;
71     }
72   mark_ev_ = 0;
73 }
74
75
76 void
77 Metronome_mark_engraver::create_items (Music *rq)
78 {
79   if (text_)
80     return;
81
82   text_ = make_item ("MetronomeMark");
83
84   announce_grob (text_, rq->self_scm ());
85 }
86
87
88 bool
89 Metronome_mark_engraver::try_music (Music* r)
90 {
91   mark_ev_ = r;
92   return true;
93 }
94
95 void
96 Metronome_mark_engraver::process_music ()
97 {
98   if (mark_ev_)
99     {
100       create_items (mark_ev_);
101
102       SCM proc = get_property ("metronomeMarkFormatter");
103       SCM result= scm_call_2 (proc, mark_ev_->self_scm (),
104                               get_parent_context ()->self_scm ()); 
105       
106       text_->set_property ("text", result);
107     }
108 }
109
110 ENTER_DESCRIPTION (Metronome_mark_engraver,
111 /* descr */       "Engrave metro nome marking. This delegates the formatting work "
112                    "to the function in the metronomeMarkFormatter property. "
113                    "The mark is put over all staves. "
114                    "The staves are taken from the @code{stavesFound} property, "
115                    "which is maintained by @code{@ref{Staff_collecting_engraver}}. "
116         
117                    ,
118 /* creats*/       "MetronomeMark",
119 /* accepts */     "metronome-change-event",
120 /* acks  */       "time-signature-interface bar-line-interface",
121 /* reads */       "stavesFound metronomeMarkFormatter",
122 /* write */       "");