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