Fix InstrumentSwitch grob definition.
[lilypond.git] / lily / custos.cc
blob79a69144dd811bf76914625e2f822d771d830edf
1 /*
2 custos.cc -- implement Custos
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2007 Juergen Reuter <reuter@ipd.uka.de>
7 */
9 /* TODO:
11 - do not show if a clef change immediately follows in the next line
13 - decide: do or do not print custos if the next line starts with a rest
16 #include <cstdio>
17 #include <cmath> // rint
18 using namespace std;
20 #include "custos.hh"
21 #include "direction.hh"
22 #include "font-interface.hh"
23 #include "international.hh"
24 #include "item.hh"
25 #include "note-head.hh"
26 #include "staff-symbol-referencer.hh"
27 #include "warn.hh"
29 MAKE_SCHEME_CALLBACK (Custos, print, 1);
30 SCM
31 Custos::print (SCM smob)
33 Item *me = (Item *)unsmob_grob (smob);
35 SCM scm_style = me->get_property ("style");
36 string style;
37 if (scm_is_symbol (scm_style))
38 style = ly_symbol2string (scm_style);
39 else
40 style = "mensural";
43 * Shall we use a common custos font character regardless if on
44 * staffline or not, or shall we use individual font characters
45 * for both cases?
47 bool adjust = true;
49 int neutral_pos = robust_scm2int (me->get_property ("neutral-position"), 0);
50 Direction neutral_direction
51 = to_dir (me->get_property ("neutral-direction"));
53 int pos = Staff_symbol_referencer::get_rounded_position (me);
54 int sz = Staff_symbol_referencer::line_count (me) - 1;
56 string font_char = "custodes." + style + ".";
57 if (pos < neutral_pos)
58 font_char += "u";
59 else if (pos > neutral_pos)
60 font_char += "d";
61 else if (neutral_direction == UP)
62 font_char += "u";
63 else if (neutral_direction == DOWN)
64 font_char += "d";
65 else // auto direction; not yet supported -> use "d"
66 font_char += "d";
68 if (adjust)
69 font_char += (((pos ^ sz) & 0x1) == 0) ? "1" : "0";
70 else
71 font_char += "2";
73 Stencil stencil
74 = Font_interface::get_default_font (me)->find_by_name (font_char);
75 if (stencil.is_empty ())
77 me->warning (_f ("custos `%s' not found", font_char));
78 return SCM_EOL;
81 return stencil.smobbed_copy ();
84 ADD_INTERFACE (Custos,
85 "A custos object. @code{style} can have four valid values:"
86 " @code{mensural}, @code{vaticana}, @code{medicaea}, and"
87 " @code{hufnagel}. @code{mensural} is the default style.",
89 /* properties */
90 "style "
91 "neutral-position "
92 "neutral-direction "