]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-bracket.cc
''
[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--2002 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <string.h>
10
11 #include "box.hh"
12 #include "debug.hh"
13 #include "font-interface.hh"
14 #include "molecule.hh"
15 #include "paper-column.hh"
16 #include "paper-def.hh"
17 #include "text-item.hh"
18 #include "volta-bracket.hh"
19 #include "group-interface.hh"
20 #include "side-position-interface.hh"
21 #include "directional-element-interface.hh"
22
23
24 /*
25   this is too complicated. Yet another version of side-positioning,
26   badly implemented.
27
28   --
29
30   * Should look for system_start_delim to find left edge of staff.
31   
32 */
33
34 MAKE_SCHEME_CALLBACK (Volta_bracket_interface,brew_molecule,1);
35 SCM
36 Volta_bracket_interface::brew_molecule (SCM smob) 
37 {
38   Grob *me = unsmob_grob (smob);
39   Link_array<Item> bar_arr
40     = Pointer_group_interface__extract_grobs (me, (Item*)0, "bars");
41
42   if (!bar_arr.size ())
43     return SCM_EOL;
44
45   Spanner *orig_span =  dynamic_cast<Spanner*> (me->original_l_);
46
47   bool first_bracket = orig_span && (orig_span->broken_into_l_arr_[0] == (Spanner*)me);
48   
49   bool last_bracket = orig_span && (orig_span->broken_into_l_arr_.top () == (Spanner*)me);
50
51   bool no_vertical_start = orig_span && !first_bracket;
52   bool no_vertical_end = orig_span && !last_bracket;
53   SCM bars = me->get_grob_property ("bars");
54   Grob * endbar =   unsmob_grob (ly_car (bars));
55   SCM glyph = endbar->get_grob_property("glyph");
56   String str = ly_scm2string(glyph);
57   const char* cs = str.ch_C();
58   no_vertical_end |=
59     (strcmp(cs,":|")!=0 && strcmp(cs,"|:")!=0 && strcmp(cs,"|.")!=0
60      && strcmp(cs,":|:")!=0 && strcmp(cs,".|")!=0);
61
62   Real staff_thick = me->paper_l ()->get_var ("linethickness");  
63   Real half_space = 0.5;
64
65   Item * bound = dynamic_cast<Spanner*> (me)->get_bound (LEFT);
66
67   /*
68     not a start, but really broken in two
69    */
70   Real left =0.;  
71   if (bound->break_status_dir () == RIGHT)
72   {
73     Paper_column *pc = bound->column_l ();
74     left = pc->extent (pc, X_AXIS)[RIGHT]   - bound->relative_coordinate (pc, X_AXIS);
75   }
76   else
77   {
78     /*
79       the volta spanner is attached to the bar-line, which is moved
80       to the right. We don't need to compensate for the left edge.
81     */
82   }
83
84   Real w = dynamic_cast<Spanner*> (me)->spanner_length () - left - half_space;
85   Real h =  gh_scm2double (me->get_grob_property ("height"));
86   Real t =  staff_thick * gh_scm2double (me->get_grob_property ("thickness"));
87
88   /*
89     ugh: should build from line segments.
90    */
91   SCM at = (scm_list_n (ly_symbol2scm ("volta"),
92                      gh_double2scm (h),
93                      gh_double2scm (w),
94                      gh_double2scm (t),
95                      gh_int2scm (no_vertical_start),
96                      gh_int2scm (no_vertical_end),
97                      SCM_UNDEFINED));
98
99   Box b (Interval (0, w), Interval (0, h));
100   Molecule mol (b, at);
101   SCM text = me->get_grob_property ("text");
102   SCM properties = scm_list_n (me->mutable_property_alist_,
103                                me->immutable_property_alist_,SCM_UNDEFINED);
104   Molecule num = Text_item::text2molecule (me, text, properties);
105
106   mol.add_at_edge (X_AXIS, LEFT, num, - num.extent (X_AXIS).length ()
107                    - 1.0);
108   mol.translate_axis (left, X_AXIS);
109   return mol.smobbed_copy ();
110 }
111
112
113 void
114 Volta_bracket_interface::add_bar (Grob *me, Item* b)
115 {
116   Pointer_group_interface::add_grob (me, ly_symbol2scm ("bars"), b);
117   Side_position_interface::add_support (me,b);
118   add_bound_item (dynamic_cast<Spanner*> (me), b); 
119 }
120
121 void
122 Volta_bracket_interface::add_column (Grob*me, Grob* c)
123 {
124   Side_position_interface::add_support (me,c);
125 }
126
127 ADD_INTERFACE (Volta_bracket_interface,"volta-bracket-interface",
128   "Volta bracket with number",
129   "bars thickness height");
130