I see that there are basically two ways to make notes (music) from within
a Scheme block. As far as I can tell, one way is powerful but cumbersome,
and the other way is simple but not very powerful. I'm hoping maybe
there's a third way that I haven't discovered yet, or that the second way
is more powerful than I know.
Here's an example of the first way:
(from http://lsr.dsi.unimi.it/LSR/Item?id=122 )
%%%%%%%%%%%%%%%%% FIRST WAY: %%%%%%%%%%%%%%%%%%%%%%
#(define (make-note-req p d)
(make-music 'NoteEvent
'duration d
'pitch p))
#(define (make-note elts)
(make-music 'EventChord
'elements elts))
#(define (seq-music-list elts)
(make-music 'SequentialMusic
'elements elts))
fooMusic = #(seq-music-list
(list (make-note (list (make-note-req (ly:make-pitch 1 0 0)
(ly:make-duration 2 0))))
(make-note (list (make-note-req (ly:make-pitch 1 1 0)
(ly:make-duration 2 0))))))
\score { \fooMusic
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
(This is actually a simplification of the full Scheme code. It works, but
the (make-note) block is still still a lot to type for each note.)
Here's an example of the second way, based on chapter 12.1.1 in the
documentation:
%%%%%%%%%%%%%%%% SECOND WAY: %%%%%%%%%%%%%%%%%%%%
function =
#(define-music-function (parser location string1 string2 firstnote)
(string? string? ly:music?)
#{
$firstnote d'_\markup { $string1 $string2 }
#})
\score { \function #"foo" #"bar" c'4
\layout { ragged-right = ##t }
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
What the second way is missing (or I haven't figured out how to use it) is
the ability to choose pitches, durations, etc. using Scheme code. As far
as I can tell, they must be manually typed within the #{ #} block (e.g.
"d'") or provided as an argument to the music-function (e.g. "c'4"); they
can't be generated from Scheme code, without resorting to the long and
cumbersome (make-music) block demonstrated in way one.
Am I wrong? Is there a way to, for example, define a "ly:music" variable
in Scheme, or convert a "string" variable to a "ly:music" variable, and
then use that "ly:music" variable either within a the #{ #} block of a
music function, or within the main \score block? And if so, is this
documented somewhere?
Below is an example of the closest I've come to maybe figuring this out,
but I'd appreciate any help.
Marcus
%%%%%%%%%%%%%%%% Perhaps I'm getting warm here: %%%%%%%%%%%%%%%%%%
\version "2.9.23"
thirdnote = { e' }
SomehowThisIdentifierMakesTheNextLineErrorFree = #(ly:export thirdnote)
#(define fourthnote thirdnote)
% This next line doesn't cause an error, but it doesn't seem to do
anything either:
#(define fifthnote (ly:export #{ g' #}))
function =
#(define-music-function (parser location string1 string2 firstnote)
(string? string? ly:music?)
#{
$firstnote d'_\markup { $string1 $string2 } $thirdnote $fourthnote
$fifthnote
#})
\score { \function #"foo" #"bar" c'4
\layout { ragged-right = ##t }
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user