]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
51add1233e0c72ff1ae1d0833c167db3944509d8
[lilypond.git] / lily / mark-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1998--2015 Jan Nieuwenhuizen <janneke@gnu.org>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <cctype>
21
22 #include "engraver.hh"
23
24 #include "axis-group-interface.hh"
25 #include "context.hh"
26 #include "grob-array.hh"
27 #include "international.hh"
28 #include "item.hh"
29 #include "stream-event.hh"
30 #include "text-interface.hh"
31 #include "warn.hh"
32
33 #include "translator.icc"
34
35 /**
36    put stuff over or next to  bars.  Examples: bar numbers, marginal notes,
37    rehearsal marks.
38 */
39 class Mark_engraver : public Engraver
40 {
41
42   void create_items (Stream_event *);
43   Item *text_;
44   Item *final_text_;
45   Stream_event *mark_ev_;
46
47 public:
48   TRANSLATOR_DECLARATIONS (Mark_engraver);
49
50 protected:
51   void process_music ();
52   void start_translation_timestep ();
53   void stop_translation_timestep ();
54   virtual void finalize ();
55
56   DECLARE_TRANSLATOR_LISTENER (mark);
57   DECLARE_ACKNOWLEDGER (break_alignment);
58 };
59
60 Mark_engraver::Mark_engraver ()
61 {
62   text_ = 0;
63   final_text_ = 0;
64   mark_ev_ = 0;
65 }
66
67 void
68 Mark_engraver::acknowledge_break_alignment (Grob_info inf)
69 {
70   Grob *s = inf.grob ();
71   if (text_
72       && dynamic_cast<Item *> (s))
73     text_->set_parent (s, X_AXIS);
74 }
75
76 void
77 Mark_engraver::start_translation_timestep ()
78 {
79   final_text_ = 0;
80 }
81
82 void
83 Mark_engraver::stop_translation_timestep ()
84 {
85   if (text_)
86     {
87       text_->set_object ("side-support-elements",
88                          grob_list_to_grob_array (get_property ("stavesFound")));
89       final_text_ = text_;
90       text_ = 0;
91     }
92   mark_ev_ = 0;
93 }
94
95 void
96 Mark_engraver::finalize ()
97 {
98   if (final_text_)
99     final_text_->set_property ("break-visibility",
100                                scm_c_make_vector (3, SCM_BOOL_T));
101   final_text_ = 0;
102 }
103
104 void
105 Mark_engraver::create_items (Stream_event *ev)
106 {
107   if (text_)
108     return;
109
110   text_ = make_item ("RehearsalMark", ev->self_scm ());
111 }
112
113 IMPLEMENT_TRANSLATOR_LISTENER (Mark_engraver, mark);
114 void
115 Mark_engraver::listen_mark (Stream_event *ev)
116 {
117   ASSIGN_EVENT_ONCE (mark_ev_, ev);
118 }
119
120 /*
121   TODO: make the increment function in Scheme.
122 */
123 void
124 Mark_engraver::process_music ()
125 {
126   if (mark_ev_)
127     {
128       create_items (mark_ev_);
129
130       /*
131         automatic marks.
132       */
133
134       SCM m = mark_ev_->get_property ("label");
135       SCM proc = get_property ("markFormatter");
136       if (!Text_interface::is_markup (m)
137           && ly_is_procedure (proc))
138         {
139           if (!scm_is_number (m))
140             m = get_property ("rehearsalMark");
141
142           if (scm_is_number (m))
143             {
144               context ()->set_property ("rehearsalMark", scm_oneplus (m));
145               m = scm_call_2 (proc, m, context ()->self_scm ());
146             }
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_alignment);
160
161 ADD_TRANSLATOR (Mark_engraver,
162                 /* doc */
163                 "Create @code{RehearsalMark} objects.  It puts them on top of"
164                 " all staves (which is taken from the property"
165                 " @code{stavesFound}).  If moving this engraver to a different"
166                 " context, @ref{Staff_collecting_engraver} must move along,"
167                 " otherwise all marks end up on the same Y@tie{}location.",
168
169                 /* create */
170                 "RehearsalMark ",
171
172                 /* read */
173                 "markFormatter "
174                 "rehearsalMark "
175                 "stavesFound ",
176
177                 /* write */
178                 ""
179                );