]> 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:03:54 +0000 (01:03 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 14 Nov 2004 01:03:54 +0000 (01:03 +0000)
* lily/grob.cc (Grob): take key argument in ctor.

* lily/lilypond-key.cc (do_compare): new file.

* lily/object-key.cc (Object_key): new file.

* lily/include/object-key.hh (class Object_key): new file.

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

33 files changed:
ChangeLog
lily/accidental-engraver.cc
lily/auto-beam-engraver.cc
lily/break-align-engraver.cc
lily/context-def.cc
lily/context-property.cc
lily/context.cc
lily/engraver.cc
lily/global-context.cc
lily/grob.cc
lily/include/context-def.hh
lily/include/context.hh
lily/include/engraver.hh
lily/include/grob.hh
lily/include/item.hh
lily/include/lily-proto.hh
lily/include/lilypond-key.hh [new file with mode: 0644]
lily/include/object-key.hh [new file with mode: 0644]
lily/include/paper-column.hh
lily/include/score-context.hh
lily/include/spanner.hh
lily/include/system.hh
lily/item.cc
lily/lily-guile.cc
lily/lilypond-key.cc [new file with mode: 0644]
lily/object-key.cc [new file with mode: 0644]
lily/paper-column.cc
lily/score-context.cc
lily/score-engraver.cc
lily/spanner.cc
lily/system-start-delimiter-engraver.cc
lily/system.cc
lily/tie-engraver.cc

index 2a0e26913e5c515d6fece6ad5231ccc821aa21b2..e97930883b838f298576b8c91c038d873e6ee3b0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2004-11-14  Han-Wen Nienhuys  <hanwen@xs4all.nl>
+
+       * lily/context.cc (Context): take key argument in ctor.
+
+       * lily/grob.cc (Grob): take key argument in ctor.  
+
+       * lily/lilypond-key.cc (do_compare): new file.
+
+       * lily/object-key.cc (Object_key): new file.
+
+       * lily/include/object-key.hh (class Object_key): new file.
+
+       * lily/include/lilypond-key.hh (class Lilypond_context_key): new file.
+
 2004-11-13  Graham Percival  <gperlist@shaw.ca>
 
        * Documentation/user/lilypond-book.itely: add small warning about
index 648b1ccf8b0ec089f8a90ff8a6b5ac15673b33df..4a59aced625c4365f046b0197a54e3683aae4109 100644 (file)
@@ -368,7 +368,9 @@ Accidental_engraver::process_acknowledged_grobs ()
              Grob *a
                = make_item_from_properties (accidentals_[i].origin_trans_,
                                             ly_symbol2scm ("Accidental"),
-                                            note->self_scm ());
+                                            note->self_scm (),
+                                            "Accidental"
+                                            );
              a->set_parent (support, Y_AXIS);
 
              if (!accidental_placement_)
