]> git.donarmstrong.com Git - lilypond.git/blob - lily/custos.cc
*** empty log message ***
[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
17 #include <cstdio>
18 #include <math.h> // rint
19
20 #include "custos.hh"
21 #include "direction.hh"
22 #include "staff-symbol-referencer.hh"
23 #include "warn.hh"
24 #include "note-head.hh"
25 #include "item.hh"
26 #include "font-interface.hh"
27
28 MAKE_SCHEME_CALLBACK (Custos,print,1);
29 SCM
30 Custos::print (SCM smob)
31 {
32   Item *me = (Item *)unsmob_grob (smob);
33
34   SCM scm_style = me->get_property ("style");
35   String style;
36   if (scm_is_symbol (scm_style))
37     {
38       style = ly_symbol2string (scm_style);
39     }
40   else
41     {
42       style = "mensural";
43     }
44
45   /*
46    * Shall we use a common custos font character regardless if on
47    * staffline or not, or shall we use individual font characters
48    * for both cases?
49    */
50   bool adjust = true; 
51
52   int neutral_pos = robust_scm2int (me->get_property ("neutral-position"), 0);
53   Direction neutral_direction =
54     to_dir (me->get_property ("neutral-direction"));
55
56   int pos = Staff_symbol_referencer::get_rounded_position (me);
57   int sz = Staff_symbol_referencer::line_count (me)-1;
58
59   String font_char = "custodes." + style + ".";
60   if (pos < neutral_pos)
61     font_char += "u";
62   else if (pos > neutral_pos)
63     font_char += "d";
64   else if (neutral_direction == UP)
65     font_char += "u";
66   else if (neutral_direction == DOWN)
67     font_char += "d";
68   else // auto direction; not yet supported -> use "d"
69     font_char += "d";
70
71   if (adjust)
72     {
73       font_char += (((pos ^ sz) & 0x1) == 0) ? "1" : "0";
74     }
75   else
76     {
77       font_char += "2";
78     }
79
80   Stencil stencil
81     = Font_interface::get_default_font (me)->find_by_name (font_char);
82   if (stencil.is_empty ())
83     {
84       me->warning (_f ("custos `%s' not found", font_char));
85       return SCM_EOL;
86     }
87
88   return stencil.smobbed_copy ();
89 }
90
91 ADD_INTERFACE (Custos, "custos-interface",
92   "A custos object.",
93   "style neutral-position neutral-direction");