]> git.donarmstrong.com Git - lilypond.git/blob - lily/custos.cc
* flower
[lilypond.git] / lily / custos.cc
1 /*
2   custos.cc -- implement Custos
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2005 Juergen Reuter <reuter@ipd.uka.de>
7 */
8
9 /* TODO:
10
11 - do not show if a clef change immediately follows in the next line
12
13 - decide: do or do not print custos if the next line starts with a rest
14 */
15
16 #include <cstdio>
17 #include <math.h> // rint
18
19 #include "custos.hh"
20 #include "direction.hh"
21 #include "staff-symbol-referencer.hh"
22 #include "warn.hh"
23 #include "note-head.hh"
24 #include "item.hh"
25 #include "font-interface.hh"
26
27 MAKE_SCHEME_CALLBACK (Custos, print, 1);
28 SCM
29 Custos::print (SCM smob)
30 {
31   Item *me = (Item *)unsmob_grob (smob);
32
33   SCM scm_style = me->get_property ("style");
34   String style;
35   if (scm_is_symbol (scm_style))
36     {
37       style = ly_symbol2string (scm_style);
38     }
39   else
40     {
41       style = "mensural";
42     }
43
44   /*
45    * Shall we use a common custos font character regardless if on
46    * staffline or not, or shall we use individual font characters
47    * for both cases?
48    */
49   bool adjust = true;
50
51   int neutral_pos = robust_scm2int (me->get_property ("neutral-position"), 0);
52   Direction neutral_direction
53     = to_dir (me->get_property ("neutral-direction"));
54
55   int pos = Staff_symbol_referencer::get_rounded_position (me);
56   int sz = Staff_symbol_referencer::line_count (me) - 1;
57
58   String font_char = "custodes." + style + ".";
59   if (pos < neutral_pos)
60     font_char += "u";
61   else if (pos > neutral_pos)
62     font_char += "d";
63   else if (neutral_direction == UP)
64     font_char += "u";
65   else if (neutral_direction == DOWN)
66     font_char += "d";
67   else // auto direction; not yet supported -> use "d"
68     font_char += "d";
69
70   if (adjust)
71     {
72       font_char += (((pos ^ sz) & 0x1) == 0) ? "1" : "0";
73     }
74   else
75     {
76       font_char += "2";
77     }
78
79   Stencil stencil
80     = Font_interface::get_default_font (me)->find_by_name (font_char);
81   if (stencil.is_empty ())
82     {
83       me->warning (_f ("custos `%s' not found", font_char));
84       return SCM_EOL;
85     }
86
87   return stencil.smobbed_copy ();
88 }
89
90 ADD_INTERFACE (Custos, "custos-interface",
91                "A custos object.",
92                "style neutral-position neutral-direction");