From: Jan Nieuwenhuizen Date: Wed, 10 Nov 2004 01:22:07 +0000 (+0000) Subject: * lily/lily-guile.cc (ly_to_string, ly_to_symbol): New function. X-Git-Tag: release/2.5.14~590 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=326d4b9575d9b8af02c246d421ba5b1fa952119e;p=lilypond.git * lily/lily-guile.cc (ly_to_string, ly_to_symbol): New function. * lily/context-selector.cc (store_context): New function. * lily/grob-selector.cc (register_grob)[TWEAK]: Apply tweak. (store_grob): New function. (identify_grob): Add Moment parameter. * lily/lily-parser.cc (parse_file)[TWEAK]: Read .ly.t file if it exists. * scm/framework-gnome.scm (save-tweaks): Write as alist. --- diff --git a/ChangeLog b/ChangeLog index b1874b715e..908f684f61 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-11-10 Jan Nieuwenhuizen + + * lily/lily-guile.cc (ly_to_string, ly_to_symbol): New function. + + * lily/context-selector.cc (store_context): New function. + + * lily/grob-selector.cc (register_grob)[TWEAK]: Apply tweak. + (store_grob): New function. + (identify_grob): Add Moment parameter. + + * lily/lily-parser.cc (parse_file)[TWEAK]: Read .ly.t file if it + exists. + + * scm/framework-gnome.scm (save-tweaks): Write as alist. + 2004-11-09 Jan Nieuwenhuizen * scm/framework-gnome.scm (item-event): Print grob id. diff --git a/lily/accidental.cc b/lily/accidental.cc index 696673d9d6..e511d7a7c5 100644 --- a/lily/accidental.cc +++ b/lily/accidental.cc @@ -4,7 +4,6 @@ source file of the GNU LilyPond music typesetter (c) 2001--2004 Han-Wen Nienhuys - ofog */ #include "font-interface.hh" #include "item.hh" diff --git a/lily/context-selector.cc b/lily/context-selector.cc index 6bfc0c9e84..c9d34a727f 100644 --- a/lily/context-selector.cc +++ b/lily/context-selector.cc @@ -28,18 +28,16 @@ Context_selector::register_context (Context *context) } /* 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 ()); + store_context (identify_context (context, count), context); } SCM Context_selector::identify_context (Context *context, int count) { /* TODO: start time, parent-context-at-start */ - return ly_symbol2scm ((context->context_name () - + "," - + context->id_string () - + "," - + to_string (count)).to_str0 ()); + return scm_list_3 (scm_makfrom0str (context->context_name ().to_str0 ()), + scm_makfrom0str (context->id_string ().to_str0 ()), + scm_int2num (count)); } SCM @@ -50,8 +48,14 @@ Context_selector::identify_context (Context *context) robust_scm2int (context->get_property ("count"), 0)); } +void +Context_selector::store_context (SCM context_id, Context *context) +{ + contexts_->set (ly_to_symbol (context_id), context->self_scm ()); +} + Context * -Context_selector::retrieve_context (SCM key) +Context_selector::retrieve_context (SCM context_id) { - return unsmob_context (contexts_->get (key)); + return unsmob_context (contexts_->get (ly_to_symbol (context_id))); } diff --git a/lily/grob-selector.cc b/lily/grob-selector.cc index 186eae8ba9..3742b1f5f2 100644 --- a/lily/grob-selector.cc +++ b/lily/grob-selector.cc @@ -15,6 +15,7 @@ #include "warn.hh" Scheme_hash_table *Grob_selector::grobs_ = 0; +Protected_scm Grob_selector::tweaks_ = SCM_EOL; void Grob_selector::register_grob (Context *context, Grob *grob) @@ -22,7 +23,8 @@ 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))) + Moment m = context->now_mom (); + if (Grob *first = retrieve_grob (identify_grob (context, m, grob, 0))) { count = robust_scm2int (first->get_property ("max"), 0); count++; @@ -31,35 +33,51 @@ Grob_selector::register_grob (Context *context, Grob *grob) grob->set_property ("count", s); } grob->set_property ("context", context->self_scm ()); - grobs_->set (identify_grob (context, grob, count), grob->self_scm ()); + SCM grob_id = identify_grob (context, m, grob, count); + store_grob (grob_id, grob); +#ifdef TWEAK + SCM tweak = ly_assoc_get (grob_id, tweaks_, SCM_BOOL_F); + if (tweak != SCM_BOOL_F) + grob->set_property (ly_symbol2string (scm_car (tweak)).to_str0 (), + scm_cadr (tweak)); +#endif } SCM -Grob_selector::identify_grob (Context *context, Grob *grob, int count) +Grob_selector::identify_grob (Context *context, Moment m, 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 ()); + return scm_list_4 (Context_selector::identify_context (context), + scm_makfrom0str (m.to_string ().to_str0 ()), + scm_makfrom0str (grob->name ().to_str0 ()), + scm_int2num (count)); } SCM Grob_selector::identify_grob (Grob *grob) { + Moment m; return identify_grob (unsmob_context (grob->get_property ("context")), + Paper_column::when_mom (((Item*) grob)->get_column ()), grob, robust_scm2int (grob->get_property ("count"), 0)); } +void +Grob_selector::store_grob (SCM grob_id, Grob *grob) +{ + grobs_->set (ly_to_symbol (grob_id), grob->self_scm ()); +} + Grob * -Grob_selector::retrieve_grob (SCM key) +Grob_selector::retrieve_grob (SCM grob_id) +{ + return unsmob_grob (grobs_->get (ly_to_symbol (grob_id))); +} + +void +Grob_selector::set_tweaks (SCM tweaks) { - return unsmob_grob (grobs_->get (key)); + tweaks_ = tweaks; } LY_DEFINE (ly_grob_id, "ly:grob-id", diff --git a/lily/include/context-selector.hh b/lily/include/context-selector.hh index 5afc659c21..ade26365a8 100644 --- a/lily/include/context-selector.hh +++ b/lily/include/context-selector.hh @@ -24,7 +24,8 @@ 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); + static Context *retrieve_context (SCM context_id); + static void store_context (SCM context_id, Context *context); }; #endif /* CONTEXT_SELECTOR_HH */ diff --git a/lily/include/grob-selector.hh b/lily/include/grob-selector.hh index be4b62b754..a235ef3ea0 100644 --- a/lily/include/grob-selector.hh +++ b/lily/include/grob-selector.hh @@ -10,6 +10,7 @@ #include "lily-guile.hh" #include "lily-proto.hh" +#include "protected-scm.hh" /** * Grob_selector: @@ -18,14 +19,16 @@ **/ class Grob_selector { - static int count_; static Scheme_hash_table *grobs_; + static Protected_scm tweaks_; public: static void register_grob (Context *context, Grob *grob); - static SCM identify_grob (Context *context, Grob *grob, int count); + static SCM identify_grob (Context *context, Moment m, Grob *grob, int count); static SCM identify_grob (Grob *grob); - static Grob *retrieve_grob (SCM key); + static Grob *retrieve_grob (SCM grob_id); + static void store_grob (SCM grob_id, Grob *grob); + static void set_tweaks (SCM tweaks); }; #endif /* GROB_SELECTOR_HH */ diff --git a/lily/include/lily-guile.hh b/lily/include/lily-guile.hh index 21da4a4595..fb3de16595 100644 --- a/lily/include/lily-guile.hh +++ b/lily/include/lily-guile.hh @@ -36,6 +36,9 @@ SCM ly_write2scm (SCM s); SCM ly_deep_copy (SCM); SCM ly_truncate_list (int k, SCM lst); +SCM ly_to_string (SCM scm); +SCM ly_to_symbol (SCM scm); + #if (__GNUC__ > 2) /* Unreliable with gcc-2.x FIXME: should add check for x86 as well? */ @@ -89,6 +92,7 @@ extern SCM global_lily_module; value; \ }) +String gulp_file_to_string (String fn, bool must_exist); String ly_scm2string (SCM s); String ly_symbol2string (SCM); diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index 24882faef2..298b374203 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -41,13 +41,25 @@ inline int my_isnan (Real r) { return isnan (r); } // #define TEST_GC +SCM +ly_to_symbol (SCM scm) +{ + return scm_string_to_symbol (ly_to_string (scm)); +} + +SCM +ly_to_string (SCM scm) +{ + return scm_call_3 (ly_scheme_function ("format"), SCM_BOOL_F, + scm_makfrom0str ("~S"), scm); +} + SCM ly_last (SCM list) { return scm_car (scm_last_pair (list)); } - SCM ly_write2scm (SCM s) { @@ -63,7 +75,6 @@ ly_write2scm (SCM s) return scm_strport_to_string (port); } - SCM ly_quote_scm (SCM s) { @@ -81,21 +92,27 @@ ly_symbol2string (SCM s) } String -gulp_file_to_string (String fn) +gulp_file_to_string (String fn, bool must_exist) { String s = global_path.find (fn); if (s == "") { - String e = _f ("can't find file: `%s'", fn); - e += " "; - e += _f ("(load path: `%s')", global_path.to_string ()); - error (e); + if (must_exist) + { + String e = _f ("can't find file: `%s'", fn); + e += " "; + e += _f ("(load path: `%s')", global_path.to_string ()); + error (e); + /* unreachable */ + } + return s; } - else if (verbose_global_b) + + if (verbose_global_b) progress_indication ("[" + s); int n; - char * str = gulp_file (s, &n); + char *str = gulp_file (s, &n); String result (str); delete[] str; @@ -111,7 +128,9 @@ LY_DEFINE (ly_gulp_file, "ly:gulp-file", "The file is looked up using the search path.") { SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string"); - return scm_makfrom0str (gulp_file_to_string (ly_scm2string (name)).to_str0 ()); + return scm_makfrom0str (gulp_file_to_string (ly_scm2string (name), + true).to_str0 ()); + } @@ -230,7 +249,7 @@ void add_scm_init_func (void (*f) ()) void ly_init_ly_module (void *) { - for (int i=scm_init_funcs_->size () ; i--;) + for (int i = scm_init_funcs_->size () ; i--;) (scm_init_funcs_->elem (i)) (); if (verbose_global_b) @@ -265,10 +284,11 @@ is_direction (SCM s) return false; } -LY_DEFINE(ly_assoc_get, "ly:assoc-get", - 2, 1, 0, - (SCM key, SCM alist, SCM default_value), - "Return value if KEY in ALIST, else DEFAULT-VALUE (or #f if not specified).") +LY_DEFINE (ly_assoc_get, "ly:assoc-get", + 2, 1, 0, + (SCM key, SCM alist, SCM default_value), + "Return value if KEY in ALIST, else DEFAULT-VALUE " + "(or #f if not specified).") { SCM handle = scm_assoc (key, alist); @@ -416,7 +436,7 @@ ly_deep_copy (SCM src) { int len = SCM_VECTOR_LENGTH (src); SCM nv = scm_c_make_vector (len, SCM_UNDEFINED); - for (int i =0 ; i < len ; i++) + for (int i = 0 ;i < len ; i++) { SCM si = scm_int2num (i); scm_vector_set_x (nv, si, ly_deep_copy (scm_vector_ref (src, si))); diff --git a/lily/lily-parser.cc b/lily/lily-parser.cc index 253cae0467..1700609a18 100644 --- a/lily/lily-parser.cc +++ b/lily/lily-parser.cc @@ -8,6 +8,7 @@ */ #include "book.hh" +#include "grob-selector.hh" #include "file-name.hh" #include "file-path.hh" #include "lily-version.hh" @@ -100,6 +101,17 @@ Lily_parser::parse_file (String init, String name, String out_name) set_yydebug (0); lexer_->new_input (init, sources_); +#ifdef TWEAK + String s = global_path.find (name + ".t"); + if (s == "") + Grob_selector::set_tweaks (SCM_EOL); + else + { + s = gulp_file_to_string (s, false); + SCM tweaks = scm_eval_string (scm_makfrom0str (s.to_str0 ())); + Grob_selector::set_tweaks (tweaks); + } +#endif /* Read .ly IN_FILE, lex, parse, write \score blocks from IN_FILE to OUT_FILE (unless IN_FILE redefines output file name). */ diff --git a/lily/moment.cc b/lily/moment.cc index 51664870b4..f4caf2823e 100644 --- a/lily/moment.cc +++ b/lily/moment.cc @@ -251,7 +251,7 @@ operator << (std::ostream &os, Moment const &m) Moment robust_scm2moment (SCM m, Moment d) { - Moment * p = unsmob_moment (m); + Moment *p = unsmob_moment (m); if (!p) return d; else @@ -262,6 +262,6 @@ robust_scm2moment (SCM m, Moment d) bool moment_less (SCM a, SCM b) { - return *unsmob_moment (a) < *unsmob_moment (b); + return *unsmob_moment (a) < *unsmob_moment (b); } diff --git a/scm/framework-gnome.scm b/scm/framework-gnome.scm index e2444d72df..921a746f66 100644 --- a/scm/framework-gnome.scm +++ b/scm/framework-gnome.scm @@ -56,7 +56,8 @@ (canvas-height #:init-keyword #:canvas-height #:accessor canvas-height)) (define-method (initialize (go )) - (let* ((button (make #:label "Exit")) + (let* ((save (make #:label "Save")) + (exit (make #:label "Exit")) (next (make #:label "Next")) (prev (make #:label "Previous")) (vbox (make #:homogeneous #f)) @@ -83,15 +84,17 @@ ;;(set-child-packing vbox hbox #f #f 0 'end) ;;(set-child-packing hbox button #f #f 0 'end) - (set-size-request button (quotient (window-width go) 2) BUTTON-HEIGHT) + (set-size-request exit (quotient (window-width go) 2) BUTTON-HEIGHT) (add hbox next) (add hbox prev) - (add hbox button) + (add hbox save) + (add hbox exit) ;; signals - (connect button 'clicked (lambda (b) (save-tweaks go) (gtk-main-quit))) + (connect exit 'clicked (lambda (b) (gtk-main-quit))) + (connect save 'clicked (lambda (b) (save-tweaks go))) (connect next 'clicked (lambda (b) (dump-page go (1+ (page-number go))))) (connect prev 'clicked (lambda (b) (dump-page go (1- (page-number go))))) (connect (window go) 'key-press-event @@ -221,7 +224,10 @@ (define-method (tweak (go ) item offset) (let* ((grob (hashq-ref (item-grobs go) item #f)) - (origin (hashq-ref (grob-tweaks go) grob '(0 . 0)))) + (extra-offset (ly:grob-property grob 'extra-offset)) + (origin (hashq-ref (grob-tweaks go) grob + (cons (car extra-offset) + (- 0 (cdr extra-offset)))))) (if grob (hashq-set! (grob-tweaks go) grob (cons (+ (car origin) (car offset)) (+ (cdr origin) (cdr offset))))) @@ -229,13 +235,16 @@ (define-method (save-tweaks (go )) (let ;;((file (current-error-port))) - ((file (open-file (string-append (name go) ".twy") "w"))) - (format file "%% TWEAKS %%\n") + ((file (open-file (string-append (name go) ".ly.t") "w"))) + (format file ";;; TWEAKS \n") + (format file ";;(define grob-id-tweak-alist \n'(\n") (hash-fold (lambda (key value seed) - (format file "~S:~S\n" - (if (ly:grob? key) (ly:grob-id key) "unidentified grob") value)) - #f (grob-tweaks go)))) + (format file "(~S extra-offset ~S)\n" + (if (ly:grob? key) (ly:grob-id key) ";;unidentified grob") + value)) + #f (grob-tweaks go)) + (format file ")\n;;)\n"))) ;;;(define (item-event go grob item event) (define (item-event go item event)