]> git.donarmstrong.com Git - lilypond.git/blob - lily/cue-clef-engraver.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / cue-clef-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5                            Mats Bengtsson <matsb@s3.kth.se>
6   Copyright (C) 2010--2014 Reinhold Kainhofer <reinhold@kainhofer.com>
7
8   LilyPond is free software: you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation, either version 3 of the License, or
11   (at your option) any later version.
12
13   LilyPond is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include <cctype>
23 using namespace std;
24
25 #include "item.hh"
26 #include "context.hh"
27 #include "staff-symbol-referencer.hh"
28 #include "engraver.hh"
29 #include "direction.hh"
30 #include "side-position-interface.hh"
31 #include "warn.hh"
32 #include "international.hh"
33
34 #include "translator.icc"
35
36 class Cue_clef_engraver : public Engraver
37 {
38 public:
39   TRANSLATOR_DECLARATIONS (Cue_clef_engraver);
40
41 protected:
42   void stop_translation_timestep ();
43   void process_music ();
44   DECLARE_ACKNOWLEDGER (bar_line);
45
46   virtual void derived_mark () const;
47 private:
48   Item *clef_;
49   Item *modifier_;
50
51   SCM prev_glyph_;
52   SCM prev_cpos_;
53   SCM prev_transposition_;
54   void create_clef ();
55   void create_end_clef ();
56   void set_glyph ();
57   void inspect_clef_properties ();
58   void create_clef_modifier (SCM oct);
59 };
60
61 void
62 Cue_clef_engraver::derived_mark () const
63 {
64   scm_gc_mark (prev_transposition_);
65   scm_gc_mark (prev_cpos_);
66   scm_gc_mark (prev_glyph_);
67 }
68
69 Cue_clef_engraver::Cue_clef_engraver ()
70 {
71   clef_ = 0;
72   modifier_ = 0;
73
74   prev_transposition_ = prev_cpos_ = prev_glyph_ = SCM_EOL;
75 }
76
77 void
78 Cue_clef_engraver::set_glyph ()
79 {
80   SCM glyph_sym = ly_symbol2scm ("glyph");
81   SCM basic = ly_symbol2scm ("CueClef");
82   execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED);
83   execute_pushpop_property (context (), basic, glyph_sym, get_property ("cueClefGlyph"));
84
85   basic = ly_symbol2scm ("CueEndClef");
86   execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED);
87   execute_pushpop_property (context (), basic, glyph_sym, get_property ("clefGlyph"));
88 }
89
90 /**
91    Generate a clef at the start of a measure. (when you see a Bar,
92    ie. a breakpoint)
93 */
94 void
95 Cue_clef_engraver::acknowledge_bar_line (Grob_info info)
96 {
97   Item *item = info.item ();
98   if (item && scm_is_string (get_property ("cueClefGlyph")))
99     create_clef ();
100 }
101
102 void
103 Cue_clef_engraver::create_clef_modifier (SCM transp)
104 {
105   if (scm_is_number (transp) && scm_to_int (transp))
106     {
107       Item *g = make_item ("ClefModifier", SCM_EOL);
108
109       int abs_transp = scm_to_int (transp);
110       int dir = sign (abs_transp);
111       abs_transp = abs (abs_transp) + 1;
112
113       SCM txt = scm_number_to_string (scm_from_int (abs_transp),
114                                       scm_from_int (10));
115
116       SCM style = get_property ("cueClefTranspositionStyle");
117
118       SCM formatter = get_property ("cueClefTranspositionFormatter");
119       if (ly_is_procedure (formatter))
120         g->set_property ("text", scm_call_2 (formatter, txt, style));
121
122       Side_position_interface::add_support (g, clef_);
123
124       g->set_parent (clef_, Y_AXIS);
125       g->set_parent (clef_, X_AXIS);
126       g->set_property ("direction", scm_from_int (dir));
127       modifier_ = g;
128     }
129 }
130
131 void
132 Cue_clef_engraver::create_clef ()
133 {
134   if (!clef_)
135     {
136       Item *c = make_item ("CueClef", SCM_EOL);
137
138       clef_ = c;
139       SCM cpos = get_property ("cueClefPosition");
140       if (scm_is_number (cpos))
141         clef_->set_property ("staff-position", cpos);
142
143       create_clef_modifier (get_property ("cueClefTransposition"));
144     }
145 }
146
147 void
148 Cue_clef_engraver::create_end_clef ()
149 {
150   if (!clef_)
151     {
152       clef_ = make_item ("CueEndClef", SCM_EOL);
153       SCM cpos = get_property ("clefPosition");
154       if (scm_is_number (cpos))
155         clef_->set_property ("staff-position", cpos);
156
157       create_clef_modifier (get_property ("clefTransposition"));
158     }
159 }
160
161 void
162 Cue_clef_engraver::process_music ()
163 {
164   inspect_clef_properties ();
165 }
166
167 void
168 Cue_clef_engraver::inspect_clef_properties ()
169 {
170   SCM glyph = get_property ("cueClefGlyph");
171   SCM clefpos = get_property ("cueClefPosition");
172   SCM transposition = get_property ("cueClefTransposition");
173
174   if (scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
175       || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
176       || scm_equal_p (transposition, prev_transposition_) == SCM_BOOL_F)
177     {
178       set_glyph ();
179       if (scm_is_string (glyph))
180         {
181           create_clef ();
182           if (clef_)
183             clef_->set_property ("non-default", SCM_BOOL_T);
184         }
185       else
186         create_end_clef ();
187
188       prev_cpos_ = clefpos;
189       prev_glyph_ = glyph;
190       prev_transposition_ = transposition;
191     }
192
193 }
194
195 void
196 Cue_clef_engraver::stop_translation_timestep ()
197 {
198   if (clef_)
199     {
200       SCM vis = 0;
201       if (to_boolean (clef_->get_property ("non-default")))
202         vis = get_property ("explicitCueClefVisibility");
203
204       if (vis)
205         clef_->set_property ("break-visibility", vis);
206
207       clef_ = 0;
208       modifier_ = 0;
209     }
210 }
211
212 ADD_ACKNOWLEDGER (Cue_clef_engraver, bar_line);
213 ADD_TRANSLATOR (Cue_clef_engraver,
214                 /* doc */
215                 "Determine and set reference point for pitches in cued voices.",
216
217                 /* create */
218                 "CueClef "
219                 "CueEndClef "
220                 "ClefModifier ",
221
222                 /* read */
223                 "cueClefGlyph "
224                 "cueClefTransposition "
225                 "cueClefTranspositionStyle "
226                 "cueClefPosition "
227                 "explicitCueClefVisibility "
228                 "middleCCuePosition "
229                 "clefTransposition ",
230
231                 /* write */
232                 ""
233                );