index d5bfa39bfccdb2011085ce1b5047e0c77b11f49c..eccfd74eac71d6761f77f672d7a0e579e9eae56c 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_);
+  Spanner *beam = new Spanner (beam_settings_, get_grob_key ("Beam"));
   for (int i = 0; i < stems_->size (); i++)
     {
       /*
index 53165f55d575d4618fec1f1b4f1d47c94954c5a9..b56a5ad2a6cb3477100b4be97958115997090e2f 100644 (file)
@@ -92,13 +92,11 @@ Break_align_engraver::acknowledge_grob (Grob_info inf)
        {
          align_ = make_item ("BreakAlignment", SCM_EOL);
 
-         
-
          Context*origin = inf.origin_contexts (this)[0];
-         left_edge_ =  make_item_from_properties (origin->implementation (),
-                                                  ly_symbol2scm ("LeftEdge"),
-                                                  SCM_EOL
-                                                  );
+         left_edge_ = make_item_from_properties (dynamic_cast<Engraver*> (origin->implementation ()),
+                                                 ly_symbol2scm ("LeftEdge"),
+                                                 SCM_EOL,
+                                                 "LeftEdge");
          add_to_group (left_edge_->get_property ("break-align-symbol"),
                        left_edge_);
        }
index def8427221a9fe0b65984a59c858ecd611e844cf..1f75b9e74fa8ceeaeeddffc0d15f3fcd8ddd291d 100644 (file)
@@ -260,14 +260,14 @@ filter_engravers (SCM ell)
 
 
 Context *
-Context_def::instantiate (SCM ops)
+Context_def::instantiate (SCM ops, Object_key const *key)
 {
   Context *tg =  0;
 
   if (context_name_ == ly_symbol2scm ("Score"))
-    tg = new Score_context ();
+    tg = new Score_context (key);
   else
-    tg = new Context ();
+    tg = new Context (key);
 
   tg->definition_ = self_scm ();
 
index d1e1c9f60d452597d40f38bcd1f2a0200c321be4..2b23b33abb72c04bbf0fa3fbe47b4514dc2fac57 100644 (file)
@@ -196,12 +196,16 @@ updated_grob_properties (Context * tg, SCM sym)
 }
 
 Item *
-make_item_from_properties (Translator *tr, SCM x, SCM cause)
+make_item_from_properties (Engraver *tr, SCM x, SCM cause, const char * name)
 {
   Context *context = tr->context ();
   
   SCM props = updated_grob_properties (context, x);
-  Item *it = new Item (props);
+
+  Object_key const*key = tr->get_grob_key (name);
+  Item *it = new Item (props, key);
+  scm_gc_unprotect_object (key->self_scm ());
+
 #ifdef TWEAK 
   Grob_selector::register_grob (context, it);
 #endif
@@ -211,12 +215,12 @@ make_item_from_properties (Translator *tr, SCM x, SCM cause)
 }
 
 Spanner*
-make_spanner_from_properties (Translator *tr, SCM x, SCM cause)
+make_spanner_from_properties (Engraver *tr, SCM x, SCM cause, const char *name)
 {
   Context *tg = tr->context ();
 
   SCM props = updated_grob_properties (tg, x);
-  Spanner *it = new Spanner (props);
+  Spanner *it = new Spanner (props, tr->get_grob_key (name));
 
   dynamic_cast<Engraver*>(tr)->announce_grob (it, cause);
 
index 6d5a94b4cc485efbd19d69fc1317f2a7d758734c..35d958f6a2b3c5fd7ffbb1fe16ce2267e5776652 100644 (file)
@@ -7,6 +7,7 @@
 
 */
 
+#include "object-key.hh"
 #include "context-def.hh"
 #include "context-selector.hh"
 #include "context.hh"
@@ -17,6 +18,7 @@
 #include "score-context.hh"
 #include "translator-group.hh"
 #include "warn.hh"
+#include "lilypond-key.hh"
 
 bool
 Context::is_removable () const
@@ -79,8 +81,15 @@ Context::add_context (Context *t)
     }
 }
 
