X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fhorizontal-bracket-engraver.cc;h=860495750ad4124c5cff1c9c0b432800b668dfb6;hb=b872748c6aa8bb721ced458691b38ac2fac5dfc8;hp=0148204f9c7953f884ae3beb41db888e5c5fd9a0;hpb=83ed05cef3bfcbd69f4148e8ee0669ca0664e214;p=lilypond.git diff --git a/lily/horizontal-bracket-engraver.cc b/lily/horizontal-bracket-engraver.cc index 0148204f9c..860495750a 100644 --- a/lily/horizontal-bracket-engraver.cc +++ b/lily/horizontal-bracket-engraver.cc @@ -1,115 +1,155 @@ /* - horizontal-bracket-engraver.cc -- implement - Horizontal_bracket_engraver + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2002--2015 Han-Wen Nienhuys - (c) 2002--2005 Han-Wen Nienhuys + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #include "engraver.hh" -#include "side-position-interface.hh" +#include "international.hh" +#include "item.hh" #include "note-column.hh" #include "pointer-group-interface.hh" +#include "side-position-interface.hh" +#include "spanner.hh" +#include "stream-event.hh" + +#include "translator.icc" class Horizontal_bracket_engraver : public Engraver { public: TRANSLATOR_DECLARATIONS (Horizontal_bracket_engraver); - Link_array bracket_stack_; - Link_array events_; - int pop_count_; - int push_count_; - - virtual bool try_music (Music *); - PRECOMPUTED_VIRTUAL void stop_translation_timestep (); - PRECOMPUTED_VIRTUAL void process_music (); - DECLARE_ACKNOWLEDGER(note_column); + vector bracket_stack_; + vector text_stack_; + vector events_; + vsize pop_count_; + vsize push_count_; + + void stop_translation_timestep (); + void process_music (); + void acknowledge_note_column (Grob_info); + void listen_note_grouping (Stream_event *); }; -#include "translator.icc" -ADD_ACKNOWLEDGER(Horizontal_bracket_engraver,note_column); -ADD_TRANSLATOR (Horizontal_bracket_engraver, - "Create horizontal brackets over notes for musical analysis purposes.", - "HorizontalBracket", - "note-grouping-event", - "", - "", - ""); - -Horizontal_bracket_engraver::Horizontal_bracket_engraver () +Horizontal_bracket_engraver::Horizontal_bracket_engraver (Context *c) + : Engraver (c) { pop_count_ = 0; push_count_ = 0; } -bool -Horizontal_bracket_engraver::try_music (Music *m) +void +Horizontal_bracket_engraver::listen_note_grouping (Stream_event *ev) { - if (m->is_mus_type ("note-grouping-event")) + Direction d = to_dir (ev->get_property ("span-direction")); + + if (d == STOP) { - Direction d = to_dir (m->get_property ("span-direction")); - - if (d == STOP) - { - pop_count_++; - if (pop_count_ > bracket_stack_.size ()) - m->origin ()->warning (_ ("don't have that many brackets")); - } - else - { - push_count_++; - events_.push (m); - } - - if (pop_count_ && push_count_) - m->origin ()->warning (_ ("conflicting note group events")); - - return true; + pop_count_++; + if (pop_count_ > bracket_stack_.size ()) + ev->origin ()->warning (_ ("do not have that many brackets")); } - return false; + else + { + push_count_++; + events_.push_back (ev); + } + + if (pop_count_ && push_count_) + ev->origin ()->warning (_ ("conflicting note group events")); } void Horizontal_bracket_engraver::acknowledge_note_column (Grob_info gi) { - for (int i = 0; i < bracket_stack_.size (); i++) + for (vsize i = 0; i < bracket_stack_.size (); i++) { Side_position_interface::add_support (bracket_stack_[i], gi.grob ()); Pointer_group_interface::add_grob (bracket_stack_[i], - ly_symbol2scm ("columns"), gi.grob ()); + ly_symbol2scm ("columns"), gi.grob ()); add_bound_item (bracket_stack_[i], - gi.grob ()); + gi.grob ()); + add_bound_item (text_stack_[i], + gi.grob ()); } } void Horizontal_bracket_engraver::process_music () { - for (int k = 0; k < push_count_; k++) + for (vsize k = 0; k < push_count_; k++) { Spanner *sp = make_spanner ("HorizontalBracket", events_[k]->self_scm ()); - for (int i = 0; i < bracket_stack_.size (); i++) - { - /* - sp is the smallest, it should be added to the bigger brackets. - */ - Side_position_interface::add_support (bracket_stack_[i], sp); - } - bracket_stack_.push (sp); + Spanner *hbt = make_spanner ("HorizontalBracketText", sp->self_scm ()); + + sp->set_object ("bracket-text", hbt->self_scm ()); + + Side_position_interface::add_support (hbt, sp); + + hbt->set_parent (sp, X_AXIS); + hbt->set_parent (sp, Y_AXIS); + hbt->set_object ("bracket", sp->self_scm ()); + + for (vsize i = 0; i < bracket_stack_.size (); i++) + /* sp is the smallest, it should be added to the bigger brackets. */ + { + Side_position_interface::add_support (bracket_stack_[i], sp); + Side_position_interface::add_support (bracket_stack_[i], hbt); + } + + bracket_stack_.push_back (sp); + text_stack_.push_back (hbt); } } void Horizontal_bracket_engraver::stop_translation_timestep () { - for (int i = pop_count_; i--;) + for (vsize i = pop_count_; i--;) { if (bracket_stack_.size ()) - bracket_stack_.pop (); + bracket_stack_.pop_back (); + if (text_stack_.size ()) + text_stack_.pop_back (); } pop_count_ = 0; push_count_ = 0; + events_.clear (); } +void +Horizontal_bracket_engraver::boot () +{ + ADD_LISTENER (Horizontal_bracket_engraver, note_grouping); + ADD_ACKNOWLEDGER (Horizontal_bracket_engraver, note_column); +} + +ADD_TRANSLATOR (Horizontal_bracket_engraver, + /* doc */ + "Create horizontal brackets over notes for musical analysis" + " purposes.", + + /* create */ + "HorizontalBracket " + "HorizontalBracketText ", + + /* read */ + "", + + /* write */ + "" + );