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