From 4a964b10c411827584eb720c63cd0d6fc5b65d72 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 14 Nov 2004 01:03:54 +0000 Subject: [PATCH] * 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. --- ChangeLog | 14 +++ lily/accidental-engraver.cc | 4 +- lily/auto-beam-engraver.cc | 2 +- lily/break-align-engraver.cc | 10 +- lily/context-def.cc | 6 +- lily/context-property.cc | 12 ++- lily/context.cc | 42 ++++++-- lily/engraver.cc | 12 +++ lily/global-context.cc | 16 ++- lily/grob.cc | 17 +++- lily/include/context-def.hh | 2 +- lily/include/context.hh | 9 +- lily/include/engraver.hh | 12 ++- lily/include/grob.hh | 16 +-- lily/include/item.hh | 7 +- lily/include/lily-proto.hh | 5 +- lily/include/lilypond-key.hh | 62 ++++++++++++ lily/include/object-key.hh | 58 +++++++++++ lily/include/paper-column.hh | 6 +- lily/include/score-context.hh | 2 + lily/include/spanner.hh | 7 +- lily/include/system.hh | 6 +- lily/item.cc | 21 ++-- lily/lily-guile.cc | 1 + lily/lilypond-key.cc | 127 ++++++++++++++++++++++++ lily/object-key.cc | 109 ++++++++++++++++++++ lily/paper-column.cc | 20 +++- lily/score-context.cc | 5 + lily/score-engraver.cc | 15 ++- lily/spanner.cc | 20 ++-- lily/system-start-delimiter-engraver.cc | 3 +- lily/system.cc | 21 +++- lily/tie-engraver.cc | 2 +- 33 files changed, 589 insertions(+), 82 deletions(-) create mode 100644 lily/include/lilypond-key.hh create mode 100644 lily/include/object-key.hh create mode 100644 lily/lilypond-key.cc create mode 100644 lily/object-key.cc diff --git a/ChangeLog b/ChangeLog index 2a0e26913e..e97930883b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2004-11-14 Han-Wen Nienhuys + + * 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 * Documentation/user/lilypond-book.itely: add small warning about diff --git a/lily/accidental-engraver.cc b/lily/accidental-engraver.cc index 648b1ccf8b..4a59aced62 100644 --- a/lily/accidental-engraver.cc +++ b/lily/accidental-engraver.cc @@ -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_) diff --git a/lily/auto-beam-engraver.cc b/lily/auto-beam-engraver.cc index d5bfa39bfc..eccfd74eac 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_); + Spanner *beam = new Spanner (beam_settings_, get_grob_key ("Beam")); for (int i = 0; i < stems_->size (); i++) { /* diff --git a/lily/break-align-engraver.cc b/lily/break-align-engraver.cc index 53165f55d5..b56a5ad2a6 100644 --- a/lily/break-align-engraver.cc +++ b/lily/break-align-engraver.cc @@ -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 (origin->implementation ()), + ly_symbol2scm ("LeftEdge"), + SCM_EOL, + "LeftEdge"); add_to_group (left_edge_->get_property ("break-align-symbol"), left_edge_); } diff --git a/lily/context-def.cc b/lily/context-def.cc index def8427221..1f75b9e74f 100644 --- a/lily/context-def.cc +++ b/lily/context-def.cc @@ -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 (); diff --git a/lily/context-property.cc b/lily/context-property.cc index d1e1c9f60d..2b23b33abb 100644 --- a/lily/context-property.cc +++ b/lily/context-property.cc @@ -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(tr)->announce_grob (it, cause); diff --git a/lily/context.cc b/lily/context.cc index 6d5a94b4cc..35d958f6a2 100644 --- a/lily/context.cc +++ b/lily/context.cc @@ -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_); diff --git a/lily/engraver.cc b/lily/engraver.cc index 5f83295e18..c2854e0330 100644 --- a/lily/engraver.cc +++ b/lily/engraver.cc @@ -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, "", "", "", diff --git a/lily/global-context.cc b/lily/global-context.cc index 580479bb94..ce3f9e9ef5 100644 --- a/lily/global-context.cc +++ b/lily/global-context.cc @@ -16,10 +16,15 @@ #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 (c); sc->prepare (w); diff --git a/lily/grob.cc b/lily/grob.cc index 7786f4d3b1..541663d30f 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -29,6 +29,12 @@ #include "ly-smobs.icc" +Grob * +Grob::clone (int count) const +{ + return new Grob (*this, count); +} + /* TODO: - remove dynamic_cast and put this code into respective @@ -37,8 +43,10 @@ #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) { diff --git a/lily/include/context-def.hh b/lily/include/context-def.hh index c734ed9240..e5e7d67493 100644 --- a/lily/include/context-def.hh +++ b/lily/include/context-def.hh @@ -43,7 +43,7 @@ public: Link_array 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 (); diff --git a/lily/include/context.hh b/lily/include/context.hh index c8a366a27d..6dfb6d752f 100644 --- a/lily/include/context.hh +++ b/lily/include/context.hh @@ -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 */ diff --git a/lily/include/engraver.hh b/lily/include/engraver.hh index 1535a245cc..01027fb48a 100644 --- a/lily/include/engraver.hh +++ b/lily/include/engraver.hh @@ -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); diff --git a/lily/include/grob.hh b/lily/include/grob.hh index c4d09fec84..b7cf46611a 100644 --- a/lily/include/grob.hh +++ b/lily/include/grob.hh @@ -16,10 +16,11 @@ #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; diff --git a/lily/include/item.hh b/lily/include/item.hh index be7b22ec84..bb0e02ef82 100644 --- a/lily/include/item.hh +++ b/lily/include/item.hh @@ -26,9 +26,10 @@ class Item : public Grob Drul_array 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; diff --git a/lily/include/lily-proto.hh b/lily/include/lily-proto.hh index e6cf9c85db..51598d8815 100644 --- a/lily/include/lily-proto.hh +++ b/lily/include/lily-proto.hh @@ -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 index 0000000000..b499814c36 --- /dev/null +++ b/lily/include/lilypond-key.hh @@ -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 + +*/ + +#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 index 0000000000..c64fcc9deb --- /dev/null +++ b/lily/include/object-key.hh @@ -0,0 +1,58 @@ +/* + object-key.hh -- declare Object_key + + source file of the GNU LilyPond music typesetter + + (c) 2004 Han-Wen Nienhuys + +*/ + +#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 */ diff --git a/lily/include/paper-column.hh b/lily/include/paper-column.hh index f69ced7147..6a8a1d3d6f 100644 --- a/lily/include/paper-column.hh +++ b/lily/include/paper-column.hh @@ -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 (); diff --git a/lily/include/score-context.hh b/lily/include/score-context.hh index 39cf74c613..7919819af6 100644 --- a/lily/include/score-context.hh +++ b/lily/include/score-context.hh @@ -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 (); diff --git a/lily/include/spanner.hh b/lily/include/spanner.hh index c4670d0122..dad07123bf 100644 --- a/lily/include/spanner.hh +++ b/lily/include/spanner.hh @@ -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 (); }; diff --git a/lily/include/system.hh b/lily/include/system.hh index 911aa0b792..1889dce65c 100644 --- a/lily/include/system.hh +++ b/lily/include/system.hh @@ -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 */ diff --git a/lily/item.cc b/lily/item.cc index c5cca666d5..c6d5ba053e 100644 --- a/lily/item.cc +++ b/lily/item.cc @@ -15,8 +15,16 @@ #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 new_copies; - Direction i=LEFT; + Direction i = LEFT; + int count = 0; do { - Grob * dolly = clone (); + Grob * dolly = clone (count ++); Item * item = dynamic_cast (dolly); pscore_->system_->typeset_grob (item); new_copies[i] =item; diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index 298b374203..92c3bca31b 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -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 index 0000000000..48f4daa446 --- /dev/null +++ b/lily/lilypond-key.cc @@ -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 + +*/ + + +#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 (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 (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 index 0000000000..2f95bec8be --- /dev/null +++ b/lily/object-key.cc @@ -0,0 +1,109 @@ +/* + object-key.cc -- implement Object_key + + source file of the GNU LilyPond music typesetter + + (c) 2004 Han-Wen Nienhuys + +*/ + + +#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 (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 ()); +} diff --git a/lily/paper-column.cc b/lily/paper-column.cc index b5fe7c1351..c964d2fa88 100644 --- a/lily/paper-column.cc +++ b/lily/paper-column.cc @@ -21,6 +21,13 @@ +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) { diff --git a/lily/score-context.cc b/lily/score-context.cc index 0e179e50c4..8730ebcd71 100644 --- a/lily/score-context.cc +++ b/lily/score-context.cc @@ -43,3 +43,8 @@ Score_context::get_output () return s->get_output (); } + +Score_context::Score_context (Object_key const *key) + : Context (key) +{ +} diff --git a/lily/score-engraver.cc b/lily/score-engraver.cc index 432d18b720..e0c39fc5c7 100644 --- a/lily/score-engraver.cc +++ b/lily/score-engraver.cc @@ -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_; diff --git a/lily/spanner.cc b/lily/spanner.cc index 058cc2f0ba..9e33b18eed 100644 --- a/lily/spanner.cc +++ b/lily/spanner.cc @@ -19,6 +19,14 @@ #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 (clone ()); + Spanner * span = dynamic_cast (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 (clone ()); + Spanner *span = dynamic_cast (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; } diff --git a/lily/system-start-delimiter-engraver.cc b/lily/system-start-delimiter-engraver.cc index 3aeb41b130..93b0f177ac 100644 --- a/lily/system-start-delimiter-engraver.cc +++ b/lily/system-start-delimiter-engraver.cc @@ -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"))); diff --git a/lily/system.cc b/lily/system.cc index 0eecf4afeb..b0d14ffe31 100644 --- a/lily/system.cc +++ b/lily/system.cc @@ -26,12 +26,27 @@ #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 const &breaking) { for (int i = 0; i < breaking.size (); i++) { - System *system = dynamic_cast (clone ()); + System *system = dynamic_cast (clone (i)); system->rank_ = i; Link_array c (breaking[i].cols_); diff --git a/lily/tie-engraver.cc b/lily/tie-engraver.cc index 1aecbe526c..0073a880ee 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_); + 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! -- 2.39.2