2 music-function.cc -- implement music_function
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "music-function.hh"
13 static scm_t_bits music_function_tag;
15 /* Print a textual represenation of the smob to a given port. */
17 print_music_function (SCM b, SCM port, scm_print_state *)
19 SCM value = SCM_CELL_OBJECT_1 (b);
21 scm_puts ("#<Music function ", port);
22 scm_write (value, port);
25 /* Non-zero means success. */
30 LY_DEFINE (ly_make_music_function, "ly:make-music-function", 2, 0, 0,
31 (SCM signature, SCM func),
32 "Make a function to process music, to be used for the "
33 "parser. @code{func} is the function, and @code{signature} describes "
34 "Its arguments. @code{signature} is a list containing either "
35 "@code{ly:music?} predicates or other type predicates.")
38 for (SCM s = signature; scm_is_pair (s); s = scm_cdr (s))
43 if (scm_car (s) == Music_type_p_proc)
45 else if (scm_car (s) == ly_scheme_function("markup?"))
47 else if (ly_c_procedure_p (scm_car (s)))
50 if (str == "") str = "noarg";
51 scm_set_object_property_x (func, ly_symbol2scm ("music-function-signature"),
54 scm_set_object_property_x (func, ly_symbol2scm ("music-function-signature-keyword"),
55 ly_symbol2scm (str.to_str0 ()));
57 SCM_RETURN_NEWSMOB (music_function_tag, func);
61 is_music_function (SCM music_function)
63 return (SCM_NIMP (music_function) && SCM_CELL_TYPE (music_function) == music_function_tag);
68 get_music_function_transform (SCM music_function)
70 if (!is_music_function (music_function))
73 return SCM_CELL_OBJECT_1 (music_function);
77 init_music_function (void)
79 music_function_tag = scm_make_smob_type ("music-function", 0);
80 scm_set_smob_mark (music_function_tag, scm_markcdr);
81 scm_set_smob_print (music_function_tag, print_music_function);
84 ADD_SCM_INIT_FUNC (music_function_tag, init_music_function);