]> git.donarmstrong.com Git - lilypond.git/commitdiff
(apply_tweaks): new function. Run tweaks on all
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 14 Nov 2004 23:38:21 +0000 (23:38 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 14 Nov 2004 23:38:21 +0000 (23:38 +0000)
grobs that have tweaks specced.

14 files changed:
ChangeLog
lily/include/lily-proto.hh
lily/include/tweak-registration.hh
lily/lilypond-key.cc
lily/main.cc
lily/object-key-dumper.cc
lily/object-key-undumper.cc
lily/object-key.cc
lily/spring-smob.cc
lily/system.cc
lily/tweak-registration.cc
scm/framework-gnome.scm
scm/lily-library.scm
scm/lily.scm

index b3e861d6c9707ef6582a3cc79c308bdafa219c3c..696b17ab39d418fa243ec6fec445ce7bb4be138d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-11-15  Han-Wen Nienhuys  <hanwen@xs4all.nl>
+
+       * lily/system.cc (apply_tweaks): new function. Run tweaks on all
+       grobs that have tweaks specced.
+       
 2004-11-14  Heikki Junes  <hjunes@cc.hut.fi>
 
        * Documentation/user/sound-output.itexi: add code snippets for MIDI.
index 51598d8815ed82f19c5305c7f6501d8f44128611..778dbf01bf809dcd9c178a45b991bae0a86f61a9 100644 (file)
@@ -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;
index 0191c2fba65460b76afea6f1230f8d95e4cf2532..61aab26f704dad1a601cf25251b191147566edb6 100644 (file)
@@ -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 */
index 08b12298dc6cf6e28daa2700ceea0acf7616ae7e..6dc69be030f790aea8ab6c7aa0c912048304a86e 100644 (file)
@@ -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))));
 }
 
 
index 25e7e68e9bd8868934bff5c8e29cc580914f7f23..a80e00e0df2384ba24da4b69474d3e3d3f347e1c 100644 (file)
@@ -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 ());
 
index 7fcbfcdc90d109fc6556dbb0f0d1ee227666e142..547707bab4fe58f2283c120ea63a5568872dad86 100644 (file)
@@ -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
index 429d9ab2bcb9a524a79a8986f498affb8f08d31f..bf0f32f993388d60bb4e320201ec95c7468c6eb7 100644 (file)
@@ -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);
        }
index 9a7ae7107bec5a768e088a44c06d16f7616357cb..ae38bfb54cafdf87da971178711497a9f6c523f7 100644 (file)
@@ -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},
 };
 
index e27a72e93db50dcb3e19431b7f2f73bba34bdd1a..e7cc63cc0ac7a422198d00b1b7100417c6d08d2e 100644 (file)
@@ -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 ("#<Spring smob>", p);
   return 1;
index b0d14ffe3186120cd48de25ab728a8e2a5616ba6..d16b5a3b4e85c1134e6e6c422c3d4a20f9c443db 100644 (file)
@@ -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"));
     }
index 7f929b0a1058b3c5f4996bf2de87a2cb89f8f586..501731400eab3041936910ff8154a27d035d9356 100644 (file)
@@ -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;
 }
index 6184b7911e7be6f05b67e75468f7c057d7a2b2a4..b142836ccc7954386aa8995f1407c4aa6e763630 100644 (file)
   (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)
                (ly:input-location music-origin)
                #f)))
 
+
 (define-method (tweak (go <gnome-outputter>) item offset)
   (let* ((grob (hashq-ref (item-grobs go) item #f))
         (extra-offset (ly:grob-property grob 'extra-offset))
                           (- 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 <gnome-outputter>))
   (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)
          
          (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))))
               
index 94852eb3b98abba592f98c80fa08fc135ecace94..9cc606a329947c59ef80ab1a401564b63e7357cd 100644 (file)
@@ -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)))
index c18f1bf3f0eea4303ff0ec4fcca80620de92c262..1fc5afbe898474debb929a2d5402259bd633aa8f 100644 (file)
@@ -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))