Thank you Valentin for this solution and the following explanation why it is likely safer.
All responses have been much appreciated. Best, Michael Sep 1, 2023, 00:15 by valen...@petzel.at: > Hi Michael, > > some time ago I created a function for exactly that for a stackexchange > question: > https://music.stackexchange.com/questions/127175/lilypond-transpose-a-sequence-to-modes-with-different-intervallic-structure > > Essentially it introduces a function to map one scale to another, and it does > so by basepitch to retain alteration. One could easily adapt this function to > match by base pitch and alteration: > > transposePitchClasses = > #(define-music-function (scaleA scaleB music) (ly:music? ly:music? ly:music?) > (let* ((scaleA (ly:music-property scaleA 'elements)) > (scaleB (ly:music-property scaleB 'elements)) > (scaleA (map (lambda (x) (ly:music-property x 'pitch)) scaleA)) > (scaleB (map (lambda (x) (ly:music-property x 'pitch)) scaleB)) > (classesA (map (lambda (p) (cons (ly:pitch-notename p) (ly:pitch- > alteration p))) scaleA))) > (map-some-music > (lambda (m) > (let ((p (ly:music-property m 'pitch))) > (if (not (null? p)) > (let* ((nn (ly:pitch-notename p)) > (oct (ly:pitch-octave p)) > (alt (ly:pitch-alteration p)) > (pos (list-index (lambda (x) (and (= (car x) nn) (= (cdr x) > alt))) classesA))) > (if pos > (let* ((p2 (list-ref scaleA pos)) > (oct2 (ly:pitch-octave p2)) > (p3 (list-ref scaleB pos)) > (new-pitch (ly:pitch-transpose p3 (ly:make-pitch (- > oct oct2) 0)))) > (ly:music-set-property! m 'pitch new-pitch))) > m) > #f))) > music) > music)) > > \transposePitchClasses {d fih g aih} {dih f gis a} > { c' cis' d' dis' f' fih' fis' g' a' aih' } > > Am Donnerstag, 31. August 2023, 12:53:26 CEST schrieb Michael Winter via > LilyPond user discussion: > >> I would like to do something (hopefully simple), which is basically a custom >> find and replace for a set of notes in an entire score. >> >> For example {c cis d dis fih g aih} -> {c cis dih dis f gis a} >> >> So basically on arbitrary list of pitches / scale to another. >> >> Is this possible without writing a custom function. If not, any hints on how >> to tackle the problem would be much appreciated. Thanks in advance. >> >> -Michael >>