]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-column.cc
* configure.in (--enable-std-vector): New option.
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.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 #include "tie-formatting-problem.hh"
22 #include "tie-configuration.hh"
23
24 using namespace std;
25
26 void
27 Tie_column::add_tie (Grob *me, Grob *tie)
28 {
29   if (tie->get_parent (Y_AXIS)
30       && Tie_column::has_interface (tie->get_parent (Y_AXIS)))
31     return;
32
33   if (!Pointer_group_interface::count (me, ly_symbol2scm ("ties")))
34     {
35       dynamic_cast<Spanner *> (me)->set_bound (LEFT, Tie::head (tie, LEFT));
36       dynamic_cast<Spanner *> (me)->set_bound (RIGHT, Tie::head (tie, RIGHT));
37     }
38
39   tie->set_parent (me, Y_AXIS);
40   Pointer_group_interface::add_grob (me, ly_symbol2scm ("ties"), tie);
41 }
42
43 /*
44   Extend the spanner over its Tie constituents.
45 */
46 MAKE_SCHEME_CALLBACK (Tie_column, before_line_breaking, 1);
47 SCM
48 Tie_column::before_line_breaking (SCM smob)
49 {
50   Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
51   for (SCM s = me->get_property ("ties"); scm_is_pair (s); s = scm_cdr (s))
52     {
53       Spanner *tie = dynamic_cast<Spanner *> (unsmob_grob (scm_car (s)));
54       Direction dir = LEFT;
55       do
56         {
57           if (dir * tie->get_bound (dir)->get_column ()->get_rank ()
58               > dir * me->get_bound (dir)->get_column ()->get_rank ())
59             me->set_bound (dir, Tie::head (tie, dir));
60         }
61       while (flip (&dir) != LEFT);
62     }
63   
64   return SCM_UNSPECIFIED;
65 }
66
67 MAKE_SCHEME_CALLBACK(Tie_column, calc_positioning_done, 1)
68 SCM
69 Tie_column::calc_positioning_done (SCM smob)
70 {
71   Grob *me = unsmob_grob (smob);
72   extract_grob_set (me, "ties", ro_ties);
73   Link_array<Grob> ties (ro_ties);
74   if (!ties.size ())
75     return SCM_BOOL_T;
76
77   if (ties.size() == 1)
78     {
79       /*
80         Already handled by standard mechanisms.
81        */
82       return SCM_BOOL_T;
83     }
84   
85   ties.sort (&Tie::compare);
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_chord_configuration ();
95
96   for (vsize i = 0; i < base.size(); i++)
97     {
98       Tie::set_control_points (ties[i], problem.common_x_refpoint (),
99                                base[i],
100                                problem.details_);
101       set_grob_direction (ties[i],
102                           base[i].dir_);
103     }
104   return SCM_BOOL_T;
105 }
106
107
108
109 ADD_INTERFACE (Tie_column, "tie-column-interface",
110                "Object that sets directions of multiple ties in a tied chord",
111
112                /* properties */
113                "positioning-done "
114                "tie-configuration "
115                );
116