]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
* lily/include/translator.icc (ADD_ACKNOWLEDGER): new macro.
[lilypond.git] / lily / mark-engraver.cc
1 /*
2   mark-engraver.cc -- implement 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 "bar-line.hh"
12 #include "context.hh"
13 #include "engraver-group-engraver.hh"
14 #include "item.hh"
15 #include "warn.hh"
16 #include "text-interface.hh"
17
18 /**
19    put stuff over or next to  bars.  Examples: bar numbers, marginal notes,
20    rehearsal marks.
21 */
22 class Mark_engraver : public Engraver
23 {
24 public:
25   TRANSLATOR_DECLARATIONS (Mark_engraver);
26 protected:
27   Item *text_;
28 protected:
29   PRECOMPUTED_VIRTUAL void stop_translation_timestep ();
30   DECLARE_ACKNOWLEDGER(bar_line);
31   void create_items (Music *);
32   virtual bool try_music (Music *ev);
33   PRECOMPUTED_VIRTUAL void process_music ();
34
35 private:
36   Music *mark_ev_;
37 };
38
39 Mark_engraver::Mark_engraver ()
40 {
41   text_ = 0;
42   mark_ev_ = 0;
43 }
44
45 void
46 Mark_engraver::acknowledge_bar_line (Grob_info inf)
47 {
48   Grob *s = inf.grob ();
49   if (text_)
50     {
51       /*
52         TODO: make this configurable. RehearsalMark cannot be
53         break-aligned, since the width of the object should not be taken
54         into alignment considerations.
55       */
56       text_->set_parent (s, X_AXIS);
57     }
58 }
59
60 void
61 Mark_engraver::stop_translation_timestep ()
62 {
63   if (text_)
64     {
65       SCM lst = get_property ("stavesFound");
66       text_->set_object ("side-support-elements", lst);
67       text_ = 0;
68     }
69   mark_ev_ = 0;
70 }
71
72 void
73 Mark_engraver::create_items (Music *ev)
74 {
75   if (text_)
76     return;
77
78   text_ = make_item ("RehearsalMark", ev->self_scm ());
79 }
80
81 bool
82 Mark_engraver::try_music (Music *r)
83 {
84   mark_ev_ = r;
85   return true;
86 }
87
88 /*
89   TODO: make the increment function in Scheme.
90 */
91 void
92 Mark_engraver::process_music ()
93 {
94   if (mark_ev_)
95     {
96       create_items (mark_ev_);
97
98       /*
99         automatic marks.
100       */
101
102       SCM m = mark_ev_->get_property ("label");
103       SCM proc = get_property ("markFormatter");
104       if (!Text_interface::markup_p (m)
105           && ly_is_procedure (proc))
106         {
107           if (!scm_is_number (m))
108             m = get_property ("rehearsalMark");
109
110           if (scm_integer_p (m) == SCM_BOOL_T
111               && scm_exact_p (m) == SCM_BOOL_T)
112             {
113               int mark_count = scm_to_int (m);
114               mark_count++;
115               context ()->set_property ("rehearsalMark",
116                                         scm_int2num (mark_count));
117             }
118
119           if (scm_is_number (m))
120             m = scm_call_2 (proc, m, context ()->self_scm ());
121           else
122             /* FIXME: constant error message.  */
123             warning (_ ("rehearsalMark must have integer value"));
124         }
125
126       if (Text_interface::markup_p (m))
127         text_->set_property ("text", m);
128       else
129         warning (_ ("mark label must be a markup object"));
130     }
131 }
132
133 #include "translator.icc"
134
135 ADD_ACKNOWLEDGER(Mark_engraver,bar_line);
136 ADD_TRANSLATOR (Mark_engraver,
137                 /* descr */ "This engraver will create RehearsalMark objects. "
138                 "It puts them on top of all staves (which is taken from "
139                 "the property @code{stavesFound}). If moving this engraver "
140                 "to a different context, "
141                 "@ref{Staff_collecting_engraver} must move along, otherwise all marks"
142                 "end up on the same Y-location",
143                 /* creats*/ "RehearsalMark",
144                 /* accepts */ "mark-event",
145                 /* acks  */ "",
146                 /* reads */ "rehearsalMark markFormatter stavesFound",
147                 /* write */ "");