lilypond-user
[Top][All Lists]
Advanced

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

Re: "smart" transposition of key signatures


From: David Kastrup
Subject: Re: "smart" transposition of key signatures
Date: Wed, 30 Oct 2013 00:35:53 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

David Kastrup <address@hidden> writes:

> Janek Warchoł <address@hidden> writes:
>
>> Also, you may be interested in this:
>> https://github.com/openlilylib/snippets/blob/master/input-shorthands/late-evaluation-of-variables.ly
>
> I can hardly count the number of ways in which this would have blown up
> in 2.14.  I don't consider most uses of eval a good idea anyway, but
> making bad ideas work as expected is still an impressive feat.

Actually, since there is Scheme syntax creeping in anyway, it might make
more sense to use Scheme macros here and have less quoting blurb, and in
particular not the ugly eval:

\version "2.16.2" % absolutely necessary!

\header {
  snippet-title = "Late evaluation of variables"
  snippet-author = "Kristóf Marussy"
  % taken from https://gist.github.com/kris7topher/6038247
  % featured on Lilypond blog (provide reference)9
  snippet-description = \markup {
    “Late-bind” variables using an arity-0 music function that looks up
    values at function call time instead of variable assignment time.
  }
  status = "unfinished"
  % TODO: tell Kristof about the snippet, reorganize description
  % add comma-separated tags to make searching more effective:
  tags = "arity-0, score organization, variable, transposition, lilypond blog"
}

%%%%%%%%%%%%%%%%%%%%%%%%%%
% here goes the snippet: %
%%%%%%%%%%%%%%%%%%%%%%%%%%

beginning = \relative c'' {
  \key as \major
  c1
}

middlesection = \relative gis' {
  \key e \major
  gis1
}

end = \relative c'' {
  \key as \major
  c1
  \bar "|."
}

% ``Late-bind'' variables using an arity-0 music function that looks up values
% at function call time instead of variable assignment time.

#(define-macro (late embedded-lilypond)
  `(define-music-function
   (parser location)
   ()
   ,embedded-lilypond))


music = #(late #{
  \beginning
  \middlesection
  \end
#})

\score {
  % The music without the enharmonic change---complex key signature!
  \new Staff \transpose as g \music
  \layout {}
}

% Apply enharmonic transposition to \middlesection.
middlesection = \transpose e fes \middlesection

\score {
  % Because variables in \music are ``late-bound'', the enharmonic
  % transposition is now respected.
  % The point is that the reassignment of middlesection variable
  % is respected despite the fact that \music was defined earlier!
  \new Staff \transpose as g \music
  \layout {}
}

-- 
David Kastrup

reply via email to

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