[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: String concatenation in sheme?
From: |
Rick Hansen (aka RickH) |
Subject: |
Re: String concatenation in sheme? |
Date: |
Wed, 15 Nov 2006 15:24:18 -0800 (PST) |
Nicolas Sceaux wrote:
>
>
> What you want is not string concatenation. { a4 b c d } is a music
> expression, not a string, so look how it is stored internally:
>
> \displayMusic { a b c d | }
> \displayMusic { e f g a | }
> \displayMusic { a b c d | e f g a | }
>
> You'll see a SequenceMusic element, containing a list of EventChord and
> BarChack elements in its 'elements property. So what you'd like is
> appending two lists. But there is another, easier, solution. Compare:
>
> \displayMusic { a b c d | }
> \displayMusic { e f g a | }
> \displayMusic { { a b c d | } { e f g a | } }
>
> (the latter being equivalent to { a4 b c d | e f g a | })
>
> There, you build a SequentialMusic object which elements are the
> previous value of the variable, and the music that is to be appended. A
> possible implementation (not tested):
>
> appendToVariable =
> #(define-music-function (parser location symbol music)
> (symbol? ly:music?)
> (ly:parser-define! parser symbol
> (make-music 'SequentialMusic
> 'elements (list (ly:parser-lookup parser symbol)
> music)))
> (make-music 'SequentialMusic 'void #t))
>
> myvar = { a4 b c d | }
> \appendToVariable #'myvar { e f g a | }
>
> { \myvar }
>
> nicolas
>
>
>
Nicolas,
I cant thank you enough, this works perfectly! I'm not quite sure where I'm
headed yet, but I may use either this technique in lilipond or the
"divert('1')" / "undivert('1')" functions of m4 to accumulate and
concatenate the music to different staff types.
Basically I want a macro that allows me to state chords in a progression,
whereby each macro invocation will generate the appropriate notes on 3
different staffs for each chord ChordName, FretBoards, and Staff (the notes
needed on each will be different inversions of the same harmony). To save
me the time of hand-coding 3 staffs separately I want my macro to simply
concatenate to the 3 staffs at once with each chord I name. At the end the
3 staff variables will be in-synch and all populated with my desired chord
progression, whereas I only have to physically maintain one list of chords,
(one list coded, generates 3 or more staffs outputted as lp source code).
IOW I'm trying to build a chord library that can output various inversions
of the same chord to multiple staffs at once, the library will grow over
time and be reused.
Still deciding if each chord entry in the library is going to be an m4 macro
or lp function, but now I know I can go either way with the ability to
concatenate my music in lp.
thanks
Rick
--
View this message in context:
http://www.nabble.com/String-concatenation-in-sheme--tf2638911.html#a7368612
Sent from the Gnu - Lilypond - User mailing list archive at Nabble.com.