Skip to content

Commit 25a0984

Browse files
committed
Find if two pitches are 1 semitone apart and move them to avoid dissonances.
Test mode for gen.py
1 parent 9bb12ca commit 25a0984

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

gen.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import os
2929
import mingus.core.scales as scales
30+
import sys
3031

3132
from src.chords2midi import c2m
3233
from chords import *
@@ -53,9 +54,18 @@
5354
# ('Cb', 'ab'), # 7 b
5455
]
5556

57+
# Chords in Major and minor scales
5658
deg_maj = ['I', 'ii', 'iii', 'IV', 'V', 'vi', 'vii']
5759
deg_min = ['i', 'ii', 'III', 'iv', 'v', 'VI', 'VII']
5860

61+
# progressions styles
62+
styles = [ '', 'basic4', 'alt4', 'hiphop' ]
63+
64+
# Test mode
65+
if len(sys.argv) > 1 and sys.argv[1] == '--test':
66+
keys = [ ('C', 'A') ]
67+
styles = [ '' ]
68+
5969
#
6070
# Generate a single chord
6171
#
@@ -144,17 +154,17 @@ def genprog(dir, key, chords, prefix, style = ''):
144154
i = i + 1
145155

146156
# Major progressions
147-
for style in [ '', 'basic4', 'alt4', 'hiphop' ]:
157+
for style in styles:
148158
for n in prog_maj:
149159
genprog(f'{base}/4 Progression/Major', root_maj, n, root_maj, style)
150160

151161
# Minor progressions
152-
for style in [ '', 'basic4', 'alt4', 'hiphop' ]:
162+
for style in styles:
153163
for n in prog_min:
154164
genprog(f'{base}/4 Progression/Minor', root_min.lower(), n, root_min, style)
155165

156166
# Modal progressions
157-
for style in [ '', 'basic4', 'alt4', 'hiphop' ]:
167+
for style in styles:
158168
for n in prog_modal:
159169
genprog(f'{base}/4 Progression/Modal', root_maj, n, root_maj, style)
160170

src/chords2midi/c2m.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,17 @@ def handle(self, argv=None):
392392
else:
393393
pitches.append(new_pitch + 12)
394394

395+
# find if two pitches are 1 semitone apart to avoid dissonances
396+
length = len(pitches)
397+
for i in range(length):
398+
for j in range(i + 1, length):
399+
if abs(pitches[i] - pitches[j]) == 1:
400+
# move the note one octave up
401+
if (bar/4) % 2 == 0:
402+
pitches[j] = pitches[j] + 12
403+
else:
404+
pitches[i] = pitches[i] + 12
405+
395406
# Bassline
396407
if bassline:
397408
pitches.append(root_pitch - 24)

0 commit comments

Comments
 (0)