[prev in list] [next in list] [prev in thread] [next in thread]
List: lilypond-user
Subject: Scheme experts, please help me improve my code
From: Manuela <manuela-g () gmx ! at>
Date: 2016-03-27 0:10:34
Message-ID: trinity-18a3bb0e-5838-4520-bd69-684ab4d0e573-1459037434585 () 3capp-gmx-bs13
[Download RAW message or body]
[Attachment #2 (text/html)]
<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>
<div>Hi altogether,</div>
<div>some time ago I had the idea to write a kind of harmony analyzer. It works in \
the following manner: you enter some notes (<span style="font-family:courier \
new,courier,monospace;">myMusik) </span>and you get a list of chords which contain \
these notes.<br/> I had no idea of Scheme, so I studies several manuals, and Harm \
from the German Lilypond forum helped me a lot but still I am sometimes lost in \
parentheses. The code as it is now is working and I am very glad about that. But \
there is much room for improvement, and the chordNameExceptions don't work, so I \
ask for your help</div>
<div>Basically I would prefer to enter a list of chords like I do in Lilypond, such \
as c:7 c:m7 c:maj7 ... and the program should do the rest, create list etc. My scheme \
knowledge is not good enough for that.</div>
<div>Please excuse the German comments.</div>
<div> </div>
<div>Here is the code:</div>
<div> </div>
<div>
<div>Hi altogether,</div>
<div>some time ago I had the idea to write a kind of harmony analyzer. It works in \
the following manner: you enter some notes and you get a list of chords which contain \
these notes.<br/> I had no idea of Scheme, so I studies several manuals, and Harm \
from the German Lilypond forum helped me a lot but still I am sometimes lost in \
parentheses. The code as it is now is working and I am very glad about that. But \
there is much room for improvement, and the chordNameExceptions don't work, so I \
ask for your help</div>
<div>Basically I would prefer to enter a list of chords like I do in Lilypond, such \
as c:7 c:m7 c:maj7 ... and the program should do the rest, create list etc. My scheme \
knowledge is not good enough for that.</div>
<div>Please excuse the German comments.</div>
<div>Here is the code:</div>
<div> </div>
<div><span style="font-family:courier new,courier,monospace;">\version \
"2.19.37"</span></div>
<div><span style="font-family:courier new,courier,monospace;">\language \
"deutsch"</span></div>
<div><span style="font-family:courier new,courier,monospace;">myMusik= < c' \
e' >1_"Input"<br/> Tonleitern=< c des d es e f fis ges g as a b h \
></span></div>
<div><span style="font-family:courier new,courier,monospace;">chExceptionMusic = \
{<br/> <c es ges>1-\markup { \super "dim" }<br/>
<c e gis>1-\markup { \super "maj" }<br/>
<c e geses>1-\markup { \super "ddim" }<br/>
<c eses ges >1-\markup { \super "dddim" }<br/>
<c e g h>1-\markup { \super "maj7" }<br/>
<c es g h>1-\markup { "m" \super "maj7" \
}<br/> <c es ges h>1-\markup { "m" \super { \
"maj7" \flat "5" } }<br/> <c e ges \
h>1-\markup { \super { "maj7" \flat "5" } }<br/> \
<c es ges heses>1-\markup { \super "dim7" }<br/> \
<c e g h d'>1-\markup { \super "maj9" }<br/> \
<c e g b d' f a' >1-\markup { \super "13" \
}<br/> %<c e g d' >1-\markup { \super "add9" \
}<br/> <c e g b des' as' >1-\markup { \super { \
\flat "9" \flat 13 } }<br/> <c e g b d' a' \
>1-\markup { \super "13" }<br/> <c e g a \
d'>1-\markup { \super "6(add9)" }<br/> }</span></div>
<div><span style="font-family:courier new,courier,monospace;">% Convert music to list \
and prepend to existing exceptions.<br/> chExceptions = #( append<br/>
\
( sequential-music-to-chord-exceptions chExceptionMusic #t)<br/> \
\
ignatzekExceptions)</span></div>
<div><span style="font-family:courier new,courier,monospace;">chExceptions = #( \
append<br/> \
( sequential-music-to-chord-exceptions chExceptionMusic #t)<br/> \
\
ignatzekExceptions)</span></div>
<div><span style="font-family:courier new,courier,monospace;">ChordI = \chordmode \
{ \germanChords<br/> \set chordNameExceptions = \
#chExceptions c:1 }<br/> ChordII = \chordmode { \germanChords<br/>
\set chordNameExceptions = #chExceptions c:2 }<br/>
ChordIII = \chordmode { \germanChords<br/>
\set chordNameExceptions = #chExceptions c:3 }<br/>
ChordIV = \chordmode { \germanChords<br/>
\set chordNameExceptions = #chExceptions c:4 }<br/>
ChordV = \chordmode { \germanChords<br/>
\set chordNameExceptions = #chExceptions c:5 }<br/>
ChordVI = \chordmode { \germanChords<br/>
\set chordNameExceptions = #chExceptions c:6 }<br/>
ChordVII = \chordmode { \germanChords<br/>
\set chordNameExceptions = #chExceptions c:7 }<br/>
ChordVIII = \chordmode { \germanChords<br/>
\set chordNameExceptions = #chExceptions c:8 }</span></div>
<div><span style="font-family:courier new,courier,monospace;">#(define MusLis \
(list<br/> \
ChordI<br/> \
ChordII<br/> \
ChordIII<br/> \
ChordIV<br/> \
ChordV<br/> \
ChordVI<br/> \
ChordVII<br/> \
ChordVIII<br/> \
))</span></div>
<div><span style="font-family:courier new,courier,monospace;">#(define (pitch-equals? \
p1 p2)<br/> (and<br/>
(= (ly:pitch-alteration p1) (ly:pitch-alteration p2))<br/>
(= (ly:pitch-notename p1) (ly:pitch-notename p2))))</span></div>
<div><span style="font-family:courier new,courier,monospace;">#(define myInput (sort \
(music-pitches myMusik) ly:pitch<?) )</span></div>
<div><span style="font-family:courier new,courier,monospace;">#(define mk-pitch<br/>
;; wir erschaffen eine Pitchliste aus der Musikliste<br/>
(lambda (ls)<br/>
(cond<br/>
;; wir haben fertig, wenn Liste leer ist<br/>
((null? ls) '())</span></div>
<div><span style="font-family:courier \
new,courier,monospace;"> ;; wenn das Listenelement ein \
gültiger Musikausdruck ist<br/> ;; dann \
fügen wir die sortierte Pitchliste als Listenelement hinzu<br/> \
((ly:music? (car ls))<br/> \
(cons (sort (music-pitches (car ls) ) \
ly:pitch<?)<br/> ;(cons (car l2) \
(vvv l1 (cdr l2)))<br/> (mk-pitch \
(cdr ls)))<br/> )<br/>
;; ansonsten machen wir mit dem Rest der Liste \
weiter<br/> (else (mk-pitch (cdr ls)))<br/>
)<br/>
)<br/>
)</span></div>
<div><span style="font-family:courier new,courier,monospace;">#(define is-in?<br/>
;; wir versuchen zu eruieren<br/>
;; ob alle Elemente der Liste l1 in l2 enthalten sind<br/>
;; genauer gesagt müssen nur notename und alteration stimmen<br/>
;; die Oktavlage interessiert uns nicht<br/>
(lambda ( l1 l2 )<br/>
( cond<br/>
;; zunächst prüfen wir, ob die \
Testliste bereits erschöpft ist<br/> ;; \
wenn ja dann ist es wahr<br/> ((null? l1) \
#t<br/> )<br/>
;; wenn die Zielliste erschöpft ist<br/>
;; ist es falsch<br/>
((null? l2) #f<br/>
)<br/>
;; wir überprüfen das erste Element \
der Testliste<br/> ;; wenn es gleich dem ersten \
Element der Zielliste ist<br/> ;; dann \
können wir mit dem restlichen Teil der Testliste fortsetzen<br/> \
((pitch-equals? (car l1) (car l2))<br/> \
(is-in? (cdr l1) l2)<br/> \
;'equalPitch<br/> \
)<br/> \
;; ansonsten versuchen wir es mit dem folgenden \
Element der Zielliste<br/> (else (is-in? l1 (cdr \
l2))<br/> )<br/>
)<br/>
)<br/>
)</span></div>
<div><span style="font-family:courier new,courier,monospace;">#(begin<br/>
(define (ist-in? l1 l2)<br/>
(every (lambda (x) (->bool (member x l2 pitch-equals?))) \
l1)<br/> )<br/>
)</span></div>
<div><span style="font-family:courier new,courier,monospace;">#(define www<br/>
;; wir wollen jetzt die Musikausdrücke in eine Liste \
hängen<br/> ;; l1 ist unsere Testliste<br/>
;; l2 enthält die Pitches<br/>
;; l3 enthält die Musik (in diesem Fall die Akkorde bzw. \
Akkordnamen</span></div>
<div><span style="font-family:courier new,courier,monospace;"> (lambda \
(l1 l2 l3)<br/> ( cond<br/>
;; wenn die Akkordliste leer ist, dann \
verabschieden wir uns<br/> ((null? l2) \
'()<br/> )<br/>
;; wenn die Testliste leer ist, dann ist es auch \
aus<br/> ((null? l1) '() )<br/>
;; wenn die Noten der Testliste im ersten Akkord \
enthalten sind,<br/> ;; wird der Akkord \
hinzugefügt<br/> ((is-in? l1 (car l2))<br/>
(cons (car l3) (www l1 (cdr l2) (cdr \
l3)))<br/> )<br/>
;; wenn die Noten von l1 nicht im ersten Akkort \
enthalten sind<br/> ;; machen wir mit der \
restlichen Akkordliste weiter<br/> (else (www l1 \
(cdr l2) (cdr l3))<br/> )<br/>
)<br/>
)<br/>
)</span></div>
<div><span style="font-family:courier new,courier,monospace;">%% Liste der \
transponierten AKkorde<br/> %% in zwei Stufen<br/>
%% die innere Funktion durchläuft die Akkordliste<br/>
%% die äußere die Tonleiterliste<br/>
%% das hat den Sinn, dass ich die Liste der Akkorde insgesamt transponieren will<br/>
%% und nicht jeden Akkord in alle Tonarten und dann den nächsten Akkord \
etc.</span></div>
<div><span style="font-family:courier new,courier,monospace;">#(define ( \
Akkorde-in-allen-Tonleitern Pitch Musik)<br/> (append-map<br/>
(lambda (p)<br/>
(map<br/>
(lambda (music)<br/>
#{ { \transpose c $p \
$music } #})<br/> Musik<br/>
)<br/>
)<br/>
(event-chord-pitches Pitch)<br/>
)<br/>
)</span></div>
<div><span style="font-family:courier new,courier,monospace;">#(define MusikListe \
(Akkorde-in-allen-Tonleitern Tonleitern MusLis))</span></div>
<div><span style="font-family:courier new,courier,monospace;">#(define PitLis \
(mk-pitch MusikListe))</span></div>
<div><span style="font-family:courier new,courier,monospace;">#(define Ergebnis (www \
myInput PitLis MusikListe )) % just for interest</span></div>
<div><span style="font-family:courier new,courier,monospace;">#(display (length \
Ergebnis))</span></div>
<div><span style="font-family:courier new,courier,monospace;">\score {<br/>
\new Staff<br/>
<<<br/>
\new Voice $(make-sequential-music (append (list \
myMusik) Ergebnis))<br/> \new ChordNames {<br/>
s1<br/>
$(make-sequential-music Ergebnis)<br/>
}<br/>
>><br/>
}</span></div>
</div>
</div></div></body></html>
["Analysator.png" (image/png)]
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic