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