]> git.donarmstrong.com Git - lilypond.git/blob - lily/ottava-bracket.cc
* lily/tuplet-bracket.cc (calc_position_and_height): check musical
[lilypond.git] / lily / ottava-bracket.cc
1 #include "molecule.hh"
2 #include "text-item.hh"
3 #include "text-spanner.hh"
4 #include "line-spanner.hh"
5 #include "spanner.hh"
6 #include "font-interface.hh"
7 #include "dimensions.hh"
8 #include "paper-def.hh"
9 #include "warn.hh"
10 #include "paper-column.hh"
11 #include "staff-symbol-referencer.hh"
12 #include "note-column.hh"
13 #include "directional-element-interface.hh"
14 #include "tuplet-bracket.hh"
15
16 struct Ottava_bracket
17 {
18   DECLARE_SCHEME_CALLBACK (brew_molecule, (SCM));
19   static bool has_interface (Grob*);
20 };
21
22
23 /*
24   TODO: the string for ottava shoudl depend on the available space, ie.
25
26   
27   Long: 15ma        Short: 15ma    Empty: 15
28          8va                8va            8
29          8va bassa          8ba            8
30
31 */
32
33 MAKE_SCHEME_CALLBACK (Ottava_bracket, brew_molecule, 1);
34 SCM
35 Ottava_bracket::brew_molecule (SCM smob)
36 {
37   Spanner*me  = dynamic_cast<Spanner*> (unsmob_grob (smob));
38   
39   
40   Interval span_points;
41   
42   Grob *common = me->get_bound (LEFT)->common_refpoint (me->get_bound (RIGHT), X_AXIS);
43   Paper_def * paper = me->get_paper();
44
45   
46   Drul_array<bool> broken;
47   Direction d = LEFT;
48   do
49     {
50       Item *b = me->get_bound (d);
51       broken[d] = (b->break_status_dir () != CENTER);
52
53       if (Note_column::has_interface (b))
54         {
55           common = common_refpoint_of_list (b->get_grob_property ("heads"), common, X_AXIS);
56         }
57     }
58   while (flip (&d) != LEFT);
59
60   SCM properties = Font_interface::font_alist_chain (me);
61   SCM markup = me->get_grob_property ("text");
62   Molecule text;
63   if (Text_item::markup_p (markup)) 
64     text = *unsmob_molecule (Text_item::interpret_markup (paper->self_scm (), properties, markup));
65
66
67   Drul_array<Real> shorten = robust_scm2interval (me->get_grob_property ("shorten-pair"),
68                                                   Interval (0,0));
69   do
70     {
71       Item *b = me->get_bound (d);
72
73       Interval ext;
74       if (Note_column::has_interface (b))
75         {
76           for (SCM s = b->get_grob_property ("note-heads"); gh_pair_p (s); s =gh_cdr (s))
77             ext.unite (unsmob_grob (gh_car (s))->extent (common, X_AXIS));
78         }
79
80       if (ext.is_empty ())
81         ext = Interval (0,0);
82       
83       span_points[d] =  (broken [d]) ? b->extent (common, X_AXIS)[-d] : ext[d];
84
85       if (broken[d])
86         shorten [d] = 0.0; 
87     }
88   while (flip (&d) != LEFT);
89
90
91   /*
92     0.3 is ~ italic correction. 
93    */
94   Real text_size =  text.extent (X_AXIS).is_empty ()
95     ? 0.0 : text.extent (X_AXIS)[RIGHT] +  0.3;
96   
97   span_points[LEFT] = span_points[LEFT]
98     <? (span_points[RIGHT] - text_size
99         - robust_scm2double (me->get_grob_property ("minimum-length"), -1.0)); 
100   
101   Interval bracket_span_points = span_points;
102   bracket_span_points[LEFT] += text_size;
103   
104   Drul_array<Real> edge_height = robust_scm2interval (me->get_grob_property ("edge-height"),
105                                                       Interval (1.0, 1.0));
106
107   
108   Drul_array<Real> flare = robust_scm2interval (me->get_grob_property ("bracket-flare"),
109                                                 Interval (0,0));
110
111
112
113   edge_height[LEFT] = 0.0;
114   edge_height[RIGHT] *=  - get_grob_direction (me);
115   if (broken[RIGHT])
116     edge_height[RIGHT] = 0.0;
117   
118   Molecule b;
119   if (!bracket_span_points.is_empty () && bracket_span_points.length () > 0.001)
120     b = Tuplet_bracket::make_bracket (me,
121                                       Y_AXIS, Offset (bracket_span_points.length (), 0),
122                                        edge_height,
123                                       0.0,
124                                       flare, shorten);
125   
126   
127   b.translate_axis (bracket_span_points[LEFT], X_AXIS);
128   text.translate_axis (span_points[LEFT], X_AXIS);
129   text.align_to (Y_AXIS, CENTER);
130   b.add_molecule (text);
131   
132   b.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
133   
134   return b.smobbed_copy ();  
135 }
136
137
138 ADD_INTERFACE (Ottava_bracket, "ottava-bracket-interface",
139                "An ottava bracket",
140                "edge-height bracket-flare shorten-pair minimum-length");
141