]> git.donarmstrong.com Git - lilypond.git/blob - lily/accidental.cc
''
[lilypond.git] / lily / accidental.cc
1 #include "font-interface.hh"
2 #include "item.hh"
3 #include "molecule.hh"
4
5 /*
6   TODO: insert support for smaller cautionaries, tie-break-reminders.
7   Either here or in new-accidental-engraver.
8
9   'accidentals should go, for a single 'accidental property -- see
10   accidental-placement.cc
11
12 */
13 class Accidental_interface
14 {
15 public:
16   DECLARE_SCHEME_CALLBACK (brew_molecule, (SCM));
17   DECLARE_SCHEME_CALLBACK (after_line_breaking, (SCM));  
18   static bool has_interface (Grob*);
19 };
20
21 Molecule
22 parenthesize (Grob*me, Molecule m)
23 {
24   Molecule open = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-leftparen"));
25   Molecule close = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-rightparen"));
26   m.add_at_edge (X_AXIS, LEFT, Molecule (open), 0);
27   m.add_at_edge (X_AXIS, RIGHT, Molecule (close), 0);
28
29   return m;
30 }
31
32
33 MAKE_SCHEME_CALLBACK (Accidental_interface,after_line_breaking,1);
34 SCM
35 Accidental_interface::after_line_breaking (SCM smob)
36 {
37   Grob *me  = unsmob_grob (smob);
38   Grob *tie = unsmob_grob (me->get_grob_property ("tie"));
39
40   if (tie && !tie->original_l_)
41     {
42       me->suicide ();
43     }
44   return SCM_UNSPECIFIED;
45 }
46   
47 MAKE_SCHEME_CALLBACK (Accidental_interface,brew_molecule,1);
48 SCM
49 Accidental_interface::brew_molecule (SCM smob)
50 {
51   Grob *me = unsmob_grob (smob);
52   bool smaller = false;
53   bool parens = false;
54   
55   bool caut  = to_boolean (me->get_grob_property ("cautionary"));
56   if (caut)
57     {
58       SCM cstyle = me->get_grob_property ("cautionary-style");
59       parens = gh_equal_p (cstyle, ly_symbol2scm ("parentheses"));
60       smaller = gh_equal_p (cstyle, ly_symbol2scm ("smaller"));
61     }
62   
63   SCM scm_style = me->get_grob_property ("style");
64   String style;
65   if (gh_symbol_p (scm_style))
66     {
67       style = ly_scm2string (scm_symbol_to_string (scm_style));
68     }
69   else
70     {
71       /*
72         preferably no name for the default style.
73        */
74       style = "";
75     }
76
77
78   Font_metric *fm = 0;
79   if (smaller)
80     {
81       SCM ac = Font_interface::font_alist_chain (me);
82       ac = gh_cons (gh_cons (gh_cons
83                              (ly_symbol2scm ("font-relative-size"),
84                               gh_int2scm (-1)), SCM_EOL),
85                     ac);
86       fm = Font_interface::get_font (me, ac);
87     }
88   else
89     fm = Font_interface::get_default_font (me);
90
91   Molecule mol;
92   for (SCM s = me->get_grob_property ("accidentals");
93        gh_pair_p (s);  s= gh_cdr (s))
94     {
95       SCM entry  = gh_car (s);
96       
97       
98       Molecule acc (fm->find_by_name (String ("accidentals-") +
99                                       style +
100                                       to_str (gh_scm2int(entry))));
101       
102       mol.add_at_edge (X_AXIS,  RIGHT, acc, 0.1);
103     }
104
105   if (parens)
106     mol = parenthesize (me, mol); 
107
108   return mol.smobbed_copy();
109 }
110
111
112
113 ADD_INTERFACE(Accidental_interface, "accidental-interface",
114               "a single accidental",
115               "style tie accidentals");