]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-bracket.cc
*** empty log message ***
[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--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <string.h>
10
11 #include "box.hh"
12 #include "warn.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 #include "lookup.hh"
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> bars
40     = Pointer_group_interface__extract_grobs (me, (Item*)0, "bars");
41
42   if (!bars.size ())
43     return SCM_EOL;
44
45   Spanner *orig_span =  dynamic_cast<Spanner*> (me->original_);
46
47   bool first_bracket = orig_span && (orig_span->broken_intos_[0] == (Spanner*)me);
48   
49   bool last_bracket = orig_span && (orig_span->broken_intos_.top () == (Spanner*)me);
50
51   bool no_vertical_start = orig_span && !first_bracket;
52   bool no_vertical_end = orig_span && !last_bracket;
53   SCM s = me->get_grob_property ("bars");
54   Grob * endbar =   unsmob_grob (ly_car (s));
55   SCM glyph = endbar->get_grob_property("glyph");
56   
57   String str;
58   if (gh_string_p (glyph))
59     str = ly_scm2string(glyph);
60   else
61     return SCM_EOL;
62   
63   const char* cs = str.to_str0 ();
64   no_vertical_end |=
65     (strcmp(cs,":|")!=0 && strcmp(cs,"|:")!=0 && strcmp(cs,"|.")!=0
66      && strcmp(cs,":|:")!=0 && strcmp(cs,".|")!=0);
67
68   Real staff_thick = me->get_paper ()->get_var ("linethickness");  
69   Real half_space = 0.5;
70
71   Item * bound = dynamic_cast<Spanner*> (me)->get_bound (LEFT);
72
73   /*
74     not a start, but really broken in two
75    */
76   Real left =0.;  
77   if (bound->break_status_dir () == RIGHT)
78   {
79     Paper_column *pc = bound->get_column ();
80     left = pc->extent (pc, X_AXIS)[RIGHT]   - bound->relative_coordinate (pc, X_AXIS);
81   }
82   else
83   {
84     /*
85       the volta spanner is attached to the bar-line, which is moved
86       to the right. We don't need to compensate for the left edge.
87     */
88   }
89
90   Real w = dynamic_cast<Spanner*> (me)->spanner_length () - left - half_space;
91   Real h =  gh_scm2double (me->get_grob_property ("height"));
92   Real t =  staff_thick * gh_scm2double (me->get_grob_property ("thickness"));
93
94
95   Molecule start,end ;
96   if (!no_vertical_start)
97     start = Lookup::line (t, Offset (0,0), Offset (0, h)); 
98   
99   if (!no_vertical_end)
100     end = Lookup::line (t, Offset (w, 0), Offset (w,h));
101
102   Molecule mol = Lookup::line (t, Offset (0, h), Offset (w,h));
103   mol.add_molecule (start);
104   mol.add_molecule (end);
105   
106   SCM text = me->get_grob_property ("text");
107   SCM properties = me->get_property_alist_chain (SCM_EOL);
108
109   Molecule num = Text_item::text2molecule (me, text, properties);
110
111   mol.add_at_edge (X_AXIS, LEFT, num, - num.extent (X_AXIS).length ()
112                    - 1.0, 0);
113   mol.translate_axis (left, X_AXIS);
114   return mol.smobbed_copy ();
115 }
116
117
118 void
119 Volta_bracket_interface::add_bar (Grob *me, Item* b)
120 {
121   Pointer_group_interface::add_grob (me, ly_symbol2scm ("bars"), b);
122   Side_position_interface::add_support (me,b);
123   add_bound_item (dynamic_cast<Spanner*> (me), b); 
124 }
125
126 void
127 Volta_bracket_interface::add_column (Grob*me, Grob* c)
128 {
129   Side_position_interface::add_support (me,c);
130 }
131
132 ADD_INTERFACE (Volta_bracket_interface,"volta-bracket-interface",
133   "Volta bracket with number",
134   "bars thickness height");
135