X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fdynamic-align-engraver.cc;h=265498658abb01358aa6cd86b18ee21986fa666b;hb=0a0274a3bf5792dfb7ce3719f5dfaef36059affe;hp=8e82b834748720e8748140fe6badc4fe7b643511;hpb=8860a7700be8348848bba7972ad86ef46721c544;p=lilypond.git diff --git a/lily/dynamic-align-engraver.cc b/lily/dynamic-align-engraver.cc index 8e82b83474..265498658a 100644 --- a/lily/dynamic-align-engraver.cc +++ b/lily/dynamic-align-engraver.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 2008--2010 Han-Wen Nienhuys + Copyright (C) 2008--2012 Han-Wen Nienhuys LilyPond is free software: you can redistribute it and/or modify @@ -34,9 +34,9 @@ class Dynamic_align_engraver : public Engraver { TRANSLATOR_DECLARATIONS (Dynamic_align_engraver); - DECLARE_TRANSLATOR_LISTENER (break_span); DECLARE_ACKNOWLEDGER (note_column); DECLARE_ACKNOWLEDGER (dynamic); + DECLARE_ACKNOWLEDGER (footnote_spanner); DECLARE_END_ACKNOWLEDGER (dynamic); protected: @@ -44,25 +44,28 @@ protected: private: void create_line_spanner (Stream_event *cause); + void set_spanner_bounds (Spanner *line, bool end); Spanner *line_; + Spanner *ended_line_; // Spanner manually broken, don't use it for new grobs + Spanner *current_dynamic_spanner_; vector ended_; vector started_; vector scripts_; vector support_; set running_; - - bool early_end_; }; Dynamic_align_engraver::Dynamic_align_engraver () { line_ = 0; - early_end_ = false; + ended_line_ = 0; + current_dynamic_spanner_ = 0; } ADD_ACKNOWLEDGER (Dynamic_align_engraver, dynamic); ADD_ACKNOWLEDGER (Dynamic_align_engraver, note_column); +ADD_ACKNOWLEDGER (Dynamic_align_engraver, footnote_spanner); ADD_END_ACKNOWLEDGER (Dynamic_align_engraver, dynamic); void @@ -70,7 +73,7 @@ Dynamic_align_engraver::create_line_spanner (Stream_event *event) { if (!line_) line_ = make_spanner ("DynamicLineSpanner", - event ? event->self_scm () : SCM_EOL); + event ? event->self_scm () : SCM_EOL); } void @@ -78,38 +81,63 @@ Dynamic_align_engraver::acknowledge_end_dynamic (Grob_info info) { if (Spanner::has_interface (info.grob ())) ended_.push_back (info.spanner ()); + + /* If the break flag is set, store the current spanner and let new dynamics + * create a new spanner + */ + bool spanner_broken = current_dynamic_spanner_ == info.spanner () + && to_boolean (current_dynamic_spanner_->get_property ("spanner-broken")); + if (spanner_broken && line_) + { + if (ended_line_) + programming_error ("already have a force-ended DynamicLineSpanner."); + ended_line_ = line_; + line_ = 0; + current_dynamic_spanner_ = 0; + } } void -Dynamic_align_engraver::acknowledge_note_column (Grob_info info) +Dynamic_align_engraver::acknowledge_footnote_spanner (Grob_info info) { - support_.push_back (info.grob ()); + Grob *parent = info.grob ()->get_parent (Y_AXIS); + if (line_ && parent + && parent->internal_has_interface (ly_symbol2scm ("dynamic-interface"))) + Axis_group_interface::add_element (line_, info.grob ()); } -IMPLEMENT_TRANSLATOR_LISTENER (Dynamic_align_engraver, break_span); void -Dynamic_align_engraver::listen_break_span (Stream_event *event) +Dynamic_align_engraver::acknowledge_note_column (Grob_info info) { - if (event->in_event_class ("break-dynamic-span-event")) - early_end_ = true; + support_.push_back (info.grob ()); } void Dynamic_align_engraver::acknowledge_dynamic (Grob_info info) { Stream_event *cause = info.event_cause (); + // Check whether an existing line spanner has the same direction + if (line_ && cause) + { + Direction line_dir = get_grob_direction (line_); + Direction grob_dir = to_dir (cause->get_property ("direction")); + + // If we have an explicit direction for the new dynamic grob + // that differs from the current line spanner, break the spanner + if (grob_dir && (line_dir != grob_dir)) + { + if (!ended_line_) + ended_line_ = line_; + line_ = 0; + current_dynamic_spanner_ = 0; + } + } + create_line_spanner (cause); if (Spanner::has_interface (info.grob ())) { started_.push_back (info.spanner ()); - /* - If we are using text spans instead of hairpins and the line - is hidden, end the alignment spanner early: this allows dynamics - to be spaced individually instead of being linked together. - */ - if (info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-text-spanner-interface")) - && (info.grob ()->get_property ("style") == ly_symbol2scm ("none"))) - early_end_ = true; + current_dynamic_spanner_ = info.spanner (); } else if (info.item ()) scripts_.push_back (info.item ()); @@ -121,7 +149,37 @@ Dynamic_align_engraver::acknowledge_dynamic (Grob_info info) if (cause) { if (Direction d = to_dir (cause->get_property ("direction"))) - set_grob_direction (line_, d); + set_grob_direction (line_, d); + } +} + +void +Dynamic_align_engraver::set_spanner_bounds (Spanner *line, bool end) +{ + if (!line) + return; + + for (LEFT_and_RIGHT (d)) + { + if ((d == LEFT && !line->get_bound (LEFT)) + || (end && d == RIGHT && !line->get_bound (RIGHT))) + { + vector const &spanners + = (d == LEFT) ? started_ : ended_; + + Grob *bound = 0; + if (scripts_.size ()) + bound = scripts_[0]; + else if (spanners.size ()) + bound = spanners[0]->get_bound (d); + else + { + bound = unsmob_grob (get_property ("currentMusicalColumn")); + programming_error ("started DynamicLineSpanner but have no left bound"); + } + + line->set_bound (d, bound); + } } } @@ -136,49 +194,31 @@ Dynamic_align_engraver::stop_translation_timestep () set::iterator it = running_.find (sp); if (it != running_.end ()) - running_.erase (it); + running_.erase (it); else - started_[i]->programming_error ("lost track of this dynamic spanner"); - } - - bool end = line_ && (running_.empty () - || early_end_); - Direction d = LEFT; - do - { - if (line_ - && ((d == LEFT && !line_->get_bound (LEFT)) - || (end && d == RIGHT && !line_->get_bound (RIGHT)))) - { - vector const &spanners - = (d == LEFT) ? started_ : ended_; - - Grob *bound = 0; - if (scripts_.size ()) - bound = scripts_[0]; - else if (spanners.size ()) - bound = spanners[0]->get_bound (d); - else - { - bound = unsmob_grob (get_property ("currentMusicalColumn")); - if (!early_end_) - programming_error ("started DynamicLineSpanner but have no left bound"); - } - - line_->set_bound (d, bound); - } + started_[i]->programming_error ("lost track of this dynamic spanner"); } - while (flip (&d) != LEFT); - for (vsize i = 0; line_ && i < support_.size (); i++) + bool end = line_ && running_.empty (); + + // Set the proper bounds for the current spanner and for a spanner that + // is ended now + set_spanner_bounds (ended_line_, true); + set_spanner_bounds (line_, end); + // If the flag is set to break the spanner after the current child, don't + // add any more support points (needed e.g. for style=none, where the + // invisible spanner should NOT be shifted since we don't have a line). + bool spanner_broken = current_dynamic_spanner_ + && to_boolean (current_dynamic_spanner_->get_property ("spanner-broken")); + for (vsize i = 0; line_ && !spanner_broken && i < support_.size (); i++) Side_position_interface::add_support (line_, support_[i]); if (end) { line_ = 0; - early_end_ = false; } + ended_line_ = 0; ended_.clear (); started_.clear (); scripts_.clear (); @@ -186,15 +226,15 @@ Dynamic_align_engraver::stop_translation_timestep () } ADD_TRANSLATOR (Dynamic_align_engraver, - /* doc */ - "Align hairpins and dynamic texts on a horizontal line.", + /* doc */ + "Align hairpins and dynamic texts on a horizontal line.", - /* create */ - "DynamicLineSpanner ", + /* create */ + "DynamicLineSpanner ", - /* read */ - "currentMusicalColumn ", + /* read */ + "currentMusicalColumn ", - /* write */ - "" - ); + /* write */ + "" + );