]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-spanner.cc
release: 1.3.118
[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--2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9
10 #include "box.hh"
11 #include "debug.hh"
12 #include "font-interface.hh"
13 #include "molecule.hh"
14 #include "paper-column.hh"
15 #include "paper-def.hh"
16 #include "text-item.hh"
17 #include "volta-spanner.hh"
18 #include "group-interface.hh"
19 #include "side-position-interface.hh"
20 #include "directional-element-interface.hh"
21
22
23 void
24 Volta_spanner::set_interface (Grob*)
25 {
26 }
27
28 /*
29   this is too complicated. Yet another version of side-positioning,
30   badly implemented.
31
32   --
33
34   * Should look for system_start_delim to find left edge of staff.
35   
36 */
37
38 MAKE_SCHEME_CALLBACK(Volta_spanner,brew_molecule,1);
39 SCM
40 Volta_spanner::brew_molecule (SCM smob) 
41 {
42   Grob *me = unsmob_grob (smob);
43   Link_array<Item> bar_arr
44     = Pointer_group_interface__extract_elements (me, (Item*)0, "bars");
45
46   if (!bar_arr.size ())
47     return SCM_EOL;
48
49   bool no_vertical_start = false;
50   bool no_vertical_end = to_boolean (me->get_grob_property ("last-volta"));
51   Spanner *orig_span =  dynamic_cast<Spanner*> (me->original_l_);
52
53   bool first_bracket = orig_span && (orig_span->broken_into_l_arr_[0] == (Spanner*)me);
54   
55   bool last_bracket = orig_span && (orig_span->broken_into_l_arr_.top () == (Spanner*)me);
56
57   no_vertical_start = orig_span && !first_bracket;
58   no_vertical_end = orig_span && !last_bracket;
59
60   Real staff_thick = me->paper_l ()->get_var ("stafflinethickness");  
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->column_l ();
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 =  gh_scm2double (me->get_grob_property ("height"));
84   Real t =  staff_thick * gh_scm2double (me->get_grob_property ("thickness"));
85
86   /*
87     ugh: should build from line segments.
88    */
89   SCM at = (gh_list (ly_symbol2scm ("volta"),
90                      gh_double2scm (h),
91                      gh_double2scm (w),
92                      gh_double2scm (t),
93                      gh_int2scm (no_vertical_start),
94                      gh_int2scm (no_vertical_end),
95                      SCM_UNDEFINED));
96
97   Box b (Interval (0, w), Interval (0, h));
98   Molecule mol (b, at);
99   SCM text = me->get_grob_property("text");
100   SCM properties = gh_list (me->mutable_property_alist_, me->immutable_property_alist_,SCM_UNDEFINED);
101   Molecule num = Text_item::text2molecule (me, text, properties);
102
103   mol.add_at_edge (X_AXIS, LEFT, num, - num.extent (X_AXIS).length ()
104                    - 1.0);
105   mol.translate_axis (left, X_AXIS);
106   return mol.smobbed_copy ();
107 }
108
109
110 void
111 Volta_spanner::add_bar  (Grob *me, Item* b)
112 {
113   Pointer_group_interface::add_element(me, "bars",b);
114   Side_position::add_support (me,b);
115   add_bound_item (dynamic_cast<Spanner*>(me), b); 
116 }
117
118 void
119 Volta_spanner::add_column (Grob*me, Grob* c)
120 {
121   Side_position::add_support (me,c);
122 }