From: Han-Wen Nienhuys Date: Sun, 14 Nov 2004 23:38:21 +0000 (+0000) Subject: (apply_tweaks): new function. Run tweaks on all X-Git-Tag: release/2.5.14~551 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e10ac37baf76ef07809e851f70870d1e5b8f3bb1;p=lilypond.git (apply_tweaks): new function. Run tweaks on all grobs that have tweaks specced. --- diff --git a/ChangeLog b/ChangeLog index b3e861d6c9..696b17ab39 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-11-15 Han-Wen Nienhuys + + * lily/system.cc (apply_tweaks): new function. Run tweaks on all + grobs that have tweaks specced. + 2004-11-14 Heikki Junes * Documentation/user/sound-output.itexi: add code snippets for MIDI. diff --git a/lily/include/lily-proto.hh b/lily/include/lily-proto.hh index 51598d8815..778dbf01bf 100644 --- a/lily/include/lily-proto.hh +++ b/lily/include/lily-proto.hh @@ -110,6 +110,8 @@ class Music_wrapper_iterator; class Note_performer; class Output_def; class Object_key; +class Object_key_dumper; +class Object_key_undumper; class Output_property; class Page; class Paper_book; diff --git a/lily/include/tweak-registration.hh b/lily/include/tweak-registration.hh index 0191c2fba6..61aab26f70 100644 --- a/lily/include/tweak-registration.hh +++ b/lily/include/tweak-registration.hh @@ -28,12 +28,15 @@ class Tweak_registry public: Object_key_undumper *undumper() const; void clear (); - void insert_tweak (SCM); + void insert_grob_tweak (Grob*, SCM); SCM get_tweaks (Grob *); SCM list_tweaks (); + void insert_tweak_from_file (SCM); Tweak_registry (); }; +extern Tweak_registry *global_registry_; + DECLARE_UNSMOB(Tweak_registry, tweak_registry); #endif /* TWEAK_REGISTRATION_HH */ diff --git a/lily/lilypond-key.cc b/lily/lilypond-key.cc index 08b12298dc..6dc69be030 100644 --- a/lily/lilypond-key.cc +++ b/lily/lilypond-key.cc @@ -163,10 +163,11 @@ Lilypond_context_key::as_scheme () const Object_key * Lilypond_context_key::from_scheme (SCM a) { - return new Lilypond_grob_key (unsmob_key (scm_car (a)), - *unsmob_moment (scm_cadr (a)), - ly_scm2string (scm_list_ref (a, scm_from_int (2))), - scm_to_int (scm_list_ref (a, scm_from_int (3)))); + return new Lilypond_context_key (unsmob_key (scm_car (a)), + *unsmob_moment (scm_cadr (a)), + ly_scm2string (scm_list_ref (a, scm_from_int (2))), + ly_scm2string (scm_list_ref (a, scm_from_int (3))), + scm_to_int (scm_list_ref (a, scm_from_int (4)))); } diff --git a/lily/main.cc b/lily/main.cc index 25e7e68e9b..a80e00e0df 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -255,15 +255,15 @@ prepend_load_path (String dir) static void determine_output_options () { - + bool found_gnome = false; bool found_tex = false; SCM formats = ly_output_formats (); for (SCM s = formats; scm_is_pair (s); s = scm_cdr (s)) { found_tex = found_tex || (ly_scm2string (scm_car (s)) == "tex"); + found_gnome = found_gnome || ly_scm2string(scm_car (s)) == "gnome"; } - if (make_pdf || make_png) { make_ps = true; @@ -276,11 +276,12 @@ determine_output_options () { make_tex = true; } - if (!(make_dvi - || make_tex - || make_ps - || make_png - || make_pdf)) + if (!found_gnome + && !(make_dvi + || make_tex + || make_ps + || make_png + || make_pdf)) { make_pdf = true; make_ps = true; @@ -292,6 +293,8 @@ determine_output_options () } } +void init_global_tweak_registry(); + static void main_with_guile (void *, int, char **) { @@ -309,7 +312,9 @@ main_with_guile (void *, int, char **) ly_c_init_guile (); call_constructors (); - + + init_global_tweak_registry (); + determine_output_options (); all_fonts_global = new All_font_metrics (global_path.to_string ()); diff --git a/lily/object-key-dumper.cc b/lily/object-key-dumper.cc index 7fcbfcdc90..547707bab4 100644 --- a/lily/object-key-dumper.cc +++ b/lily/object-key-dumper.cc @@ -51,8 +51,8 @@ Object_key_dumper::Object_key_dumper () SCM Object_key_dumper::key_serial (int k) { - return scm_cons (ly_symbol2scm ("key"), - scm_from_int (k)); + return scm_list_2 (ly_symbol2scm ("key"), + scm_from_int (k)); } SCM diff --git a/lily/object-key-undumper.cc b/lily/object-key-undumper.cc index 429d9ab2bc..bf0f32f993 100644 --- a/lily/object-key-undumper.cc +++ b/lily/object-key-undumper.cc @@ -104,17 +104,17 @@ Object_key_undumper::parse_contents (SCM contents) SCM *tail = &new_key; for (SCM t = skey; scm_is_pair (t); t = scm_cdr (t)) { - SCM entry = scm_car (t); - if (scm_is_pair (entry) - && scm_car (entry) == ly_symbol2scm ("key")) + SCM item = scm_car (t); + if (scm_is_pair (item) + && scm_car (item) == ly_symbol2scm ("key")) { - int index = scm_to_int (scm_cadr (entry)); + int index = scm_to_int (scm_cadr (item)); Object_key const *key = get_key (index); *tail = scm_cons (key->self_scm(), SCM_EOL); } else { - *tail = scm_cons (entry, SCM_EOL); + *tail = scm_cons (item, SCM_EOL); } tail = SCM_CDRLOC(*tail); } diff --git a/lily/object-key.cc b/lily/object-key.cc index 9a7ae7107b..ae38bfb54c 100644 --- a/lily/object-key.cc +++ b/lily/object-key.cc @@ -107,9 +107,9 @@ struct { } undumpers[] = { {BASE_KEY, Object_key::from_scheme}, {COPIED_KEY, Copied_key::from_scheme}, + {GENERAL_KEY, Lilypond_general_key::from_scheme}, {GROB_KEY, Lilypond_grob_key::from_scheme}, {CONTEXT_KEY, Lilypond_context_key::from_scheme}, - {GENERAL_KEY, Lilypond_general_key::from_scheme}, {KEY_COUNT,0}, }; diff --git a/lily/spring-smob.cc b/lily/spring-smob.cc index e27a72e93d..e7cc63cc0a 100644 --- a/lily/spring-smob.cc +++ b/lily/spring-smob.cc @@ -26,7 +26,7 @@ SCM Spring_smob::mark_smob (SCM) { return SCM_UNSPECIFIED; } int -Spring_smob::print_smob (SCM s, SCM p, scm_print_state *) +Spring_smob::print_smob (SCM, SCM p, scm_print_state *) { scm_puts ("#", p); return 1; diff --git a/lily/system.cc b/lily/system.cc index b0d14ffe31..d16b5a3b4e 100644 --- a/lily/system.cc +++ b/lily/system.cc @@ -25,6 +25,7 @@ #include "staff-symbol-referencer.hh" #include "paper-book.hh" #include "paper-system.hh" +#include "tweak-registration.hh" System::System (System const &src, int count) @@ -277,6 +278,21 @@ System::add_column (Paper_column*p) Axis_group_interface::add_element (me, p); } +void +apply_tweaks (Grob *g, bool broken) +{ + if (bool (g->original_) == broken) + { + SCM tweaks = global_registry_->get_tweaks (g); + for (SCM s = tweaks; scm_is_pair (s); s = scm_cdr (s)) + { + SCM proc = scm_caar (s); + SCM rest = scm_cdar (s); + scm_apply_1 (proc, g->self_scm(), rest); + } + } +} + void System::pre_processing () { @@ -290,7 +306,11 @@ System::pre_processing () unsmob_grob (scm_car (s))->handle_prebroken_dependencies (); fixup_refpoints (get_property ("all-elements")); + + for (SCM s = get_property ("all-elements"); scm_is_pair (s); s = scm_cdr (s)) + apply_tweaks (unsmob_grob (scm_car (s)), false); + for (SCM s = get_property ("all-elements"); scm_is_pair (s); s = scm_cdr (s)) { Grob *sc = unsmob_grob (scm_car (s)); @@ -315,6 +335,9 @@ System::post_processing () for (SCM s = get_property ("all-elements"); scm_is_pair (s); s = scm_cdr (s)) { Grob *g = unsmob_grob (scm_car (s)); + + apply_tweaks (g, true); + g->calculate_dependencies (POSTCALCED, POSTCALCING, ly_symbol2scm ("after-line-breaking-callback")); } diff --git a/lily/tweak-registration.cc b/lily/tweak-registration.cc index 7f929b0a10..501731400e 100644 --- a/lily/tweak-registration.cc +++ b/lily/tweak-registration.cc @@ -25,7 +25,7 @@ Tweak_registry::clear () } void -Tweak_registry::insert_tweak (SCM tweak) +Tweak_registry::insert_tweak_from_file (SCM tweak) { SCM skey = scm_car (tweak); @@ -41,6 +41,20 @@ Tweak_registry::insert_tweak (SCM tweak) tweaks_[key] = scm_cons (scm_cdr (tweak), tweaks_[key]); } + +void +Tweak_registry::insert_grob_tweak (Grob *g, SCM tweak) +{ + Object_key const * key = g->get_key (); + if (tweaks_.find (key) == tweaks_.end()) + { + tweaks_[key] = SCM_EOL; + } + + tweaks_[key] = scm_cons (tweak, tweaks_[key]); +} + + SCM Tweak_registry::get_tweaks (Grob *g) { @@ -75,7 +89,7 @@ Tweak_registry::list_tweaks () const Object_key * key = (*i).first; for (SCM t = (*i).second; scm_is_pair (t); t = scm_cdr (t)) { - retval = scm_cons (key->self_scm(), scm_car (t)); + retval = scm_cons (scm_cons (key->self_scm(), scm_car (t)), retval); } } @@ -95,10 +109,12 @@ Tweak_registry::mark_smob (SCM smob) scm_gc_mark ((*i).second); } - return me->undumper_ ? me->undumper_->self_scm() : SCM_EOL; + if (me->undumper_) + scm_gc_mark (me->undumper_->self_scm()); + + return SCM_EOL; } - int Tweak_registry::print_smob (SCM smob, SCM port, scm_print_state*) { @@ -121,12 +137,11 @@ Tweak_registry * global_registry_; void init_global_tweak_registry() { - // global_registry_ = new Tweak_registry(); + global_registry_ = new Tweak_registry(); } -ADD_SCM_INIT_FUNC(init_global_tweak_registry,init_global_tweak_registry); -LY_DEFINE(ly_clear_tweak_registry, "ly:clear-tweak-registry", +LY_DEFINE(ly_clear_tweak_registry, "ly:tweak-clear-registry", 0,0,0,(), "Clear global tweak registry" ) @@ -135,8 +150,24 @@ LY_DEFINE(ly_clear_tweak_registry, "ly:clear-tweak-registry", return SCM_UNSPECIFIED; } +LY_DEFINE(ly_insert_tweak, "ly:insert-tweak", + 2,0,0, + (SCM grob, SCM tweak), + "add new tweak for grob." + ) +{ + Grob *gr = unsmob_grob (grob); + SCM_ASSERT_TYPE(gr, grob, SCM_ARG1, __FUNCTION__, "Grob"); + SCM_ASSERT_TYPE(scm_list_p (tweak) == SCM_BOOL_T + && ly_c_procedure_p (scm_car (tweak)), + tweak, SCM_ARG2, __FUNCTION__, "Tweak"); + + global_registry_->insert_grob_tweak (gr, tweak); + return SCM_UNSPECIFIED; +} + -LY_DEFINE(ly_tweak_read_keys, "ly:tweak-read-keys", +LY_DEFINE(ly_tweak_read_keys, "ly:tweak-define-keys", 1,0,0,(SCM keys), "Read keys" ) @@ -145,14 +176,24 @@ LY_DEFINE(ly_tweak_read_keys, "ly:tweak-read-keys", return SCM_UNSPECIFIED; } -LY_DEFINE(ly_tweak_read_tweaks, "ly:tweak-read-tweaks", + +LY_DEFINE(ly_all_tweaks, "ly:all-tweaks", + 0,0,0,(), + "all tweaks" + ) +{ + return global_registry_->list_tweaks(); +} + + +LY_DEFINE(ly_tweak_read_tweaks, "ly:tweak-define-tweaks", 1,0,0,(SCM tweaks), "Read tweaks" ) { for (SCM s = tweaks; scm_is_pair (s); s = scm_cdr (s)) { - global_registry_->insert_tweak (scm_car (s)); + global_registry_->insert_tweak_from_file (scm_car (s)); } return SCM_UNSPECIFIED; } diff --git a/scm/framework-gnome.scm b/scm/framework-gnome.scm index 6184b7911e..b142836ccc 100644 --- a/scm/framework-gnome.scm +++ b/scm/framework-gnome.scm @@ -114,7 +114,6 @@ (text-items #:init-value '() #:accessor text-items) (grob #:init-value #f #:accessor grob) (item-grobs #:init-value (make-hash-table 31) #:accessor item-grobs) - (grob-tweaks #:init-value (make-hash-table 31) #:accessor grob-tweaks) (window-width #:init-keyword #:window-width #:accessor window-width) (window-height #:init-keyword #:window-height #:accessor window-height) (canvas-width #:init-keyword #:canvas-width #:accessor canvas-width) @@ -297,6 +296,7 @@ (ly:input-location music-origin) #f))) + (define-method (tweak (go ) item offset) (let* ((grob (hashq-ref (item-grobs go) item #f)) (extra-offset (ly:grob-property grob 'extra-offset)) @@ -305,41 +305,32 @@ (- 0 (cdr extra-offset)))))) (if grob - (hashq-set! (grob-tweaks go) grob - (cons - 'extra-offset - (list - (cons (+ (car origin) (car offset)) - (- 0 (+ (cdr origin) (cdr offset)))))))))) - -;; FIXME: this only saves new tweaks, old tweaks are lost. + (ly:insert-tweak grob (list tweak-grob-property + 'extra-offset + (offset-add origin offset)))))) + (define-method (save-tweaks (go )) (let* ((dumper (ly:make-dumper)) - (tweaks (hash-fold - (lambda (grob value seed) - (cons - (list 'set-property - (list - 'key - (ly:dumper-key-serial dumper (ly:grob-key grob))) - value) - seed)) - '() (grob-tweaks go)))) - - (if (not (null? tweaks)) + (tweaks (ly:all-tweaks)) + (serialized-tweaks (map + (lambda (tweak) + (append + (list + (ly:dumper-key-serial dumper (car tweak)) + (list 'unquote (procedure-name (cadr tweak)))) + (cddr tweak))) + tweaks))) + + (if (not (null? serialized-tweaks)) (let ((file (open-file (string-append (name go) ".twy") "w"))) (format file ";;;tweaks. Generated file. Do not edit. -;;; KEYS -(ly:clear-keys) -(ly:define-keys `~S) -;;; TWEAKS \n -(ly:clear-twbeaks) -(ly:define-tweaks `~S)" - +(ly:tweak-clear-registry) +(ly:tweak-define-keys `~S) +(ly:tweak-define-tweaks `~S)" (ly:dumper-definitions dumper) - tweaks))))) + serialized-tweaks))))) ;;;(define (item-event go grob item event) (define (item-event go item event) @@ -394,7 +385,6 @@ (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)))) diff --git a/scm/lily-library.scm b/scm/lily-library.scm index 94852eb3b9..9cc606a329 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -249,6 +249,10 @@ L1 is copied, L2 not. ))) +(define-public (offset-add a b) + (cons (+ (car a) (car b)) + (+ (cdr a) (cdr b)))) + (define-public (interval-length x) "Length of the number-pair X, when an interval" (max 0 (- (cdr x) (car x))) diff --git a/scm/lily.scm b/scm/lily.scm index c18f1bf3f0..1fc5afbe89 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -351,3 +351,5 @@ predicates. Print a message at LOCATION if any predicate failed." (exit 0)))) +(define-public (tweak-grob-property grob sym val) + (set! (ly:grob-property grob sym) val))