]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-column.cc
Fix some bugs in the dynamic engraver and PostScript backend
[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 "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 *me, Grob *tie)
29 {
30   if (tie->get_parent (Y_AXIS)
31       && Tie_column::has_interface (tie->get_parent (Y_AXIS)))
32     return;
33
34   if (!Pointer_group_interface::count (me, ly_symbol2scm ("ties")))
35     {
36       dynamic_cast<Spanner *> (me)->set_bound (LEFT, Tie::head (tie, LEFT));
37       dynamic_cast<Spanner *> (me)->set_bound (RIGHT, Tie::head (tie, RIGHT));
38     }
39
40   tie->set_parent (me, Y_AXIS);
41   Pointer_group_interface::add_grob (me, ly_symbol2scm ("ties"), tie);
42 }
43
44 /*
45   Extend the spanner over its Tie constituents.
46 */
47 MAKE_SCHEME_CALLBACK (Tie_column, before_line_breaking, 1);
48 SCM
49 Tie_column::before_line_breaking (SCM smob)
50 {
51   Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
52   for (SCM s = me->get_property ("ties"); scm_is_pair (s); s = scm_cdr (s))
53     {
54       Spanner *tie = dynamic_cast<Spanner *> (unsmob_grob (scm_car (s)));
55       Direction dir = LEFT;
56       do
57         {
58           if (dir * tie->get_bound (dir)->get_column ()->get_rank ()
59               > dir * me->get_bound (dir)->get_column ()->get_rank ())
60             me->set_bound (dir, Tie::head (tie, dir));
61         }
62       while (flip (&dir) != LEFT);
63     }
64   
65   return SCM_UNSPECIFIED;
66 }
67
68 MAKE_SCHEME_CALLBACK(Tie_column, calc_positioning_done, 1)
69 SCM
70 Tie_column::calc_positioning_done (SCM smob)
71 {
72   Grob *me = unsmob_grob (smob);
73   extract_grob_set (me, "ties", ro_ties);
74   vector<Grob*> ties (ro_ties);
75   if (!ties.size ())
76     return SCM_BOOL_T;
77
78   if (ties.size() == 1)
79     {
80       /*
81         Already handled by standard mechanisms.
82        */
83       return SCM_BOOL_T;
84     }
85   
86   vector_sort (ties, &Tie::compare);
87
88   Tie_formatting_problem problem;
89   problem.from_ties (ties);
90
91   SCM manual_configs = me->get_property ("tie-configuration");
92   problem.set_manual_tie_configuration (manual_configs);
93
94
95   Ties_configuration base = problem.generate_optimal_chord_configuration ();
96
97   for (vsize i = 0; i < base.size(); i++)
98     {
99       Tie::set_control_points (ties[i], problem.common_x_refpoint (),
100                                base[i],
101                                problem.details_);
102       set_grob_direction (ties[i],
103                           base[i].dir_);
104
105 #if DEBUG_TIE_SCORING
106       if (to_boolean (me->layout ()
107                       ->lookup_variable (ly_symbol2scm ("debug-tie-scoring"))))
108         {
109           string card = to_string ("%d (%.2f): ", base[i].position_, base[i].delta_y_)
110             + base[i].card () + base.tie_card (i);
111
112           
113           if (i == 0)
114             card += base.card ();
115           if (i == base.size () - 1)
116             card += to_string ("TOTAL=%.2f", base.score ());
117           
118           ties[i]->set_property ("quant-score",
119                                  scm_makfrom0str (card.c_str ()));
120         }
121 #endif
122       
123     }
124   return SCM_BOOL_T;
125 }
126
127
128
129 ADD_INTERFACE (Tie_column, "tie-column-interface",
130                "Object that sets directions of multiple ties in a tied chord",
131
132                /* properties */
133                "positioning-done "
134                "tie-configuration "
135                );
136