]> git.donarmstrong.com Git - lilypond.git/blob - lily/metronome-engraver.cc
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--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       
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", rq->self_scm () );
83
84 }
85
86
87 bool
88 Metronome_mark_engraver::try_music (Music* r)
89 {
90   mark_ev_ = r;
91   return true;
92 }
93
94 void
95 Metronome_mark_engraver::process_music ()
96 {
97   if (mark_ev_)
98     {
99       create_items (mark_ev_);
100
101       SCM proc = get_property ("metronomeMarkFormatter");
102       SCM result= scm_call_2 (proc, mark_ev_->self_scm (),
103                               context ()->self_scm ()); 
104       
105       text_->set_property ("text", result);
106     }
107 }
108
109 ENTER_DESCRIPTION (Metronome_mark_engraver,
110 /* descr */       "Engrave metro nome marking. This delegates the formatting work "
111                    "to the function in the metronomeMarkFormatter property. "
112                    "The mark is put over all staves. "
113                    "The staves are taken from the @code{stavesFound} property, "
114                    "which is maintained by @code{@ref{Staff_collecting_engraver}}. "
115         
116                    ,
117 /* creats*/       "MetronomeMark",
118 /* accepts */     "metronome-change-event",
119 /* acks  */       "time-signature-interface bar-line-interface",
120 /* reads */       "stavesFound metronomeMarkFormatter",
121 /* write */       "");