From 7f5363be4d24bb512d9c25dcd8c975ed87e4c923 Mon Sep 17 00:00:00 2001 From: Neil Puttock Date: Wed, 27 Jan 2010 01:41:04 +0000 Subject: [PATCH] Set context-id for implicit voices in polyphony shorthand. Since voicify-music now uses the context alias `Bottom' to create the appropriate voice-level contexts in a << { } \\ { } >> construct, the context-id sent via context-spec-music is ignored. * add context-id as arg to Global_context/Context::get_default_interpreter (), with empty string as default * pass context-id to Context::get_default_interpreter () so it can be used in call to create_context () instead of empty string * add regtest, which will fail to compile if context-id is invalid --- .../automatic-polyphony-context-id.ly | 36 +++++++++++++++++++ lily/context.cc | 10 +++--- lily/global-context.cc | 2 +- lily/include/context.hh | 2 +- lily/include/global-context.hh | 2 +- 5 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 input/regression/automatic-polyphony-context-id.ly diff --git a/input/regression/automatic-polyphony-context-id.ly b/input/regression/automatic-polyphony-context-id.ly new file mode 100644 index 0000000000..31b42a36a3 --- /dev/null +++ b/input/regression/automatic-polyphony-context-id.ly @@ -0,0 +1,36 @@ +\version "2.13.12" + +\header { + texidoc = "The bottom-level contexts in polyphony shorthand are +allocated a context id in order of creation, starting with +@code{\"1\"}. +This snippet will fail to compile if either voice has an invalid +@code{context-id} string. +" +} + +assertContextId = +#(define-music-function (parser location id) (string?) + (let ((music (make-music 'ApplyContext + 'procedure + (lambda (ctx) + (and + (not (string=? (ly:context-id ctx) id)) + (ly:error "context-id mismatch found: expecting ~s, got ~s" + id + (ly:context-id ctx))))))) + music)) + +\relative c'' { + << + { + \assertContextId "1" + c4 d e2 + } + \\ + { + \assertContextId "2" + a,4 b c2 + } + >> +} diff --git a/lily/context.cc b/lily/context.cc index fedaeae5b0..8328205214 100644 --- a/lily/context.cc +++ b/lily/context.cc @@ -114,7 +114,7 @@ Context::create_unique_context (SCM name, string id, SCM operations) if (gthis && gthis->get_score_context ()) return gthis->get_score_context ()->create_unique_context (name, id, operations); - vector path = path_to_acceptable_context (name); + vector path = path_to_acceptable_context (name); if (path.size ()) { Context *current = this; @@ -168,7 +168,7 @@ Context::find_create_context (SCM n, string id, SCM operations) if (n == ly_symbol2scm ("Bottom")) { - Context *tg = get_default_interpreter (); + Context *tg = get_default_interpreter (id); return tg; } @@ -386,7 +386,7 @@ Context::is_bottom_context () const } Context * -Context::get_default_interpreter () +Context::get_default_interpreter (string context_id) { if (!is_bottom_context ()) { @@ -401,8 +401,8 @@ Context::get_default_interpreter () t = unsmob_context_def (this->definition_); } - Context *tg = create_context (t, "", SCM_EOL); - return tg->get_default_interpreter (); + Context *tg = create_context (t, context_id, SCM_EOL); + return tg->get_default_interpreter (context_id); } return this; } diff --git a/lily/global-context.cc b/lily/global-context.cc index 3a29a6f24a..160b7b6278 100644 --- a/lily/global-context.cc +++ b/lily/global-context.cc @@ -200,7 +200,7 @@ Global_context::previous_moment () const } Context * -Global_context::get_default_interpreter () +Global_context::get_default_interpreter (string /* context_id */) { if (get_score_context ()) return get_score_context ()->get_default_interpreter (); diff --git a/lily/include/context.hh b/lily/include/context.hh index b0601bde7e..45e94ab9e5 100644 --- a/lily/include/context.hh +++ b/lily/include/context.hh @@ -114,7 +114,7 @@ public: virtual Context *get_score_context () const; virtual Output_def *get_output_def () const; virtual Moment now_mom () const; - virtual Context *get_default_interpreter (); + virtual Context *get_default_interpreter (string context_id = ""); bool is_alias (SCM) const; void add_alias (SCM); diff --git a/lily/include/global-context.hh b/lily/include/global-context.hh index d69bb598ab..561cd6e49c 100644 --- a/lily/include/global-context.hh +++ b/lily/include/global-context.hh @@ -46,7 +46,7 @@ public: virtual SCM get_output (); virtual Output_def *get_output_def () const; virtual Moment now_mom () const; - virtual Context *get_default_interpreter (); + virtual Context *get_default_interpreter (string context_id = ""); Moment previous_moment () const; protected: -- 2.39.2