From db3e78a1d3ac62dff61e80a3f0ccf60009f535ed Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sat, 24 Sep 2011 23:53:25 +0200 Subject: [PATCH] parser.yy et al: Make \relative a music function. --- lily/lily-lexer.cc | 1 - lily/music-scheme.cc | 19 ++++++++++++++++++ lily/parser.yy | 41 ++------------------------------------ ly/music-functions-init.ly | 8 ++++++++ 4 files changed, 29 insertions(+), 40 deletions(-) diff --git a/lily/lily-lexer.cc b/lily/lily-lexer.cc index f80ea67703..6c1336744b 100644 --- a/lily/lily-lexer.cc +++ b/lily/lily-lexer.cc @@ -75,7 +75,6 @@ static Keyword_ent the_key_tab[] {"once", ONCE}, {"override", OVERRIDE}, {"paper", PAPER}, - {"relative", RELATIVE}, {"remove", REMOVE}, {"repeat", REPEAT}, {"rest", REST}, diff --git a/lily/music-scheme.cc b/lily/music-scheme.cc index 89c810a567..34545fa911 100644 --- a/lily/music-scheme.cc +++ b/lily/music-scheme.cc @@ -20,6 +20,7 @@ #include "music.hh" #include "duration.hh" +#include "program-option.hh" #include "warn.hh" LY_DEFINE (ly_music_length, "ly:music-length", @@ -158,6 +159,24 @@ LY_DEFINE (ly_music_compress, "ly:music-compress", return sc->self_scm (); } +LY_DEFINE (ly_make_music_relative_x, "ly:make-music-relative!", + 2, 0, 0, (SCM music, SCM pitch), + "Make @var{music} relative to @var{pitch}," + " return final pitch.") +{ + LY_ASSERT_TYPE (unsmob_music, music, 1); + LY_ASSERT_TYPE (unsmob_pitch, pitch, 2); + + Pitch start = *unsmob_pitch (pitch); + Music *m = unsmob_music (music); + Pitch last = m->to_relative_octave (start); + if (lily_1_8_relative) + m->set_property ("last-pitch", last.smobbed_copy ()); + + return last.smobbed_copy (); +} + + LY_DEFINE (ly_music_duration_length, "ly:music-duration-length", 1, 0, 0, (SCM mus), "Extract the duration field from @var{mus} and return the" diff --git a/lily/parser.yy b/lily/parser.yy index 4714f67326..b0a584ff91 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -62,6 +62,8 @@ or PITCH_IDENTIFIER NOTENAME_PITCH TONICNAME_PITCH SCM_FUNCTION SCM_IDENTIFIER SCM_TOKEN UNSIGNED DURATION_IDENTIFIER + CHORDMODE CHORDS DRUMMODE DRUMS FIGUREMODE FIGURES LYRICMODE LYRICS + NOTEMODE /* The above are the symbols that can start function arguments */ @@ -107,10 +109,8 @@ using namespace std; #include "main.hh" #include "misc.hh" #include "music.hh" -#include "music.hh" #include "output-def.hh" #include "paper-book.hh" -#include "program-option.hh" #include "scm-hash.hh" #include "score.hh" #include "text-interface.hh" @@ -156,7 +156,6 @@ 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 *parser, Input loc, SCM func, SCM args); SCM check_scheme_arg (Lily_parser *parser, Input loc, SCM fallback, SCM arg, SCM args, SCM pred); @@ -217,7 +216,6 @@ void set_music_properties (Music *p, SCM a); %token ONCE "\\once" %token OVERRIDE "\\override" %token PAPER "\\paper" -%token RELATIVE "\\relative" %token REMOVE "\\remove" %token REPEAT "\\repeat" %token REST "\\rest" @@ -370,7 +368,6 @@ If we give names, Bison complains. %type post_event %type post_event_nofinger %type re_rhythmed_music -%type relative_music %type simple_element %type simple_music_property_def %type start_symbol @@ -385,7 +382,6 @@ If we give names, Bison complains. %type music_function_call %type music_list -%type absolute_pitch %type assignment_id %type bare_number %type unsigned_number @@ -1329,7 +1325,6 @@ complex_music: $$ = MAKE_SYNTAX ("time-scaled-music", @$, $2, $3); } | repeated_music { $$ = $1; } - | relative_music { $$ = $1; } | re_rhythmed_music { $$ = $1; } ; @@ -1417,18 +1412,6 @@ mode_changing_head_with_context: } ; - -relative_music: - RELATIVE absolute_pitch music { - Pitch start = *unsmob_pitch ($2); - $$ = make_music_relative (start, $3, @$); - } - | RELATIVE composite_music { - Pitch middle_c (0, 0, 0); - $$ = make_music_relative (middle_c, $2, @$); - } - ; - new_lyrics: ADDLYRICS { PARSER->lexer_->push_lyric_state (); } /*cont */ @@ -2160,13 +2143,6 @@ script_dir: | '-' { $$ = CENTER; } ; - -absolute_pitch: - pitch { - $$ = $1; - } - ; - duration_length: multiplied_duration { $$ = $1; @@ -3010,19 +2986,6 @@ ly_input_procedure_p (SCM x) || (scm_is_pair (x) && ly_is_procedure (scm_car (x))); } -SCM -make_music_relative (Pitch start, SCM music, Input loc) -{ - Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic", loc); - relative->set_property ("element", music); - - Music *m = unsmob_music (music); - Pitch last = m->to_relative_octave (start); - if (lily_1_8_relative) - m->set_property ("last-pitch", last.smobbed_copy ()); - return relative->unprotect (); -} - int yylex (YYSTYPE *s, YYLTYPE *loc, void *v) { diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index e0b36696ba..7d80c6b511 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -869,6 +869,14 @@ usually contains spacers or multi-measure rests.") 'element main-music 'quoted-music-name what)) +relative = +#(define-music-function (parser location pitch music) + ((ly:pitch? (ly:make-pitch 0 0 0)) ly:music?) + (_i "Make @var{music} relative to @var{pitch} (default @code{c'}).") + (ly:make-music-relative! music pitch) + (make-music 'RelativeOctaveMusic + 'element music)) + removeWithTag = #(define-music-function (parser location tag music) (symbol? ly:music?) (_i "Remove elements of @var{music} that are tagged with @var{tag}.") -- 2.39.5