]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-column.cc
Merge branch 'lilypond/translation' of ssh://git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / lily / tie-column.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2000--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "tie-column.hh"
21
22 #include <cmath>
23
24 #include "output-def.hh"
25 #include "skyline.hh"
26 #include "warn.hh"
27 #include "paper-column.hh"
28 #include "spanner.hh"
29 #include "pointer-group-interface.hh"
30 #include "tie.hh"
31 #include "directional-element-interface.hh"
32 #include "tie-column-format.hh"
33 #include "tie-formatting-problem.hh"
34 #include "tie-configuration.hh"
35
36 using namespace std;
37
38 void
39 Tie_column::add_tie (Grob *tc, Grob *tie)
40 {
41   Spanner *me = dynamic_cast<Spanner *> (tc);
42   
43   if (tie->get_parent (Y_AXIS)
44       && Tie_column::has_interface (tie->get_parent (Y_AXIS)))
45     return;
46
47   if (!me->get_bound (LEFT)
48       || (Paper_column::get_rank (me->get_bound (LEFT)->get_column ())
49           > Paper_column::get_rank (dynamic_cast<Spanner*> (tie)->get_bound (LEFT)->get_column ())))
50     {
51         me->set_bound (LEFT, Tie::head (tie, LEFT));
52         me->set_bound (RIGHT, Tie::head (tie, RIGHT));
53     }
54       
55   tie->set_parent (me, Y_AXIS);
56   Pointer_group_interface::add_grob (me, ly_symbol2scm ("ties"), tie);
57 }
58
59 /*
60   Extend the spanner over its Tie constituents.
61 */
62 MAKE_SCHEME_CALLBACK (Tie_column, before_line_breaking, 1);
63 SCM
64 Tie_column::before_line_breaking (SCM smob)
65 {
66   Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
67   for (SCM s = me->get_property ("ties"); scm_is_pair (s); s = scm_cdr (s))
68     {
69       Spanner *tie = dynamic_cast<Spanner *> (unsmob_grob (scm_car (s)));
70       Direction dir = LEFT;
71       do
72         {
73           if (dir * tie->get_bound (dir)->get_column ()->get_rank ()
74               > dir * me->get_bound (dir)->get_column ()->get_rank ())
75             me->set_bound (dir, Tie::head (tie, dir));
76         }
77       while (flip (&dir) != LEFT);
78     }
79   
80   return SCM_UNSPECIFIED;
81 }
82
83 MAKE_SCHEME_CALLBACK (Tie_column, calc_positioning_done, 1)
84 SCM
85 Tie_column::calc_positioning_done (SCM smob)
86 {
87   Grob *me = unsmob_grob (smob);
88   extract_grob_set (me, "ties", ro_ties);
89   vector<Grob*> ties (ro_ties);
90   if (!ties.size ())
91     return SCM_BOOL_T;
92
93
94   me->set_property ("positioning-done", SCM_BOOL_T);
95
96   vector_sort (ties, Tie::less);
97
98   Tie_formatting_problem problem;
99   problem.from_ties (ties);
100
101   SCM manual_configs = me->get_property ("tie-configuration");
102   problem.set_manual_tie_configuration (manual_configs);
103
104
105   Ties_configuration base = problem.generate_optimal_configuration ();
106
107   for (vsize i = 0; i < base.size (); i++)
108     {
109       SCM cp = Tie::get_control_points (ties[i], problem.common_x_refpoint (),
110                                         base[i],
111                                         problem.details_);
112
113       ties[i]->set_property ("control-points", cp);
114       set_grob_direction (ties[i],
115                           base[i].dir_);
116
117       problem.set_debug_scoring (base);
118     }
119   return SCM_BOOL_T;
120 }
121
122
123
124 ADD_INTERFACE (Tie_column,
125                "Object that sets directions of multiple ties in a tied chord.",
126
127                /* properties */
128                "positioning-done "
129                "tie-configuration "
130                );
131