From: David Kastrup Date: Tue, 5 Mar 2013 10:33:04 +0000 (+0100) Subject: Issue 3225: Decouple \defaultchild from \accepts list in contexts X-Git-Tag: release/2.17.14-1~4 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=91aeca2562af49ff24110e923d5196bebd95f372;p=lilypond.git Issue 3225: Decouple \defaultchild from \accepts list in contexts The definition of a Bottom context previously was a context not accepting any subcontexts. Now it is a context without a \defaultchild. The defaultchild of a context previously was the first found in the \accepts list (if necessary, moving it there). While \defaultchild was tracked in context definitions, it was not explicit in instantiated contexts. Decoupling those makes for more flexible arrangements of contexts. For example, one might let Voice accept a SubVoice context without forcing SubVoice to be created when a Bottom context is called for when in Voice, simply by not giving Voice a \defaultchild. --- diff --git a/Documentation/notation/changing-defaults.itely b/Documentation/notation/changing-defaults.itely index 25771a986c..09cf63b5c0 100644 --- a/Documentation/notation/changing-defaults.itely +++ b/Documentation/notation/changing-defaults.itely @@ -195,8 +195,10 @@ a piece in mensural style. @unnumberedsubsubsec Bottom-level contexts - voices Voice-level contexts initialise certain properties and start -appropriate engravers. Being bottom-level contexts, they cannot -contain other contexts. +appropriate engravers. A bottom-level context is one without +@code{defaultchild}. While it is possible to let it +accept/@/contain subcontexts, they can only be created and entered +explicitly. @strong{@emph{Voice}} diff --git a/lily/context-def.cc b/lily/context-def.cc index 1f823bf503..9ef10bea96 100644 --- a/lily/context-def.cc +++ b/lily/context-def.cc @@ -316,6 +316,7 @@ Context_def::instantiate (SCM ops) context->definition_mods_ = ops; context->aliases_ = context_aliases_; context->accepts_list_ = get_accepted (ops); + context->default_child_ = get_default_child (ops); return context; } @@ -342,6 +343,10 @@ Context_def::to_alist () const get_translator_names (SCM_EOL)), ell); ell = scm_cons (scm_cons (ly_symbol2scm ("description"), description_), ell); ell = scm_cons (scm_cons (ly_symbol2scm ("aliases"), context_aliases_), ell); + ell = scm_cons (scm_cons (ly_symbol2scm ("accepts"), get_accepted (SCM_EOL)), + ell); + if (scm_is_symbol (default_child_)) + ell = scm_acons (ly_symbol2scm ("default-child"), default_child_, ell); ell = scm_cons (scm_cons (ly_symbol2scm ("accepts"), get_accepted (SCM_EOL)), ell); ell = scm_cons (scm_cons (ly_symbol2scm ("property-ops"), property_ops_), @@ -381,7 +386,7 @@ bool Context_def::is_alias (SCM sym) const { if (scm_is_eq (sym, ly_symbol2scm ("Bottom"))) - return !scm_is_pair (get_accepted (SCM_EOL)); + return !scm_is_symbol (get_default_child (SCM_EOL)); if (scm_is_eq (sym, get_context_name ())) return true; diff --git a/lily/context.cc b/lily/context.cc index d2c93155a5..3da638fe55 100644 --- a/lily/context.cc +++ b/lily/context.cc @@ -86,6 +86,7 @@ Context::Context () implementation_ = 0; properties_scm_ = SCM_EOL; accepts_list_ = SCM_EOL; + default_child_ = SCM_EOL; context_list_ = SCM_EOL; definition_ = SCM_EOL; definition_mods_ = SCM_EOL; @@ -401,9 +402,7 @@ Context::create_context (Context_def *cdef, SCM Context::default_child_context_name () const { - return scm_is_pair (accepts_list_) - ? scm_car (accepts_list_) - : SCM_EOL; + return default_child_; } bool @@ -492,10 +491,9 @@ Context::internal_send_stream_event (SCM type, Input *origin, SCM props[]) bool Context::is_alias (SCM sym) const { - if (sym == ly_symbol2scm ("Bottom") - && !scm_is_pair (accepts_list_)) - return true; - if (sym == unsmob_context_def (definition_)->get_context_name ()) + if (scm_is_eq (sym, ly_symbol2scm ("Bottom"))) + return is_bottom_context (); + if (scm_is_eq (sym, context_name_symbol ())) return true; return scm_c_memq (sym, aliases_) != SCM_BOOL_F; @@ -687,6 +685,7 @@ Context::mark_smob (SCM sm) scm_gc_mark (me->definition_mods_); scm_gc_mark (me->properties_scm_); scm_gc_mark (me->accepts_list_); + scm_gc_mark (me->default_child_); if (me->implementation_) scm_gc_mark (me->implementation_->self_scm ()); diff --git a/lily/global-context.cc b/lily/global-context.cc index 005c54b45e..8f22b943ef 100644 --- a/lily/global-context.cc +++ b/lily/global-context.cc @@ -58,7 +58,8 @@ Global_context::Global_context (Output_def *o) for (; scm_is_pair (p); p = scm_cdr (p)) scm_hashq_set_x (ancestor_lookup_, scm_caar (p), scm_car (p)); - accepts_list_ = scm_list_1 (ly_symbol2scm ("Score")); + default_child_ = ly_symbol2scm ("Score"); + accepts_list_ = scm_list_1 (default_child_); } Output_def * diff --git a/lily/include/context.hh b/lily/include/context.hh index 5543235c25..794f275287 100644 --- a/lily/include/context.hh +++ b/lily/include/context.hh @@ -55,6 +55,7 @@ protected: SCM properties_scm_; SCM context_list_; SCM accepts_list_; + SCM default_child_; SCM aliases_; Translator_group *implementation_; string id_string_; diff --git a/ly/performer-init.ly b/ly/performer-init.ly index e39bcf4c48..b06587ce74 100644 --- a/ly/performer-init.ly +++ b/ly/performer-init.ly @@ -35,6 +35,7 @@ \context { \name Global \accepts Score + \defaultchild Score \description "Hard coded entry point for LilyPond. Cannot be tuned." EventClasses = #all-event-classes } @@ -267,6 +268,7 @@ \type "Performer_group" \consists "Staff_performer" \accepts ChordNameVoice + \defaultchild ChordNameVoice \name ChordNames }