]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
* scripts/convert-ly.py (FatalConversionError.conv): add #'() case
[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   staff_ = 0;
49 }
50
51 void
52 Mark_engraver::acknowledge_grob (Grob_info inf)
53 {
54   Grob * s = inf.grob_;
55   if (text_ && Bar_line::has_interface (s))
56     {
57       /*
58       TODO: make this configurable. RehearsalMark cannot be
59       break-aligned, since the width of the object should not be taken
60       into alignment considerations.
61       */
62       text_->set_parent (s, X_AXIS);
63     }
64 }
65
66 void 
67 Mark_engraver::stop_translation_timestep ()
68 {
69   if (text_)
70     {
71       SCM lst = get_property ("stavesFound");
72       text_->set_property ("side-support-elements" , lst);
73       typeset_grob (text_);
74       text_ =0;
75     }
76   mark_ev_ = 0;
77 }
78
79
80 void
81 Mark_engraver::create_items (Music *ev)
82 {
83   if (text_)
84     return;
85
86   text_ = make_item ("RehearsalMark");
87   announce_grob (text_, ev->self_scm ());
88 }
89
90
91 bool
92 Mark_engraver::try_music (Music* r)
93 {
94   mark_ev_ = r;
95   return true;
96 }
97
98
99 /*
100   TODO: make the increment function in Scheme.
101 */
102 void
103 Mark_engraver::process_music ()
104 {
105   if (mark_ev_)
106     {
107       create_items (mark_ev_);
108
109       /*
110         automatic marks.
111        */
112
113       
114       SCM m = mark_ev_->get_property ("label");
115       SCM proc = get_property ("markFormatter");
116       if (!Text_item::markup_p (m) &&
117           gh_procedure_p (proc))
118         {
119           if (!gh_number_p (m)) 
120             m =  get_property ("rehearsalMark");
121
122           if (scm_integer_p (m) == SCM_BOOL_T
123               && scm_exact_p (m) == SCM_BOOL_T)
124             {
125               int mark_count = gh_scm2int (m);
126               mark_count ++;
127               daddy_context_->set_property ("rehearsalMark",
128                                             gh_int2scm (mark_count));
129             }
130
131           if (gh_number_p (m))
132             m = scm_call_2 (proc, m, daddy_context_->self_scm ());
133           else
134             warning ("rehearsalMark does not have integer value.");
135         }
136
137       if (Text_item::markup_p (m))
138         text_->set_property ("text", m);
139       else
140         warning ("Mark label should be markup object.");
141     }
142 }
143
144 ENTER_DESCRIPTION (Mark_engraver,
145 /* descr */       "This engraver will create RehearsalMark objects. "
146                    "It puts them on top of all staves (which is taken from "
147                    "the property @code{stavesFound}). If moving this engraver "
148                    "to a different context, "
149                    "@ref{Staff_collecting_engraver} must move along, otherwise all marks"
150                    "end up on the same Y-location"
151                    ,
152 /* creats*/       "RehearsalMark",
153 /* accepts */     "mark-event",
154 /* acks  */       "bar-line-interface",
155 /* reads */       "rehearsalMark markFormatter stavesFound",
156 /* write */       "");