[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lilypond-user
Subject:    Re: custom replace/map of one set of pitches to another
From:       Michael Winter via LilyPond user discussion <lilypond-user () gnu ! org>
Date:       2023-08-31 22:51:57
Message-ID: NdCmwxz--3-9 () unboundedpress ! org
[Download RAW message or body]

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 valentin@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
> > 


[Attachment #3 (text/html)]

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



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic