From: Han-Wen Nienhuys Date: Tue, 4 May 2004 22:45:15 +0000 (+0000) Subject: * input/regression/music-head.ly (texidoc): new file. X-Git-Tag: release/2.3.1~24 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e0988eeea32b500865c544cf2580e7239f4cea3e;p=lilypond.git * input/regression/music-head.ly (texidoc): new file. * lily/include/music-head.hh (is_music_head): new file. * lily/music-head.cc (get_music_head_transform): new file. --- diff --git a/ChangeLog b/ChangeLog index d51100910f..6fdd422bb1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2004-05-05 Han-Wen Nienhuys + * input/regression/music-head.ly (texidoc): new file. + * lily/parser.yy (Generic_prefix_music): allow generic music-transformation functions. diff --git a/input/regression/music-head.ly b/input/regression/music-head.ly new file mode 100644 index 0000000000..e300c3bd5f --- /dev/null +++ b/input/regression/music-head.ly @@ -0,0 +1,25 @@ +\header +{ +texidoc = "Music heads are generic music transformation functions, +which can be used to extend music syntax seamlessly." + +} +\version "2.3.1" + +#(define myBar + (ly:make-music-head + (lambda (where type) + (context-spec-music + (context-spec-music (make-property-set whichBar type) 'Timing) + 'Score)) + (list string?) + + )) + +\score{ + \notes { + d4 \myBar #"|:" d4 + + } +} + diff --git a/lily/include/music-head.hh b/lily/include/music-head.hh new file mode 100644 index 0000000000..b010c2278b --- /dev/null +++ b/lily/include/music-head.hh @@ -0,0 +1,20 @@ +/* + music-head.hh -- declare Music_head + + source file of the GNU LilyPond music typesetter + + (c) 2004 Han-Wen Nienhuys + +*/ + +#ifndef MUSIC_HEAD_HH +#define MUSIC_HEAD_HH + +#include "lily-guile.hh" + +SCM ly_make_music_head (SCM, SCM); +SCM get_music_head_transform (SCM); +bool is_music_head (SCM); + +#endif /* MUSIC_HEAD_HH */ + diff --git a/lily/include/music.hh b/lily/include/music.hh index 78d1be7bde..902c151b89 100644 --- a/lily/include/music.hh +++ b/lily/include/music.hh @@ -68,7 +68,7 @@ protected: friend SCM ly_extended_make_music(SCM,SCM); }; - +DECLARE_TYPE_P(Music); DECLARE_UNSMOB(Music,music); Music* make_music_by_name (SCM sym); diff --git a/lily/include/smobs.hh b/lily/include/smobs.hh index 0feae768fd..a31ce06e45 100644 --- a/lily/include/smobs.hh +++ b/lily/include/smobs.hh @@ -134,7 +134,7 @@ unsmob_ ## name (SCM s) \ return CL::unsmob (s); \ } - +#define DECLARE_TYPE_P(CL) extern SCM CL_ ## _type_p_proc #endif /* SMOBS_HH */ diff --git a/lily/music-head.cc b/lily/music-head.cc new file mode 100644 index 0000000000..e847b298fd --- /dev/null +++ b/lily/music-head.cc @@ -0,0 +1,94 @@ +/* + music-head.cc -- implement Music_head + + source file of the GNU LilyPond music typesetter + + (c) 2004 Han-Wen Nienhuys + +*/ +#include "music-head.hh" +#include "string.hh" + +/* + C&P from example/box.c + */ + +static scm_t_bits music_head_tag; + +/* Print a textual represenation of the smob to a given port. */ +static int +print_music_head (SCM b, SCM port, scm_print_state *) +{ + SCM value = SCM_CELL_OBJECT_1 (b); + + scm_puts ("#", port); + + /* Non-zero means success. */ + return 1; +} + + +/* This defines the primitve `make-music_head', which returns a new smob of + type `music_head', initialized to `#f'. */ +LY_DEFINE (ly_make_music_head, "ly:make-music-head", 2, 0, 0, + (SCM func, SCM signature), + "Make a function to process music, to be used for the " + "parser. @code{func} is the function, and @code{signature} describes " + "Its arguments. @code{signature} is a list containing either " + "@code{ly:music?} predicates or other type predicates.") +{ + /* This macro creates the new objects, stores the value `#f' into it + and returns it to the caller. */ + String str = ""; + + int k = 0; + for (SCM s = signature; ly_c_pair_p (s); s = ly_cdr (s)) + { + if (str != "") + str += "-"; + + if (ly_car (s) == Music_type_p_proc) + str += "music"; + else if (ly_procedure_p (ly_car (s))) + str += "scm"; + + k++; + } + + scm_set_object_property_x (func, ly_symbol2scm ("music-head-signature"), + signature); + + scm_set_object_property_x (func, ly_symbol2scm ("music-head-signature-keyword"), + ly_symbol2scm (str.to_str0 ())); + + SCM_RETURN_NEWSMOB (music_head_tag, func); +} + +bool +is_music_head (SCM music_head) +{ + return (SCM_NIMP (music_head) && SCM_CELL_TYPE (music_head) == music_head_tag); +} + + +/* This is the primitive `music_head-ref' which returns the object stored in + the music_head. */ +SCM +get_music_head_transform (SCM music_head) +{ + if (!is_music_head (music_head)) + return SCM_UNDEFINED; + + return SCM_CELL_OBJECT_1 (music_head); +} + +static void +init_music_head (void) +{ + music_head_tag = scm_make_smob_type ("music-head", 0); + scm_set_smob_mark (music_head_tag, scm_markcdr); + scm_set_smob_print (music_head_tag, print_music_head); +} +ADD_SCM_INIT_FUNC (music_head_tag, init_music_head);