2005-11-02 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * scm/output-lib.scm (chain-grob-member-functions): replace
+ chained-callback.cc
+
+ * lily/chained-callback.cc (Module): remove file.
+
* lily/rest-collision.cc (force_shift_callback_rest): change to
chained callback.
* lily/include/dimension-cache.hh (class Dimension_cache): remove
callback administration.
- * lily/simple-closure.cc: new file. Smob type that allows "grob"
- member functions
+ * lily/simple-closure.cc: new file. Smob type that allows "grob
+ member functions",
(ly:make-simple-closure FUNC A B)
+++ /dev/null
-/*
- chained-callback.cc -- chained callbacks.
-
- source file of the GNU LilyPond music typesetter
-
- (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
-
-*/
-
-#include "lily-guile.hh"
-
-static scm_t_bits chain_tag;
-
-bool
-is_callback_chain (SCM s)
-{
- return (SCM_NIMP (s) && SCM_CELL_TYPE (s) == chain_tag);
-}
-
-SCM
-callback_chain_extract_procedures (SCM chain_smob)
-{
- assert (is_callback_chain (chain_smob));
- return (SCM) SCM_CELL_WORD_1(chain_smob);
-}
-
-LY_DEFINE(ly_callback_chain_p, "ly:callback-chain?",
- 1,0,0, (SCM chain),
- "Type predicate.")
-{
- return scm_from_bool (is_callback_chain (chain));
-}
-
-LY_DEFINE(ly_make_callback_chain, "ly:make-callback-chain",
- 0, 0, 1, (SCM procedures),
- "Make a grob callback chain. @var{procedures} should be a "
- "list of procedures taking 2 arguments.")
-{
- SCM z;
-
- for (SCM s = procedures;
- scm_is_pair (s); s = scm_cdr (s))
- {
- SCM proc = scm_car (s);
- if (!ly_is_procedure (proc))
- {
- scm_misc_error ("Must be a procedure: ~a",
- "ly:make-callback-chain",
- proc);
- }
-
- if (procedure_arity (proc) != 2)
- {
- scm_misc_error ("Procedure should take 2 arguments: ~a",
- "ly:make-callback-chain",
- proc);
- }
- }
-
- SCM_NEWSMOB(z, chain_tag, procedures);
- return z;
-}
-
-int
-print_callback_chain (SCM s, SCM port, scm_print_state *)
-{
- scm_puts ("#<callback-chain ", port);
- scm_display (scm_cdr (s), port);
- scm_puts (" >", port);
- return 1;
-}
-
-
-void init_chained_callback ()
-{
- chain_tag = scm_make_smob_type ("callback-chain", 0);
- scm_set_smob_mark (chain_tag, scm_markcdr);
- scm_set_smob_print (chain_tag, print_callback_chain);
-};
-
-
-
-ADD_SCM_INIT_FUNC(chain, init_chained_callback);
SCM value = SCM_EOL;
if (ly_is_procedure (proc))
value = scm_call_1 (proc, self_scm ());
- else if (is_callback_chain (proc))
- {
- for (SCM s = callback_chain_extract_procedures (proc);
- scm_is_pair (s); s = scm_cdr (s))
- {
- value = scm_call_2 (scm_car (s), self_scm (), value);
- }
- }
else if (is_simple_closure (proc))
{
value = evaluate_with_simple_closure (self_scm (),
Interval robust_relative_extent (Grob *, Grob *, Axis);
-bool is_callback_chain (SCM s);
-SCM callback_chain_extract_procedures (SCM chain_smob);
-
SCM axis_offset_symbol (Axis a);
SCM axis_self_offset_symbol (Axis a);
return expr;
else if (scm_car (expr) == ly_symbol2scm ("quote"))
return scm_cadr (expr);
- else
+ else if (ly_is_procedure (scm_car (expr)))
{
- return scm_apply_0 (scm_car (expr), evaluate_args (delayed_argument, scm_cdr (expr)));
+ return scm_apply_0 (scm_car (expr),
+ evaluate_args (delayed_argument, scm_cdr (expr)));
}
-
+ else
+ // ugh. deviation from standard. Should print error?
+ return evaluate_args (delayed_argument, scm_cdr (expr));
+
assert (false);
return SCM_EOL;
}
}
LY_DEFINE(ly_make_simple_closure, "ly:make-simple-closure",
- 0, 0, 1, (SCM expr),
+ 1, 0, 0, (SCM expr),
"Make a simple closure. @var{expr} should be form of "
"@code{(@var{func} @var{a1} @var{A2} ...)}, and will be invoked "
"as @code{(@var{func} @var{delayed-arg} @var{a1} @var{a2} ... )}.")
;; todo: clean this up a bit: the list is getting
;; rather long.
(gap . 0.8)
-
- (positions . ,(ly:make-callback-chain
- Beam::calc_least_squares_positions
- Beam::slope_damping
- Beam::shift_region_to_valid
- Beam::quanting
- Beam::set_stem_lengths
- ))
+ (positions . ,(ly:make-simple-closure
+ (ly:make-simple-closure
+ (list chain-grob-member-functions
+ `(,cons 0 0)
+ Beam::calc_least_squares_positions
+ Beam::slope_damping
+ Beam::shift_region_to_valid
+ Beam::quanting
+ Beam::set_stem_lengths
+ ))))
+
(concaveness . ,Beam::calc_concaveness)
(direction . ,Beam::calc_direction)
(stencil . ,Beam::print)
(ly:stencil-translate-axis lp (- (car x-ext) padding) X)
(ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))
))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+
+(define-public (chain-grob-member-functions grob value . funcs)
+ (for-each
+ (lambda (func)
+ (set! value (func grob value)))
+ funcs)
+
+ value)