]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/context.cc (Context): take key argument in ctor.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 14 Nov 2004 01:37:01 +0000 (01:37 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 14 Nov 2004 01:37:01 +0000 (01:37 +0000)
* lily/lilypond-key.cc (do_compare): new file.

* lily/include/lilypond-key.hh (class Lilypond_context_key): new file.

14 files changed:
lily/auto-beam-engraver.cc
lily/context-property.cc
lily/context.cc
lily/engraver.cc
lily/global-context.cc
lily/include/context.hh
lily/include/engraver.hh
lily/include/grob.hh
lily/include/lilypond-key.hh
lily/lilypond-key.cc
lily/score-engraver.cc
lily/score.cc
lily/tie-engraver.cc
lily/translator-group.cc

index eccfd74eac71d6761f77f672d7a0e579e9eae56c..61ef8a47d4ab57f9dd890d4379b3365b4f3df17b 100644 (file)
@@ -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++)
     {
       /*
index 2b23b33abb72c04bbf0fa3fbe47b4514dc2fac57..0e9a0e129a4462a41fcd2459508dd5beb7096ae7 100644 (file)
@@ -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<Engraver*>(tr)->announce_grob (it, cause);
 
index 35d958f6a2b3c5fd7ffbb1fe16ce2267e5776652..cf678b4e215d4643891afc07784f722ff6dd5cf1 100644 (file)
@@ -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<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();
+    }
+}
index c2854e0330af4af32782593f7a9ce9fa2a6d7841..4430ab4fc6eda2f5eb77a8aca8dfeaf28796125b 100644 (file)
@@ -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,
                   "", "",
                  "",
index ce3f9e9ef5b4e2f9aa9fab2b44b2bdec3b72606c..869e93622fe1bf6f60fc1c00a11d9bc790eb8eed 100644 (file)
@@ -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());
index 6dfb6d752f38d38a973814111c5d53ea945a6ac8..bb45f7254bdece9cd43ee3ab3bb4ae45818a7144 100644 (file)
@@ -9,6 +9,8 @@
 #ifndef CONTEXT_HH
 #define CONTEXT_HH
 
+#include <map>
+
 #include "moment.hh"
 #include "lily-proto.hh"
 
@@ -26,7 +28,10 @@ private:
   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_;
@@ -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;
index 01027fb48a8b53003a2d9490720be36759177e12..dfe333ef781abf714f507b0318e4082b65ab87a2 100644 (file)
@@ -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
     */
index b7cf46611ace15d44c220ec70c9f6cc4b1a4549e..b09e6e9ac049cba09638cfd5c69ed51c19e11e28 100644 (file)
@@ -74,8 +74,6 @@ public:
   DECLARE_SCHEME_CALLBACK (stencil_extent, (SCM smob, SCM axis));
  
   String name () const;
-
-
   /*
     Properties
    */
index b499814c36b43118c1b5a55c9010fff56c3422ab..afdb72f6daac8335903cc5816694a62429062759 100644 (file)
@@ -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;
index 48f4daa446640cb8f1ee7bef021474defe9ef306..df8d027caf2a9850e8ebe1c62fc02dbb7714082e 100644 (file)
 
 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;
 }
index e0c39fc5c7065460289bdda4842993005f77c64d..316afa65f20309c95a4269a240bdb6e24b7798fe 100644 (file)
@@ -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 ());
   
index 0622d64f7a31be897f7aa866d413e57de29fd15f..4c09db30211b4b56d980a15aa84d93dc39b72b5a 100644 (file)
@@ -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);
index 0073a880eeb084dc319d105d9b5ecf184af20874..6cfc5b6457a3bdcf2662a3be0e7d728f278b6483 100644 (file)
@@ -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!
          
index 113a4595a85b7c01fdf5e00aaf2719c6ba750f1c..5ed918f3cbfdb4af7e54da6e3de74d545cb38078 100644 (file)
@@ -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)
 {