]> git.donarmstrong.com Git - lilypond.git/blob - lily/figured-bass-position-engraver.cc
Update mailmap.
[lilypond.git] / lily / figured-bass-position-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "engraver.hh"
22
23 #include "context.hh"
24 #include "spanner.hh"
25 #include "item.hh"
26 #include "side-position-interface.hh"
27 #include "translator.icc"
28 #include "axis-group-interface.hh"
29
30 class Figured_bass_position_engraver : public Engraver
31 {
32   TRANSLATOR_DECLARATIONS (Figured_bass_position_engraver);
33
34   Spanner *bass_figure_alignment_;
35   Spanner *positioner_;
36   vector<Grob*> support_;
37   vector<Grob*> span_support_;
38 protected:
39   DECLARE_ACKNOWLEDGER (note_column);
40   DECLARE_ACKNOWLEDGER (slur);
41   DECLARE_END_ACKNOWLEDGER (slur);
42   DECLARE_ACKNOWLEDGER (tie);
43   DECLARE_ACKNOWLEDGER (bass_figure_alignment);
44   DECLARE_END_ACKNOWLEDGER (bass_figure_alignment);
45
46   virtual void finalize ();
47   void start_spanner ();
48   void stop_spanner ();
49   void stop_translation_timestep ();
50 };
51
52 Figured_bass_position_engraver::Figured_bass_position_engraver ()
53 {
54   positioner_ = 0;
55   bass_figure_alignment_ = 0;
56 }
57
58 void
59 Figured_bass_position_engraver::start_spanner ()
60 {
61   assert (!positioner_);
62
63   positioner_ = make_spanner ("BassFigureAlignmentPositioning", bass_figure_alignment_->self_scm ());
64   positioner_->set_bound (LEFT, bass_figure_alignment_->get_bound (LEFT));
65   Axis_group_interface::add_element (positioner_, bass_figure_alignment_);
66 }
67
68 void
69 Figured_bass_position_engraver::stop_spanner ()
70 {
71   if (positioner_ && !positioner_->get_bound (RIGHT))
72     {
73       positioner_->set_bound (RIGHT, bass_figure_alignment_->get_bound (RIGHT));
74     }
75   
76   positioner_ = 0;
77   bass_figure_alignment_ = 0;
78 }
79
80 void
81 Figured_bass_position_engraver::finalize () 
82 {
83   stop_spanner ();
84 }
85
86 void
87 Figured_bass_position_engraver::acknowledge_note_column (Grob_info info)
88 {
89   support_.push_back (info.grob ());
90 }
91
92 void
93 Figured_bass_position_engraver::acknowledge_end_slur (Grob_info info)
94 {
95   vector<Grob*>::iterator i = find (span_support_.begin (), span_support_.end (),
96                                     info.grob ());
97
98   if (i < span_support_.end ())
99     span_support_.erase (i);
100 }
101
102 void
103 Figured_bass_position_engraver::acknowledge_slur (Grob_info info)
104 {
105   span_support_.push_back (info.grob ());
106 }
107
108 void
109 Figured_bass_position_engraver::acknowledge_tie (Grob_info info)
110 {
111   support_.push_back (info.grob ());
112 }
113
114 void
115 Figured_bass_position_engraver::stop_translation_timestep ()
116 {
117   if (positioner_)
118     {
119       for (vsize i = 0; i < span_support_.size (); i++)
120         Side_position_interface::add_support (positioner_, span_support_[i]);
121       for (vsize i = 0; i < support_.size (); i++)
122         Side_position_interface::add_support (positioner_, support_[i]);
123     }
124
125   support_.clear ();
126 }
127
128 void
129 Figured_bass_position_engraver::acknowledge_end_bass_figure_alignment (Grob_info /* info */)
130 {
131   stop_spanner ();
132 }
133
134 void
135 Figured_bass_position_engraver::acknowledge_bass_figure_alignment (Grob_info info)
136 {
137   bass_figure_alignment_ = dynamic_cast<Spanner*> (info.grob ());
138   start_spanner ();
139 }
140
141
142 ADD_ACKNOWLEDGER (Figured_bass_position_engraver, note_column);
143 ADD_ACKNOWLEDGER (Figured_bass_position_engraver, slur);
144 ADD_END_ACKNOWLEDGER (Figured_bass_position_engraver, slur);
145
146 ADD_ACKNOWLEDGER (Figured_bass_position_engraver, tie);
147 ADD_ACKNOWLEDGER (Figured_bass_position_engraver, bass_figure_alignment);
148 ADD_END_ACKNOWLEDGER (Figured_bass_position_engraver, bass_figure_alignment);
149
150 ADD_TRANSLATOR (Figured_bass_position_engraver,
151                 /* doc */
152                 "Position figured bass alignments over notes.",
153                 
154                 /* create */
155                 "BassFigureAlignmentPositioning ",
156
157                 /* read */
158                 "",
159
160                 /* write */
161                 ""
162                 );