]> git.donarmstrong.com Git - lilypond.git/commitdiff
parser.yy et al: Make \relative a music function.
authorDavid Kastrup <dak@gnu.org>
Sat, 24 Sep 2011 21:53:25 +0000 (23:53 +0200)
committerDavid Kastrup <dak@gnu.org>
Sat, 24 Sep 2011 22:34:35 +0000 (00:34 +0200)
lily/lily-lexer.cc
lily/music-scheme.cc
lily/parser.yy
ly/music-functions-init.ly

index f80ea67703010594d088202f86e12702d27879c8..6c1336744b3286f6e2f0ca21d13ad8c5d4a508ca 100644 (file)
@@ -75,7 +75,6 @@ static Keyword_ent the_key_tab[]
   {"once", ONCE},
   {"override", OVERRIDE},
   {"paper", PAPER},
-  {"relative", RELATIVE},
   {"remove", REMOVE},
   {"repeat", REPEAT},
   {"rest", REST},
index 89c810a5679df344d5ab41ee8f4f70c2b9dbfd81..34545fa911d33da5293c4c656e2342da1d4ad329 100644 (file)
@@ -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"
index 4714f67326d9595728c8d7fe798483a2f297a19d..b0a584ff91e93fd71465659a7d181c7321093bce 100644 (file)
@@ -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 <scm> post_event
 %type <scm> post_event_nofinger
 %type <scm> re_rhythmed_music
-%type <scm> relative_music
 %type <scm> simple_element
 %type <scm> simple_music_property_def
 %type <scm> start_symbol
@@ -385,7 +382,6 @@ If we give names, Bison complains.
 
 %type <scm> music_function_call
 %type <scm> music_list
-%type <scm> absolute_pitch
 %type <scm> assignment_id
 %type <scm> bare_number
 %type <scm> 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)
 {
index e0b36696bab23c20eefaede5e1c1e634baa87faa..7d80c6b511f4e3b7ae12be007f70d6bc803f4e4c 100644 (file)
@@ -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}.")