2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2002--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
20 #include "engraver.hh"
21 #include "international.hh"
23 #include "note-column.hh"
24 #include "pointer-group-interface.hh"
25 #include "side-position-interface.hh"
27 #include "stream-event.hh"
29 #include "translator.icc"
31 class Horizontal_bracket_engraver : public Engraver
34 TRANSLATOR_DECLARATIONS (Horizontal_bracket_engraver);
35 vector<Spanner *> bracket_stack_;
36 vector<Stream_event *> events_;
40 void stop_translation_timestep ();
41 void process_music ();
42 DECLARE_ACKNOWLEDGER (note_column);
43 DECLARE_TRANSLATOR_LISTENER (note_grouping);
46 Horizontal_bracket_engraver::Horizontal_bracket_engraver ()
52 IMPLEMENT_TRANSLATOR_LISTENER (Horizontal_bracket_engraver, note_grouping);
54 Horizontal_bracket_engraver::listen_note_grouping (Stream_event *ev)
56 Direction d = to_dir (ev->get_property ("span-direction"));
61 if (pop_count_ > bracket_stack_.size ())
62 ev->origin ()->warning (_ ("do not have that many brackets"));
67 events_.push_back (ev);
70 if (pop_count_ && push_count_)
71 ev->origin ()->warning (_ ("conflicting note group events"));
75 Horizontal_bracket_engraver::acknowledge_note_column (Grob_info gi)
77 for (vsize i = 0; i < bracket_stack_.size (); i++)
79 Side_position_interface::add_support (bracket_stack_[i], gi.grob ());
80 Pointer_group_interface::add_grob (bracket_stack_[i],
81 ly_symbol2scm ("columns"), gi.grob ());
82 add_bound_item (bracket_stack_[i],
88 Horizontal_bracket_engraver::process_music ()
90 for (vsize k = 0; k < push_count_; k++)
92 Spanner *sp = make_spanner ("HorizontalBracket", events_[k]->self_scm ());
94 for (vsize i = 0; i < bracket_stack_.size (); i++)
95 /* sp is the smallest, it should be added to the bigger brackets. */
96 Side_position_interface::add_support (bracket_stack_[i], sp);
97 bracket_stack_.push_back (sp);
102 Horizontal_bracket_engraver::stop_translation_timestep ()
104 for (vsize i = pop_count_; i--;)
105 if (bracket_stack_.size ())
106 bracket_stack_.pop_back ();
112 ADD_ACKNOWLEDGER (Horizontal_bracket_engraver, note_column);
113 ADD_TRANSLATOR (Horizontal_bracket_engraver,
115 "Create horizontal brackets over notes for musical analysis"
119 "HorizontalBracket ",