]> git.donarmstrong.com Git - lilypond.git/blob - lily/figured-bass-position-engraver.cc
Merge branch 'master' of ssh://jomand@git.sv.gnu.org/srv/git/lilypond into lilypond...
[lilypond.git] / lily / figured-bass-position-engraver.cc
1 /*
2   figured-bass-position-engraver.cc -- implement Figured_bass_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10 #include "engraver.hh"
11
12 #include "context.hh"
13 #include "spanner.hh"
14 #include "item.hh"
15 #include "side-position-interface.hh"
16 #include "translator.icc"
17 #include "axis-group-interface.hh"
18
19 class Figured_bass_position_engraver : public Engraver
20 {
21   TRANSLATOR_DECLARATIONS (Figured_bass_position_engraver);
22
23   Spanner *bass_figure_alignment_;
24   Spanner *positioner_;
25   vector<Grob*> support_;
26   vector<Grob*> span_support_;
27 protected:
28   DECLARE_ACKNOWLEDGER (note_column);
29   DECLARE_ACKNOWLEDGER (slur);
30   DECLARE_END_ACKNOWLEDGER (slur);
31   DECLARE_ACKNOWLEDGER (tie);
32   DECLARE_ACKNOWLEDGER (bass_figure_alignment);
33   DECLARE_END_ACKNOWLEDGER (bass_figure_alignment);
34
35   virtual void finalize ();
36   void start_spanner ();
37   void stop_spanner ();
38   void stop_translation_timestep ();
39 };
40
41 Figured_bass_position_engraver::Figured_bass_position_engraver ()
42 {
43   positioner_ = 0;
44   bass_figure_alignment_ = 0;
45 }
46
47 void
48 Figured_bass_position_engraver::start_spanner ()
49 {
50   assert (!positioner_);
51
52   positioner_ = make_spanner ("BassFigureAlignmentPositioning", bass_figure_alignment_->self_scm ());
53   positioner_->set_bound (LEFT, bass_figure_alignment_->get_bound (LEFT));
54   Axis_group_interface::add_element (positioner_, bass_figure_alignment_);
55 }
56
57 void
58 Figured_bass_position_engraver::stop_spanner ()
59 {
60   if (positioner_ && !positioner_->get_bound (RIGHT))
61     {
62       positioner_->set_bound (RIGHT, bass_figure_alignment_->get_bound (RIGHT));
63     }
64   
65   positioner_ = 0;
66   bass_figure_alignment_ = 0;
67 }
68
69 void
70 Figured_bass_position_engraver::finalize () 
71 {
72   stop_spanner ();
73 }
74
75 void
76 Figured_bass_position_engraver::acknowledge_note_column (Grob_info info)
77 {
78   support_.push_back (info.grob ());
79 }
80
81 void
82 Figured_bass_position_engraver::acknowledge_end_slur (Grob_info info)
83 {
84   vector<Grob*>::iterator i = find (span_support_.begin (), span_support_.end (),
85                                     info.grob ());
86
87   if (i < span_support_.end ())
88     span_support_.erase (i);
89 }
90
91 void
92 Figured_bass_position_engraver::acknowledge_slur (Grob_info info)
93 {
94   span_support_.push_back (info.grob ());
95 }
96
97 void
98 Figured_bass_position_engraver::acknowledge_tie (Grob_info info)
99 {
100   support_.push_back (info.grob ());
101 }
102
103 void
104 Figured_bass_position_engraver::stop_translation_timestep ()
105 {
106   if (positioner_)
107     {
108       for (vsize i = 0; i < span_support_.size (); i++)
109         Side_position_interface::add_support (positioner_, span_support_[i]);
110       for (vsize i = 0; i < support_.size (); i++)
111         Side_position_interface::add_support (positioner_, support_[i]);
112     }
113
114   support_.clear ();
115 }
116
117 void
118 Figured_bass_position_engraver::acknowledge_end_bass_figure_alignment (Grob_info /* info */)
119 {
120   stop_spanner ();
121 }
122
123 void
124 Figured_bass_position_engraver::acknowledge_bass_figure_alignment (Grob_info info)
125 {
126   bass_figure_alignment_ = dynamic_cast<Spanner*> (info.grob ());
127   start_spanner ();
128 }
129
130
131 ADD_ACKNOWLEDGER (Figured_bass_position_engraver, note_column);
132 ADD_ACKNOWLEDGER (Figured_bass_position_engraver, slur);
133 ADD_END_ACKNOWLEDGER (Figured_bass_position_engraver, slur);
134
135 ADD_ACKNOWLEDGER (Figured_bass_position_engraver, tie);
136 ADD_ACKNOWLEDGER (Figured_bass_position_engraver, bass_figure_alignment);
137 ADD_END_ACKNOWLEDGER (Figured_bass_position_engraver, bass_figure_alignment);
138
139 ADD_TRANSLATOR (Figured_bass_position_engraver,
140                 /* doc */
141                 "Position figured bass alignments over notes.",
142                 
143                 /* create */
144                 "BassFigureAlignmentPositioning ",
145
146                 /* read */
147                 "",
148
149                 /* write */
150                 ""
151                 );