]> git.donarmstrong.com Git - lilypond.git/blob - lily/cue-clef-engraver.cc
Doc-fr: update for 2.16.1 (second part)
[lilypond.git] / lily / cue-clef-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
5                            Mats Bengtsson <matsb@s3.kth.se>
6   Copyright (C) 2010--2012 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 *octavate_;
50
51   SCM prev_glyph_;
52   SCM prev_cpos_;
53   SCM prev_octavation_;
54   void create_clef ();
55   void create_end_clef ();
56   void set_glyph ();
57   void inspect_clef_properties ();
58   void create_octavate_eight (SCM oct);
59 };
60
61 void
62 Cue_clef_engraver::derived_mark () const
63 {
64   scm_gc_mark (prev_octavation_);
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   octavate_ = 0;
73
74   prev_octavation_ = 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_octavate_eight (SCM oct)
104 {
105   if (scm_is_number (oct) && scm_to_int (oct))
106     {
107       Item *g = make_item ("OctavateEight", SCM_EOL);
108
109       int abs_oct = scm_to_int (oct);
110       int dir = sign (abs_oct);
111       abs_oct = abs (abs_oct) + 1;
112
113       SCM txt = scm_number_to_string (scm_from_int (abs_oct),
114                                       scm_from_int (10));
115
116       g->set_property ("text",
117                        scm_list_n (ly_lily_module_constant ("vcenter-markup"),
118                                    txt, SCM_UNDEFINED));
119       Side_position_interface::add_support (g, clef_);
120
121       g->set_parent (clef_, Y_AXIS);
122       g->set_parent (clef_, X_AXIS);
123       g->set_property ("direction", scm_from_int (dir));
124       octavate_ = g;
125     }
126 }
127
128 void
129 Cue_clef_engraver::create_clef ()
130 {
131   if (!clef_)
132     {
133       Item *c = make_item ("CueClef", SCM_EOL);
134
135       clef_ = c;
136       SCM cpos = get_property ("cueClefPosition");
137       if (scm_is_number (cpos))
138         clef_->set_property ("staff-position", cpos);
139
140       create_octavate_eight (get_property ("cueClefOctavation"));
141     }
142 }
143
144 void
145 Cue_clef_engraver::create_end_clef ()
146 {
147   if (!clef_)
148     {
149       clef_ = make_item ("CueEndClef", SCM_EOL);
150       SCM cpos = get_property ("clefPosition");
151       if (scm_is_number (cpos))
152         clef_->set_property ("staff-position", cpos);
153
154       create_octavate_eight (get_property ("clefOctavation"));
155     }
156 }
157
158 void
159 Cue_clef_engraver::process_music ()
160 {
161   inspect_clef_properties ();
162 }
163
164 void
165 Cue_clef_engraver::inspect_clef_properties ()
166 {
167   SCM glyph = get_property ("cueClefGlyph");
168   SCM clefpos = get_property ("cueClefPosition");
169   SCM octavation = get_property ("cueClefOctavation");
170
171   if (scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
172       || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
173       || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F)
174     {
175       set_glyph ();
176       if (scm_is_string (glyph))
177         {
178           create_clef ();
179           if (clef_)
180             clef_->set_property ("non-default", SCM_BOOL_T);
181         }
182       else
183         create_end_clef ();
184
185       prev_cpos_ = clefpos;
186       prev_glyph_ = glyph;
187       prev_octavation_ = octavation;
188     }
189
190 }
191
192 void
193 Cue_clef_engraver::stop_translation_timestep ()
194 {
195   if (clef_)
196     {
197       SCM vis = 0;
198       if (to_boolean (clef_->get_property ("non-default")))
199         vis = get_property ("explicitCueClefVisibility");
200
201       if (vis)
202         clef_->set_property ("break-visibility", vis);
203
204       clef_ = 0;
205       octavate_ = 0;
206     }
207 }
208
209 ADD_ACKNOWLEDGER (Cue_clef_engraver, bar_line);
210 ADD_TRANSLATOR (Cue_clef_engraver,
211                 /* doc */
212                 "Determine and set reference point for pitches in cued voices.",
213
214                 /* create */
215                 "CueClef "
216                 "CueEndClef "
217                 "OctavateEight ",
218
219                 /* read */
220                 "cueClefGlyph "
221                 "cueClefOctavation "
222                 "cueClefPosition "
223                 "explicitCueClefVisibility "
224                 "middleCCuePosition "
225                 "clefOctavation ",
226
227                 /* write */
228                 ""
229                );