]> git.donarmstrong.com Git - lilypond.git/blob - lily/custos.cc
a96e509d7f7e1f3100ca1c3d32837a8c14703ead
[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, 2002 Juergen Reuter <reuter@ipd.uka.de>
7 */
8
9 /* TODO:
10
11  - merge create_ledger_line () and Note_head::create_ledger_line ()
12
13  - rewrite create_ledger_line () to support short and thin ledger lines
14
15  - do not show if a clef change immediately follows in the next line
16
17  - decide: do or do not print custos if the next line starts with a rest
18
19 */
20
21
22 #include <stdio.h>
23 #include "direction.hh"
24 #include "staff-symbol-referencer.hh"
25 #include "custos.hh"
26 #include "molecule.hh"
27 #include "warn.hh"
28 #include "note-head.hh"
29 #include "item.hh"
30 #include "font-interface.hh"
31 #include "math.h" // rint
32
33 MAKE_SCHEME_CALLBACK (Custos,brew_molecule,1);
34 SCM
35 Custos::brew_molecule (SCM smob)
36 {
37   Item *me = (Item *)unsmob_grob (smob);
38   SCM scm_style = me->get_grob_property ("style");
39
40   if (gh_symbol_p (scm_style))
41     {
42       String style = ly_scm2string (scm_symbol_to_string (scm_style));
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 =
50         to_boolean (me->get_grob_property ("adjust-if-on-staffline"));
51
52       String idx = "custodes-" + style + "-";
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       if (pos < neutral_pos)
68         idx += "u";
69       else if (pos > neutral_pos)
70         idx += "d";
71       else if (neutral_direction == UP)
72         idx += "u";
73       else if (neutral_direction == DOWN)
74         idx += "d";
75       else // auto direction; not yet supported -> use "d"
76         idx += "d";
77
78       if (adjust)
79         {
80           idx += (((pos ^ sz) & 0x1) == 0) ? "1" : "0";
81         }
82       else
83         {
84           idx += "2";
85         }
86
87       Molecule molecule
88         = Font_interface::get_default_font (me)->find_by_name (idx);
89       if (molecule.empty_b ())
90         {
91           String message = "no such custos: `" + idx + "'";
92           warning (_ (message.to_str0 ()));
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), true);
105               molecule.add_molecule (ledger_lines);
106             }
107           return molecule.smobbed_copy ();
108         }
109     }
110   else
111     return SCM_EOL;
112 }
113
114
115 ADD_INTERFACE (Custos, "custos-interface",
116   "A custos is a staff context symbol that appears at the end of a
117   staff line with monophonic musical contents (i.e. with a single
118   voice).  It anticipates the pitch of the first note of the following
119   line and thus helps the player or singer to manage line breaks
120   during performance, thus enhancing readability of a score.
121
122   Custodes were frequently used in music notation until the 16th
123   century.  There were different appearences for different notation
124   styles.  Nowadays, they have survived only in special forms of
125   musical notation such as via the editio vaticana dating back to the
126   beginning of the 20th century.
127
128 [TODO: add to glossary]",
129   "style adjust-if-on-staffline neutral-direction neutral-position");