]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/lily-guile.cc (ly_to_string, ly_to_symbol): New function.
authorJan Nieuwenhuizen <janneke@gnu.org>
Wed, 10 Nov 2004 01:22:07 +0000 (01:22 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Wed, 10 Nov 2004 01:22:07 +0000 (01:22 +0000)
* 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.

ChangeLog
lily/accidental.cc
lily/context-selector.cc
lily/grob-selector.cc
lily/include/context-selector.hh
lily/include/grob-selector.hh
lily/include/lily-guile.hh
lily/lily-guile.cc
lily/lily-parser.cc
lily/moment.cc
scm/framework-gnome.scm

index b1874b715e3b645d44e24798285db523950fd6e5..908f684f6175f869588bf5ad1caba7adba91f0f2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2004-11-10  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+       * 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  <janneke@gnu.org>
 
        * scm/framework-gnome.scm (item-event): Print grob id.
index 696673d9d6ea3ed203133a0b54601f35f35e8310..e511d7a7c5a26411b194f7c46e9481dc89cf1aac 100644 (file)
@@ -4,7 +4,6 @@
   source file of the GNU LilyPond music typesetter
   
   (c) 2001--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-  ofog
 */
 #include "font-interface.hh"
 #include "item.hh"
index 6bfc0c9e844c6effc91f9343510e0d84048772ca..c9d34a727f3a911838e596b1e2946a1d78092fc3 100644 (file)
@@ -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)));
 }
index 186eae8ba906fec1f479f6b7935a8189ef6d2771..3742b1f5f2845ebc7c3a73e68346fbd81577bd21 100644 (file)
@@ -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",
index 5afc659c21f1751d2a66e0135e752a010046cb8c..ade26365a852ae652effbc9f96776aa949628204 100644 (file)
@@ -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 */
index be4b62b7540dc0985db56cc51ec43d0e3fc0f561..a235ef3ea07cce0da429960c4a964fd1b90c89a6 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "lily-guile.hh"
 #include "lily-proto.hh"
+#include "protected-scm.hh"
 
 /**
  * Grob_selector:
  **/
 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 */
index 21da4a45950d6a3bf149f60f75bd66e222931442..fb3de165958e42c8e534208bb97e89e808f65253 100644 (file)
@@ -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);
index 24882faef24afaaabc062a761a7dba471f4eeb9c..298b374203bdbb34cff32fc6dd66abf5c6a4d3c3 100644 (file)
@@ -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))); 
index 253cae0467955b2d1a2be2525e46d570af7f8e50..1700609a18149506d75da9d336760229931457a0 100644 (file)
@@ -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).  */
index 51664870b46c917078c3dd282f311bd5827d2615..f4caf2823e9b4ab1186a12800485861367f23557 100644 (file)
@@ -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);
 }
 
index e2444d72df18686ebd239d89b08ad485fda0d3b9..921a746f6687c6a080f5a6035389f8a08f7824f9 100644 (file)
@@ -56,7 +56,8 @@
   (canvas-height #:init-keyword #:canvas-height #:accessor canvas-height))
 
 (define-method (initialize (go <gnome-outputter>))
-  (let* ((button (make <gtk-button> #:label "Exit"))
+  (let* ((save (make <gtk-button> #:label "Save"))
+        (exit (make <gtk-button> #:label "Exit"))
         (next (make <gtk-button> #:label "Next"))
         (prev (make <gtk-button> #:label "Previous"))
         (vbox (make <gtk-vbox> #:homogeneous #f))
     ;;(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
 
 (define-method (tweak (go <gnome-outputter>) 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)))))
 
 (define-method (save-tweaks (go <gnome-outputter>))
   (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)