]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-column.cc
* scm/define-context-properties.scm
[lilypond.git] / lily / tie-column.cc
1 /*
2   tie-column.cc -- implement Tie_column
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "tie-column.hh"
10
11 #include <cmath>
12
13 #include "skyline.hh"
14 #include "warn.hh"
15 #include "paper-column.hh"
16 #include "spanner.hh"
17 #include "pointer-group-interface.hh"
18 #include "tie.hh"
19 #include "directional-element-interface.hh"
20 #include "tie-column-format.hh"
21
22 using namespace std;
23
24 void
25 Tie_column::add_tie (Grob *me, Grob *tie)
26 {
27   if (tie->get_parent (Y_AXIS)
28       && Tie_column::has_interface (tie->get_parent (Y_AXIS)))
29     return;
30
31   if (!Pointer_group_interface::count (me, ly_symbol2scm ("ties")))
32     {
33       dynamic_cast<Spanner *> (me)->set_bound (LEFT, Tie::head (tie, LEFT));
34       dynamic_cast<Spanner *> (me)->set_bound (RIGHT, Tie::head (tie, RIGHT));
35     }
36
37   tie->set_parent (me, Y_AXIS);
38   Pointer_group_interface::add_grob (me, ly_symbol2scm ("ties"), tie);
39 }
40
41 /*
42   Extend the spanner over its Tie constituents.
43 */
44 MAKE_SCHEME_CALLBACK (Tie_column, before_line_breaking, 1);
45 SCM
46 Tie_column::before_line_breaking (SCM smob)
47 {
48   Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
49   for (SCM s = me->get_property ("ties"); scm_is_pair (s); s = scm_cdr (s))
50     {
51       Spanner *tie = dynamic_cast<Spanner *> (unsmob_grob (scm_car (s)));
52       Direction dir = LEFT;
53       do
54         {
55           if (dir * tie->get_bound (dir)->get_column ()->get_rank ()
56               > dir * me->get_bound (dir)->get_column ()->get_rank ())
57             me->set_bound (dir, Tie::head (tie, dir));
58         }
59       while (flip (&dir) != LEFT);
60     }
61   
62   return SCM_UNSPECIFIED;
63 }
64
65 MAKE_SCHEME_CALLBACK(Tie_column, calc_positioning_done, 1)
66 SCM
67 Tie_column::calc_positioning_done (SCM smob)
68 {
69   Grob *me = unsmob_grob (smob);
70   extract_grob_set (me, "ties", ro_ties);
71   Link_array<Grob> ties (ro_ties);
72   if (!ties.size ())
73     return SCM_BOOL_T;
74
75   if (ties.size() == 1)
76     {
77       /*
78         Already handled by standard mechanisms.
79        */
80       return SCM_BOOL_T;
81     }
82   
83   ties.sort (&Tie::compare);
84
85   Array<Tie_configuration> tie_configs;
86   for (int i = 0; i < ties.size (); i++)
87     {
88       Tie_configuration conf;
89       conf.dir_ = get_grob_direction (ties[i]);
90       conf.position_ = Tie::get_position (ties[i]);
91       tie_configs.push (conf);
92     }
93
94   SCM manual_configs = me->get_property ("tie-configuration");
95   bool manual_override = false;
96   set_manual_tie_configuration (&tie_configs,
97                                 &manual_override,
98                                 manual_configs);
99   set_tie_config_directions (&tie_configs);
100
101   Grob *common = me;
102   for (int i = 0; i < ties.size (); i++)
103     {
104       common = dynamic_cast<Spanner*> (ties[i])->get_bound (LEFT)->common_refpoint (common, X_AXIS); 
105       common = dynamic_cast<Spanner*> (ties[i])->get_bound (RIGHT)->common_refpoint (common, X_AXIS); 
106     }
107
108   Drul_array< Array<Skyline_entry> > skylines;
109   set_chord_outlines (&skylines, ties, common);
110   
111   Tie_details details;
112   details.init (ties[0]);
113
114   /*
115     Let the ties flow out, according to our single-tie formatting.
116    */
117   if (!manual_override)
118     {
119       Tie::get_configuration (ties[0], common, &tie_configs.elem_ref (0),
120                               &skylines,
121                               details
122                               );
123       Tie::get_configuration (ties.top (), common,
124                               &tie_configs.elem_ref (tie_configs.size()-1),
125                               &skylines,
126                               details
127                               );
128     }
129
130   /*
131     Calculate final width and shape of the ties.
132    */
133   for (int i = 0; i < ties.size(); i++)
134     {
135       if (!manual_override
136           && (i == 0 || i == ties.size () -1))
137         continue;
138
139
140       final_shape_adjustment (tie_configs[i],
141                               skylines,
142                               ties[0],
143                               details);
144     }
145
146   
147   /*
148     Try to shift small ties into available spaces.
149    */
150   if (!manual_override)
151     {
152       shift_small_ties (&tie_configs, ties[0], details);
153     }
154   
155   for (int i = 0; i < ties.size(); i++)
156     {
157       Tie::set_control_points (ties[i], common, tie_configs[i],
158                                details
159                                );
160       set_grob_direction (ties[i], tie_configs[i].dir_);
161     }
162   return SCM_BOOL_T;
163 }
164
165
166
167 ADD_INTERFACE (Tie_column, "tie-column-interface",
168                "Object that sets directions of multiple ties in a tied chord",
169
170                /* properties */
171                "positioning-done "
172                "tie-configuration "
173                );
174