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