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>
{
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);
--- /dev/null
+/*
+ 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 */
+
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). */
}
-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;
void
Paper_outputter::close ()
{
- scm_close_port (file_);
+ if (scm_port_p (file_) == SCM_BOOL_T)
+ scm_close_port (file_);
}
--- /dev/null
+/*
+ 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;
+}
(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)))))