-Context::Context ()
+Object_key const*
+Context::get_key () const
 {
+  return key_;
+}
+
+Context::Context (Object_key const* key)
+{
+  key_ = key;
   daddy_context_ = 0;
   init_ = false;
   aliases_ = SCM_EOL;
@@ -134,14 +143,22 @@ Context::find_create_context (SCM n, String id, SCM operations)
        {
          SCM ops = (i == path.size () -1) ? operations : SCM_EOL;
 
-         Context * new_group
-           = path[i]->instantiate (ops);
-
+         String this_id = "";
          if (i == path.size () -1)
            {
-             new_group->id_string_ = id;
+             this_id = id;
            }
-
+         
+         Object_key * key = new Lilypond_context_key (current->get_key(),
+                                                      now_mom(),
+                                                      ly_symbol2string (path[i]->get_context_name()),
+                                                      this_id);
+                                                       
+         Context * new_group
+           = path[i]->instantiate (ops, key);
+         scm_gc_unprotect_object (key->self_scm ());
+         
+         new_group->id_string_ = this_id;
          current->add_context (new_group);
          apply_property_operations (new_group, ops);
          
@@ -194,13 +211,20 @@ Context::get_default_interpreter ()
       SCM nm = default_child_context_name ();
       SCM st = find_context_def (get_output_def (), nm);
 
+      String name = ly_symbol2string (nm);
       Context_def *t = unsmob_context_def (st);
       if (!t)
        {
-         warning (_f ("can't find or create: `%s'", ly_symbol2string (nm).to_str0 ()));
+         warning (_f ("can't find or create: `%s'", name.to_str0 ()));
          t = unsmob_context_def (this->definition_);
        }
-      Context *tg = t->instantiate (SCM_EOL);
+
+      Object_key *key = new Lilypond_context_key (get_key(),
+                                                 now_mom(),
+                                                 name,
+                                                 "");
+      
+      Context *tg = t->instantiate (SCM_EOL, key);
       add_context (tg);
       if (!tg->is_bottom_context ())
        return tg->get_default_interpreter ();
@@ -397,7 +421,7 @@ SCM
 Context::mark_smob (SCM sm)
 {
   Context *me = (Context*) SCM_CELL_WORD_1 (sm);
-  
+  scm_gc_mark (me->key_->self_scm ());  
   scm_gc_mark (me->context_list_);
   scm_gc_mark (me->aliases_);
   scm_gc_mark (me->definition_);  
index 5f83295e18e8135c77b7bb95540b6b080ff70e3f..c2854e0330af4af32782593f7a9ce9fa2a6d7841 100644 (file)
@@ -16,6 +16,7 @@
 #include "item.hh"
 #include "context.hh"
 #include "score-context.hh"
+#include "lilypond-key.hh"
 
 Engraver_group_engraver*
 Engraver::get_daddy_engraver () const
@@ -66,6 +67,17 @@ 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 580479bb94f46c5e43ece28e13afd5cde3f7a52f..ce3f9e9ef5b4e2f9aa9fab2b44b2bdec3b72606c 100644 (file)
 #include "score-context.hh"
 #include "context-def.hh"
 #include "output-def.hh"
-#include "grace-fixup.hh"
+#include "lilypond-key.hh"
 
 Global_context::Global_context (Output_def *o, Moment final)
+  : Context (new Lilypond_context_key(0,
+                                     Moment(0),
+                                     "Global", ""))
 {
+  scm_gc_unprotect_object (key_->self_scm());
+  
   output_def_ = o;
   final_mom_ = final;
   definition_ = find_context_def (o, ly_symbol2scm ("Global"));
@@ -151,13 +156,16 @@ Global_context::run_iterator_on_me (Music_iterator * iter)
 
       if (!get_score_context ()) 
        {
-         SCM key = ly_symbol2scm ("Score");
-         Context_def * t = unsmob_context_def (find_context_def (get_output_def (), key));
+         SCM sym = ly_symbol2scm ("Score");
+         Context_def * t = unsmob_context_def (find_context_def (get_output_def (), sym));
          if (!t)
            error (_f ("can't find `%s' context", "Score"));
 
-         Context *c = t->instantiate (SCM_EOL);
+         Object_key *key = new Lilypond_context_key (get_key(), now_mom(),
+                                                     "Score", "");
+         Context *c = t->instantiate (SCM_EOL, key);
          add_context (c);
+         scm_gc_unprotect_object (key->self_scm());
 
          Score_context *sc = dynamic_cast<Score_context*> (c);
          sc->prepare (w);
index 7786f4d3b1e05fb4d805a85f5900625fdc392706..541663d30fe093ab42a9e537929bd890871f3fc5 100644 (file)
 
 #include "ly-smobs.icc"
 
+Grob * 
+Grob::clone (int count) const
+{
+  return new Grob (*this, count);
+}
+
 /* TODO:
 
   - remove dynamic_cast<Spanner,Item> and put this code into respective
 #define HASH_SIZE 3
 #define INFINITY_MSG "Infinity or NaN encountered"
 
-Grob::Grob (SCM basicprops)
+Grob::Grob (SCM basicprops,
+           Object_key const* key)
 {
+  key_ = key;
   /* FIXME: default should be no callback.  */
   self_scm_ = SCM_EOL;
   pscore_= 0;
@@ -102,9 +110,10 @@ Grob::Grob (SCM basicprops)
     }
 }
 
-Grob::Grob (Grob const &s)
+Grob::Grob (Grob const &s, int copy_index)
    : dim_cache_ (s.dim_cache_)
 {
+  key_ = new Copied_key (s.key_, copy_index);
   original_ = (Grob*) &s;
   self_scm_ = SCM_EOL;
 
@@ -117,6 +126,7 @@ Grob::Grob (Grob const &s)
   pscore_ = 0;
 
   smobify_self ();
+  scm_gc_unprotect_object (key_->self_scm ());
 }
 
 Grob::~Grob ()
@@ -234,7 +244,6 @@ Grob::get_uncached_stencil () const
 
 /*
   VIRTUAL STUBS
-
  */
 void
 Grob::do_break_processing ()
@@ -638,6 +647,8 @@ Grob::discretionary_processing ()
 {
 }
 
+
+
 bool
 Grob::internal_has_interface (SCM k)
 {
index c734ed924086a6a5a7bcf65e25a78c0d016d75db..e5e7d67493b378868fc218b577f4fdc36b3e76d3 100644 (file)
@@ -43,7 +43,7 @@ public:
 
   Link_array<Context_def> path_to_acceptable_context (SCM type_string,
                                                      Output_def*) const;
-  Context * instantiate (SCM extra_ops);
+  Context * instantiate (SCM extra_ops, Object_key const*);
 
   SCM to_alist () const;
   static SCM make_scm ();
index c8a366a27d8e3bf779d8fa23748b99f941bb3131..6dfb6d752f38d38a973814111c5d53ea945a6ac8 100644 (file)
@@ -28,6 +28,7 @@ private:
   bool init_;
   
 protected:
+  Object_key const * key_;
   Context * daddy_context_;
   SCM definition_;
   SCM properties_scm_;
@@ -38,15 +39,17 @@ protected:
   String id_string_;
 
   friend class Context_def;
+
 public:
+  Object_key const *get_key () const;
   String id_string () const { return id_string_; } 
   SCM children_contexts () const { return context_list_; }
   SCM default_child_context_name () const;
 
   Translator_group* implementation () const;
   Context *get_parent_context () const;
-  Context ();
-
+  Context (Object_key const*);
+  
   /* properties:  */
   void execute_pushpop_property (SCM prop, SCM sym, SCM val);
   SCM internal_get_property (SCM name_sym) const;
@@ -95,8 +98,6 @@ bool melisma_busy (Context *);
 Context *get_voice_to_lyrics (Context *lyrics);
 Grob *get_current_note_head (Context *voice);
 Grob *get_current_rest (Context *voice);
-Context *unsmob_context (SCM);
-
 DECLARE_UNSMOB(Context, context);
 
 #endif /* CONTEXT_HH */
index 1535a245cc1408d8235e8cd90ca065e3f081de1b..01027fb48a8b53003a2d9490720be36759177e12 100644 (file)
@@ -41,8 +41,10 @@ protected:
 
   virtual void announce_grob (Grob_info);
   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
     */
@@ -55,10 +57,10 @@ public:
   TRANSLATOR_DECLARATIONS(Engraver);
 };
 
-#define make_item(x,cause) make_item_from_properties (this, ly_symbol2scm (x), cause)
-#define make_spanner(x,cause) make_spanner_from_properties (this, ly_symbol2scm (x), cause)
-Item* make_item_from_properties (Translator * tg, SCM x, SCM cause);
-Spanner* make_spanner_from_properties (Translator * tg, SCM x, SCM cause);
+#define make_item(x,cause) make_item_from_properties (this, ly_symbol2scm (x), cause, x)
+#define make_spanner(x,cause) make_spanner_from_properties (this, ly_symbol2scm (x), cause, x)
+Item* make_item_from_properties (Engraver * tg, SCM x, SCM cause, const char *name);
+Spanner* make_spanner_from_properties (Engraver * tg, SCM x, SCM cause, const char*name);
 
 
 
index c4d09fec84cd2ef92afdfc43a30a5062dc973af0..b7cf46611ace15d44c220ec70c9f6cc4b1a4549e 100644 (file)
 #include "smobs.hh"
 #include "dimension-cache.hh"
 #include "grob-interface.hh"
+#include "object-key.hh"
 
 /**
-    for administration of what was done already
-    */
+   for administration of what was done already
+*/
 enum Grob_status {
   ORPHAN=0,                    // not yet added to Paper_score
   PRECALCING,
@@ -43,8 +44,8 @@ class Grob
 private:  
   DECLARE_SMOBS (Grob, foo);
   void init ();
-
 protected:
+  Object_key const * key_;
   SCM immutable_property_alist_;
   SCM mutable_property_alist_;
   
@@ -57,6 +58,8 @@ protected:
   char status_;
   
 public:
+  Object_key const *get_key () const;
+  
   Grob *original_;
 
   /* TODO: junk this member. */
@@ -64,9 +67,10 @@ public:
 
   Dimension_cache dim_cache_[NO_AXES];
 
-  Grob (SCM basic_props);
-  Grob (Grob const&);
-  VIRTUAL_COPY_CONSTRUCTOR (Grob, Grob);
+  Grob (SCM basic_props, Object_key const *);
+  Grob (Grob const&, int copy_count);
+
+  virtual Grob *clone (int count) const;
   DECLARE_SCHEME_CALLBACK (stencil_extent, (SCM smob, SCM axis));
  
   String name () const;
index be7b22ec8435190b91dcbfc63a811fe7607c5bb8..bb0e02ef82f872c05cbc493176fd5babe98310d5 100644 (file)
@@ -26,9 +26,10 @@ class Item : public Grob
   Drul_array<Item*> broken_to_drul_;
 
 public:
-  Item (SCM);
-  Item (Item const &);
-  VIRTUAL_COPY_CONSTRUCTOR (Grob, Item);
+  Item (SCM, Object_key const*);
+  Item (Item const &, int count);
+  
+  virtual Grob *clone (int count) const;
 
   static bool is_breakable (Grob *);
   bool is_broken () const;
index e6cf9c85db16f8ed719541dd33d4ffbf1198511e..51598d8815ed82f19c5305c7f6501d8f44128611 100644 (file)
@@ -72,6 +72,8 @@ class Keyword_table;
 class Ligature_bracket_engraver;
 class Ligature_engraver;
 class Lily_lexer;
+class Lilypond_context_key;
+class Lilypond_grob_key;
 class Line_group_engraver_group;
 class Lookup;
 class Lyric_combine_music;
@@ -107,8 +109,7 @@ class Music_wrapper;
 class Music_wrapper_iterator;
 class Note_performer;
 class Output_def;
-class Output_def;
-class Output_def;
+class Object_key;
 class Output_property;
 class Page;
 class Paper_book;
diff --git a/lily/include/lilypond-key.hh b/lily/include/lilypond-key.hh
new file mode 100644 (file)
index 0000000..b499814
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+  lilypond-key.hh -- declare Lilypond_{grob,context}_key
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+#ifndef LILYPOND_KEY_HH
+#define LILYPOND_KEY_HH
+
+#include "object-key.hh"
+#include "lily-proto.hh"
+#include "moment.hh"
+#include "string.hh"
+
+class Lilypond_grob_key : public Object_key
+{
+  Object_key const *context_;
+  Moment creation_moment_;
+  String grob_name_;
+
+  // 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,
+                   Moment start,
+                   String name);
+protected:
+  virtual int get_type () const;
+  virtual void derived_mark () const; 
+  virtual int do_compare (Object_key const* a) const;
+};
+
+class Lilypond_context_key : public Object_key
+{
+  Object_key const *parent_context_;
+  Moment start_moment_;
+  String context_name_;
+  String id_;
+
+  // see above. 
+  // int ambiguity_count_;
+public:
+  Lilypond_context_key (Object_key const * parent,
+                       Moment start,
+                       String type,
+                       String id);
+    //                 int count);
+protected:
+  virtual int get_type () const;
+  virtual int do_compare (Object_key const* a) const;
+  virtual void derived_mark () const; 
+};
+
+
+#endif /* LILYPOND_KEY_HH */
+
diff --git a/lily/include/object-key.hh b/lily/include/object-key.hh
new file mode 100644 (file)
index 0000000..c64fcc9
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+  object-key.hh -- declare Object_key
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+#ifndef OBJECT_KEY_HH
+#define OBJECT_KEY_HH
+
+#include "smobs.hh"
+
+/*
+  Object_keys are read-only values, suitable for storing references to
+  transient objects (such as grobs or contexts) on disk.
+
+  In the future, they might also act as handles for external processes
+  requesting notation to be drawn.
+ */
+class Object_key
+{
+  DECLARE_SMOBS(Object_key,);
+
+protected:
+  Object_key();
+  virtual void derived_mark () const;
+  virtual int get_type () const;
+  virtual int do_compare (Object_key const * other) const;
+public:
+  int compare (Object_key const *other) const;
+};
+
+enum Object_key_type {
+  GENERAL_KEY, 
+  GROB_KEY,
+  CONTEXT_KEY,
+  COPIED_KEY,
+};
+
+class Copied_key : public Object_key
+{
+
+private:
+  Object_key const * original_;
+  int copy_count_;
+protected:
+  virtual void derived_mark () const;
+  virtual int get_type () const;
+  virtual int do_compare (Object_key const * other) const;
+public:
+  Copied_key (Object_key const*, int); 
+};
+
+DECLARE_UNSMOB(Object_key, key);
+
+#endif /* OBJECT_KEY_HH */
index f69ced71477729d69ae27225c5c1247eb75cde95..6a8a1d3d6f80fb3fc1ba3d5eef4744bef3969302 100644 (file)
@@ -21,8 +21,10 @@ public:
   /// if lines are broken then this column is in #line#
   System *system_;
 
-  Paper_column (SCM);
-  VIRTUAL_COPY_CONSTRUCTOR (Grob, Paper_column);
+  Paper_column (SCM, Object_key const*);
+  Paper_column (Paper_column const&, int count);
+  
+  virtual Grob *clone (int count) const;
 
   static bool has_interface (Grob*);
   virtual void do_break_processing ();
index 39cf74c61364397e10738b79bb58c6a94f0bde68..7919819af67a536bb21c5d7f3d5bbc0b39740832 100644 (file)
@@ -13,6 +13,8 @@
 class Score_context : public Context
 {
  public:
+  Score_context (Object_key const*);
+  
   virtual Music_output *get_output ();     
   virtual void prepare (Moment);
   virtual void finish ();
index c4670d0122bd78def662a0a791abd21f27170f77..dad07123bf5ed9e4b8313002bc585f52c41399a0 100644 (file)
@@ -48,8 +48,8 @@ public:
   void set_bound (Direction d, Grob*);
   Item *get_bound (Direction d) const;
   
-  Spanner (SCM);
-  Spanner (Spanner const &);
+  Spanner (SCM, Object_key const*);
+  Spanner (Spanner const &, int copy_count);
   bool is_broken () const;
   void do_break ();
   Real spanner_length () const;
@@ -62,8 +62,7 @@ public:
 
 protected:
   void set_my_columns ();
-
-  VIRTUAL_COPY_CONSTRUCTOR (Grob, Spanner);
+  virtual Grob *clone (int count) const;
   virtual void do_break_processing ();
 };
 
index 911aa0b792fac365016dbf9388c7929c98bab6ca..1889dce65ce82b9b484f1c40fdda309f17597512 100644 (file)
@@ -27,7 +27,10 @@ public:
   SCM get_line ();
   SCM get_lines ();
 
-  System (SCM);
+  System (SCM, Object_key const*);
+  System (System const&, int);
+  virtual Grob *clone (int count) const;
+  
   int element_count () const;
   int spanner_count () const;
 
@@ -42,7 +45,6 @@ public:
   void pre_processing ();
 
 protected:
-  VIRTUAL_COPY_CONSTRUCTOR (Grob, System);
 };
 
 #endif /* SYSTEM_HH */
index c5cca666d565605b205a2bf719876a3d60cb551e..c6d5ba053ea211af782d35d79608e3273679d5ed 100644 (file)
 #include "system.hh"
 #include "group-interface.hh"
 
-Item::Item (SCM s)
-  : Grob (s)
+
+Grob * 
+Item::clone (int count) const
+{
+  return new Item (*this, count);
+}
+
+
+Item::Item (SCM s, Object_key const *key)
+  : Grob (s, key)
 {
   broken_to_drul_[LEFT] = broken_to_drul_[RIGHT]=0;
   Group_interface::add_thing (this, ly_symbol2scm ("interfaces"), ly_symbol2scm ("item-interface"));
@@ -25,8 +33,8 @@ Item::Item (SCM s)
 /**
    Item copy ctor.  Copy nothing: everything should be a elt property
    or a special purpose pointer (such as broken_to_drul_[]) */
-Item::Item (Item const &s)
-  : Grob (s)
+Item::Item (Item const &s, int copy_count)
+  : Grob (s, copy_count)
 {
   broken_to_drul_[LEFT] = broken_to_drul_[RIGHT] =0;
 }
@@ -64,10 +72,11 @@ void
 Item::copy_breakable_items ()
 {
   Drul_array<Item *> new_copies;
-  Direction  i=LEFT;
+  Direction i = LEFT;
+  int count = 0;
   do 
     {
-      Grob * dolly = clone ();
+      Grob * dolly = clone (count ++);
       Item * item = dynamic_cast<Item*> (dolly);
       pscore_->system_->typeset_grob (item);
       new_copies[i] =item;
index 298b374203bdbb34cff32fc6dd66abf5c6a4d3c3..92c3bca31b5025522b7db3115e95065565bdc94d 100644 (file)
@@ -147,6 +147,7 @@ ly_display_scm (SCM s)
 String
 ly_scm2string (SCM str)
 {
+  assert (scm_is_string (str));
   return String ((Byte*)scm_i_string_chars (str),
                 (int) scm_i_string_length (str));
 }
diff --git a/lily/lilypond-key.cc b/lily/lilypond-key.cc
new file mode 100644 (file)
index 0000000..48f4daa
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+  lilypond-key.cc --  implement Lilypond_{grob,context}_key
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+
+#include "object-key.hh"
+#include "lilypond-key.hh"
+
+Lilypond_grob_key::Lilypond_grob_key (Object_key const *context,
+                                     Moment start,
+                                     String name)
+  // int ambiguity_count,
+{
+  context_ = context;
+  creation_moment_ = start;
+  grob_name_ = name;
+  //  ambiguity_count_ = ambiguity_count;
+}
+
+void
+Lilypond_grob_key::derived_mark () const
+{
+  scm_gc_mark (context_->self_scm ());
+}
+
+int
+Lilypond_grob_key::do_compare (Object_key const* key) const
+{
+  Lilypond_grob_key const * other = dynamic_cast<Lilypond_grob_key const*> (key); 
+  int c;
+
+  c = context_->compare (other->context_);
+  if (c)
+    return c;
+  
+  c = Moment::compare (creation_moment_, other->creation_moment_);
+  if (c)
+    return c;
+
+  c = String::compare (grob_name_, other->grob_name_);
+  if (c)
+    return c;
+#if 0
+  c = sign (ambiguity_count_ - other->ambiguity_count_); 
+  if (c)
+    return c;
+#endif
+  
+  return 0;
+}
+
+
+int
+Lilypond_grob_key::get_type () const
+{
+  return GROB_KEY;
+}
+
+/****************************************************************/
+
+
+void
+Lilypond_context_key::derived_mark () const
+{
+  if (parent_context_)
+    scm_gc_mark (parent_context_->self_scm ());
+}
+
+Lilypond_context_key::Lilypond_context_key (Object_key const *parent,
+                                           Moment start,
+                                           String type,
+                                           String id
+                                           // int count
+                                           )
+{
+  parent_context_ = parent;
+  start_moment_ = start;
+  context_name_ = type;
+  id_ = id;
+}
+
+
+int
+Lilypond_context_key::do_compare (Object_key const *key) const
+{
+  Lilypond_context_key const * other
+    = dynamic_cast<Lilypond_context_key const*> (key); 
+
+  int c;
+  if (parent_context_)
+    {
+      c = parent_context_->compare (other->parent_context_);
+      if (c)
+       return c;
+    }
+  
+  c = Moment::compare (start_moment_, other->start_moment_);
+  if (c)
+    return c;
+
+  c = String::compare (context_name_, other->context_name_);
+  if (c)
+    return c;
+
+  c = String::compare (id_, other->id_);
+  if (c)
+    return c;
+
+#if 0
+  c = sign (ambiguity_count_ - other->ambiguity_count_);
+  if (c)
+    return c;
+#endif
+  
+  return 0;
+}
+
+int
+Lilypond_context_key::get_type () const
+{
+  return CONTEXT_KEY;
+}
diff --git a/lily/object-key.cc b/lily/object-key.cc
new file mode 100644 (file)
index 0000000..2f95bec
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+  object-key.cc --  implement Object_key
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+
+#include "object-key.hh"
+#include "ly-smobs.icc"
+
+SCM
+Object_key::mark_smob (SCM key)
+{
+  Object_key* k = (Object_key*) SCM_CELL_WORD_1 (key);
+  k->derived_mark();
+  return SCM_EOL;
+}
+
+void
+Object_key::derived_mark () const
+{
+  
+}
+
+Object_key::~Object_key()
+{
+}
+
+int
+Object_key::get_type () const
+{
+  return GENERAL_KEY;
+}
+
+int
+Object_key::print_smob (SCM smob, SCM port, scm_print_state*)
+{
+  return 1;
+}
+
+Object_key::Object_key ()
+{
+  smobify_self ();
+}
+
+int
+Object_key::compare (Object_key const *other) const
+{
+  if (this == other)
+    return 0;
+  
+  int c = sign (get_type () -  other->get_type());
+  if (c)
+    return c;
+  else
+    return do_compare (other);
+}
+
+IMPLEMENT_SMOBS (Object_key);
+
+SCM
+Object_key::equal_p (SCM a , SCM b) 
+{
+  Object_key *ka = unsmob_key (a);
+  Object_key *kb = unsmob_key (b);
+  
+  return (ka->compare (kb)) ? SCM_BOOL_F : SCM_BOOL_T;
+}
+
+int
+Object_key::do_compare (Object_key const *other) const
+{
+  return 0;
+}
+
+/****************************************************************/
+
+Copied_key::Copied_key (Object_key const* key, int count)
+{
+  copy_count_ = count;
+  original_ = key;
+}
+
+int
+Copied_key::get_type () const
+{
+  return COPIED_KEY;
+}
+
+int
+Copied_key::do_compare (Object_key const *key) const
+{
+  Copied_key const *other = dynamic_cast<Copied_key const*> (key);
+  
+  int c = original_->compare (other->original_);
+  if (c)
+    return c;
+
+  return sign (copy_count_ - other->copy_count_);
+}
+
+void
+Copied_key::derived_mark () const
+{
+  scm_gc_mark (original_->self_scm ());
+}
index b5fe7c1351d76467983f1871da69f9039ed6c42b..c964d2fa88f0eb8af2198d6a7e353b6097f9986c 100644 (file)
 
 
 
+Grob * 
+Paper_column::clone (int count) const
+{
+  return new Paper_column (*this, count);
+}
+
+
 ADD_INTERFACE (Paper_column, "paper-column-interface",
               "@code{Paper_column} objects form the top-most X-parents for items. "
               "  The are two types of columns: musical columns, where are attached to, and "
@@ -64,13 +71,22 @@ Paper_column::get_column () const
   return (Paper_column*) (this);
 }
 
-Paper_column::Paper_column (SCM l)
-  : Item (l)           // guh.?
+Paper_column::Paper_column (SCM l, Object_key const*key)
+  : Item (l, key)              // guh.?
 {
   system_ = 0;
   rank_ = -1;
 }
 
+
+Paper_column::Paper_column (Paper_column const& src, int count)
+  : Item (src, count)
+{
+  system_ = 0;
+  rank_ = count;
+}
+
+
 Moment
 Paper_column::when_mom (Grob *me)
 {
index 0e179e50c4ebe71f535789ea165b54b430e09ee7..8730ebcd7172829f96e73dea2eaea0eee944ccec 100644 (file)
@@ -43,3 +43,8 @@ Score_context::get_output ()
   return s->get_output ();
 }
 
+
+Score_context::Score_context (Object_key const *key)
+  : Context (key)
+{
+}
index 432d18b720bef59146ccafa4a4346d08ea9c1492..e0c39fc5c7065460289bdda4842993005f77c64d 100644 (file)
@@ -49,10 +49,17 @@ Score_engraver::make_columns ()
       SCM nmp
        = updated_grob_properties (context (),
                                   ly_symbol2scm ("NonMusicalPaperColumn"));
+
+      Object_key const *key1 = get_grob_key ("NonMusicalPaperColumn");
+      
       SCM pc = updated_grob_properties (context (),
                                        ly_symbol2scm ("PaperColumn"));
-      
-      set_columns (new Paper_column (nmp), new Paper_column (pc));
+      Object_key const *key2 = get_grob_key ("PaperColumn");      
+      set_columns (new Paper_column (nmp, key1), new Paper_column (pc, key2));
+
+
+      scm_gc_unprotect_object (key1->self_scm());
+      scm_gc_unprotect_object (key2->self_scm());      
 
       Grob_info i1;
       i1.grob_ = command_column_;
@@ -115,7 +122,9 @@ Score_engraver::initialize ()
 
   SCM props = updated_grob_properties (context (), ly_symbol2scm ("System"));
 
-  pscore_->typeset_line (new System (props));
+  Object_key const *sys_key = get_grob_key ("System");
+  pscore_->typeset_line (new System (props, sys_key));
+  scm_gc_unprotect_object (sys_key->self_scm ());
   
   make_columns ();
   system_ = pscore_->system_;
index 058cc2f0ba4bd0fe19cb910737c1e917a1a0c236..9e33b18eed27f4227a430d28faa95c4ddf2d1617 100644 (file)
 #include "system.hh"
 #include "group-interface.hh"
 
+
+
+Grob * 
+Spanner::clone (int count) const
+{
+  return new Spanner (*this, count);
+}
+
 void
 Spanner::do_break_processing ()
 {
@@ -62,7 +70,7 @@ Spanner::do_break_processing ()
            programming_error ("no broken bound");
          else if (bound->get_system ())
            {
-             Spanner * span = dynamic_cast<Spanner*> (clone ());
+             Spanner * span = dynamic_cast<Spanner*> (clone (broken_intos_.size ()));
              span->set_bound (LEFT, bound);
              span->set_bound (RIGHT, bound);
 
@@ -99,7 +107,7 @@ Spanner::do_break_processing ()
              continue; 
            }
 
-         Spanner *span = dynamic_cast<Spanner*> (clone ());
+         Spanner *span = dynamic_cast<Spanner*> (clone (broken_intos_.size ()));
          span->set_bound (LEFT,bounds[LEFT]);
          span->set_bound (RIGHT,bounds[RIGHT]);
 
@@ -198,8 +206,8 @@ Spanner::set_bound (Direction d, Grob*s)
     }
 }
 
-Spanner::Spanner (SCM s)
-  : Grob (s)
+Spanner::Spanner (SCM s, Object_key const*key)
+  : Grob (s, key)
 {
   break_index_ = 0;
   spanned_drul_[LEFT]=0;
@@ -208,8 +216,8 @@ Spanner::Spanner (SCM s)
   Group_interface::add_thing (this, ly_symbol2scm ("interfaces"), ly_symbol2scm ("spanner-interface"));
 }
 
-Spanner::Spanner (Spanner const &s)
-  : Grob (s)
+Spanner::Spanner (Spanner const &s, int count)
+  : Grob (s, count)
 {
   spanned_drul_[LEFT] = spanned_drul_[RIGHT] =0;
 }
index 3aeb41b1304ca74462c1a80fc75a937fffca4d74..93b0f177ac01476f24e51f4000e6aa3fa55fb670 100644 (file)
@@ -73,7 +73,8 @@ System_start_delimiter_engraver::process_music ()
   if (!delim_)
     {
       SCM delim_name =get_property ("systemStartDelimiter");
-      delim_ = make_spanner_from_properties (this, delim_name, SCM_EOL);
+      delim_ = make_spanner_from_properties (this, delim_name, SCM_EOL,
+                                            ly_symbol2string (delim_name).to_str0());
 
       delim_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
       
index 0eecf4afebc1949dd1d1ac008993e2a2d21c976a..b0d14ffe3186120cd48de25ab728a8e2a5616ba6 100644 (file)
 #include "paper-book.hh"
 #include "paper-system.hh"
 
-System::System (SCM s)
-  : Spanner (s)
+
+System::System (System const &src, int count)
+  : Spanner (src, count)
+{
+  rank_ = 0;
+}
+
+System::System (SCM s, Object_key const*key)
+  : Spanner (s, key)
 {
   rank_ = 0;
 }
 
+
+Grob * 
+System::clone (int count) const
+{
+  return new System (*this, count);
+}
+
+
 int
 System::element_count () const
 {
@@ -230,7 +245,7 @@ System::break_into_pieces (Array<Column_x_positions> const &breaking)
 {
   for (int i = 0; i < breaking.size (); i++)
     {
-      System *system = dynamic_cast <System*> (clone ());
+      System *system = dynamic_cast <System*> (clone (i));
       system->rank_ = i;
 
       Link_array<Grob> c (breaking[i].cols_);
index 1aecbe526cb16b4a18ca5bc8e5cd0a81b93e1c23..0073a880eeb084dc319d105d9b5ecf184af20874 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_);
+             Grob * p = new Spanner  (tie_start_definition_, get_grob_key ("Tie"));
              announce_grob (p, last_event_->self_scm ());
              Tie::set_interface (p); // cannot remove yet!