]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-bracket.cc
Update.
[lilypond.git] / lily / volta-bracket.cc
1 /*
2   volta-bracket.cc -- implement Volta_bracket_interface
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <cstring>
10
11 #include "warn.hh"
12 #include "font-interface.hh"
13 #include "line-interface.hh"
14 #include "paper-column.hh"
15 #include "output-def.hh"
16 #include "text-item.hh"
17 #include "volta-bracket.hh"
18 #include "group-interface.hh"
19 #include "side-position-interface.hh"
20 #include "directional-element-interface.hh"
21 #include "lookup.hh"
22
23 /*
24   this is too complicated. Yet another version of side-positioning,
25   badly implemented.
26
27   --
28
29   * Should look for system_start_delim to find left edge of staff.
30   */
31
32 MAKE_SCHEME_CALLBACK (Volta_bracket_interface, print, 1);
33 SCM
34 Volta_bracket_interface::print (SCM smob)
35 {
36   Grob *me = unsmob_grob (smob);
37   Spanner *orig_span = dynamic_cast<Spanner *> (me->original_);
38
39   bool broken_first_bracket = orig_span && (orig_span->broken_intos_[0] == (Spanner *)me);
40
41   bool broken_last_bracket = orig_span && (orig_span->broken_intos_.top () == (Spanner *)me);
42
43   bool no_vertical_start = orig_span && !broken_first_bracket;
44   bool no_vertical_end = orig_span && !broken_last_bracket;
45   SCM s = me->get_property ("bars");
46   Grob *endbar = scm_is_pair (s) ? unsmob_grob (scm_car (s)) : 0;
47   SCM glyph = endbar ? endbar->get_property ("glyph") : SCM_EOL;
48
49   String str;
50   if (scm_is_string (glyph))
51     str = ly_scm2string (glyph);
52   else
53     str = "|";
54
55   const char *cs = str.to_str0 ();
56   no_vertical_end
57     |= (strcmp (cs, ":|") != 0 && strcmp (cs, "|:") != 0 && strcmp (cs, "|.") != 0
58         && strcmp (cs, ":|:") != 0 && strcmp (cs, ".|") != 0);
59
60   Output_def *layout = me->get_layout ();
61   Real half_space = 0.5;
62
63   Item *bound = dynamic_cast<Spanner *> (me)->get_bound (LEFT);
64
65   /*
66     not a start, but really broken in two
67   */
68   Real left = 0.;
69   if (bound->break_status_dir () == RIGHT)
70     {
71       Paper_column *pc = bound->get_column ();
72       left = pc->extent (pc, X_AXIS)[RIGHT] - bound->relative_coordinate (pc, X_AXIS);
73     }
74   else
75     {
76       /*
77         the volta spanner is attached to the bar-line, which is moved
78         to the right. We don't need to compensate for the left edge.
79       */
80     }
81
82   Real w = dynamic_cast<Spanner *> (me)->spanner_length () - left - half_space;
83   Real h = robust_scm2double (me->get_property ("height"), 1);
84
85   Stencil start, end;
86   if (!no_vertical_start)
87     start = Line_interface::line (me, Offset (0, 0), Offset (0, h));
88
89   if (!no_vertical_end)
90     end = Line_interface::line (me, Offset (w, 0), Offset (w, h));
91
92   Stencil mol = Line_interface::line (me, Offset (0, h), Offset (w, h));
93   mol.add_stencil (start);
94   mol.add_stencil (end);
95
96   if (!orig_span || broken_first_bracket)
97     {
98       SCM text = me->get_property ("text");
99       SCM properties = me->get_property_alist_chain (SCM_EOL);
100       SCM snum = Text_interface::interpret_markup (layout->self_scm (), properties, text);
101       Stencil num = *unsmob_stencil (snum);
102
103       mol.add_at_edge (X_AXIS, LEFT, num, - num.extent (X_AXIS).length ()
104                        - 1.0, 0);
105     }
106   mol.translate_axis (left, X_AXIS);
107   return mol.smobbed_copy ();
108 }
109
110 void
111 Volta_bracket_interface::add_bar (Grob *me, Item *b)
112 {
113   Pointer_group_interface::add_grob (me, ly_symbol2scm ("bars"), b);
114   Side_position_interface::add_support (me, b);
115   add_bound_item (dynamic_cast<Spanner *> (me), b);
116 }
117
118 void
119 Volta_bracket_interface::add_column (Grob *me, Grob *c)
120 {
121   Side_position_interface::add_support (me, c);
122 }
123
124 ADD_INTERFACE (Volta_bracket_interface, "volta-bracket-interface",
125                "Volta bracket with number",
126                "bars thickness height");
127