From: janneke Date: Tue, 9 Nov 2004 00:00:42 +0000 (+0000) Subject: * scm/framework-gnome.scm (item-event): Print grob id. X-Git-Tag: release/2.5.23~1007 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e34203bfc28ddde1c54e6f5db92f6366cc4383ce;p=lilypond.git * scm/framework-gnome.scm (item-event): Print grob id. * lily/context-property.cc (make_item_from_properties): Register grob. * lily/context.cc (add_context): Register context. * lily/include/context-selector.hh: * lily/include/grob-selector.hh: * lily/context-selector.cc: * lily/grob-selector.cc: New file. --- diff --git a/ChangeLog b/ChangeLog index 6c27b4f10d..ee479778d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2004-11-09 Jan Nieuwenhuizen + + * scm/framework-gnome.scm (item-event): Print grob id. + + * lily/context-property.cc (make_item_from_properties): Register grob. + * lily/context.cc (add_context): Register context. + + * lily/include/context-selector.hh: + * lily/include/grob-selector.hh: + * lily/context-selector.cc: + * lily/grob-selector.cc: New file. + 2004-11-08 Han-Wen Nienhuys * lily/slur.cc: add 'positions to interface diff --git a/lily/auto-beam-engraver.cc b/lily/auto-beam-engraver.cc index 186c923de4..d5bfa39bfc 100644 --- a/lily/auto-beam-engraver.cc +++ b/lily/auto-beam-engraver.cc @@ -276,15 +276,13 @@ Auto_beam_engraver::consider_end (Moment test_mom) } } -Spanner* +Spanner * Auto_beam_engraver::create_beam () { if (to_boolean (get_property ("skipTypesetting"))) - { - return 0; - } + return 0; - Spanner* beam = new Spanner (beam_settings_); + Spanner *beam = new Spanner (beam_settings_); for (int i = 0; i < stems_->size (); i++) { /* diff --git a/lily/context-def.cc b/lily/context-def.cc index dded720471..def8427221 100644 --- a/lily/context-def.cc +++ b/lily/context-def.cc @@ -320,15 +320,15 @@ Context_def::instantiate (SCM ops) scm_gc_unprotect_object (g->self_scm ()); - tg->accepts_list_ = get_accepted (ops); - + tg->accepts_list_ = get_accepted (ops); + return tg; } SCM Context_def::clone_scm () const { - Context_def * t = new Context_def (*this); + Context_def *t = new Context_def (*this); SCM x = t->self_scm (); scm_gc_unprotect_object (x); return x; @@ -337,7 +337,7 @@ Context_def::clone_scm () const SCM Context_def::make_scm () { - Context_def* t = new Context_def; + Context_def *t = new Context_def; SCM x = t->self_scm (); scm_gc_unprotect_object (x); return x; diff --git a/lily/context-property.cc b/lily/context-property.cc index 4796980d9f..8d5923c132 100644 --- a/lily/context-property.cc +++ b/lily/context-property.cc @@ -1,18 +1,19 @@ -/* - translator-property.cc -- implement manipulation of immutable Grob +/* + context-property.cc -- implement manipulation of immutable Grob property lists. source file of the GNU LilyPond music typesetter (c) 2004 Han-Wen Nienhuys - */ +*/ -#include "main.hh" #include "context.hh" -#include "warn.hh" +#include "grob-selector.hh" +#include "engraver.hh" #include "item.hh" +#include "main.hh" #include "spanner.hh" -#include "engraver.hh" +#include "warn.hh" /* Grob descriptions (ie. alists with layout properties) are @@ -178,7 +179,7 @@ updated_grob_properties (Context * tg, SCM sym) else { SCM copy = daddy_props; - SCM * tail = © + SCM *tail = © SCM p = scm_car (props); while (p != based_on) { @@ -194,16 +195,17 @@ updated_grob_properties (Context * tg, SCM sym) } } -Item* +Item * make_item_from_properties (Translator *tr, SCM x, SCM cause) { - Context *tg = tr->context (); + Context *context = tr->context (); - SCM props = updated_grob_properties (tg, x); - Item *it= new Item (props); + SCM props = updated_grob_properties (context, x); + Item *it = new Item (props); + Grob_selector::register_grob (context, it); dynamic_cast(tr)->announce_grob (it, cause); - + return it; } @@ -211,11 +213,11 @@ Spanner* make_spanner_from_properties (Translator *tr, SCM x, SCM cause) { Context *tg = tr->context (); - + SCM props = updated_grob_properties (tg, x); - Spanner *it= new Spanner (props); + Spanner *it = new Spanner (props); dynamic_cast(tr)->announce_grob (it, cause); - + return it; } diff --git a/lily/context-selector.cc b/lily/context-selector.cc new file mode 100644 index 0000000000..717bd5c24d --- /dev/null +++ b/lily/context-selector.cc @@ -0,0 +1,55 @@ +/* + context-selector.cc -- implement Context selection. + + source file of the GNU LilyPond music typesetter + + (c) 2004 Jan Nieuwenhuizen +*/ + +#include "context-selector.hh" +#include "context.hh" +#include "scm-hash.hh" + +Scheme_hash_table *Context_selector::contexts_ = 0; + +void +Context_selector::register_context (Context *context) +{ + if (!contexts_) + contexts_ = new Scheme_hash_table (); + int count = 0; + if (Context *first = retrieve_context (identify_context (context, 0))) + { + count = robust_scm2int (first->get_property ("max"), 0); + count++; + SCM s = scm_int2num (count); + first->set_property ("max", s); + context->set_property ("count", s); + } + /* FIXME: must alway set count, for get_property () not to segfault. */ + context->set_property ("count", scm_int2num (count)); + contexts_->set (identify_context (context, count), context->self_scm ()); +} + +SCM +Context_selector::identify_context (Context *context, int count) +{ + /* TODO: start time, parent-context-at-start */ + return ly_symbol2scm ((context->context_name () + + "," + + to_string (count)).to_str0 ()); +} + +SCM +Context_selector::identify_context (Context *context) +{ + return + identify_context (context, + robust_scm2int (context->get_property ("count"), 0)); +} + +Context * +Context_selector::retrieve_context (SCM key) +{ + return unsmob_context (contexts_->get (key)); +} diff --git a/lily/context.cc b/lily/context.cc index 75b378c8f3..3dd2c482e2 100644 --- a/lily/context.cc +++ b/lily/context.cc @@ -7,15 +7,16 @@ */ -#include "translator-group.hh" #include "context-def.hh" +#include "context-selector.hh" #include "context.hh" -#include "warn.hh" +#include "ly-smobs.icc" +#include "main.hh" #include "output-def.hh" #include "scm-hash.hh" -#include "main.hh" -#include "ly-smobs.icc" #include "score-context.hh" +#include "translator-group.hh" +#include "warn.hh" bool Context::is_removable () const @@ -29,7 +30,7 @@ Context::check_removal () { for (SCM p = context_list_; scm_is_pair (p); p = scm_cdr (p)) { - Context *trg = unsmob_context (scm_car (p)); + Context *trg = unsmob_context (scm_car (p)); trg->check_removal (); if (trg->is_removable ()) @@ -45,14 +46,14 @@ Context::Context (Context const&) assert (false); } -Scheme_hash_table* +Scheme_hash_table * Context::properties_dict () const { return Scheme_hash_table::unsmob (properties_scm_); } void -Context::add_context (Context*t) +Context::add_context (Context *t) { SCM ts = t->self_scm (); context_list_ = ly_append2 (context_list_, @@ -62,9 +63,10 @@ Context::add_context (Context*t) if (!t->init_) { t->init_ = true; - + Context_selector::register_context (t); + scm_gc_unprotect_object (ts); - Context_def * td = unsmob_context_def (t->definition_); + Context_def *td = unsmob_context_def (t->definition_); /* this can not move before add_context (), because \override @@ -306,11 +308,11 @@ find_context_below (Context * where, return where; } - Context * found = 0; + Context *found = 0; for (SCM s = where->children_contexts (); !found && scm_is_pair (s); s = scm_cdr (s)) { - Context * tr = unsmob_context (scm_car (s)); + Context *tr = unsmob_context (scm_car (s)); found = find_context_below (tr, type, id); } @@ -327,22 +329,21 @@ Context::properties_as_alist () const SCM Context::context_name_symbol () const { - Context_def * td = unsmob_context_def (definition_ ); + Context_def *td = unsmob_context_def (definition_); return td->get_context_name (); } String Context::context_name () const { - return ly_symbol2string (context_name_symbol ()); + return ly_symbol2string (context_name_symbol ()); } Score_context* Context::get_score_context () const { - if (Score_context *sc =dynamic_cast ((Context*) this)) + if (Score_context *sc = dynamic_cast ((Context*) this)) return sc; - else if (daddy_context_) return daddy_context_->get_score_context (); else @@ -352,8 +353,7 @@ Context::get_score_context () const Output_def * Context::get_output_def () const { - return (daddy_context_) - ? daddy_context_->get_output_def () : 0; + return daddy_context_ ? daddy_context_->get_output_def () : 0; } Context::~Context () @@ -374,7 +374,7 @@ Context::print_smob (SCM s, SCM port, scm_print_state *) scm_puts ("#<", port); scm_puts (classname (sc), port); - if (Context_def *d=unsmob_context_def (sc->definition_)) + if (Context_def *d = unsmob_context_def (sc->definition_)) { scm_puts (" ", port); scm_display (d->get_context_name (), port); @@ -398,7 +398,7 @@ Context::print_smob (SCM s, SCM port, scm_print_state *) SCM Context::mark_smob (SCM sm) { - Context * me = (Context*) SCM_CELL_WORD_1 (sm); + Context *me = (Context*) SCM_CELL_WORD_1 (sm); scm_gc_mark (me->context_list_); scm_gc_mark (me->aliases_); diff --git a/lily/grob-selector.cc b/lily/grob-selector.cc new file mode 100644 index 0000000000..58574a45b0 --- /dev/null +++ b/lily/grob-selector.cc @@ -0,0 +1,71 @@ +/* + grob-selector.cc -- implement Grob selection. + + source file of the GNU LilyPond music typesetter + + (c) 2004 Jan Nieuwenhuizen +*/ + +#include "context-selector.hh" +#include "context.hh" +#include "grob-selector.hh" +#include "grob.hh" +#include "paper-column.hh" +#include "scm-hash.hh" + +Scheme_hash_table *Grob_selector::grobs_ = 0; + +void +Grob_selector::register_grob (Context *context, Grob *grob) +{ + if (!grobs_) + grobs_ = new Scheme_hash_table (); + int count = 0; + if (Grob *first = retrieve_grob (identify_grob (context, grob, 0))) + { + count = robust_scm2int (first->get_property ("max"), 0); + count++; + SCM s = scm_int2num (count); + first->set_property ("max", s); + grob->set_property ("count", s); + } + grob->set_property ("context", context->self_scm ()); + grobs_->set (identify_grob (context, grob, count), grob->self_scm ()); +} + +SCM +Grob_selector::identify_grob (Context *context, Grob *grob, int count) +{ + return ly_symbol2scm ((ly_symbol2string (Context_selector::identify_context (context)) + + "," + + grob->name () +#if 0 // "when" not defined yet? + + "," + + Paper_column::when_mom (((Item*)grob)->get_column ()).to_string (), +#endif + + "," + + to_string (count)).to_str0 ()); +} + +SCM +Grob_selector::identify_grob (Grob *grob) +{ + return identify_grob (unsmob_context (grob->get_property ("context")), + grob, + robust_scm2int (grob->get_property ("count"), 0)); +} + +Grob * +Grob_selector::retrieve_grob (SCM key) +{ + return unsmob_grob (grobs_->get (key)); +} + +LY_DEFINE (ly_grob_id, "ly:grob-id", + 1, 0, 0, (SCM grob_scm), + "Return grob id.") +{ + Grob *grob = unsmob_grob (grob_scm); + SCM s = Grob_selector::identify_grob (grob); + return s; +} diff --git a/lily/include/context-selector.hh b/lily/include/context-selector.hh new file mode 100644 index 0000000000..5afc659c21 --- /dev/null +++ b/lily/include/context-selector.hh @@ -0,0 +1,31 @@ +/* + context-selector.hh -- declare Context_selector + + source file of the LilyPond music typesetter + + (c) 2004 Jan Nieuwenhuizen +*/ +#ifndef CONTEXT_SELECTOR_HH +#define CONTEXT_SELECTOR_HH + +#include "lily-guile.hh" +#include "lily-proto.hh" + +/** + * Context_selector: + * @register_context: register new #CONTEXT. + # + **/ +class Context_selector +{ + static Scheme_hash_table *contexts_; + +public: + static void register_context (Context *context); + static SCM identify_context (Context *context, int count); + static SCM identify_context (Context *context); + static Context *retrieve_context (SCM key); +}; + +#endif /* CONTEXT_SELECTOR_HH */ + diff --git a/lily/include/grob-selector.hh b/lily/include/grob-selector.hh new file mode 100644 index 0000000000..be4b62b754 --- /dev/null +++ b/lily/include/grob-selector.hh @@ -0,0 +1,31 @@ +/* + grob-selector.hh -- declare Grob_selector + + source file of the LilyPond music typesetter + + (c) 2004 Jan Nieuwenhuizen +*/ +#ifndef GROB_SELECTOR_HH +#define GROB_SELECTOR_HH + +#include "lily-guile.hh" +#include "lily-proto.hh" + +/** + * Grob_selector: + * @register_grob: register new #GROB. + # + **/ +class Grob_selector +{ + static int count_; + static Scheme_hash_table *grobs_; + +public: + static void register_grob (Context *context, Grob *grob); + static SCM identify_grob (Context *context, Grob *grob, int count); + static SCM identify_grob (Grob *grob); + static Grob *retrieve_grob (SCM key); +}; + +#endif /* GROB_SELECTOR_HH */ diff --git a/lily/include/grob.hh b/lily/include/grob.hh index 52f4a0feec..c4d09fec84 100644 --- a/lily/include/grob.hh +++ b/lily/include/grob.hh @@ -151,4 +151,3 @@ SCM ly_grobs2scm (Link_array a); Interval robust_relative_extent (Grob*, Grob*, Axis); #endif /* GROB_HH */ - diff --git a/lily/include/lily-guile.hh b/lily/include/lily-guile.hh index e06a507d62..21da4a4595 100644 --- a/lily/include/lily-guile.hh +++ b/lily/include/lily-guile.hh @@ -281,6 +281,6 @@ LY_DEFINE_WITHOUT_DECL (CLASS ## FNAME, CLASS::FNAME, PRIMNAME, REQ, OPT, \ VAR, ARGLIST, DOCSTRING) #define get_property(x) internal_get_property (ly_symbol2scm (x)) -#define set_property(x,y) internal_set_property (ly_symbol2scm (x), y) +#define set_property(x, y) internal_set_property (ly_symbol2scm (x), y) #endif /* LILY_GUILE_HH */ diff --git a/lily/include/scm-hash.hh b/lily/include/scm-hash.hh index c5c2769e67..a823494505 100644 --- a/lily/include/scm-hash.hh +++ b/lily/include/scm-hash.hh @@ -54,11 +54,12 @@ public: Scheme_hash_table (Scheme_hash_table const &); SCM to_alist () const; + private: SCM hash_tab_; unsigned elt_count_; - DECLARE_SMOBS (Scheme_hash_table,foo); + DECLARE_SMOBS (Scheme_hash_table, foo); }; diff --git a/lily/include/score-context.hh b/lily/include/score-context.hh index 796fbee32d..39cf74c613 100644 --- a/lily/include/score-context.hh +++ b/lily/include/score-context.hh @@ -1,18 +1,15 @@ -/* -score-context.hh -- declare Score_notation_context - -source file of the GNU LilyPond music typesetter - -(c) 2004 Han-Wen Nienhuys - - */ - +/* + score-context.hh -- declare Score_context + + source file of the GNU LilyPond music typesetter + + (c) 2004 Han-Wen Nienhuys +*/ #ifndef SCORE_CONTEXT_HH #define SCORE_CONTEXT_HH #include "global-context.hh" - class Score_context : public Context { public: @@ -22,6 +19,4 @@ class Score_context : public Context virtual void one_time_step (); }; - - #endif /* SCORE_CONTEXT_HH */ diff --git a/lily/include/slur.hh b/lily/include/slur.hh index 125697632c..003fa48083 100644 --- a/lily/include/slur.hh +++ b/lily/include/slur.hh @@ -1,14 +1,13 @@ -/* +/* slur.hh -- declare Slur source file of the GNU LilyPond music typesetter (c) 2004 Han-Wen Nienhuys - */ -#ifndef NEW_SLUR_HH -#define NEW_SLUR_HH +#ifndef SLUR_HH +#define SLUR_HH #include "lily-proto.hh" #include "lily-guile.hh" @@ -26,5 +25,4 @@ public: static Bezier get_curve (Grob*me); }; -#endif /* NEW_SLUR_HH */ - +#endif /* SLUR_HH */ diff --git a/lily/paper-column.cc b/lily/paper-column.cc index d4d5a03e7e..a955c6663c 100644 --- a/lily/paper-column.cc +++ b/lily/paper-column.cc @@ -72,15 +72,12 @@ Paper_column::Paper_column (SCM l) } Moment -Paper_column::when_mom (Grob*me) +Paper_column::when_mom (Grob *me) { SCM m = me->get_property ("when"); - Moment s (0); - if (unsmob_moment (m)) - { - return *unsmob_moment (m); - } - return s; + if (Moment *when = unsmob_moment (m)) + return *when; + return Moment (0); } bool diff --git a/lily/scm-hash.cc b/lily/scm-hash.cc index 7497d699d4..2cdbb1d50c 100644 --- a/lily/scm-hash.cc +++ b/lily/scm-hash.cc @@ -4,8 +4,8 @@ source file of the GNU LilyPond music typesetter (c) 1999--2004 Han-Wen Nienhuys - - */ +*/ + #include #include "scm-hash.hh" @@ -58,6 +58,10 @@ Scheme_hash_table::operator = (Scheme_hash_table const & src) elt_count_ = copy_scm_hashes (hash_tab_, src.hash_tab_); } +Scheme_hash_table::~Scheme_hash_table () +{ +} + SCM Scheme_hash_table::mark_smob (SCM s) { @@ -89,7 +93,6 @@ Scheme_hash_table::try_retrieve (SCM k, SCM *v) } else return false; - } bool @@ -104,9 +107,7 @@ Scheme_hash_table::set (SCM k, SCM v) assert (scm_is_symbol (k)); SCM handle = scm_hashq_create_handle_x (hash_tab_, k, SCM_UNDEFINED); if (scm_cdr (handle) == SCM_UNDEFINED) - { - elt_count_++; - } + elt_count_++; scm_set_cdr_x (handle, v); @@ -135,32 +136,21 @@ void Scheme_hash_table::remove (SCM k) { scm_hashq_remove_x (hash_tab_, k); - /* - don't decrease elt_count_ , as this may cause underflow. The exact - value of elt_count_ is not important. - */ -} - -Scheme_hash_table::~Scheme_hash_table () -{ + /* Do not decrease elt_count_ as this may cause underflow. The exact + value of elt_count_ is not important. */ } SCM Scheme_hash_table::to_alist () const { - SCM l = SCM_EOL; + SCM lst = SCM_EOL; for (int i = SCM_VECTOR_LENGTH (hash_tab_); i--;) - for (SCM s = scm_vector_ref (hash_tab_, scm_int2num (i)); scm_is_pair (s); s = scm_cdr (s)) - { - l = scm_acons (scm_caar (s), scm_cdar (s), l); - } - return l; + for (SCM s = scm_vector_ref (hash_tab_, scm_int2num (i)); scm_is_pair (s); + s = scm_cdr (s)) + lst = scm_acons (scm_caar (s), scm_cdar (s), lst); + return lst; } - - - - IMPLEMENT_SMOBS (Scheme_hash_table); IMPLEMENT_DEFAULT_EQUAL_P (Scheme_hash_table); diff --git a/lily/score-context.cc b/lily/score-context.cc index 6cbd6a5559..0e179e50c4 100644 --- a/lily/score-context.cc +++ b/lily/score-context.cc @@ -1,9 +1,9 @@ -/* - score-context.cc -- implement Score_context - - source file of the GNU LilyPond music typesetter - - (c) 2004 Han-Wen Nienhuys +/* + score-context.cc -- implement Score_context + + source file of the GNU LilyPond music typesetter + + (c) 2004 Han-Wen Nienhuys */ #include "score-context.hh" diff --git a/lily/simple-spacer.cc b/lily/simple-spacer.cc index eb20f0b1da..d9413d5b8e 100644 --- a/lily/simple-spacer.cc +++ b/lily/simple-spacer.cc @@ -268,7 +268,7 @@ LY_DEFINE(ly_solve_spring_rod_problem, "ly:solve-spring-rod-problem", length, SCM_ARG3, __FUNCTION__, "number or #f"); - bool is_ragged = ragged == SCM_BOOL_T; + bool is_ragged = ragged == SCM_BOOL_T; Simple_spacer spacer; for (SCM s = springs; scm_is_pair (s); s = scm_cdr (s)) { diff --git a/scm/framework-gnome.scm b/scm/framework-gnome.scm index 968d8132d1..631c762f87 100644 --- a/scm/framework-gnome.scm +++ b/scm/framework-gnome.scm @@ -235,6 +235,7 @@ (let ((properties (ly:grob-properties grob)) (basic-properties (ly:grob-basic-properties grob)) + (id (ly:grob-id grob)) (x (inexact->exact (gdk-event-button:x-root event))) (y (inexact->exact (gdk-event-button:y-root event)))) @@ -248,7 +249,7 @@ (add window vbox) (connect button 'clicked (lambda (b) (destroy window))) - + (for-each (lambda (x) (let ((button (make @@ -260,7 +261,7 @@ (format #f "~S" (cdr x)))))) (set-size-request button 150 BUTTON-HEIGHT) (add vbox button))) - properties) + (cons (list id) properties)) (add vbox button) ;; FIXME: how to do window placement?