Hi, opening a new thread. It was quite offtopic in "Emacs integration" http://lilypond.1069038.n5.nabble.com/Emacs-integration-td150015.html
2013/8/31 Thomas Morley <[email protected]>: > 2013/8/31 David Kastrup <[email protected]>: >> Thomas Morley <[email protected]> writes: >> >>> \version "2.17.25" >>> >>> scalesAndTriads = >>> #(define-music-function (parser location m music)(ly:music? ly:music?) >>> (let* ((elts (ly:music-property m 'elements)) >>> (pitches (map (lambda (x) (ly:music-property x 'pitch)) elts)) >>> (pitch-octaves (map (lambda (x) (ly:pitch-octave x)) pitches)) >> >> (pitch-octaves (map ly:pitch-octave pitches)) >> >>> (pitch-notename (map (lambda (x) (ly:pitch-notename x)) pitches)) >> >> (pitch-notename (map ly:pitch-notename pitches)) >> >>> (pitch-alteration (map (lambda (x) (ly:pitch-alteration x)) >>> pitches))) >> >> guess... lol >> >>> #{ >>> $(make-simultaneous-music >>> (map >>> (lambda (octave note alter) >>> #{ >>> \new Staff >>> \transpose c $(ly:make-pitch octave note alter) >>> \relative $music >>> #}) >>> pitch-octaves pitch-notename pitch-alteration)) >>> #})) >> >> What's the point of picking the pitches apart into octave/note/alter and >> then assembling them into a pitch again without change? Why not map >> over the pitches directly in the first place? Silly me. >> >>> } >>> >>> \scalesAndTriads { c f bes ees aes des ges g d a e b fis } \scale >>> >>> >>> >>> Franky, it took me more than two minutes, although I recycled some old >>> code for tranposing sequential music, but less than 30 min. >>> >>> _And_ I now have two functions to reuse again and again: One for >>> sequential and another for simultaneous music. >> >> Why use two? Just do (music-clone m 'origin location 'elements (map ... I didn't know 'music-clone'. A quick search in the archives resulted in _one_ other result. http://lilypond.1069038.n5.nabble.com/Defining-pitches-in-variables-td142862.html#a142864 :) Although I didn't use it in the code below, I'm quite happy, that I learn something new eyery time you have a look on my functions! >> And then you use either >> \scalesAndTriads { c f bes ees aes des ges g d a e b fis } >> or >> \scalesAndTriads << c f bes ees aes des ges g d a e b fis >> >> >> I'd not use \relative $music here: that looks like asking for trouble. Not sure what you suspect. May I ask for some details? >> If people want \relative music, they should spell it out. >> >> -- >> David Kastrup >> >> >> _______________________________________________ >> lilypond-user mailing list >> [email protected] >> https://lists.gnu.org/mailman/listinfo/lilypond-user > > Hi David, > > thanks for the hints. Will see how I manage to integrate them. > > -Harm I now come up with: \version "2.17.25" multipleTranspose = #(define-music-function (parser location m music)(ly:music? ly:music?) (let* ((elts (ly:music-property m 'elements)) (pitches (map (lambda (x) (ly:music-property x 'pitch)) elts)) (transposed-music-list (map (lambda (pitch) #{ \transpose c $pitch $music #}) pitches))) #{ $(cond ((music-is-of-type? m 'sequential-music) (make-sequential-music transposed-music-list)) ((music-is-of-type? m 'simultaneous-music) (make-simultaneous-music (map (lambda (el) #{ \new Staff $el #}) transposed-music-list))) ;; Not sure whether there's need for, ;; though, better be a paranoiac. (else (ly:error "m should be sequential or simultaneous-music. Typo?"))) #})) %% Examples \new Staff \multipleTranspose { c cis } \relative c'' { g a } \new StaffGroup \multipleTranspose << c cis >> \relative c'' { g a } Thanks, Harm _______________________________________________ lilypond-user mailing list [email protected] https://lists.gnu.org/mailman/listinfo/lilypond-user
