]> git.donarmstrong.com Git - lilypond.git/blob - lily/cue-clef-engraver.cc
Issue 4550 (2/2) Avoid "using namespace std;" in included files
[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
24 #include "item.hh"
25 #include "context.hh"
26 #include "staff-symbol-referencer.hh"
27 #include "engraver.hh"
28 #include "direction.hh"
29 #include "side-position-interface.hh"
30 #include "warn.hh"
31 #include "international.hh"
32
33 #include "translator.icc"
34
35 class Cue_clef_engraver : public Engraver
36 {
37 public:
38   TRANSLATOR_DECLARATIONS (Cue_clef_engraver);
39
40 protected:
41   void stop_translation_timestep ();
42   void process_music ();
43   DECLARE_ACKNOWLEDGER (bar_line);
44
45   virtual void derived_mark () const;
46 private:
47   Item *clef_;
48   Item *modifier_;
49
50   SCM prev_glyph_;
51   SCM prev_cpos_;
52   SCM prev_transposition_;
53   void create_clef ();
54   void create_end_clef ();
55   void set_glyph ();
56   void inspect_clef_properties ();
57   void create_clef_modifier (SCM oct);
58 };
59
60 void
61 Cue_clef_engraver::derived_mark () const
62 {
63   scm_gc_mark (prev_transposition_);
64   scm_gc_mark (prev_cpos_);
65   scm_gc_mark (prev_glyph_);
66 }
67
68 Cue_clef_engraver::Cue_clef_engraver ()
69 {
70   clef_ = 0;
71   modifier_ = 0;
72
73   prev_transposition_ = prev_cpos_ = prev_glyph_ = SCM_EOL;
74 }
75
76 void
77 Cue_clef_engraver::set_glyph ()
78 {
79   SCM glyph_sym = ly_symbol2scm ("glyph");
80   SCM basic = ly_symbol2scm ("CueClef");
81   execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED);
82   execute_pushpop_property (context (), basic, glyph_sym, get_property ("cueClefGlyph"));
83
84   basic = ly_symbol2scm ("CueEndClef");
85   execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED);
86   execute_pushpop_property (context (), basic, glyph_sym, get_property ("clefGlyph"));
87 }
88
89 /**
90    Generate a clef at the start of a measure. (when you see a Bar,
91    ie. a breakpoint)
92 */
93 void
94 Cue_clef_engraver::acknowledge_bar_line (Grob_info info)
95 {
96   Item *item = info.item ();
97   if (item && scm_is_string (get_property ("cueClefGlyph")))
98     create_clef ();
99 }
100
101 void
102 Cue_clef_engraver::create_clef_modifier (SCM transp)
103 {
104   if (scm_is_number (transp) && scm_to_int (transp))
105     {
106       Item *g = make_item ("ClefModifier", SCM_EOL);
107
108       int abs_transp = scm_to_int (transp);
109       int dir = sign (abs_transp);
110       abs_transp = abs (abs_transp) + 1;
111
112       SCM txt = scm_number_to_string (scm_from_int (abs_transp),
113                                       scm_from_int (10));
114
115       SCM style = get_property ("cueClefTranspositionStyle");
116
117       SCM formatter = get_property ("cueClefTranspositionFormatter");
118       if (ly_is_procedure (formatter))
119         g->set_property ("text", scm_call_2 (formatter, txt, style));
120
121       Side_position_interface::add_support (g, clef_);
122
123       g->set_parent (clef_, Y_AXIS);
124       g->set_parent (clef_, X_AXIS);
125       g->set_property ("direction", scm_from_int (dir));
126       modifier_ = g;
127     }
128 }
129
130 void
131 Cue_clef_engraver::create_clef ()
132 {
133   if (!clef_)
134     {
135       Item *c = make_item ("CueClef", SCM_EOL);
136
137       clef_ = c;
138       SCM cpos = get_property ("cueClefPosition");
139       if (scm_is_number (cpos))
140         clef_->set_property ("staff-position", cpos);
141
142       create_clef_modifier (get_property ("cueClefTransposition"));
143     }
144 }
145
146 void
147 Cue_clef_engraver::create_end_clef ()
148 {
149   if (!clef_)
150     {
151       clef_ = make_item ("CueEndClef", SCM_EOL);
152       SCM cpos = get_property ("clefPosition");
153       if (scm_is_number (cpos))
154         clef_->set_property ("staff-position", cpos);
155
156       create_clef_modifier (get_property ("clefTransposition"));
157     }
158 }
159
160 void
161 Cue_clef_engraver::process_music ()
162 {
163   inspect_clef_properties ();
164 }
165
166 void
167 Cue_clef_engraver::inspect_clef_properties ()
168 {
169   SCM glyph = get_property ("cueClefGlyph");
170   SCM clefpos = get_property ("cueClefPosition");
171   SCM transposition = get_property ("cueClefTransposition");
172
173   if (!ly_is_equal (glyph, prev_glyph_)
174       || !ly_is_equal (clefpos, prev_cpos_)
175       || !ly_is_equal (transposition, prev_transposition_))
176     {
177       set_glyph ();
178       if (scm_is_string (glyph))
179         {
180           create_clef ();
181           if (clef_)
182             clef_->set_property ("non-default", SCM_BOOL_T);
183         }
184       else
185         create_end_clef ();
186
187       prev_cpos_ = clefpos;
188       prev_glyph_ = glyph;
189       prev_transposition_ = transposition;
190     }
191
192 }
193
194 void
195 Cue_clef_engraver::stop_translation_timestep ()
196 {
197   if (clef_)
198     {
199       SCM vis = 0;
200       if (to_boolean (clef_->get_property ("non-default")))
201         vis = get_property ("explicitCueClefVisibility");
202
203       if (vis)
204         clef_->set_property ("break-visibility", vis);
205
206       clef_ = 0;
207       modifier_ = 0;
208     }
209 }
210
211 ADD_ACKNOWLEDGER (Cue_clef_engraver, bar_line);
212 ADD_TRANSLATOR (Cue_clef_engraver,
213                 /* doc */
214                 "Determine and set reference point for pitches in cued voices.",
215
216                 /* create */
217                 "CueClef "
218                 "CueEndClef "
219                 "ClefModifier ",
220
221                 /* read */
222                 "cueClefGlyph "
223                 "cueClefTransposition "
224                 "cueClefTranspositionStyle "
225                 "cueClefPosition "
226                 "explicitCueClefVisibility "
227                 "middleCCuePosition "
228                 "clefTransposition ",
229
230                 /* write */
231                 ""
232                );