* lily/lilypond-key.cc (do_compare): new file.
* lily/include/lilypond-key.hh (class Lilypond_context_key): new file.
if (to_boolean (get_property ("skipTypesetting")))
return 0;
- Spanner *beam = new Spanner (beam_settings_, get_grob_key ("Beam"));
+ Spanner *beam = new Spanner (beam_settings_, context ()->get_grob_key ("Beam"));
for (int i = 0; i < stems_->size (); i++)
{
/*
SCM props = updated_grob_properties (context, x);
- Object_key const*key = tr->get_grob_key (name);
+ Object_key const*key = context->get_grob_key (name);
Item *it = new Item (props, key);
scm_gc_unprotect_object (key->self_scm ());
Spanner*
make_spanner_from_properties (Engraver *tr, SCM x, SCM cause, const char *name)
{
- Context *tg = tr->context ();
+ Context *context = tr->context ();
- SCM props = updated_grob_properties (tg, x);
- Spanner *it = new Spanner (props, tr->get_grob_key (name));
+ SCM props = updated_grob_properties (context, x);
+ Spanner *it = new Spanner (props, context->get_grob_key (name));
dynamic_cast<Engraver*>(tr)->announce_grob (it, cause);
this_id = id;
}
- Object_key * key = new Lilypond_context_key (current->get_key(),
- now_mom(),
- ly_symbol2string (path[i]->get_context_name()),
- this_id);
+ Object_key const *key = get_context_key (ly_symbol2string (path[i]->get_context_name()), this_id);
Context * new_group
= path[i]->instantiate (ops, key);
return ret;
}
+Object_key const*
+Context::get_context_key (String type, String id)
+{
+ String now_key = type + "@" + id;
+
+ int disambiguation_count = 0;
+ if (context_counts_.find (now_key) != context_counts_.end ())
+ {
+ disambiguation_count = context_counts_[now_key];
+ }
+
+ context_counts_[now_key] = disambiguation_count + 1;
+
+
+ return new Lilypond_context_key (get_key (),
+ now_mom(),
+ type, id,
+ disambiguation_count);
+}
+
+Object_key const*
+Context::get_grob_key (String name)
+{
+ int disambiguation_count = 0;
+ if (grob_counts_.find (name) != grob_counts_.end ())
+ {
+ disambiguation_count = grob_counts_[name];
+ }
+ grob_counts_[name] = disambiguation_count + 1;
+
+ Object_key * k = new Lilypond_grob_key (get_key(),
+ now_mom(),
+ name,
+ disambiguation_count);
+
+ return k;
+}
+
+
+
/*
Default child context as a SCM string, or something else if there is
none.
t = unsmob_context_def (this->definition_);
}
- Object_key *key = new Lilypond_context_key (get_key(),
- now_mom(),
- name,
- "");
+ Object_key const *key = get_context_key (name, "");
Context *tg = t->instantiate (SCM_EOL, key);
add_context (tg);
{
return dynamic_cast<Translator_group*> (unsmob_translator (implementation_));
}
+
+void
+Context::clear_key_disambiguations ()
+{
+ grob_counts_.clear();
+ context_counts_.clear();
+ for (SCM s = context_list_; scm_is_pair (s); s = scm_cdr (s))
+ {
+ unsmob_context (scm_car (s))->clear_key_disambiguations();
+ }
+}
}
-Object_key const*
-Engraver::get_grob_key (String name) const
-{
- Object_key * k = new Lilypond_grob_key (context()->get_key(),
- now_mom(),
- name);
-
- return k;
-}
-
-
ENTER_DESCRIPTION (Engraver,
"", "",
"",
Global_context::Global_context (Output_def *o, Moment final)
: Context (new Lilypond_context_key(0,
Moment(0),
- "Global", ""))
+ "Global", "", 0))
{
scm_gc_unprotect_object (key_->self_scm());
prev_mom_ = now_mom_;
now_mom_ = m;
+ clear_key_disambiguations ();
if (get_score_context ())
get_score_context ()->prepare (m);
+
}
Moment
if (!t)
error (_f ("can't find `%s' context", "Score"));
- Object_key *key = new Lilypond_context_key (get_key(), now_mom(),
- "Score", "");
+ Object_key const *key = get_context_key ("Score", "");
Context *c = t->instantiate (SCM_EOL, key);
add_context (c);
scm_gc_unprotect_object (key->self_scm());
#ifndef CONTEXT_HH
#define CONTEXT_HH
+#include <map>
+
#include "moment.hh"
#include "lily-proto.hh"
friend class Interpretation_context_handle;
int iterator_count_;
bool init_;
-
+
+ std::map<String, int> grob_counts_;
+ std::map<String, int> context_counts_;
+
protected:
Object_key const * key_;
Context * daddy_context_;
String id_string_;
friend class Context_def;
+ void clear_key_disambiguations ();
public:
Object_key const *get_key () const;
+ Object_key const *get_grob_key (String);
+ Object_key const *get_context_key (String, String);
+
String id_string () const { return id_string_; }
SCM children_contexts () const { return context_list_; }
SCM default_child_context_name () const;
Engraver_group_engraver*get_daddy_engraver () const;
public:
- Object_key const * get_grob_key (String name) const;
-
/**
Announce element. Default: pass on to daddy. Utility
*/
DECLARE_SCHEME_CALLBACK (stencil_extent, (SCM smob, SCM axis));
String name () const;
-
-
/*
Properties
*/
Object_key const *context_;
Moment creation_moment_;
String grob_name_;
+ int disambiguation_count_;
- // FIXME: need to figure out smart solution for
- // the problem of creating
- // many equally named grobs at the same time.
-
- // int ambiguity_count_;
public:
- Lilypond_grob_key(Object_key const*context,
+ Lilypond_grob_key(Object_key const *context,
Moment start,
- String name);
+ String name, int);
+
protected:
virtual int get_type () const;
virtual void derived_mark () const;
Moment start_moment_;
String context_name_;
String id_;
+ int disambiguation_count_;
- // see above.
- // int ambiguity_count_;
public:
Lilypond_context_key (Object_key const * parent,
Moment start,
String type,
- String id);
- // int count);
+ String id,
+ int count);
+
protected:
virtual int get_type () const;
virtual int do_compare (Object_key const* a) const;
Lilypond_grob_key::Lilypond_grob_key (Object_key const *context,
Moment start,
- String name)
- // int ambiguity_count,
+ String name,
+ int disambiguation_count)
{
context_ = context;
creation_moment_ = start;
grob_name_ = name;
- // ambiguity_count_ = ambiguity_count;
+ disambiguation_count_ = disambiguation_count;
}
void
c = String::compare (grob_name_, other->grob_name_);
if (c)
return c;
-#if 0
- c = sign (ambiguity_count_ - other->ambiguity_count_);
+
+ c = sign (disambiguation_count_ - other->disambiguation_count_);
if (c)
return c;
-#endif
return 0;
}
Lilypond_context_key::Lilypond_context_key (Object_key const *parent,
Moment start,
String type,
- String id
- // int count
- )
+ String id,
+ int count)
{
+ disambiguation_count_ = count;
parent_context_ = parent;
start_moment_ = start;
context_name_ = type;
if (c)
return c;
-#if 0
- c = sign (ambiguity_count_ - other->ambiguity_count_);
+ c = sign (disambiguation_count_ - other->disambiguation_count_);
if (c)
return c;
-#endif
return 0;
}
= updated_grob_properties (context (),
ly_symbol2scm ("NonMusicalPaperColumn"));
- Object_key const *key1 = get_grob_key ("NonMusicalPaperColumn");
+ Object_key const *key1 = context()->get_grob_key ("NonMusicalPaperColumn");
SCM pc = updated_grob_properties (context (),
ly_symbol2scm ("PaperColumn"));
- Object_key const *key2 = get_grob_key ("PaperColumn");
+ Object_key const *key2 = context()->get_grob_key ("PaperColumn");
set_columns (new Paper_column (nmp, key1), new Paper_column (pc, key2));
SCM props = updated_grob_properties (context (), ly_symbol2scm ("System"));
- Object_key const *sys_key = get_grob_key ("System");
+ Object_key const *sys_key = context()->get_grob_key ("System");
pscore_->typeset_line (new System (props, sys_key));
scm_gc_unprotect_object (sys_key->self_scm ());
Cpu_timer timer;
Global_context *trans = new Global_context (odef, music->get_length ());
-
if (!trans)
{
programming_error ("no toplevel translator");
return SCM_BOOL_F;
}
+
progress_indication (_ ("Interpreting music... "));
SCM protected_iter = Music_iterator::get_static_get_iterator (music);
&& ly_c_equal_p (right_mus->get_property ("pitch"),
left_mus->get_property ("pitch")))
{
- Grob * p = new Spanner (tie_start_definition_, get_grob_key ("Tie"));
+ Grob * p = new Spanner (tie_start_definition_, context()->get_grob_key ("Tie"));
announce_grob (p, last_event_->self_scm ());
Tie::set_interface (p); // cannot remove yet!
return simple_trans_list_;
}
+
void
recurse_over_translators (Context * c, Translator_method ptr, Direction dir)
{