From a8aed07c25a2b875b3e6dde590258d04735df868 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 14 Nov 2004 17:17:16 +0000 Subject: [PATCH] *** empty log message *** --- ChangeLog | 7 ++ lily/include/object-key-undumper.hh | 4 +- lily/include/tweak-registration.hh | 40 +++++++ lily/lily-parser.cc | 13 +-- lily/object-key-undumper.cc | 24 +++-- lily/paper-outputter.cc | 3 +- lily/tweak-registration.cc | 158 ++++++++++++++++++++++++++++ scm/framework-gnome.scm | 10 +- 8 files changed, 238 insertions(+), 21 deletions(-) create mode 100644 lily/include/tweak-registration.hh create mode 100644 lily/tweak-registration.cc diff --git a/ChangeLog b/ChangeLog index b71ab97d76..12413b86a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,13 @@ 2004-11-14 Han-Wen Nienhuys + * 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 diff --git a/lily/include/object-key-undumper.hh b/lily/include/object-key-undumper.hh index 8c516cad76..d99041a89e 100644 --- a/lily/include/object-key-undumper.hh +++ b/lily/include/object-key-undumper.hh @@ -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 index 0000000000..0191c2fba6 --- /dev/null +++ b/lily/include/tweak-registration.hh @@ -0,0 +1,40 @@ +/* + tweak-registration.hh -- declare + + source file of the GNU LilyPond music typesetter + + (c) 2004 Han-Wen Nienhuys + +*/ + +#ifndef TWEAK_REGISTRATION_HH +#define TWEAK_REGISTRATION_HH + +#include + +#include "lily-proto.hh" +#include "smobs.hh" +#include "lily-guile.hh" + +typedef std::map 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 */ + diff --git a/lily/lily-parser.cc b/lily/lily-parser.cc index 566d789e07..1f031bcce8 100644 --- a/lily/lily-parser.cc +++ b/lily/lily-parser.cc @@ -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). */ diff --git a/lily/object-key-undumper.cc b/lily/object-key-undumper.cc index 01ac9b4e89..429d9ab2bc 100644 --- a/lily/object-key-undumper.cc +++ b/lily/object-key-undumper.cc @@ -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; diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index 0a28aa242e..0471b7a180 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -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 index 0000000000..ae8482941a --- /dev/null +++ b/lily/tweak-registration.cc @@ -0,0 +1,158 @@ +/* + tweak-registration.cc -- implement Tweak_registry + + source file of the GNU LilyPond music typesetter + + (c) 2004 Han-Wen Nienhuys + +*/ + + +#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 ("#", 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; +} diff --git a/scm/framework-gnome.scm b/scm/framework-gnome.scm index 37cf4bcb55..f2c6495d80 100644 --- a/scm/framework-gnome.scm +++ b/scm/framework-gnome.scm @@ -329,7 +329,15 @@ (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))))) -- 2.39.5