/*
This file is part of LilyPond, the GNU music typesetter.
- Copyright (C) 2004--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ Copyright (C) 2004--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
LilyPond is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
bool
Context::is_removable () const
{
- return context_list_ == SCM_EOL && ! iterator_count_
+ return context_list_ == SCM_EOL && ! client_count_
&& !dynamic_cast<Global_context const *> (daddy_context_);
}
{
daddy_context_ = 0;
aliases_ = SCM_EOL;
- iterator_count_ = 0;
+ client_count_ = 0;
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;
/* TODO: this shares code with find_create_context (). */
Context *
-Context::create_unique_context (SCM name, string id, SCM operations)
+Context::create_unique_context (SCM name, const string &id, SCM operations)
{
/*
Don't create multiple score contexts.
}
Context *
-Context::find_create_context (SCM n, string id, SCM operations)
+Context::find_create_context (SCM n, const string &id, SCM operations)
{
/*
Don't create multiple score contexts.
*/
Global_context *gthis = dynamic_cast<Global_context *> (this);
- if (gthis && gthis->get_score_context ())
- return gthis->get_score_context ()->find_create_context (n, id, operations);
+ if (gthis)
+ {
+ if (gthis->get_score_context ())
+ return gthis->get_score_context ()->find_create_context (n, id, operations);
+
+ // Special case: If we use \set Timing.xxx = whatever before
+ // Score is established, the alias of Score to Timing will not
+ // be taken into account. We check for this particular case
+ // here. Aliases apart from Score-level ones don't warrant
+ // context creation as they could create unwanted contexts, like
+ // RhythmicVoice instead of Voice. Creating a Score context,
+ // however, can't really do anything wrong.
+
+ SCM score_name = default_child_context_name ();
+ SCM score_def = find_context_def (get_output_def (), score_name);
+
+ if (Context_def *cd = unsmob_context_def (score_def))
+ {
+ if (cd->is_alias (n))
+ return create_context (cd, id, operations);
+ }
+ }
+
if (Context *existing = find_context_below (this, n, id))
return existing;
if (scm_is_symbol (sym))
{
SCM val = ev->get_property ("value");
+
+ if (SCM_UNBNDP (val)) {
+ unset_property (sym);
+ return;
+ }
+
bool ok = true;
- if (val != SCM_EOL)
- ok = type_check_assignment (sym, val, ly_symbol2scm ("translation-type?"));
+ ok = type_check_assignment (sym, val, ly_symbol2scm ("translation-type?"));
+
if (ok)
set_property (sym, val);
}
if (path.size () != 1)
{
- programming_error (_f ("Invalid CreateContext event: Cannot create %s context", type.c_str ()));
+ programming_error (to_string ("Invalid CreateContext event: Cannot create %s context", type.c_str ()));
return;
}
Context_def *cdef = path[0];
// The 'accepts elements in definition_mods_ is a list of ('accepts string),
// but the Context_def expects to see elements of the form ('accepts symbol).
SCM accepts = SCM_EOL;
- for (SCM s = scm_reverse (definition_mods_); scm_is_pair (s); s = scm_cdr (s))
+ for (SCM s = definition_mods_; scm_is_pair (s); s = scm_cdr (s))
if (scm_caar (s) == ly_symbol2scm ("accepts"))
{
SCM elt = scm_list_2 (scm_caar (s), scm_string_to_symbol (scm_cadar (s)));
return unsmob_context_def (definition_)->path_to_acceptable_context (name,
get_output_def (),
- accepts);
+ scm_reverse_x (accepts, SCM_EOL));
}
Context *
Context::create_context (Context_def *cdef,
- string id,
+ const string &id,
SCM ops)
{
infant_event_ = 0;
SCM
Context::default_child_context_name () const
{
- return scm_is_pair (accepts_list_)
- ? scm_car (accepts_list_)
- : SCM_EOL;
+ return default_child_;
}
bool
}
Context *
-Context::get_default_interpreter (string context_id)
+Context::get_default_interpreter (const string &context_id)
{
if (!is_bottom_context ())
{
warning (_f ("cannot find or create: `%s'", name.c_str ()));
t = unsmob_context_def (this->definition_);
}
-
- Context *tg = create_context (t, context_id, SCM_EOL);
- return tg->get_default_interpreter (context_id);
+ if (scm_is_symbol (t->get_default_child (SCM_EOL)))
+ {
+ Context *tg = create_context (t, "\\new", SCM_EOL);
+ return tg->get_default_interpreter (context_id);
+ }
+ return create_context (t, context_id, SCM_EOL);
+ }
+ else if (!context_id.empty () && context_id != id_string ())
+ {
+ if (daddy_context_ && !dynamic_cast<Global_context *> (daddy_context_))
+ return daddy_context_->get_default_interpreter (context_id);
+ warning (_f ("cannot find or create new Bottom = \"%s\"",
+ context_id.c_str ()));
}
return this;
}
void
Context::internal_send_stream_event (SCM type, Input *origin, SCM props[])
{
- Stream_event *e = new Stream_event (type, origin);
+ Stream_event *e = new Stream_event
+ (scm_call_1 (ly_lily_module_constant ("ly:make-event-class"), type),
+ origin);
for (int i = 0; props[i]; i += 2)
{
e->set_property (props[i], props[i + 1]);
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;
void
Context::internal_set_property (SCM sym, SCM val)
{
+ bool type_check_ok = type_check_assignment (sym, val, ly_symbol2scm ("translation-type?"));
+
if (do_internal_type_checking_global)
- assert (type_check_assignment (sym, val, ly_symbol2scm ("translation-type?")));
+ assert (type_check_ok);
- properties_dict ()->set (sym, val);
+ if (type_check_ok)
+ properties_dict ()->set (sym, val);
}
/*
*/
Context *
find_context_below (Context *where,
- SCM type, string id)
+ SCM type, const string &id)
{
if (where->is_alias (type))
{
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 ());