* 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-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.
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"
}
/* 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
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)));
}
#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)
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++;
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",
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 */
#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 */
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? */
value; \
})
+String gulp_file_to_string (String fn, bool must_exist);
String ly_scm2string (SCM s);
String ly_symbol2string (SCM);
// #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)
{
return scm_strport_to_string (port);
}
-
SCM
ly_quote_scm (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;
"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 ());
+
}
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)
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);
{
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)));
*/
#include "book.hh"
+#include "grob-selector.hh"
#include "file-name.hh"
#include "file-path.hh"
#include "lily-version.hh"
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). */
Moment
robust_scm2moment (SCM m, Moment d)
{
- Moment * p = unsmob_moment (m);
+ Moment *p = unsmob_moment (m);
if (!p)
return d;
else
bool
moment_less (SCM a, SCM b)
{
- return *unsmob_moment (a) < *unsmob_moment (b);
+ return *unsmob_moment (a) < *unsmob_moment (b);
}
(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)