From a7c89f9839ec3276ae33d8cfe80ed7beeedc7a50 Mon Sep 17 00:00:00 2001 From: Nicolas Sceaux Date: Sat, 15 May 2004 16:28:11 +0000 Subject: [PATCH] * ly/music-functions-init.ly (def-music-function): new helper macro for defining music functions. \addlyrics \appoggiatura \acciaccatura \grace \partcombine \autochange \applycontext \applyoutput and \breathe are now defined here thanks to it. * lily/parser.yy: * lily/my-lily-lexer.cc: \addlyrics \appoggiatura \acciaccatura \grace \partcombine \autochange \applycontext \applyoutput and \breathe keywords removed from the parser. * lily/parser.yy: * lily/music-function.cc (ly_make_music_function): * lily/lexer.ll (music_function_type): added a case for 0-arg music functions. --- ChangeLog | 17 ++++++ lily/lexer.ll | 4 ++ lily/music-function.cc | 2 +- lily/my-lily-lexer.cc | 9 --- lily/parser.yy | 121 +++---------------------------------- ly/music-functions-init.ly | 69 +++++++++++++++++---- 6 files changed, 85 insertions(+), 137 deletions(-) diff --git a/ChangeLog b/ChangeLog index baf09eb697..41482760cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2004-05-15 Nicolas Sceaux + + * ly/music-functions-init.ly (def-music-function): new helper + macro for defining music functions. \addlyrics \appoggiatura + \acciaccatura \grace \partcombine \autochange \applycontext + \applyoutput and \breathe are now defined here thanks to it. + + * lily/parser.yy: + * lily/my-lily-lexer.cc: \addlyrics \appoggiatura \acciaccatura + \grace \partcombine \autochange \applycontext \applyoutput and + \breathe keywords removed from the parser. + + * lily/parser.yy: + * lily/music-function.cc (ly_make_music_function): + * lily/lexer.ll (music_function_type): added a case for 0-arg + music functions. + 2004-05-14 Nicolas Sceaux * scm/ly-from-scheme.scm (read-lily-expression): A variable diff --git a/lily/lexer.ll b/lily/lexer.ll index 5e2e7d99f0..b8a502edc1 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -917,6 +917,10 @@ music_function_type (SCM func) { return MUSIC_FUNCTION_SCM_SCM_MUSIC; } + else if (type == ly_symbol2scm ("noarg")) + { + return MUSIC_FUNCTION; + } else { /* TODO: print location */ diff --git a/lily/music-function.cc b/lily/music-function.cc index ed7e3fa4e6..6e3c5ac93e 100644 --- a/lily/music-function.cc +++ b/lily/music-function.cc @@ -45,7 +45,7 @@ LY_DEFINE (ly_make_music_function, "ly:make-music-function", 2, 0, 0, else if (ly_c_procedure_p (ly_car (s))) str += "scm"; } - + if (str == "") str = "noarg"; scm_set_object_property_x (func, ly_symbol2scm ("music-function-signature"), signature); diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index f7a8eabae9..5acae67b8b 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -25,19 +25,12 @@ static Keyword_ent the_key_tab[] = { - {"acciaccatura", ACCIACCATURA}, {"accepts", ACCEPTS}, - {"addlyrics", ADDLYRICS}, {"addquote", ADDQUOTE}, {"alias", ALIAS}, {"alternative", ALTERNATIVE}, - {"applycontext", APPLYCONTEXT}, - {"applyoutput", APPLYOUTPUT}, - {"appoggiatura", APPOGGIATURA}, - {"autochange", AUTOCHANGE}, {"bar", BAR}, {"book", BOOK}, - {"breathe", BREATHE}, {"change", CHANGE}, {"chords", CHORDS}, {"clef", CLEF}, @@ -49,7 +42,6 @@ static Keyword_ent the_key_tab[] = { {"drums", DRUMS}, {"description", DESCRIPTION}, {"figures",FIGURES}, - {"grace", GRACE}, {"grobdescriptions", GROBDESCRIPTIONS}, {"header", HEADER}, {"key", KEY}, @@ -66,7 +58,6 @@ static Keyword_ent the_key_tab[] = { {"once", ONCE}, {"override", OVERRIDE}, {"paper", PAPER}, - {"partcombine", PARTCOMBINE}, {"partial", PARTIAL}, {"quote", QUOTE}, {"relative", RELATIVE}, diff --git a/lily/parser.yy b/lily/parser.yy index 781cde635e..89a1a02973 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -242,17 +242,12 @@ or %pure_parser %token ACCEPTS -%token ADDLYRICS %token ADDQUOTE %token LYRICSTO %token ALIAS %token ALTERNATIVE -%token APPLYCONTEXT -%token APPLYOUTPUT -%token AUTOCHANGE %token BAR %token BOOK -%token BREATHE %token CHANGE %token CHORDMODIFIERS %token CHORDS @@ -269,9 +264,6 @@ or %token EXTENDER %token FIGURES FIGURE_OPEN FIGURE_CLOSE %token FIGURE_BRACKET_CLOSE FIGURE_BRACKET_OPEN -%token GRACE -%token ACCIACCATURA -%token APPOGGIATURA %token GROBDESCRIPTIONS %token HEADER %token HYPHEN @@ -289,7 +281,6 @@ or %token ONCE %token OVERRIDE SET REVERT %token PAPER -%token PARTCOMBINE %token PARTIAL %token QUOTE %token RELATIVE @@ -358,6 +349,7 @@ or %token MARKUP_HEAD_SCM0_SCM1_SCM2 %token MARKUP_HEAD_SCM0_SCM1_MARKUP2 +%token MUSIC_FUNCTION %token MUSIC_FUNCTION_SCM %token MUSIC_FUNCTION_MUSIC %token MUSIC_FUNCTION_SCM_MUSIC @@ -371,7 +363,6 @@ or %type book_block book_body %type exclamations questions dots optional_rest %type bass_mod -%type grace_head %type oct_check %type context_mod_list %type lyric_element @@ -911,20 +902,6 @@ Simultaneous_music: Simple_music: event_chord { $$ = $1; } - | APPLYOUTPUT embedded_scm { - if (!ly_input_procedure_p ($2)) - THIS->parser_error (_ ("\\applycontext takes function argument")); - $$ = MY_MAKE_MUSIC ("ApplyOutputEvent"); - $$->set_property ("procedure", $2); - $$->set_spot (THIS->here_input ()); - } - | APPLYCONTEXT embedded_scm { - if (!ly_input_procedure_p ($2)) - THIS->parser_error (_ ("\\applycontext takes function argument")); - $$ = MY_MAKE_MUSIC ("ApplyContext"); - $$->set_property ("procedure", $2); - $$->set_spot (THIS->here_input ()); - } | MUSIC_IDENTIFIER { $$ = unsmob_music ($1); } @@ -943,12 +920,6 @@ optional_context_mod: } ; -grace_head: - GRACE { $$ = scm_makfrom0str ("Grace"); } - | ACCIACCATURA { $$ = scm_makfrom0str ("Acciaccatura"); } - | APPOGGIATURA { $$ = scm_makfrom0str ("Appoggiatura"); } - ; - context_mod_list: /* */ { $$ = SCM_EOL; } | context_mod_list context_mod { @@ -968,7 +939,10 @@ Grouped_music_list: ; Generic_prefix_music_scm: - MUSIC_FUNCTION_SCM { + MUSIC_FUNCTION { + $$ = scm_list_2 ($1, make_input (THIS->here_input ())); + } + | MUSIC_FUNCTION_SCM { THIS->push_spot (); } embedded_scm { $$ = scm_list_3 ($1, make_input (THIS->pop_spot ()), $3); @@ -1044,76 +1018,6 @@ Prefix_composite_music: Generic_prefix_music { $$ = $1; } - |AUTOCHANGE Music { - SCM proc = ly_scheme_function ("make-autochange-music"); - - SCM res = scm_call_1 (proc, $2->self_scm ()); - scm_gc_unprotect_object ($2->self_scm ()); - $$ = unsmob_music (res); - scm_gc_protect_object (res); - $$->set_spot (THIS->here_input ()); - } - | PARTCOMBINE Music Music { - SCM proc = ly_scheme_function ("make-part-combine-music"); - - SCM res = scm_call_1 (proc, scm_listify ($2->self_scm (), - $3->self_scm (), SCM_UNDEFINED)); - scm_gc_unprotect_object ($3->self_scm ()); - scm_gc_unprotect_object ($2->self_scm ()); - $$ = unsmob_music (res); - scm_gc_protect_object (res); - $$->set_spot (THIS->here_input ()); - } - | grace_head Music { -#if 1 - /* - The other version is for easier debugging of - Sequential_music_iterator in combination with grace notes. - */ - -/* - -TODO: should distinguish between both grace types in the -basic music objects too, since the meaning is different. - -*/ - - String start_str = "start" + ly_scm2string ($1) + "Music"; - String stop_str = "stop" + ly_scm2string ($1) + "Music"; - - SCM start = THIS->lexer_->lookup_identifier (start_str); - SCM stop = THIS->lexer_->lookup_identifier (stop_str); - - Music *startm = unsmob_music (start); - Music *stopm = unsmob_music (stop); - - SCM ms = SCM_EOL; - if (stopm) { - stopm = stopm->clone (); - ms = scm_cons (stopm->self_scm (), ms); - scm_gc_unprotect_object (stopm->self_scm ()); - } - ms = scm_cons ($2->self_scm (), ms); - scm_gc_unprotect_object ($2->self_scm ()); - if (startm) { - startm = startm->clone (); - ms = scm_cons (startm->self_scm (), ms); - scm_gc_unprotect_object (startm->self_scm ()); - } - - Music* seq = MY_MAKE_MUSIC ("SequentialMusic"); - seq->set_property ("elements", ms); - - - $$ = MY_MAKE_MUSIC ("GraceMusic"); - $$->set_property ("element", seq->self_scm ()); - scm_gc_unprotect_object (seq->self_scm ()); -#else - $$ = MY_MAKE_MUSIC ("GraceMusic"); - $$->set_property ("element", $2->self_scm ()); - scm_gc_unprotect_object ($2->self_scm ()); -#endif - } | CONTEXT simple_string '=' simple_string optional_context_mod Music { $$ = context_spec_music ($2, $4, $6, $5); @@ -1268,15 +1172,7 @@ new_lyrics: ; re_rhythmed_music: - ADDLYRICS Music Music { - Music *m = MY_MAKE_MUSIC ("LyricCombineMusic"); - m->set_property ("elements", scm_listify ($2->self_scm (), - $3->self_scm (), SCM_UNDEFINED)); - scm_gc_unprotect_object ($3->self_scm ()); - scm_gc_unprotect_object ($2->self_scm ()); - $$ = m; - } - | Grouped_music_list new_lyrics { + Grouped_music_list new_lyrics { /* FIXME: should find out uniqueXXX name from music */ SCM name = $1->get_property ("context-id"); @@ -1695,10 +1591,7 @@ command_element: ; command_req: - BREATHE { - $$ = MY_MAKE_MUSIC ("BreathingSignEvent"); - } - | E_TILDE { + E_TILDE { $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent"); } | MARK DEFAULT { diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 7eeae8d54c..1d34fca85a 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -1,11 +1,62 @@ -applymusic = #(ly:make-music-function - (list procedure? ly:music?) ; signature - (lambda (where func music) ; the function - (func music))) +\version "2.3.2" -\version "2.3.1" +#(defmacro-public def-music-function (args signature . body) + "Helper macro for `ly:make-music-function'. +Syntax: + (def-music-function (location arg1 arg2 ...) (arg1-type? arg2-type? ...) + ...function body...) +" + `(ly:make-music-function (list ,@signature) + (lambda (,@args) + ,@body))) +applymusic = #(def-music-function (location func music) (procedure? ly:music?) + (func music)) +addlyrics = #(def-music-function (location music lyrics) (ly:music? ly:music?) + (make-music 'LyricCombineMusic 'elements (list music lyrics))) + +#(use-modules (srfi srfi-1)) +#(define-public (symbol-or-symbols? obj) + "Return #t iif obj is a symbol or a symbol list." + (or (symbol? obj) + (and (list? obj) + (null? (remove symbol? obj))))) + +%{ +%% \mytag #'foo { ... } ==> OK +%% c-\mytag #'foo ^4 ==> KO +mytag = #(def-music-function (location tagname music) (symbol-or-symbols? ly:music?) + (set! (ly:music-property music 'tags) + ((if (list? tagname) append cons) tagname (ly:music-property music 'tags))) + music) +%} + +#(defmacro def-grace-function (start stop) + `(def-music-function (location music) (ly:music?) + (make-music 'GraceMusic + 'element (make-music 'SequentialMusic + 'elements (list (ly:music-deep-copy ,start) + music + (ly:music-deep-copy ,stop)))))) +grace = #(def-grace-function startGraceMusic stopGraceMusic) +acciaccatura = #(def-grace-function startAcciaccaturaMusic stopAcciaccaturaMusic) +appoggiatura = #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic) + +partcombine = #(def-music-function (location part1 part2) (ly:music? ly:music?) + (make-part-combine-music (list part1 part2))) + +autochange = #(def-music-function (location music) (ly:music?) + (make-autochange-music music)) + +applycontext = #(def-music-function (location proc) (procedure?) + (make-music 'ApplyContext 'procedure proc)) + +applyoutput = #(def-music-function (location proc) (procedure?) + (make-music 'ApplyOutputEvent 'procedure proc)) + +breathe = #(def-music-function (location) () + (make-music 'EventChord 'elements (list (make-music 'BreathingSignEvent)))) %{ @@ -13,15 +64,7 @@ TODO: remove these from the parser, and softcode here: - * \addlyrics * \tag - * \appoggiatura, \acciaccatura, \grace - * \partcombine - * \autochange - * \applycontext - * \applyoutput - * \breathe - with small syntax changes, we could also do -- 2.39.5