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