]> git.donarmstrong.com Git - lilypond.git/commitdiff
*** empty log message ***
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 14 Nov 2004 17:17:16 +0000 (17:17 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 14 Nov 2004 17:17:16 +0000 (17:17 +0000)
ChangeLog
lily/include/object-key-undumper.hh
lily/include/tweak-registration.hh [new file with mode: 0644]
lily/lily-parser.cc
lily/object-key-undumper.cc
lily/paper-outputter.cc
lily/tweak-registration.cc [new file with mode: 0644]
scm/framework-gnome.scm

index b71ab97d764d65bca351fea880e021eb8b720437..12413b86a5383285a845093c4182a6636a16e063 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,13 @@
 
 2004-11-14  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
+       * lily/include/tweak-registration.hh: new file.
+
+       * lily/tweak-registration.cc: new file.
+
+       * scm/framework-gnome.scm (save-tweaks): use new key mechanism for
+       saving tweaks.
+
        * scm/output-gnome.scm (text): comment dribble.
 
 2004-11-14  Jan Nieuwenhuizen  <janneke@gnu.org>
index 8c516cad76e2249406bf27b8f738cdeb5fde4403..d99041a89e8efef32dd02d0ca95b3cc5946b6493 100644 (file)
@@ -19,9 +19,9 @@ struct Object_key_undumper
 {
   DECLARE_SMOBS(Object_key_undumper,);
   Int_to_key_map keys_;
-  void parse_contents (SCM);
 public:
-  Object_key_undumper (SCM s);
+  void parse_contents (SCM);
+  Object_key_undumper ();
   Object_key const *get_key (int k);
 };
 DECLARE_UNSMOB(Object_key_undumper, key_undumper);
diff --git a/lily/include/tweak-registration.hh b/lily/include/tweak-registration.hh
new file mode 100644 (file)
index 0000000..0191c2f
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+  tweak-registration.hh -- declare
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+#ifndef TWEAK_REGISTRATION_HH
+#define TWEAK_REGISTRATION_HH
+
+#include  <map>
+
+#include "lily-proto.hh"
+#include "smobs.hh"
+#include "lily-guile.hh"
+
+typedef std::map<Object_key const*, SCM, Object_key_less> Tweak_map ;
+
+class Tweak_registry
+{
+  Tweak_map tweaks_;
+  Object_key_undumper *undumper_;
+
+  DECLARE_SMOBS(Tweak_registry,);
+  
+public:
+  Object_key_undumper *undumper() const;
+  void clear ();
+  void insert_tweak (SCM);
+  SCM get_tweaks (Grob *);
+  SCM list_tweaks ();
+  Tweak_registry ();
+};
+
+DECLARE_UNSMOB(Tweak_registry, tweak_registry);
+
+#endif /* TWEAK_REGISTRATION_HH */
+
index 566d789e07512db265616c8c64f895c2cb71a70e..1f031bcce83ce8ee1e10bea3c8ac6d8c758f5786 100644 (file)
@@ -105,19 +105,10 @@ Lily_parser::parse_file (String init, String name, String out_name)
 
   lexer_->new_input (init, sources_);
 
-#ifdef TWEAK
   File_name f (name);
   String s = global_path.find (f.base_ + ".twy");
-  if (1 || 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);
-    }
-  Context_selector::set_tweaks (SCM_EOL);
-#endif  
+  s = gulp_file_to_string (s, false);
+  scm_eval_string (scm_makfrom0str (s.to_str0 ()));
 
   /* Read .ly IN_FILE, lex, parse, write \score blocks from IN_FILE to
      OUT_FILE (unless IN_FILE redefines output file name).  */
index 01ac9b4e89a5f70de31549ef82824ec003158447..429d9ab2bcb9a524a79a8986f498affb8f08d31f 100644 (file)
@@ -40,20 +40,32 @@ Object_key_undumper::print_smob (SCM s, SCM port, scm_print_state*)
 }
 
 
-Object_key_undumper::Object_key_undumper (SCM s)
+Object_key_undumper::Object_key_undumper ()
 {
   smobify_self();
-  parse_contents (s);
 }
 
 
