]> git.donarmstrong.com Git - lilypond.git/blob - lily/metronome-engraver.cc
*** empty log message ***
[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--2003 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 *req);
34   virtual void start_translation_timestep ();
35   virtual void process_music ();
36   
37 private:
38   Music * mark_req_;
39 };
40
41 Metronome_mark_engraver::Metronome_mark_engraver ()
42 {
43   text_ =0;
44   mark_req_ = 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_grob_property ("side-support-elements" , get_property ("stavesFound"));
69       typeset_grob (text_);
70       text_ =0;
71     }
72   mark_req_ = 0;
73 }
74
75
76 void
77 Metronome_mark_engraver::create_items (Music *rq)
78 {
79   if (text_)
80     return;
81
82   SCM s = get_property ("MetronomeMark");
83   text_ = new Item (s);
84
85   announce_grob(text_, rq->self_scm());
86 }
87
88
89 bool
90 Metronome_mark_engraver::try_music (Music* r)
91 {
92   mark_req_ = r;
93   return true;
94 }
95
96 void
97 Metronome_mark_engraver::process_music ()
98 {
99   if (mark_req_)
100     {
101       create_items (mark_req_);
102
103       SCM proc = get_property ("metronomeMarkFormatter");
104       SCM result= scm_call_2 (proc, mark_req_->self_scm (),
105                               daddy_trans_->self_scm()); 
106       
107       text_->set_grob_property ("text", result);
108     }
109 }
110
111 ENTER_DESCRIPTION(Metronome_mark_engraver,
112 /* descr */       "Engrave metro nome marking. This delegates the real work to the function in the metronomeMarkFormatter property",
113 /* creats*/       "MetronomeMark",
114 /* accepts */     "metronome-change-event",
115 /* acks  */       "time-signature-interface bar-line-interface",
116 /* reads */       "stavesFound metronomeMarkFormatter",
117 /* write */       "");