]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-column.cc
Run `make grand-replace'.
[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--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "tie-column.hh"
10
11 #include <cmath>
12
13 #include "output-def.hh"
14 #include "skyline.hh"
15 #include "warn.hh"
16 #include "paper-column.hh"
17 #include "spanner.hh"
18 #include "pointer-group-interface.hh"
19 #include "tie.hh"
20 #include "directional-element-interface.hh"
21 #include "tie-column-format.hh"
22 #include "tie-formatting-problem.hh"
23 #include "tie-configuration.hh"
24
25 using namespace std;
26
27 void
28 Tie_column::add_tie (Grob *tc, Grob *tie)
29 {
30   Spanner *me = dynamic_cast<Spanner *> (tc);
31   
32   if (tie->get_parent (Y_AXIS)
33       && Tie_column::has_interface (tie->get_parent (Y_AXIS)))
34     return;
35
36   if (!me->get_bound (LEFT)
37       || (Paper_column::get_rank (me->get_bound (LEFT)->get_column ())
38           > Paper_column::get_rank (dynamic_cast<Spanner*> (tie)->get_bound (LEFT)->get_column ())))
39     {
40         me->set_bound (LEFT, Tie::head (tie, LEFT));
41         me->set_bound (RIGHT, Tie::head (tie, RIGHT));
42     }
43       
44   tie->set_parent (me, Y_AXIS);
45   Pointer_group_interface::add_grob (me, ly_symbol2scm ("ties"), tie);
46 }
47
48 /*
49   Extend the spanner over its Tie constituents.
50 */
51 MAKE_SCHEME_CALLBACK (Tie_column, before_line_breaking, 1);
52 SCM
53 Tie_column::before_line_breaking (SCM smob)
54 {
55   Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
56   for (SCM s = me->get_property ("ties"); scm_is_pair (s); s = scm_cdr (s))
57     {
58       Spanner *tie = dynamic_cast<Spanner *> (unsmob_grob (scm_car (s)));
59       Direction dir = LEFT;
60       do
61         {
62           if (dir * tie->get_bound (dir)->get_column ()->get_rank ()
63               > dir * me->get_bound (dir)->get_column ()->get_rank ())
64             me->set_bound (dir, Tie::head (tie, dir));
65         }
66       while (flip (&dir) != LEFT);
67     }
68   
69   return SCM_UNSPECIFIED;
70 }
71
72 MAKE_SCHEME_CALLBACK (Tie_column, calc_positioning_done, 1)
73 SCM
74 Tie_column::calc_positioning_done (SCM smob)
75 {
76   Grob *me = unsmob_grob (smob);
77   extract_grob_set (me, "ties", ro_ties);
78   vector<Grob*> ties (ro_ties);
79   if (!ties.size ())
80     return SCM_BOOL_T;
81
82
83   me->set_property ("positioning-done", SCM_BOOL_T);
84
85   vector_sort (ties, Tie::less);
86
87   Tie_formatting_problem problem;
88   problem.from_ties (ties);
89
90   SCM manual_configs = me->get_property ("tie-configuration");
91   problem.set_manual_tie_configuration (manual_configs);
92
93
94   Ties_configuration base = problem.generate_optimal_configuration ();
95
96   for (vsize i = 0; i < base.size (); i++)
97     {
98       SCM cp = Tie::get_control_points (ties[i], problem.common_x_refpoint (),
99                                         base[i],
100                                         problem.details_);
101
102       ties[i]->set_property ("control-points", cp);
103       set_grob_direction (ties[i],
104                           base[i].dir_);
105
106       problem.set_debug_scoring (base);
107     }
108   return SCM_BOOL_T;
109 }
110
111
112
113 ADD_INTERFACE (Tie_column,
114                "Object that sets directions of multiple ties in a tied chord.",
115
116                /* properties */
117                "positioning-done "
118                "tie-configuration "
119                );
120