]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
Merge branch 'master' of git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond
[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--2007 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 "stream-event.hh"
21 #include "text-interface.hh"
22 #include "warn.hh"
23
24 #include "translator.icc"
25
26 /**
27    put stuff over or next to  bars.  Examples: bar numbers, marginal notes,
28    rehearsal marks.
29 */
30 class Mark_engraver : public Engraver
31 {
32
33   void create_items (Stream_event *);
34   Item *text_;
35   Stream_event *mark_ev_;
36
37 public:
38   TRANSLATOR_DECLARATIONS (Mark_engraver);
39
40 protected:
41   void process_music ();
42   void stop_translation_timestep ();
43
44   DECLARE_TRANSLATOR_LISTENER (mark);
45   DECLARE_ACKNOWLEDGER (break_alignment);
46   DECLARE_ACKNOWLEDGER (break_aligned);
47 };
48
49 Mark_engraver::Mark_engraver ()
50 {
51   text_ = 0;
52   mark_ev_ = 0;
53 }
54
55 /*
56   This is a flawed approach, since various break-aligned objects may
57   not appear depending on key signature etc.
58
59    We keep it in case someone puts the engraver in a lower context than score.
60  */
61 void
62 Mark_engraver::acknowledge_break_aligned (Grob_info inf)
63 {
64   Grob *s = inf.grob ();
65   if (text_
66       && !text_->get_parent (X_AXIS)
67       && (text_->get_property_data ("break-align-symbol")
68           == s->get_property_data ("break-align-symbol"))
69       && Axis_group_interface::has_interface (s))
70     {
71       /*
72         RehearsalMark cannot be break-aligned, since the width of the
73         object should not be taken into alignment considerations.
74       */
75       text_->set_parent (s, X_AXIS);
76     }
77 }
78
79 void
80 Mark_engraver::acknowledge_break_alignment (Grob_info inf)
81 {
82   Grob *s = inf.grob ();
83   if (text_
84       && dynamic_cast<Item *> (s))
85     {
86       text_->set_parent (s, X_AXIS);
87     }
88 }
89
90
91 void
92 Mark_engraver::stop_translation_timestep ()
93 {
94   text_ = 0;
95   mark_ev_ = 0;
96 }
97
98 void
99 Mark_engraver::create_items (Stream_event *ev)
100 {
101   if (text_)
102     return;
103
104   text_ = make_item ("RehearsalMark", ev->self_scm ());
105 }
106
107 IMPLEMENT_TRANSLATOR_LISTENER (Mark_engraver, mark);
108 void
109 Mark_engraver::listen_mark (Stream_event *ev)
110 {
111   ASSIGN_EVENT_ONCE (mark_ev_, ev);
112 }
113
114 /*
115   TODO: make the increment function in Scheme.
116 */
117 void
118 Mark_engraver::process_music ()
119 {
120   if (mark_ev_)
121     {
122       create_items (mark_ev_);
123
124       /*
125         automatic marks.
126       */
127
128       SCM m = mark_ev_->get_property ("label");
129       SCM proc = get_property ("markFormatter");
130       if (!Text_interface::is_markup (m)
131           && ly_is_procedure (proc))
132         {
133           if (!scm_is_number (m))
134             m = get_property ("rehearsalMark");
135
136           if (scm_integer_p (m) == SCM_BOOL_T
137               && scm_exact_p (m) == SCM_BOOL_T)
138             {
139               int mark_count = scm_to_int (m);
140               mark_count++;
141               context ()->set_property ("rehearsalMark",
142                                         scm_from_int (mark_count));
143             }
144
145           if (scm_is_number (m))
146             m = scm_call_2 (proc, m, context ()->self_scm ());
147           else
148             /* FIXME: constant error message.  */
149             warning (_ ("rehearsalMark must have integer value"));
150         }
151
152       if (Text_interface::is_markup (m))
153         text_->set_property ("text", m);
154       else
155         warning (_ ("mark label must be a markup object"));
156     }
157 }
158
159 ADD_ACKNOWLEDGER (Mark_engraver, break_aligned);
160 ADD_ACKNOWLEDGER (Mark_engraver, break_alignment);
161
162 ADD_TRANSLATOR (Mark_engraver,
163                 /* doc */ "This engraver will create RehearsalMark objects. "
164                 "It puts them on top of all staves (which is taken from "
165                 "the property @code{stavesFound}). If moving this engraver "
166                 "to a different context, "
167                 "@ref{Staff_collecting_engraver} must move along, otherwise all marks"
168                 "end up on the same Y-location",
169                 
170                 /* create */ "RehearsalMark",
171                 /* read */
172                 "markFormatter "
173                 "rehearsalMark "
174                 "stavesFound ",
175                 
176                 /* write */ "");