From 5c44c7e89f7871f2949a5507b1f5c38d6b02a447 Mon Sep 17 00:00:00 2001 From: Mike Solomon Date: Sat, 9 Mar 2013 07:39:26 +0100 Subject: [PATCH] Adds Slur_proto_engraver as a base class for Slur_engraver and Phrasing_slur_engraver. --- lily/include/slur-proto-engraver.hh | 73 +++++++ lily/phrasing-slur-engraver.cc | 258 +----------------------- lily/slur-engraver.cc | 272 +------------------------ lily/slur-proto-engraver.cc | 297 ++++++++++++++++++++++++++++ 4 files changed, 382 insertions(+), 518 deletions(-) create mode 100644 lily/include/slur-proto-engraver.hh create mode 100644 lily/slur-proto-engraver.cc diff --git a/lily/include/slur-proto-engraver.hh b/lily/include/slur-proto-engraver.hh new file mode 100644 index 0000000000..0b0861775c --- /dev/null +++ b/lily/include/slur-proto-engraver.hh @@ -0,0 +1,73 @@ +/* + This file is part of LilyPond, the GNU music typesetter. + + Copyright (C) 2013 Mike Solomon + + 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 . +*/ + +#ifndef SLUR_PROTO_ENGRAVER_HH +#define SLUR_PROTO_ENGRAVER_HH + +#include "engraver.hh" +#include "moment.hh" + +class Slur_proto_engraver : public Engraver +{ +protected: + Slur_proto_engraver (const char* double_property_name, + const char* grob_name, const char* object_name, const char* event_name) : + double_property_name_ (double_property_name), + grob_name_ (grob_name), object_name_ (object_name), + event_name_ (event_name) {} + + // protected so that subclasses can see them + vector start_events_; + vector stop_events_; + vector slurs_; + vector end_slurs_; + vector objects_to_acknowledge_; + const char* double_property_name_; + const char* grob_name_; + const char* object_name_; + const char* event_name_; + + DECLARE_ACKNOWLEDGER (inline_accidental); + DECLARE_ACKNOWLEDGER (fingering); + DECLARE_ACKNOWLEDGER (note_column); + DECLARE_ACKNOWLEDGER (script); + DECLARE_ACKNOWLEDGER (dots); + DECLARE_ACKNOWLEDGER (text_script); + DECLARE_END_ACKNOWLEDGER (tie); + DECLARE_ACKNOWLEDGER (tuplet_number); + + void internal_listen_slur (Stream_event *ev); + void acknowledge_extra_object (Grob_info); + void stop_translation_timestep (); + void process_music (); + + bool can_create_slur (string, vsize, vsize *, Stream_event *); + void create_slur (string spanner_id, Stream_event *ev_cause, Grob *g_cause, Direction dir, bool left_broken); + bool try_to_end (Stream_event *ev); + + virtual void set_melisma (bool); + virtual void finalize (); + virtual void derived_mark () const; + +public: + // no TRANSLATOR_DECLARATIONS (Slur_proto_engraver) needed since this + // class is abstract +}; + +#endif // SLUR_PROTO_ENGRAVER_HH diff --git a/lily/phrasing-slur-engraver.cc b/lily/phrasing-slur-engraver.cc index 7e6c3c63fe..6d9aac7af6 100644 --- a/lily/phrasing-slur-engraver.cc +++ b/lily/phrasing-slur-engraver.cc @@ -24,141 +24,33 @@ #include "international.hh" #include "note-column.hh" #include "slur.hh" +#include "slur-proto-engraver.hh" #include "spanner.hh" #include "stream-event.hh" #include "warn.hh" #include "translator.icc" -/* - NOTE NOTE NOTE - - This is largely similar to Slur_engraver. Check if fixes - apply there too. - - (on principle, engravers don't use inheritance for code sharing) - - */ - -/* - It is possible that a slur starts and ends on the same note. At - least, it is for phrasing slurs: a note can be both beginning and - ending of a phrase. -*/ -class Phrasing_slur_engraver : public Engraver +class Phrasing_slur_engraver : public Slur_proto_engraver { - vector start_events_; - vector stop_events_; - vector slurs_; - vector end_slurs_; - vector objects_to_acknowledge_; - protected: DECLARE_TRANSLATOR_LISTENER (phrasing_slur); - DECLARE_ACKNOWLEDGER (inline_accidental); - DECLARE_ACKNOWLEDGER (fingering); - DECLARE_ACKNOWLEDGER (note_column); DECLARE_ACKNOWLEDGER (slur); - DECLARE_ACKNOWLEDGER (script); - DECLARE_ACKNOWLEDGER (dots); - DECLARE_ACKNOWLEDGER (text_script); - DECLARE_END_ACKNOWLEDGER (tie); - DECLARE_ACKNOWLEDGER (tuplet_number); - - void acknowledge_extra_object (Grob_info); - void stop_translation_timestep (); - void process_music (); - - virtual void finalize (); - virtual void derived_mark () const; public: TRANSLATOR_DECLARATIONS (Phrasing_slur_engraver); }; -Phrasing_slur_engraver::Phrasing_slur_engraver () +Phrasing_slur_engraver::Phrasing_slur_engraver () : + Slur_proto_engraver (0, "PhrasingSlur", "phrasing slur", "phrasing-slur-event") { } -void -Phrasing_slur_engraver::derived_mark () const -{ - for (vsize i = start_events_.size (); i--;) - scm_gc_mark (start_events_[i]->self_scm ()); - for (vsize i = stop_events_.size (); i--;) - scm_gc_mark (stop_events_[i]->self_scm ()); -} - IMPLEMENT_TRANSLATOR_LISTENER (Phrasing_slur_engraver, phrasing_slur); void Phrasing_slur_engraver::listen_phrasing_slur (Stream_event *ev) { - Direction d = to_dir (ev->get_property ("span-direction")); - if (d == START) - start_events_.push_back (ev); - else if (d == STOP) - stop_events_.push_back (ev); - else ev->origin ()->warning (_f ("direction of %s invalid: %d", - "phrasing-slur-event", int (d))); -} - -void -Phrasing_slur_engraver::acknowledge_note_column (Grob_info info) -{ - Grob *e = info.grob (); - for (vsize i = slurs_.size (); i--;) - Slur::add_column (slurs_[i], e); - for (vsize i = end_slurs_.size (); i--;) - Slur::add_column (end_slurs_[i], e); -} - -void -Phrasing_slur_engraver::acknowledge_extra_object (Grob_info info) -{ - objects_to_acknowledge_.push_back (info); -} - -void -Phrasing_slur_engraver::acknowledge_inline_accidental (Grob_info info) -{ - acknowledge_extra_object (info); -} - -void -Phrasing_slur_engraver::acknowledge_dots (Grob_info info) -{ - acknowledge_extra_object (info); -} - -void -Phrasing_slur_engraver::acknowledge_fingering (Grob_info info) -{ - acknowledge_extra_object (info); -} - -void -Phrasing_slur_engraver::acknowledge_tuplet_number (Grob_info info) -{ - acknowledge_extra_object (info); -} - -void -Phrasing_slur_engraver::acknowledge_script (Grob_info info) -{ - if (!info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface"))) - acknowledge_extra_object (info); -} - -void -Phrasing_slur_engraver::acknowledge_text_script (Grob_info info) -{ - acknowledge_extra_object (info); -} - -void -Phrasing_slur_engraver::acknowledge_end_tie (Grob_info info) -{ - acknowledge_extra_object (info); + internal_listen_slur (ev); } void @@ -167,146 +59,6 @@ Phrasing_slur_engraver::acknowledge_slur (Grob_info info) acknowledge_extra_object (info); } -void -Phrasing_slur_engraver::finalize () -{ - for (vsize i = 0; i < slurs_.size (); i++) - { - slurs_[i]->warning (_ ("unterminated phrasing slur")); - slurs_[i]->suicide (); - } - slurs_.clear (); -} - -void -Phrasing_slur_engraver::process_music () -{ - for (vsize i = 0; i < stop_events_.size (); i++) - { - Stream_event *ev = stop_events_[i]; - string id = robust_scm2string (ev->get_property ("spanner-id"), ""); - - // Find the slurs that are ended with this event (by checking the spanner-id) - bool ended = false; - for (vsize j = slurs_.size (); j--;) - { - if (id == robust_scm2string (slurs_[j]->get_property ("spanner-id"), "")) - { - ended = true; - end_slurs_.push_back (slurs_[j]); - slurs_.erase (slurs_.begin () + j); - } - } - if (ended) - { - // Ignore redundant stop events for this id - for (vsize j = stop_events_.size (); --j > i;) - { - if (id == robust_scm2string (stop_events_[j]->get_property ("spanner-id"), "")) - stop_events_.erase (stop_events_.begin () + j); - } - } - else - ev->origin ()->warning (_ ("cannot end phrasing slur")); - } - - vsize old_slurs = slurs_.size (); - for (vsize i = start_events_.size (); i--;) - { - Stream_event *ev = start_events_[i]; - string id = robust_scm2string (ev->get_property ("spanner-id"), ""); - Direction updown = to_dir (ev->get_property ("direction")); - - bool completed; - for (vsize j = slurs_.size (); !(completed = (j-- == 0));) - { - // Check if we already have a slur with the same spanner-id. - if (id == robust_scm2string (slurs_[j]->get_property ("spanner-id"), "")) - { - if (j < old_slurs) - { - // We already have an old slur, so give a warning - // and completely ignore the new slur. - ev->origin ()->warning (_ ("already have phrasing slur")); - start_events_.erase (start_events_.begin () + i); - break; - } - - // If this slur event has no direction, it will not - // contribute anything new to the existing slur(s), so - // we can ignore it. - - if (!updown) - break; - - Stream_event *c = unsmob_stream_event (slurs_[j]->get_property ("cause")); - - if (!c) - { - slurs_[j]->programming_error ("phrasing slur without a cause"); - continue; - } - - Direction slur_dir = to_dir (c->get_property ("direction")); - - // If the existing slur does not have a direction yet, - // we'd rather take the new one. - - if (!slur_dir) - { - slurs_[j]->suicide (); - slurs_.erase (slurs_.begin () + j); - continue; - } - - // If the existing slur has the same direction as ours, drop ours - - if (slur_dir == updown) - break; - } - } - // If the loop completed, our slur is new - if (completed) - { - Grob *slur = make_spanner ("PhrasingSlur", ev->self_scm ()); - slur->set_property ("spanner-id", ly_string2scm (id)); - if (updown) - set_grob_direction (slur, updown); - slurs_.push_back (slur); - } - } -} - -void -Phrasing_slur_engraver::stop_translation_timestep () -{ - if (Grob *g = unsmob_grob (get_property ("currentCommandColumn"))) - { - for (vsize i = 0; i < end_slurs_.size (); i++) - Slur::add_extra_encompass (end_slurs_[i], g); - - if (!start_events_.size ()) - for (vsize i = 0; i < slurs_.size (); i++) - Slur::add_extra_encompass (slurs_[i], g); - } - - for (vsize i = 0; i < end_slurs_.size (); i++) - { - Spanner *s = dynamic_cast (end_slurs_[i]); - if (!s->get_bound (RIGHT)) - s->set_bound (RIGHT, unsmob_grob (get_property ("currentMusicalColumn"))); - announce_end_grob (s, SCM_EOL); - } - - for (vsize i = 0; i < objects_to_acknowledge_.size (); i++) - Slur::auxiliary_acknowledge_extra_object (objects_to_acknowledge_[i], slurs_, end_slurs_); - - objects_to_acknowledge_.clear (); - end_slurs_.clear (); - start_events_.clear (); - stop_events_.clear (); -} - ADD_ACKNOWLEDGER (Phrasing_slur_engraver, inline_accidental); ADD_ACKNOWLEDGER (Phrasing_slur_engraver, fingering) ADD_ACKNOWLEDGER (Phrasing_slur_engraver, note_column); diff --git a/lily/slur-engraver.cc b/lily/slur-engraver.cc index 49f92ab0ed..a8a54f535a 100644 --- a/lily/slur-engraver.cc +++ b/lily/slur-engraver.cc @@ -24,298 +24,40 @@ #include "international.hh" #include "note-column.hh" #include "slur.hh" +#include "slur-proto-engraver.hh" #include "spanner.hh" #include "stream-event.hh" #include "warn.hh" #include "translator.icc" -/* - NOTE NOTE NOTE - - This is largely similar to Phrasing_slur_engraver. Check if fixes - apply there too. - - (on principle, engravers don't use inheritance for code sharing) - - */ - -/* - It is possible that a slur starts and ends on the same note. At - least, it is for phrasing slurs: a note can be both beginning and - ending of a phrase. -*/ -class Slur_engraver : public Engraver +class Slur_engraver : public Slur_proto_engraver { - vector start_events_; - vector stop_events_; - vector slurs_; - vector end_slurs_; - vector objects_to_acknowledge_; - - void set_melisma (bool); + virtual void set_melisma (bool); protected: DECLARE_TRANSLATOR_LISTENER (slur); - DECLARE_ACKNOWLEDGER (inline_accidental); - DECLARE_ACKNOWLEDGER (fingering); - DECLARE_ACKNOWLEDGER (note_column); - DECLARE_ACKNOWLEDGER (script); - DECLARE_ACKNOWLEDGER (dots); - DECLARE_ACKNOWLEDGER (text_script); - DECLARE_END_ACKNOWLEDGER (tie); - DECLARE_ACKNOWLEDGER (tuplet_number); - - void acknowledge_extra_object (Grob_info); - void stop_translation_timestep (); - void process_music (); - - virtual void finalize (); - virtual void derived_mark () const; public: TRANSLATOR_DECLARATIONS (Slur_engraver); }; -Slur_engraver::Slur_engraver () +Slur_engraver::Slur_engraver () : + Slur_proto_engraver ("doubleSlurs", "Slur", "slur", "slur-event") { } -void -Slur_engraver::derived_mark () const -{ - for (vsize i = start_events_.size (); i--;) - scm_gc_mark (start_events_[i]->self_scm ()); - for (vsize i = stop_events_.size (); i--;) - scm_gc_mark (stop_events_[i]->self_scm ()); -} - IMPLEMENT_TRANSLATOR_LISTENER (Slur_engraver, slur); void Slur_engraver::listen_slur (Stream_event *ev) { - Direction d = to_dir (ev->get_property ("span-direction")); - if (d == START) - start_events_.push_back (ev); - else if (d == STOP) - stop_events_.push_back (ev); - else ev->origin ()->warning (_f ("direction of %s invalid: %d", - "slur-event", int (d))); + internal_listen_slur (ev); } void Slur_engraver::set_melisma (bool m) { - context ()->set_property ("slurMelismaBusy", m ? SCM_BOOL_T : SCM_BOOL_F); -} - -void -Slur_engraver::acknowledge_note_column (Grob_info info) -{ - Grob *e = info.grob (); - for (vsize i = slurs_.size (); i--;) - Slur::add_column (slurs_[i], e); - for (vsize i = end_slurs_.size (); i--;) - Slur::add_column (end_slurs_[i], e); -} - -void -Slur_engraver::acknowledge_extra_object (Grob_info info) -{ - objects_to_acknowledge_.push_back (info); -} - -void -Slur_engraver::acknowledge_inline_accidental (Grob_info info) -{ - acknowledge_extra_object (info); -} - -void -Slur_engraver::acknowledge_dots (Grob_info info) -{ - acknowledge_extra_object (info); -} - -void -Slur_engraver::acknowledge_fingering (Grob_info info) -{ - acknowledge_extra_object (info); -} - -void -Slur_engraver::acknowledge_tuplet_number (Grob_info info) -{ - acknowledge_extra_object (info); -} - -void -Slur_engraver::acknowledge_script (Grob_info info) -{ - if (!info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface"))) - acknowledge_extra_object (info); -} - -void -Slur_engraver::acknowledge_text_script (Grob_info info) -{ - acknowledge_extra_object (info); -} - -void -Slur_engraver::acknowledge_end_tie (Grob_info info) -{ - acknowledge_extra_object (info); -} - -void -Slur_engraver::finalize () -{ - for (vsize i = 0; i < slurs_.size (); i++) - { - slurs_[i]->warning (_ ("unterminated slur")); - slurs_[i]->suicide (); - } - slurs_.clear (); -} - -void -Slur_engraver::process_music () -{ - for (vsize i = 0; i < stop_events_.size (); i++) - { - Stream_event *ev = stop_events_[i]; - string id = robust_scm2string (ev->get_property ("spanner-id"), ""); - - // Find the slurs that are ended with this event (by checking the spanner-id) - bool ended = false; - for (vsize j = slurs_.size (); j--;) - { - if (id == robust_scm2string (slurs_[j]->get_property ("spanner-id"), "")) - { - ended = true; - end_slurs_.push_back (slurs_[j]); - slurs_.erase (slurs_.begin () + j); - } - } - if (ended) - { - // Ignore redundant stop events for this id - for (vsize j = stop_events_.size (); --j > i;) - { - if (id == robust_scm2string (stop_events_[j]->get_property ("spanner-id"), "")) - stop_events_.erase (stop_events_.begin () + j); - } - } - else - ev->origin ()->warning (_ ("cannot end slur")); - } - - vsize old_slurs = slurs_.size (); - for (vsize i = start_events_.size (); i--;) - { - Stream_event *ev = start_events_[i]; - string id = robust_scm2string (ev->get_property ("spanner-id"), ""); - Direction updown = to_dir (ev->get_property ("direction")); - - bool completed; - for (vsize j = slurs_.size (); !(completed = (j-- == 0));) - { - // Check if we already have a slur with the same spanner-id. - if (id == robust_scm2string (slurs_[j]->get_property ("spanner-id"), "")) - { - if (j < old_slurs) - { - // We already have an old slur, so give a warning - // and completely ignore the new slur. - ev->origin ()->warning (_ ("already have slur")); - start_events_.erase (start_events_.begin () + i); - break; - } - - // If this slur event has no direction, it will not - // contribute anything new to the existing slur(s), so - // we can ignore it. - - if (!updown) - break; - - Stream_event *c = unsmob_stream_event (slurs_[j]->get_property ("cause")); - - if (!c) - { - slurs_[j]->programming_error ("slur without a cause"); - continue; - } - - Direction slur_dir = to_dir (c->get_property ("direction")); - - // If the existing slur does not have a direction yet, - // we'd rather take the new one. - - if (!slur_dir) - { - slurs_[j]->suicide (); - slurs_.erase (slurs_.begin () + j); - continue; - } - - // If the existing slur has the same direction as ours, drop ours - - if (slur_dir == updown) - break; - } - } - // If the loop completed, our slur is new - if (completed) - { - Grob *slur = make_spanner ("Slur", ev->self_scm ()); - slur->set_property ("spanner-id", ly_string2scm (id)); - if (updown) - set_grob_direction (slur, updown); - slurs_.push_back (slur); - - if (to_boolean (get_property ("doubleSlurs"))) - { - set_grob_direction (slur, DOWN); - slur = make_spanner ("Slur", ev->self_scm ()); - slur->set_property ("spanner-id", ly_string2scm (id)); - set_grob_direction (slur, UP); - slurs_.push_back (slur); - } - } - } - set_melisma (slurs_.size ()); -} - -void -Slur_engraver::stop_translation_timestep () -{ - if (Grob *g = unsmob_grob (get_property ("currentCommandColumn"))) - { - for (vsize i = 0; i < end_slurs_.size (); i++) - Slur::add_extra_encompass (end_slurs_[i], g); - - if (!start_events_.size ()) - for (vsize i = 0; i < slurs_.size (); i++) - Slur::add_extra_encompass (slurs_[i], g); - } - - for (vsize i = 0; i < end_slurs_.size (); i++) - { - Spanner *s = dynamic_cast (end_slurs_[i]); - if (!s->get_bound (RIGHT)) - s->set_bound (RIGHT, unsmob_grob (get_property ("currentMusicalColumn"))); - announce_end_grob (s, SCM_EOL); - } - - for (vsize i = 0; i < objects_to_acknowledge_.size (); i++) - Slur::auxiliary_acknowledge_extra_object (objects_to_acknowledge_[i], slurs_, end_slurs_); - - objects_to_acknowledge_.clear (); - end_slurs_.clear (); - start_events_.clear (); - stop_events_.clear (); + context ()->set_property ("slurMelismaBusy", ly_bool2scm (m)); } ADD_ACKNOWLEDGER (Slur_engraver, inline_accidental); diff --git a/lily/slur-proto-engraver.cc b/lily/slur-proto-engraver.cc new file mode 100644 index 0000000000..fbc5f00b84 --- /dev/null +++ b/lily/slur-proto-engraver.cc @@ -0,0 +1,297 @@ +/* + This file is part of LilyPond, the GNU music typesetter. + + Copyright (C) 2013 Mike Solomon + + 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 "context.hh" +#include "directional-element-interface.hh" +#include "international.hh" +#include "note-column.hh" +#include "slur.hh" +#include "slur-proto-engraver.hh" +#include "spanner.hh" +#include "stream-event.hh" +#include "warn.hh" + +#include "translator.icc" + +void +Slur_proto_engraver::derived_mark () const +{ + for (vsize i = start_events_.size (); i--;) + scm_gc_mark (start_events_[i]->self_scm ()); + for (vsize i = stop_events_.size (); i--;) + scm_gc_mark (stop_events_[i]->self_scm ()); +} + +void +Slur_proto_engraver::internal_listen_slur (Stream_event *ev) +{ + Direction d = to_dir (ev->get_property ("span-direction")); + if (d == START) + start_events_.push_back (ev); + else if (d == STOP) + stop_events_.push_back (ev); + else ev->origin ()->warning (_f ("direction of %s invalid: %d", + event_name_, int (d))); +} + +void +Slur_proto_engraver::acknowledge_note_column (Grob_info info) +{ + Grob *e = info.grob (); + for (vsize i = slurs_.size (); i--;) + Slur::add_column (slurs_[i], e); + for (vsize i = end_slurs_.size (); i--;) + Slur::add_column (end_slurs_[i], e); +} + +void +Slur_proto_engraver::acknowledge_extra_object (Grob_info info) +{ + objects_to_acknowledge_.push_back (info); +} + +void +Slur_proto_engraver::acknowledge_inline_accidental (Grob_info info) +{ + acknowledge_extra_object (info); +} + +void +Slur_proto_engraver::acknowledge_dots (Grob_info info) +{ + acknowledge_extra_object (info); +} + +void +Slur_proto_engraver::acknowledge_fingering (Grob_info info) +{ + acknowledge_extra_object (info); +} + +void +Slur_proto_engraver::acknowledge_tuplet_number (Grob_info info) +{ + acknowledge_extra_object (info); +} + +void +Slur_proto_engraver::acknowledge_script (Grob_info info) +{ + if (!info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface"))) + acknowledge_extra_object (info); +} + +void +Slur_proto_engraver::acknowledge_text_script (Grob_info info) +{ + acknowledge_extra_object (info); +} + +void +Slur_proto_engraver::acknowledge_end_tie (Grob_info info) +{ + acknowledge_extra_object (info); +} + +void +Slur_proto_engraver::finalize () +{ + for (vsize i = 0; i < slurs_.size (); i++) + { + slurs_[i]->warning (_f ("unterminated %s", object_name_)); + slurs_[i]->suicide (); + } + slurs_.clear (); +} + +void +Slur_proto_engraver::create_slur (string spanner_id, Stream_event *ev_cause, Grob *g_cause, Direction dir, bool left_broken) +{ + Grob *ccc = unsmob_grob (get_property ("currentCommandColumn")); + SCM cause = ev_cause ? ev_cause->self_scm () : g_cause->self_scm (); + Spanner *slur = make_spanner (grob_name_, cause); + slur->set_property ("spanner-id", ly_string2scm (spanner_id)); + if (dir) + set_grob_direction (slur, dir); + if (left_broken) + slur->set_bound (LEFT, ccc); + slurs_.push_back (slur); + if (double_property_name_ + && to_boolean (get_property (double_property_name_))) + { + set_grob_direction (slur, DOWN); + slur = make_spanner (grob_name_, cause); + slur->set_property ("spanner-id", ly_string2scm (spanner_id)); + set_grob_direction (slur, UP); + if (left_broken) + slur->set_bound (LEFT, ccc); + slurs_.push_back (slur); + } + +} + +bool +Slur_proto_engraver::can_create_slur (string id, vsize old_slurs, vsize *event_idx, Stream_event *ev) +{ + for (vsize j = slurs_.size (); j--;) + { + Grob *slur = slurs_[j]; + Direction updown = to_dir (ev->get_property ("direction")); + + // Check if we already have a slur with the same spanner-id. + if (id == robust_scm2string (slur->get_property ("spanner-id"), "")) + { + if (j < old_slurs) + { + // We already have an old slur, so give a warning + // and completely ignore the new slur. + ev->origin ()->warning (_f ("already have %s", object_name_)); + if (event_idx) + start_events_.erase (start_events_.begin () + (*event_idx)); + return false; + } + + // If this slur event has no direction, it will not + // contribute anything new to the existing slur(s), so + // we can ignore it. + + if (!updown) + return false; + + Stream_event *c = unsmob_stream_event (slur->get_property ("cause")); + + if (!c) + { + slur->programming_error (_f ("%s without a cause", object_name_)); + return true; + } + + Direction slur_dir = to_dir (c->get_property ("direction")); + + // If the existing slur does not have a direction yet, + // we'd rather take the new one. + + if (!slur_dir) + { + slur->suicide (); + slurs_.erase (slurs_.begin () + j); + return true; + } + + // If the existing slur has the same direction as ours, drop ours + + if (slur_dir == updown) + return false; + } + } + return true; +} + +bool +Slur_proto_engraver::try_to_end (Stream_event *ev) +{ + string id = robust_scm2string (ev->get_property ("spanner-id"), ""); + + // Find the slurs that are ended with this event (by checking the spanner-id) + bool ended = false; + for (vsize j = slurs_.size (); j--;) + { + if (id == robust_scm2string (slurs_[j]->get_property ("spanner-id"), "")) + { + ended = true; + end_slurs_.push_back (slurs_[j]); + slurs_.erase (slurs_.begin () + j); + } + } + return ended; +} + +void +Slur_proto_engraver::process_music () +{ + for (vsize i = 0; i < stop_events_.size (); i++) + { + string id = robust_scm2string (stop_events_[i]->get_property ("spanner-id"), ""); + bool ended = try_to_end (stop_events_[i]); + if (ended) + { + // Ignore redundant stop events for this id + for (vsize j = stop_events_.size (); --j > i;) + { + if (id == robust_scm2string (stop_events_[j]->get_property ("spanner-id"), "")) + stop_events_.erase (stop_events_.begin () + j); + } + } + else + stop_events_[i]->origin ()->warning (_f ("cannot end %s", object_name_)); + } + + vsize old_slurs = slurs_.size (); + for (vsize i = start_events_.size (); i--;) + { + Stream_event *ev = start_events_[i]; + string id = robust_scm2string (ev->get_property ("spanner-id"), ""); + Direction updown = to_dir (ev->get_property ("direction")); + + if (can_create_slur (id, old_slurs, &i, ev)) + create_slur (id, ev, 0, updown, false); + } + + set_melisma (slurs_.size ()); +} + +void +Slur_proto_engraver::set_melisma (bool) +{ +} + +void +Slur_proto_engraver::stop_translation_timestep () +{ + if (Grob *g = unsmob_grob (get_property ("currentCommandColumn"))) + { + for (vsize i = 0; i < end_slurs_.size (); i++) + Slur::add_extra_encompass (end_slurs_[i], g); + + if (!start_events_.size ()) + for (vsize i = 0; i < slurs_.size (); i++) + Slur::add_extra_encompass (slurs_[i], g); + } + + for (vsize i = 0; i < end_slurs_.size (); i++) + { + Spanner *s = dynamic_cast (end_slurs_[i]); + if (!s->get_bound (RIGHT)) + s->set_bound (RIGHT, unsmob_grob (get_property ("currentMusicalColumn"))); + announce_end_grob (s, SCM_EOL); + } + + for (vsize i = 0; i < objects_to_acknowledge_.size (); i++) + Slur::auxiliary_acknowledge_extra_object (objects_to_acknowledge_[i], slurs_, end_slurs_); + + objects_to_acknowledge_.clear (); + end_slurs_.clear (); + start_events_.clear (); + stop_events_.clear (); +} + +// no ADD_ACKNOWLEDGER / ADD_TRANSLATOR macro calls +// since this class is abstract -- 2.39.5