]> git.donarmstrong.com Git - lilypond.git/blob - lily/figured-bass-position-engraver.cc
Web-ja: update introduction
[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--2015 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   void acknowledge_note_column (Grob_info);
40   void acknowledge_slur (Grob_info);
41   void acknowledge_end_slur (Grob_info);
42   void acknowledge_end_tie (Grob_info);
43   void acknowledge_bass_figure_alignment (Grob_info);
44   void acknowledge_end_bass_figure_alignment (Grob_info);
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 (Context *c)
53   : Engraver (c)
54 {
55   positioner_ = 0;
56   bass_figure_alignment_ = 0;
57 }
58
59 void
60 Figured_bass_position_engraver::start_spanner ()
61 {
62   assert (!positioner_);
63
64   positioner_ = make_spanner ("BassFigureAlignmentPositioning", bass_figure_alignment_->self_scm ());
65   positioner_->set_bound (LEFT, bass_figure_alignment_->get_bound (LEFT));
66   Axis_group_interface::add_element (positioner_, bass_figure_alignment_);
67 }
68
69 void
70 Figured_bass_position_engraver::stop_spanner ()
71 {
72   if (positioner_ && !positioner_->get_bound (RIGHT))
73     {
74       positioner_->set_bound (RIGHT, bass_figure_alignment_->get_bound (RIGHT));
75     }
76
77   positioner_ = 0;
78   bass_figure_alignment_ = 0;
79 }
80
81 void
82 Figured_bass_position_engraver::finalize ()
83 {
84   stop_spanner ();
85 }
86
87 void
88 Figured_bass_position_engraver::acknowledge_note_column (Grob_info info)
89 {
90   support_.push_back (info.grob ());
91 }
92
93 void
94 Figured_bass_position_engraver::acknowledge_end_slur (Grob_info info)
95 {
96   vector<Grob *>::iterator i = find (span_support_.begin (), span_support_.end (),
97                                      info.grob ());
98
99   if (i < span_support_.end ())
100     span_support_.erase (i);
101 }
102
103 void
104 Figured_bass_position_engraver::acknowledge_slur (Grob_info info)
105 {
106   span_support_.push_back (info.grob ());
107 }
108
109 void
110 Figured_bass_position_engraver::acknowledge_end_tie (Grob_info info)
111 {
112   support_.push_back (info.grob ());
113 }
114
115 void
116 Figured_bass_position_engraver::stop_translation_timestep ()
117 {
118   if (positioner_)
119     {
120       for (vsize i = 0; i < span_support_.size (); i++)
121         Side_position_interface::add_support (positioner_, span_support_[i]);
122       for (vsize i = 0; i < support_.size (); i++)
123         Side_position_interface::add_support (positioner_, support_[i]);
124     }
125
126   support_.clear ();
127 }
128
129 void
130 Figured_bass_position_engraver::acknowledge_end_bass_figure_alignment (Grob_info /* info */)
131 {
132   stop_spanner ();
133 }
134
135 void
136 Figured_bass_position_engraver::acknowledge_bass_figure_alignment (Grob_info info)
137 {
138   bass_figure_alignment_ = dynamic_cast<Spanner *> (info.grob ());
139   start_spanner ();
140 }
141
142
143
144 void
145 Figured_bass_position_engraver::boot ()
146 {
147   ADD_ACKNOWLEDGER (Figured_bass_position_engraver, note_column);
148   ADD_ACKNOWLEDGER (Figured_bass_position_engraver, slur);
149   ADD_END_ACKNOWLEDGER (Figured_bass_position_engraver, slur);
150   ADD_END_ACKNOWLEDGER (Figured_bass_position_engraver, tie);
151   ADD_ACKNOWLEDGER (Figured_bass_position_engraver, bass_figure_alignment);
152   ADD_END_ACKNOWLEDGER (Figured_bass_position_engraver, bass_figure_alignment);
153 }
154
155 ADD_TRANSLATOR (Figured_bass_position_engraver,
156                 /* doc */
157                 "Position figured bass alignments over notes.",
158
159                 /* create */
160                 "BassFigureAlignmentPositioning ",
161
162                 /* read */
163                 "",
164
165                 /* write */
166                 ""
167                );