]> git.donarmstrong.com Git - lilypond.git/blob - lily/cue-clef-engraver.cc
Web-ja: update introduction
[lilypond.git] / lily / cue-clef-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5                            Mats Bengtsson <matsb@s3.kth.se>
6   Copyright (C) 2010--2015 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   void acknowledge_bar_line (Grob_info);
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 (Context *c)
70   : Engraver (c)
71 {
72   clef_ = 0;
73   modifier_ = 0;
74
75   prev_transposition_ = prev_cpos_ = prev_glyph_ = SCM_EOL;
76 }
77
78 void
79 Cue_clef_engraver::set_glyph ()
80 {
81   SCM glyph_sym = ly_symbol2scm ("glyph");
82   SCM basic = ly_symbol2scm ("CueClef");
83   execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED);
84   execute_pushpop_property (context (), basic, glyph_sym, get_property ("cueClefGlyph"));
85
86   basic = ly_symbol2scm ("CueEndClef");
87   execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED);
88   execute_pushpop_property (context (), basic, glyph_sym, get_property ("clefGlyph"));
89 }
90
91 /**
92    Generate a clef at the start of a measure. (when you see a Bar,
93    ie. a breakpoint)
94 */
95 void
96 Cue_clef_engraver::acknowledge_bar_line (Grob_info info)
97 {
98   Item *item = info.item ();
99   if (item && scm_is_string (get_property ("cueClefGlyph")))
100     create_clef ();
101 }
102
103 void
104 Cue_clef_engraver::create_clef_modifier (SCM transp)
105 {
106   if (scm_is_number (transp) && scm_to_int (transp))
107     {
108       Item *g = make_item ("ClefModifier", SCM_EOL);
109
110       int abs_transp = scm_to_int (transp);
111       int dir = sign (abs_transp);
112       abs_transp = abs (abs_transp) + 1;
113
114       SCM txt = scm_number_to_string (scm_from_int (abs_transp),
115                                       scm_from_int (10));
116
117       SCM style = get_property ("cueClefTranspositionStyle");
118
119       SCM formatter = get_property ("cueClefTranspositionFormatter");
120       if (ly_is_procedure (formatter))
121         g->set_property ("text", scm_call_2 (formatter, txt, style));
122
123       Side_position_interface::add_support (g, clef_);
124
125       g->set_parent (clef_, Y_AXIS);
126       g->set_parent (clef_, X_AXIS);
127       g->set_property ("direction", scm_from_int (dir));
128       modifier_ = g;
129     }
130 }
131
132 void
133 Cue_clef_engraver::create_clef ()
134 {
135   if (!clef_)
136     {
137       Item *c = make_item ("CueClef", SCM_EOL);
138
139       clef_ = c;
140       SCM cpos = get_property ("cueClefPosition");
141       if (scm_is_number (cpos))
142         clef_->set_property ("staff-position", cpos);
143
144       create_clef_modifier (get_property ("cueClefTransposition"));
145     }
146 }
147
148 void
149 Cue_clef_engraver::create_end_clef ()
150 {
151   if (!clef_)
152     {
153       clef_ = make_item ("CueEndClef", SCM_EOL);
154       SCM cpos = get_property ("clefPosition");
155       if (scm_is_number (cpos))
156         clef_->set_property ("staff-position", cpos);
157
158       create_clef_modifier (get_property ("clefTransposition"));
159     }
160 }
161
162 void
163 Cue_clef_engraver::process_music ()
164 {
165   inspect_clef_properties ();
166 }
167
168 void
169 Cue_clef_engraver::inspect_clef_properties ()
170 {
171   SCM glyph = get_property ("cueClefGlyph");
172   SCM clefpos = get_property ("cueClefPosition");
173   SCM transposition = get_property ("cueClefTransposition");
174
175   if (!ly_is_equal (glyph, prev_glyph_)
176       || !ly_is_equal (clefpos, prev_cpos_)
177       || !ly_is_equal (transposition, prev_transposition_))
178     {
179       set_glyph ();
180       if (scm_is_string (glyph))
181         {
182           create_clef ();
183           if (clef_)
184             clef_->set_property ("non-default", SCM_BOOL_T);
185         }
186       else
187         create_end_clef ();
188
189       prev_cpos_ = clefpos;
190       prev_glyph_ = glyph;
191       prev_transposition_ = transposition;
192     }
193
194 }
195
196 void
197 Cue_clef_engraver::stop_translation_timestep ()
198 {
199   if (clef_)
200     {
201       if (to_boolean (clef_->get_property ("non-default")))
202         {
203           SCM vis = get_property ("explicitCueClefVisibility");
204
205           if (scm_is_vector (vis))
206             clef_->set_property ("break-visibility", vis);
207         }
208
209       clef_ = 0;
210       modifier_ = 0;
211     }
212 }
213
214 void
215 Cue_clef_engraver::boot ()
216 {
217   ADD_ACKNOWLEDGER (Cue_clef_engraver, bar_line);
218 }
219
220 ADD_TRANSLATOR (Cue_clef_engraver,
221                 /* doc */
222                 "Determine and set reference point for pitches in cued voices.",
223
224                 /* create */
225                 "CueClef "
226                 "CueEndClef "
227                 "ClefModifier ",
228
229                 /* read */
230                 "cueClefGlyph "
231                 "cueClefTransposition "
232                 "cueClefTranspositionStyle "
233                 "cueClefPosition "
234                 "explicitCueClefVisibility "
235                 "middleCCuePosition "
236                 "clefTransposition ",
237
238                 /* write */
239                 ""
240                );