]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
Fix some bugs in the dynamic engraver and PostScript backend
[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_alignment);
43   DECLARE_ACKNOWLEDGER (break_aligned);
44 };
45
46 Mark_engraver::Mark_engraver ()
47 {
48   text_ = 0;
49   mark_ev_ = 0;
50 }
51
52 /*
53   This is a flawed approach, since various break-aligned objects may
54   not appear depending on key signature etc.
55
56    We keep it in case someone puts the engraver in a lower context than score.
57  */
58 void
59 Mark_engraver::acknowledge_break_aligned (Grob_info inf)
60 {
61   Grob *s = inf.grob ();
62   if (text_
63       && !text_->get_parent (X_AXIS)
64       && (text_->get_property_data (ly_symbol2scm ("break-align-symbol"))
65           == s->get_property_data (ly_symbol2scm ("break-align-symbol")))
66       && Axis_group_interface::has_interface (s))
67     {
68       /*
69         RehearsalMark cannot be break-aligned, since the width of the
70         object should not be taken into alignment considerations.
71       */
72       text_->set_parent (s, X_AXIS);
73     }
74 }
75
76 void
77 Mark_engraver::acknowledge_break_alignment (Grob_info inf)
78 {
79   Grob *s = inf.grob ();
80   if (text_
81       && dynamic_cast<Item *> (s))
82     {
83       text_->set_parent (s, X_AXIS);
84     }
85 }
86
87
88 void
89 Mark_engraver::stop_translation_timestep ()
90 {
91   if (text_)
92     {
93       text_->set_object ("side-support-elements",
94                          grob_list_to_grob_array (get_property ("stavesFound")));
95       text_ = 0;
96     }
97   mark_ev_ = 0;
98 }
99
100 void
101 Mark_engraver::create_items (Music *ev)
102 {
103   if (text_)
104     return;
105
106   text_ = make_item ("RehearsalMark", ev->self_scm ());
107 }
108
109 bool
110 Mark_engraver::try_music (Music *r)
111 {
112   mark_ev_ = r;
113   return true;
114 }
115
116 /*
117   TODO: make the increment function in Scheme.
118 */
119 void
120 Mark_engraver::process_music ()
121 {
122   if (mark_ev_)
123     {
124       create_items (mark_ev_);
125
126       /*
127         automatic marks.
128       */
129
130       SCM m = mark_ev_->get_property ("label");
131       SCM proc = get_property ("markFormatter");
132       if (!Text_interface::is_markup (m)
133           && ly_is_procedure (proc))
134         {
135           if (!scm_is_number (m))
136             m = get_property ("rehearsalMark");
137
138           if (scm_integer_p (m) == SCM_BOOL_T
139               && scm_exact_p (m) == SCM_BOOL_T)
140             {
141               int mark_count = scm_to_int (m);
142               mark_count++;
143               context ()->set_property ("rehearsalMark",
144                                         scm_from_int (mark_count));
145             }
146
147           if (scm_is_number (m))
148             m = scm_call_2 (proc, m, context ()->self_scm ());
149           else
150             /* FIXME: constant error message.  */
151             warning (_ ("rehearsalMark must have integer value"));
152         }
153
154       if (Text_interface::is_markup (m))
155         text_->set_property ("text", m);
156       else
157         warning (_ ("mark label must be a markup object"));
158     }
159 }
160
161 #include "translator.icc"
162
163 ADD_ACKNOWLEDGER (Mark_engraver, break_aligned);
164 ADD_ACKNOWLEDGER (Mark_engraver, break_alignment);
165
166 ADD_TRANSLATOR (Mark_engraver,
167                 /* doc */ "This engraver will create RehearsalMark objects. "
168                 "It puts them on top of all staves (which is taken from "
169                 "the property @code{stavesFound}). If moving this engraver "
170                 "to a different context, "
171                 "@ref{Staff_collecting_engraver} must move along, otherwise all marks"
172                 "end up on the same Y-location",
173                 
174                 /* create */ "RehearsalMark",
175                 /* accept */ "mark-event",
176                 /* read */
177                 "markFormatter "
178                 "rehearsalMark "
179                 "stavesFound ",
180                 
181                 /* write */ "");