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