]> git.donarmstrong.com Git - lilypond.git/blob - lily/custos.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / custos.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2000--2015 Juergen Reuter <reuter@ipd.uka.de>
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 /* TODO:
21
22 - do not show if a clef change immediately follows in the next line
23
24 - decide: do or do not print custos if the next line starts with a rest
25 */
26
27 #include <cstdio>
28 #include <cmath> // rint
29 using namespace std;
30
31 #include "custos.hh"
32 #include "direction.hh"
33 #include "font-interface.hh"
34 #include "international.hh"
35 #include "item.hh"
36 #include "note-head.hh"
37 #include "staff-symbol-referencer.hh"
38 #include "warn.hh"
39
40 using std::string;
41
42 MAKE_SCHEME_CALLBACK (Custos, print, 1);
43 SCM
44 Custos::print (SCM smob)
45 {
46   Item *me = (Item *)unsmob<Grob> (smob);
47
48   SCM scm_style = me->get_property ("style");
49   string style;
50   if (scm_is_symbol (scm_style))
51     style = ly_symbol2string (scm_style);
52   else
53     style = "mensural";
54
55   /*
56    * Shall we use a common custos font character regardless if on
57    * staffline or not, or shall we use individual font characters
58    * for both cases?
59    */
60   bool adjust = true;
61
62   int neutral_pos = robust_scm2int (me->get_property ("neutral-position"), 0);
63   Direction neutral_direction
64     = to_dir (me->get_property ("neutral-direction"));
65
66   int pos = Staff_symbol_referencer::get_rounded_position (me);
67
68   string font_char = "custodes." + style + ".";
69   if (pos < neutral_pos)
70     font_char += "u";
71   else if (pos > neutral_pos)
72     font_char += "d";
73   else if (neutral_direction == UP)
74     font_char += "u";
75   else if (neutral_direction == DOWN)
76     font_char += "d";
77   else // auto direction; not yet supported -> use "d"
78     font_char += "d";
79
80   if (adjust)
81     font_char += Staff_symbol_referencer::on_line (me, pos) ? "1" : "0";
82   else
83     font_char += "2";
84
85   Stencil stencil
86     = Font_interface::get_default_font (me)->find_by_name (font_char);
87   if (stencil.is_empty ())
88     {
89       me->warning (_f ("custos `%s' not found", font_char));
90       return SCM_EOL;
91     }
92
93   return stencil.smobbed_copy ();
94 }
95
96 ADD_INTERFACE (Custos,
97                "A custos object.  @code{style} can have four valid values:"
98                " @code{mensural}, @code{vaticana}, @code{medicaea}, and"
99                " @code{hufnagel}.  @code{mensural} is the default style.",
100
101                /* properties */
102                "style "
103                "neutral-position "
104                "neutral-direction "
105               );