Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / custos.cc
blobf312e4a8abbaebebfba22bf585fbcf8eb2e6f7ce
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2011 Juergen Reuter <reuter@ipd.uka.de>
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.
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.
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/>.
20 /* TODO:
22 - do not show if a clef change immediately follows in the next line
24 - decide: do or do not print custos if the next line starts with a rest
27 #include <cstdio>
28 #include <cmath> // rint
29 using namespace std;
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"
40 MAKE_SCHEME_CALLBACK (Custos, print, 1);
41 SCM
42 Custos::print (SCM smob)
44 Item *me = (Item *)unsmob_grob (smob);
46 SCM scm_style = me->get_property ("style");
47 string style;
48 if (scm_is_symbol (scm_style))
49 style = ly_symbol2string (scm_style);
50 else
51 style = "mensural";
54 * Shall we use a common custos font character regardless if on
55 * staffline or not, or shall we use individual font characters
56 * for both cases?
58 bool adjust = true;
60 int neutral_pos = robust_scm2int (me->get_property ("neutral-position"), 0);
61 Direction neutral_direction
62 = to_dir (me->get_property ("neutral-direction"));
64 int pos = Staff_symbol_referencer::get_rounded_position (me);
65 int sz = Staff_symbol_referencer::line_count (me) - 1;
67 string font_char = "custodes." + style + ".";
68 if (pos < neutral_pos)
69 font_char += "u";
70 else if (pos > neutral_pos)
71 font_char += "d";
72 else if (neutral_direction == UP)
73 font_char += "u";
74 else if (neutral_direction == DOWN)
75 font_char += "d";
76 else // auto direction; not yet supported -> use "d"
77 font_char += "d";
79 if (adjust)
80 font_char += (((pos ^ sz) & 0x1) == 0) ? "1" : "0";
81 else
82 font_char += "2";
84 Stencil stencil
85 = Font_interface::get_default_font (me)->find_by_name (font_char);
86 if (stencil.is_empty ())
88 me->warning (_f ("custos `%s' not found", font_char));
89 return SCM_EOL;
92 return stencil.smobbed_copy ();
95 ADD_INTERFACE (Custos,
96 "A custos object. @code{style} can have four valid values:"
97 " @code{mensural}, @code{vaticana}, @code{medicaea}, and"
98 " @code{hufnagel}. @code{mensural} is the default style.",
100 /* properties */
101 "style "
102 "neutral-position "
103 "neutral-direction "