]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 3225: Decouple \defaultchild from \accepts list in contexts
authorDavid Kastrup <dak@gnu.org>
Tue, 5 Mar 2013 10:33:04 +0000 (11:33 +0100)
committerDavid Kastrup <dak@gnu.org>
Fri, 8 Mar 2013 23:45:02 +0000 (00:45 +0100)
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.

Documentation/notation/changing-defaults.itely
lily/context-def.cc
lily/context.cc
lily/global-context.cc
lily/include/context.hh
ly/performer-init.ly

index 25771a986c71c972e4add0075931ba8b6856b142..09cf63b5c020b30e65197d128adb9605595f621e 100644 (file)
@@ -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}}
 
index 1f823bf50368f747aff414b68bd6e8181c6b9b7c..9ef10bea966a6f631b2338138cfc46836342dfd1 100644 (file)
@@ -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;
index d2c93155a578964e5cf439400fe626236b611ca3..3da638fe557922cdee4817b22d98e937f6ba38a5 100644 (file)
@@ -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 ());
index 005c54b45e67b97b38e256e1d639eaea638c2e7b..8f22b943effe787d69033023ce8196d99486cafb 100644 (file)
@@ -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 *
index 5543235c25d4b668d2140300697bcb2914a68799..794f275287e1f9fcbe404d22c44dfc731c782e6d 100644 (file)
@@ -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_;
index e39bcf4c4840542101d3758dded226b195355bcd..b06587ce743b09428f77d90ab38c38b54c999064 100644 (file)
@@ -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
 }
   \type "Performer_group"
   \consists "Staff_performer"
   \accepts ChordNameVoice
+  \defaultchild ChordNameVoice
   \name ChordNames
 }