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