]> git.donarmstrong.com Git - lilypond.git/blob - lily/metronome-engraver.cc
2003 -> 2004
[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
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   
29 protected:
30   virtual void stop_translation_timestep ();
31   virtual void acknowledge_grob (Grob_info);
32   void create_items (Music*);
33   virtual bool try_music (Music *ev);
34   virtual void process_music ();
35   
36 private:
37   Music *mark_ev_;
38 };
39
40 Metronome_mark_engraver::Metronome_mark_engraver ()
41 {
42   text_ =0;
43   mark_ev_ = 0;
44 }
45
46 void
47 Metronome_mark_engraver::acknowledge_grob (Grob_info inf)
48 {
49   if (Bar_line::has_interface (inf.grob_))
50     {
51       bar_line_ = inf.grob_;
52     }
53   else if (text_ && Time_signature::has_interface (inf.grob_))
54     {
55       text_->set_parent (inf.grob_, X_AXIS);
56     }
57 }
58
59 void 
60 Metronome_mark_engraver::stop_translation_timestep ()
61 {
62   if (text_)
63     {
64       if (bar_line_ && !text_->get_parent (X_AXIS))
65         text_->set_parent (bar_line_, X_AXIS);
66       
67       text_->set_grob_property ("side-support-elements" , get_property ("stavesFound"));
68       typeset_grob (text_);
69       text_ =0;
70     }
71   mark_ev_ = 0;
72 }
73
74
75 void
76 Metronome_mark_engraver::create_items (Music *rq)
77 {
78   if (text_)
79     return;
80
81   text_ = make_item ("MetronomeMark");
82
83   announce_grob(text_, rq->self_scm());
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                               daddy_trans_->self_scm()); 
104       
105       text_->set_grob_property ("text", result);
106     }
107 }
108
109 ENTER_DESCRIPTION(Metronome_mark_engraver,
110 /* descr */       "Engrave metro nome marking. This delegates the real work to the function in the metronomeMarkFormatter property",
111 /* creats*/       "MetronomeMark",
112 /* accepts */     "metronome-change-event",
113 /* acks  */       "time-signature-interface bar-line-interface",
114 /* reads */       "stavesFound metronomeMarkFormatter",
115 /* write */       "");