]> git.donarmstrong.com Git - lilypond.git/commitdiff
* ly/music-functions-init.ly (def-music-function): new helper
authorNicolas Sceaux <nicolas.sceaux@free.fr>
Sat, 15 May 2004 16:28:11 +0000 (16:28 +0000)
committerNicolas Sceaux <nicolas.sceaux@free.fr>
Sat, 15 May 2004 16:28:11 +0000 (16:28 +0000)
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
lily/lexer.ll
lily/music-function.cc
lily/my-lily-lexer.cc
lily/parser.yy
ly/music-functions-init.ly

index baf09eb6979abf5d1fd77e1fc55a0c317f62d2ee..41482760cfc4852fefcd8085cbeaf3da4e1478ad 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2004-05-15  Nicolas Sceaux  <nicolas.sceaux@free.fr>
+
+       * 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  <nicolas.sceaux@free.fr>
 
        * scm/ly-from-scheme.scm (read-lily-expression):  A variable
index 5e2e7d99f0a2b4e98a78ebd8d189542a6b2aaeb0..b8a502edc127113667e558202797cd6ebd2ab10a 100644 (file)
@@ -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 */
index ed7e3fa4e6ecf2cf72cdfe8edc696d31fbf7f6a8..6e3c5ac93e3e51ebdb90e3c078be1ddb89426b2a 100644 (file)
@@ -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);
   
index f7a8eabae938e4776499190eba24f49990c06aed..5acae67b8bf6c6b0110d821c7c0d52b72c1115d1 100644 (file)
 
 
 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},
index 781cde635ecb7944b1619f012db624488f160e25..89a1a02973ec43b444a0c0c50c49f9d2a14352f7 100644 (file)
@@ -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 <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
 
+%token <scm> MUSIC_FUNCTION
 %token <scm> MUSIC_FUNCTION_SCM 
 %token <scm> MUSIC_FUNCTION_MUSIC 
 %token <scm> MUSIC_FUNCTION_SCM_MUSIC 
@@ -371,7 +363,6 @@ or
 %type <book>   book_block book_body
 %type <i>      exclamations questions dots optional_rest
 %type <i>      bass_mod
-%type <scm>    grace_head
 %type <scm>    oct_check
 %type <scm>    context_mod_list
 %type <scm>    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  {
index 7eeae8d54c3c21058741659e8607ea2d040e58eb..1d34fca85a2b0216a29c3428b59e379349a07a20 100644 (file)
@@ -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