]> git.donarmstrong.com Git - lilypond.git/blob - lily/custos.cc
8024fa946541e59d257712466d73a67f6fc4f64f
[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--2004 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
18 #include <stdio.h>
19 #include "direction.hh"
20 #include "staff-symbol-referencer.hh"
21 #include "custos.hh"
22 #include "molecule.hh"
23 #include "warn.hh"
24 #include "note-head.hh"
25 #include "item.hh"
26 #include "font-interface.hh"
27 #include "math.h" // rint
28
29 MAKE_SCHEME_CALLBACK (Custos,print,1);
30 SCM
31 Custos::print (SCM smob)
32 {
33   Item *me = (Item *)unsmob_grob (smob);
34
35   SCM scm_style = me->get_grob_property ("style");
36   String style;
37   if (gh_symbol_p (scm_style))
38     {
39       style = ly_symbol2string (scm_style);
40     }
41   else
42     {
43       style = "mensural";
44     }
45
46   /*
47    * Shall we use a common custos font character regardless if on
48    * staffline or not, or shall we use individual font characters
49    * for both cases?
50    */
51   bool adjust
52     = to_boolean (me->get_grob_property ("adjust-if-on-staffline"));
53
54   int neutral_pos;
55   SCM ntr_pos = me->get_grob_property ("neutral-position");
56   if (gh_number_p (ntr_pos))
57     neutral_pos = gh_scm2int (ntr_pos);
58   else
59     neutral_pos = 0;
60
61   Direction neutral_direction =
62     to_dir (me->get_grob_property ("neutral-direction"));
63
64   int pos = (int)rint (Staff_symbol_referencer::get_position (me));
65   int sz = Staff_symbol_referencer::line_count (me)-1;
66
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";
78
79   if (adjust)
80     {
81       font_char += (((pos ^ sz) & 0x1) == 0) ? "1" : "0";
82     }
83   else
84     {
85       font_char += "2";
86     }
87
88   Molecule molecule
89     = Font_interface::get_default_font (me)->find_by_name (font_char);
90   if (molecule.is_empty ())
91     {
92       me->warning (_f ("custos `%s' not found", font_char));
93       return SCM_EOL;
94     }
95   else
96     {
97       // add ledger lines
98       int pos = (int)rint (Staff_symbol_referencer::get_position (me));
99       int interspaces = Staff_symbol_referencer::line_count (me)-1;
100       if (abs (pos) - interspaces > 1)
101         {
102           Molecule ledger_lines =
103             Note_head::brew_ledger_lines (me, pos, interspaces,
104                                           molecule.extent (X_AXIS), 0, true);
105           molecule.add_molecule (ledger_lines);
106         }
107       return molecule.smobbed_copy ();
108     }
109 }
110
111 ADD_INTERFACE (Custos, "custos-interface",
112   "Engrave custodes",
113   "style adjust-if-on-staffline neutral-direction neutral-position");