+LY_DEFINE(ly_undumper_read_keys, "ly:undumper-read-keys",
+         2,0,0,
+         (SCM undumper, SCM keys),
+         "Read serialized @var{keys} into @var{undumper}."
+         )
+{
+  Object_key_undumper *u = unsmob_key_undumper (undumper);
+  SCM_ASSERT_TYPE(u, undumper, SCM_ARG1, __FUNCTION__, "Undumper");
+
+  u->parse_contents (keys);
+  return SCM_UNSPECIFIED;
+}
+
 LY_DEFINE(ly_make_undumper, "ly:make-undumper",
-         1,0,0,
-         (SCM contents),
-         "Create a key undumper for @var{contents}. "
+         0, 0,0,
+         (),
+         "Create a key undumper. "
          )
 {
-  Object_key_undumper *u = new Object_key_undumper (contents);
+  Object_key_undumper *u = new Object_key_undumper ();
   SCM x = u->self_scm();
   scm_gc_unprotect_object (x);
   return x;
index 0a28aa242eceb5cbb1afca6ba81c8d463006999c..0471b7a180f34741dc8ef99ea5d0088d6096fd39 100644 (file)
@@ -146,5 +146,6 @@ LY_DEFINE (ly_outputter_dump_string, "ly:outputter-dump-string",
 void
 Paper_outputter::close ()
 {
-  scm_close_port (file_);
+  if (scm_port_p (file_) == SCM_BOOL_T)
+    scm_close_port (file_);
 }
diff --git a/lily/tweak-registration.cc b/lily/tweak-registration.cc
new file mode 100644 (file)
index 0000000..ae84829
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+  tweak-registration.cc --  implement Tweak_registry
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+
+#include "object-key-undumper.hh"
+#include "tweak-registration.hh"
+#include "object-key.hh"
+#include "grob.hh"
+
+#include "ly-smobs.icc"
+
+
+void
+Tweak_registry::clear ()
+{
+  tweaks_.clear ();
+  undumper_ = new Object_key_undumper();
+  scm_gc_unprotect_object (undumper_->self_scm ());
+}
+
+void
+Tweak_registry::insert_tweak (SCM tweak)
+{
+  SCM skey = scm_car (tweak);
+
+  assert(scm_is_pair (skey) &&
+        scm_car (skey) == ly_symbol2scm ("key"));
+
+  Object_key const * key =  undumper_->get_key (scm_to_int (scm_cadr (skey)));
+  if (tweaks_.find (key) == tweaks_.end())
+    {
+      tweaks_[key] = SCM_EOL;
+    }
+
+  tweaks_[key] = scm_cons (scm_cdr (tweak), tweaks_[key]);
+}
+
+SCM
+Tweak_registry::get_tweaks (Grob *g) 
+{
+  Object_key const *key = g->get_key();
+  if (tweaks_.find (key) == tweaks_.end())
+    {
+      return SCM_EOL;
+    }
+  return tweaks_[key];
+}
+
+Tweak_registry::Tweak_registry ()
+{
+  undumper_ = 0;
+  smobify_self();
+  undumper_ = new Object_key_undumper();
+  scm_gc_unprotect_object (undumper_->self_scm ());
+}
+
+Tweak_registry::~Tweak_registry ()
+{
+}
+
+SCM
+Tweak_registry::list_tweaks ()
+{
+  SCM retval = SCM_EOL;
+  for (Tweak_map::const_iterator i (tweaks_.begin ());
+       i != tweaks_.end();
+       i++)
+    {
+      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));
+       }
+    }
+
+  return retval;
+}
+
+SCM
+Tweak_registry::mark_smob (SCM smob)
+{
+  Tweak_registry *me = (Tweak_registry*) SCM_CELL_WORD_1(smob);
+
+  for (Tweak_map::const_iterator i (me->tweaks_.begin ());
+       i != me->tweaks_.end();
+       i++)
+    {
+      scm_gc_mark ((*i).first->self_scm());
+      scm_gc_mark ((*i).second);
+    }
+
+  return me->undumper_ ? me->undumper_->self_scm() : SCM_EOL;
+}
+
+
+int
+Tweak_registry::print_smob (SCM smob, SCM port, scm_print_state*)
+{
+  scm_puts ("#<Tweak_registry>", port); 
+  return 1;
+}
+
+Object_key_undumper*
+Tweak_registry::undumper () const
+{
+  return undumper_;
+}
+
+IMPLEMENT_DEFAULT_EQUAL_P(Tweak_registry);
+IMPLEMENT_SMOBS(Tweak_registry);
+
+
+Tweak_registry  * global_registry_;
+
+void
+init_global_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",
+         0,0,0,(),
+         "Clear global tweak registry"
+         )
+{
+  global_registry_->clear ();
+  return SCM_UNSPECIFIED;
+}
+
+
+LY_DEFINE(ly_tweak_read_keys, "ly:tweak-read-keys",
+         1,0,0,(SCM keys),
+         "Read keys"
+         )
+{
+  global_registry_->undumper ()->parse_contents (keys); 
+  return SCM_UNSPECIFIED;
+}
+
+LY_DEFINE(ly_tweak_read_tweaks, "ly:tweak-read-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));
+    }
+  return SCM_UNSPECIFIED;
+}
index 37cf4bcb5572355cc4e865cf86b0a1eb8d13f2c3..f2c6495d80ff40bff06304ad51e606eb1abc0b19 100644 (file)
     
     (if (not (null? tweaks))
        (let ((file (open-file (string-append (name go) ".twy") "w")))
-         (format file ";;; KEYS\n`~S\n;;; TWEAKS \n`~S\n"
+         (format file
+                 ";;;tweaks. Generated file. Do not edit. 
+;;; KEYS
+(ly:clear-keys)
+(ly:define-keys `~S)
+;;; TWEAKS \n
+(ly:clear-tweaks)
+(ly:define-tweaks `~S)"
+
                  (ly:dumper-definitions dumper)
                  tweaks)))))