lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Patch] make post-event music functions direction-aware (issue3743043)


From: v . villenave
Subject: [Patch] make post-event music functions direction-aware (issue3743043)
Date: Mon, 20 Dec 2010 15:08:33 +0000

Reviewers: Neil Puttock,

Message:
Greetings everybody,

here's a patch that Neil suggested to me (if you remember my earlier
postfix-dynamics patch, you may guess where I'm getting at with this).

Thoughts?

Cheers,
Valentin.

Description:
Add direction-awareness ability to post-event music functions.

Please review this at http://codereview.appspot.com/3743043/

Affected files:
  A input/regression/music-function-post-event.ly
  M lily/parser.yy
  M scm/ly-syntax-constructors.scm


Index: input/regression/music-function-post-event.ly
diff --git a/input/regression/music-function-post-event.ly b/input/regression/music-function-post-event.ly
new file mode 100644
index 0000000000000000000000000000000000000000..eab5d5b758d3163b41464c924daf02281058ea85
--- /dev/null
+++ b/input/regression/music-function-post-event.ly
@@ -0,0 +1,22 @@
+\version "2.13.43"
+
+\header
+{
+
+  texidoc = "Music functions may be attached to notes;
+in this case they must be introduced by a direction
+indicator.  If a non-neutral direction is given (i.e.
+anything else than a dash), then the 'direction property
+of the resulting object is set accordingly."
+
+}
+
+dynScript =
+#(define-music-function (parser location text) (string?)
+   (make-dynamic-script text))
+
+\relative c' {
+  c1-\dynScript "pp"
+  c^\dynScript "fp"
+  c_\dynScript "spz"
+}
\ No newline at end of file
Index: lily/parser.yy
diff --git a/lily/parser.yy b/lily/parser.yy
index 94dacc5d3eebc2491fc96bd34c68eee5b658ece5..240ca8ba41823d5126bdff18692f863528e3db12 100644
--- a/lily/parser.yy
+++ b/lily/parser.yy
@@ -145,7 +145,7 @@ SCM get_next_unique_lyrics_context_id ();

 static Music *make_music_with_input (SCM name, Input where);
 SCM make_music_relative (Pitch start, SCM music, Input loc);
-SCM run_music_function (Lily_parser *, SCM expr);
+SCM run_music_function (Lily_parser *, SCM expr, int dir);
 SCM get_first_context_id (SCM type, Music *m);
 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
 SCM make_chord_step (int step, Rational alter);
@@ -1128,7 +1128,7 @@ optional_id:

 prefix_composite_music:
        generic_prefix_music_scm {
-               $$ = run_music_function (PARSER, $1);
+               $$ = run_music_function (PARSER, $1, 0);
        }
        | CONTEXT simple_string optional_id optional_context_mod music {
                 Context_mod *ctxmod = unsmob_context_mod ($4);
@@ -1575,7 +1575,7 @@ chord_body_element:
                $$ = n->unprotect ();
        }
        | music_function_chord_body {
-               $$ = run_music_function (PARSER, $1);
+               $$ = run_music_function (PARSER, $1, 0);
        }
        ;

@@ -1706,8 +1706,8 @@ post_event:
        direction_less_event {
                $$ = $1;
        }
-       | '-' music_function_event {
-               $$ = run_music_function (PARSER, $2);
+       | script_dir music_function_event {
+               $$ = run_music_function (PARSER, $2, $1);
        }
        | HYPHEN {
                if (!PARSER->lexer_->is_lyric_state ())
@@ -2646,12 +2646,13 @@ get_next_unique_lyrics_context_id ()


 SCM
-run_music_function (Lily_parser *parser, SCM expr)
+run_music_function (Lily_parser *parser, SCM expr, int dir)
 {
        SCM func = scm_car (expr);
        Input *loc = unsmob_input (scm_cadr (expr));
        SCM args = scm_cddr (expr);
SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
+       SCM direction = (dir == 0) ? (SCM SCM_BOOL_F) : (scm_from_int (dir));

        SCM type_check_proc = ly_lily_module_constant ("type-check-list");

@@ -2661,7 +2662,7 @@ run_music_function (Lily_parser *parser, SCM expr)
return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("void-music"), scm_list_2 (parser->self_scm (), make_input (*loc)));
        }

- SCM syntax_args = scm_list_4 (parser->self_scm (), make_input (*loc), func, args); + SCM syntax_args = scm_list_5 (parser->self_scm (), make_input (*loc), func, args, direction); return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
 }

Index: scm/ly-syntax-constructors.scm
diff --git a/scm/ly-syntax-constructors.scm b/scm/ly-syntax-constructors.scm
index c34f5c9dd1dc81864acc7d2f143e7ba0d1e5dc7a..1a051d1f40c89e97317a0801ac1690fe47f53fc0 100644
--- a/scm/ly-syntax-constructors.scm
+++ b/scm/ly-syntax-constructors.scm
@@ -43,10 +43,12 @@
        m)))

 ;; Music function: Apply function and check return value.
-(define-ly-syntax-loc (music-function parser loc fun args)
+(define-ly-syntax-loc (music-function parser loc fun args dir)
   (let ((m (apply fun (cons* parser loc args))))
     (if (ly:music? m)
-       m
+       (begin
+         (if dir (ly:music-set-property! m 'direction dir))
+         m)
        (begin
(ly:parser-error parser (_ "Music head function must return Music object") loc)
          (make-music 'Music)))))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]