]> git.donarmstrong.com Git - lilypond.git/blob - lily/time-signature.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / time-signature.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1996--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "time-signature.hh"
21
22 #include "grob.hh"
23 #include "font-interface.hh"
24 #include "international.hh"
25 #include "output-def.hh"
26 #include "text-interface.hh"
27
28 /*
29   TODO:
30
31   this file should go ; The formatting can completely be done with
32   markups.
33 */
34
35 MAKE_SCHEME_CALLBACK (Time_signature, print, 1);
36 SCM
37 Time_signature::print (SCM smob)
38 {
39   Grob *me = unsmob_grob (smob);
40   SCM st = me->get_property ("style");
41   SCM frac = me->get_property ("fraction");
42   int n = 4;
43   int d = 4;
44   if (scm_is_pair (frac))
45     {
46       n = scm_to_int (scm_car (frac));
47       d = scm_to_int (scm_cdr (frac));
48     }
49
50   Stencil m;
51   if (st == ly_symbol2scm ("single-digit"))
52     m = numbered_time_signature (me, n, 0);
53   else if (scm_is_symbol (st))
54     m = special_time_signature (me, st, n, d);
55   else
56     m = numbered_time_signature (me, n, d);
57
58   return m.smobbed_copy ();
59 }
60
61 Stencil
62 Time_signature::special_time_signature (Grob *me, SCM scm_style, int n, int d)
63 {
64   string style = robust_symbol2string (scm_style, "default");
65
66   if (style == "numbered")
67     return numbered_time_signature (me, n, d);
68
69   if ((style == "default") || (style == ""))
70     style = ::to_string ("C");
71
72   if (style == "C")
73     {
74       if /* neither C2/2 nor C4/4 */
75       (((n != 2) || (d != 2))
76           && ((n != 4) || (d != 4)))
77         return numbered_time_signature (me, n, d);
78     }
79
80   string char_name = style + ::to_string (n) + ::to_string (d);
81   me->set_property ("font-encoding", ly_symbol2scm ("fetaMusic"));
82   Stencil out = Font_interface::get_default_font (me)
83                 ->find_by_name ("timesig." + char_name);
84   if (!out.is_empty ())
85     return out;
86
87   /* If there is no such symbol, we default to the numbered style.
88      (Here really with a warning!) */
89   me->warning (_f ("time signature symbol `%s' not found; "
90                    "reverting to numbered style", char_name));
91   return numbered_time_signature (me, n, d);
92 }
93
94 Stencil
95 Time_signature::numbered_time_signature (Grob *me, int num, int den)
96 {
97   SCM chain = me->get_property_alist_chain (Font_interface::text_font_alist_chain (me));
98   chain = scm_cons (scm_list_1 (scm_cons (ly_symbol2scm ("font-encoding"),
99                                           ly_symbol2scm ("fetaText"))),
100                     chain);
101
102   SCM sn = Text_interface::interpret_markup (me->layout ()->self_scm (), chain,
103                                              ly_string2scm (::to_string (num)));
104   SCM sd = Text_interface::interpret_markup (me->layout ()->self_scm (), chain,
105                                              ly_string2scm (::to_string (den)));
106
107   Stencil n = *unsmob_stencil (sn);
108   Stencil d = *unsmob_stencil (sd);
109
110   n.align_to (X_AXIS, CENTER);
111   d.align_to (X_AXIS, CENTER);
112   Stencil m;
113   if (den)
114     {
115       m.add_at_edge (Y_AXIS, UP, n, 0.0);
116       m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
117     }
118   else
119     {
120       m = n;
121       m.align_to (Y_AXIS, CENTER);
122     }
123
124   m.align_to (X_AXIS, LEFT);
125
126   return m;
127 }
128
129 ADD_INTERFACE (Time_signature,
130                "A time signature, in different styles.  The following values"
131                " for @code{style} are are recognized:\n"
132                "\n"
133                "@table @code\n"
134                "@item C\n"
135                "4/4 and 2/2 are typeset as C and struck C, respectively."
136                "  All other time signatures are written with two digits."
137                "  The value @code{default} is equivalent to @code{C}.\n"
138                "@item neomensural\n"
139                "2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8, and 9/8 are"
140                " typeset with neo-mensural style mensuration marks.  All"
141                " other time signatures are written with two digits.\n"
142                "@item mensural\n"
143                "2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8, and 9/8 are"
144                " typeset with mensural style mensuration marks.  All other"
145                " time signatures are written with two digits.\n"
146                "@item single-digit\n"
147                "All time signatures are typeset with a single digit, e.g.,"
148                " 3/2 is written as 3.\n"
149                "@item numbered\n"
150                "All time signatures are typeset with two digits.\n"
151                "@end table",
152
153                /* properties */
154                "fraction "
155                "style "
156               );