From 5d09d767066abb2f2d53cd18cf0c0a0b1188d1a7 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 14 Nov 2004 01:37:01 +0000 Subject: [PATCH] * lily/context.cc (Context): take key argument in ctor. * lily/lilypond-key.cc (do_compare): new file. * lily/include/lilypond-key.hh (class Lilypond_context_key): new file. --- lily/auto-beam-engraver.cc | 2 +- lily/context-property.cc | 8 ++--- lily/context.cc | 61 +++++++++++++++++++++++++++++++----- lily/engraver.cc | 11 ------- lily/global-context.cc | 7 +++-- lily/include/context.hh | 11 ++++++- lily/include/engraver.hh | 2 -- lily/include/grob.hh | 2 -- lily/include/lilypond-key.hh | 19 +++++------ lily/lilypond-key.cc | 21 ++++++------- lily/score-engraver.cc | 6 ++-- lily/score.cc | 2 +- lily/tie-engraver.cc | 2 +- lily/translator-group.cc | 1 + 14 files changed, 95 insertions(+), 60 deletions(-) diff --git a/lily/auto-beam-engraver.cc b/lily/auto-beam-engraver.cc index eccfd74eac..61ef8a47d4 100644 --- a/lily/auto-beam-engraver.cc +++ b/lily/auto-beam-engraver.cc @@ -282,7 +282,7 @@ Auto_beam_engraver::create_beam () 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++) { /* diff --git a/lily/context-property.cc b/lily/context-property.cc index 2b23b33abb..0e9a0e129a 100644 --- a/lily/context-property.cc +++ b/lily/context-property.cc @@ -202,7 +202,7 @@ make_item_from_properties (Engraver *tr, SCM x, SCM cause, const char * name) 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 ()); @@ -217,10 +217,10 @@ make_item_from_properties (Engraver *tr, SCM x, SCM cause, const char * name) 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(tr)->announce_grob (it, cause); diff --git a/lily/context.cc b/lily/context.cc index 35d958f6a2..cf678b4e21 100644 --- a/lily/context.cc +++ b/lily/context.cc @@ -149,10 +149,7 @@ Context::find_create_context (SCM n, String id, SCM operations) 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); @@ -184,6 +181,46 @@ Context::find_create_context (SCM n, String id, SCM operations) 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. @@ -219,10 +256,7 @@ Context::get_default_interpreter () 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); @@ -475,3 +509,14 @@ Context::implementation () const { return dynamic_cast (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(); + } +} diff --git a/lily/engraver.cc b/lily/engraver.cc index c2854e0330..4430ab4fc6 100644 --- a/lily/engraver.cc +++ b/lily/engraver.cc @@ -67,17 +67,6 @@ Engraver::get_score_engraver () const } -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, "", "", "", diff --git a/lily/global-context.cc b/lily/global-context.cc index ce3f9e9ef5..869e93622f 100644 --- a/lily/global-context.cc +++ b/lily/global-context.cc @@ -21,7 +21,7 @@ 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()); @@ -80,8 +80,10 @@ Global_context::prepare (Moment m) prev_mom_ = now_mom_; now_mom_ = m; + clear_key_disambiguations (); if (get_score_context ()) get_score_context ()->prepare (m); + } Moment @@ -161,8 +163,7 @@ Global_context::run_iterator_on_me (Music_iterator * iter) 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()); diff --git a/lily/include/context.hh b/lily/include/context.hh index 6dfb6d752f..bb45f7254b 100644 --- a/lily/include/context.hh +++ b/lily/include/context.hh @@ -9,6 +9,8 @@ #ifndef CONTEXT_HH #define CONTEXT_HH +#include + #include "moment.hh" #include "lily-proto.hh" @@ -26,7 +28,10 @@ private: friend class Interpretation_context_handle; int iterator_count_; bool init_; - + + std::map grob_counts_; + std::map context_counts_; + protected: Object_key const * key_; Context * daddy_context_; @@ -39,9 +44,13 @@ protected: 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; diff --git a/lily/include/engraver.hh b/lily/include/engraver.hh index 01027fb48a..dfe333ef78 100644 --- a/lily/include/engraver.hh +++ b/lily/include/engraver.hh @@ -43,8 +43,6 @@ protected: 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 */ diff --git a/lily/include/grob.hh b/lily/include/grob.hh index b7cf46611a..b09e6e9ac0 100644 --- a/lily/include/grob.hh +++ b/lily/include/grob.hh @@ -74,8 +74,6 @@ public: DECLARE_SCHEME_CALLBACK (stencil_extent, (SCM smob, SCM axis)); String name () const; - - /* Properties */ diff --git a/lily/include/lilypond-key.hh b/lily/include/lilypond-key.hh index b499814c36..afdb72f6da 100644 --- a/lily/include/lilypond-key.hh +++ b/lily/include/lilypond-key.hh @@ -20,16 +20,13 @@ class Lilypond_grob_key : public Object_key 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; @@ -42,15 +39,15 @@ class Lilypond_context_key : public Object_key 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; diff --git a/lily/lilypond-key.cc b/lily/lilypond-key.cc index 48f4daa446..df8d027caf 100644 --- a/lily/lilypond-key.cc +++ b/lily/lilypond-key.cc @@ -13,13 +13,13 @@ 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 @@ -45,11 +45,10 @@ Lilypond_grob_key::do_compare (Object_key const* key) const 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; } @@ -74,10 +73,10 @@ Lilypond_context_key::derived_mark () const 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; @@ -111,11 +110,9 @@ Lilypond_context_key::do_compare (Object_key const *key) const 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; } diff --git a/lily/score-engraver.cc b/lily/score-engraver.cc index e0c39fc5c7..316afa65f2 100644 --- a/lily/score-engraver.cc +++ b/lily/score-engraver.cc @@ -50,11 +50,11 @@ Score_engraver::make_columns () = 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)); @@ -122,7 +122,7 @@ Score_engraver::initialize () 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 ()); diff --git a/lily/score.cc b/lily/score.cc index 0622d64f7a..4c09db3021 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -109,12 +109,12 @@ LY_DEFINE (ly_run_translator, "ly:run-translator", 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); diff --git a/lily/tie-engraver.cc b/lily/tie-engraver.cc index 0073a880ee..6cfc5b6457 100644 --- a/lily/tie-engraver.cc +++ b/lily/tie-engraver.cc @@ -109,7 +109,7 @@ Tie_engraver::acknowledge_grob (Grob_info i) && 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! diff --git a/lily/translator-group.cc b/lily/translator-group.cc index 113a4595a8..5ed918f3cb 100644 --- a/lily/translator-group.cc +++ b/lily/translator-group.cc @@ -102,6 +102,7 @@ Translator_group::get_simple_trans_list () return simple_trans_list_; } + void recurse_over_translators (Context * c, Translator_method ptr, Direction dir) { -- 2.39.2