Skip to content

Commit c1bec76

Browse files
authored
Add files via upload
1 parent 36e1bde commit c1bec76

File tree

2 files changed

+320
-0
lines changed

2 files changed

+320
-0
lines changed

ReadMe.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
RandomChords 1.2.2
2+
3+
The purpose of the program is to generate random chords to inspire music creation.
4+
Run the executable and you will be asked if you want to configure parameters or generate a chord with
5+
the default parameters.
6+
Input "c" to configure or Enter for default.
7+
8+
- Parameters -
9+
How many clashes allowed? - Input a number from 0 to 13 to tell the program how many clashes (notes at one
10+
semitone distance) the chord should contain. The default value is 1.
11+
How many repeated notes allowed? - Input a number from 0 to 13 to determine how many notes can be repeated
12+
in the chord. The default value is 0.
13+
How many notes? - This is the number of notes you want the chord to contain. Input a number from 4 to 13.
14+
The default value is 6.
15+
Lowest interval? - The lowest interval between notes expressed in number of semitones. Accepts values from
16+
1 to 11. The default value is 2.
17+
Highest interval? - The highest interval between notes expressed in number of semitones. Accepts values
18+
from 2 to 11.
19+
20+
If the program cannot find a chord with the parameters you have set, it will try 10,000 combinations, then
21+
modify the parameters, by increasing the number of clashes and repeated notes allowed, then try 10,000 more
22+
combinations. In order to reset the parameters, you will have to choose the configuration option again at
23+
the prompt.
24+
25+
The chord will be displayed in a terminal window, in the following format:
26+
27+
root= D
28+
lowest= C
29+
Intervals= [6, 2, 5, 3]
30+
chord= D C F# G# C# E
31+
32+
Root: the chord root, placed on octave n. 2 of a preset inside a DAW or other music program.
33+
Lowest: the lowest note of the chord, placed on octave 4.
34+
Intervals: first interval is the distance in semitones from the lowest note, second interval distance from
35+
the second note and so on.
36+
Chord: the chord expressed in note names. First note is the root on octave 2, second note is the lowest note
37+
of the chord on octave 4, the other notes are above the lowest note, ending possibly on higher octaves.
38+
39+
At prompt input Enter to generate a new chord, "q" to quit the program. Just closing the terminal window will
40+
also close the program.
41+
42+
New in this version:
43+
44+
- Better algorithm, allows more than one interval below 8 semitones.

randomchords_1.2.2.py

Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
"""Random Chords 1.2.2 - A very simple random chord generator.
2+
Copyright (C) 2023 Fonazza-Stent
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>."""
16+
17+
import random
18+
from random import randint
19+
notes=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"]
20+
clashes=1
21+
repeats=0
22+
firstchord=0
23+
clashlist=["CC#","C#D","DD#","D#E","EF","FF#","F#G","GG#","G#A","AA#","A#B","BC"]
24+
index=1
25+
lowrange=2
26+
hirange=7
27+
notesnumber=6
28+
trycheck=0
29+
def init():
30+
global oktwo
31+
global okeight
32+
global oknine
33+
global okten
34+
global okeleven
35+
global chordnotes
36+
global counter
37+
global chord
38+
global chordstring
39+
global clash
40+
global repeat
41+
global notelist
42+
global occurrencies
43+
global clash_occ
44+
global repeatthree
45+
46+
oktwo=0
47+
okfive=0
48+
okeight=0
49+
oknine=0
50+
okten=0
51+
okeleven=0
52+
chordnotes=[]
53+
chord=[]
54+
counter=1
55+
octave=4
56+
chordstring=""
57+
clash=0
58+
repeat=0
59+
repeatthree=False
60+
notelist=[]
61+
occurrencies=[]
62+
clash_occ=[0,0,0,0,0,0,0,0,0,0,0,0]
63+
random.seed()
64+
65+
66+
67+
68+
def validate_chord():
69+
global clash
70+
global repeat
71+
global notelist
72+
global occurrencies
73+
global clash_occ
74+
global clashcount
75+
global repeatthree
76+
for note in chord:
77+
#print (note)
78+
for checknote in chord:
79+
pair=note+checknote
80+
for clashtype in clashlist:
81+
if pair==clashtype:
82+
clash_occ[clashlist.index(clashtype)]=clash_occ[clashlist.index(clashtype)]+1
83+
for eachclash in clash_occ:
84+
clash=clash+eachclash
85+
86+
occ_check=0
87+
note_occ=chord[0]
88+
notelist.append(note_occ)
89+
occurrencies.append(0)
90+
for note in chord:
91+
note_occ=note
92+
items=len(notelist)
93+
for x in range (0,items):
94+
if note_occ==notelist[x]:
95+
count=int(occurrencies[x])
96+
occurrencies[x]=count+1
97+
occ_check=1
98+
if occ_check==0:
99+
notelist.append(note_occ)
100+
occurrencies.append(1)
101+
occ_check=0
102+
for value in occurrencies:
103+
if value>1:
104+
repeat=repeat+value
105+
if value>2:
106+
repeatthree=True
107+
108+
init()
109+
110+
while True:
111+
112+
root= randint(1,12)
113+
randomloop=randint(3,15)
114+
for n in range (1,randomloop):
115+
randreset=randint(2,11)
116+
lowest=randint(2,11)
117+
chord.append(notes[root-1])
118+
lowestvalue=root+lowest
119+
if lowestvalue>12:
120+
lowestvalue=lowestvalue-12
121+
chord.append(notes[lowestvalue-1])
122+
123+
notevalue=lowestvalue
124+
125+
while counter<notesnumber-1:
126+
interval=randint(lowrange,hirange)
127+
if interval!=2 and interval<8:
128+
chordnotes.append(interval)
129+
notevalue=notevalue+interval
130+
if notevalue>12:
131+
notevalue=notevalue-12
132+
chord.append(notes[notevalue-1])
133+
counter=counter+1
134+
if interval==2 and oktwo==0:
135+
chordnotes.append(interval)
136+
notevalue=notevalue+interval
137+
if notevalue>12:
138+
notevalue=notevalue-12
139+
chord.append(notes[notevalue-1])
140+
counter=counter+1
141+
if interval==8 and okeight==0:
142+
chordnotes.append(interval)
143+
notevalue=notevalue+interval
144+
if notevalue>12:
145+
notevalue=notevalue-12
146+
chord.append(notes[notevalue-1])
147+
counter=counter+1
148+
if interval==9 and oknine==0:
149+
chordnotes.append(interval)
150+
notevalue=notevalue+interval
151+
if notevalue>12:
152+
notevalue=notevalue-12
153+
chord.append(notes[notevalue-1])
154+
counter=counter+1
155+
if interval==10 and okten==0:
156+
chordnotes.append(interval)
157+
notevalue=notevalue+interval
158+
if notevalue>12:
159+
notevalue=notevalue-12
160+
chord.append(notes[notevalue-1])
161+
counter=counter+1
162+
if interval==11 and okeleven==0:
163+
chordnotes.append(interval)
164+
notevalue=notevalue+interval
165+
if notevalue>12:
166+
notevalue=notevalue-12
167+
chord.append(notes[notevalue-1])
168+
counter=counter+1
169+
if interval==2:
170+
oktwo=1
171+
if interval==5:
172+
okfive=1
173+
if interval==6:
174+
oksix=1
175+
if interval==7:
176+
okseven=1
177+
if interval==8:
178+
okeight=1
179+
if interval==9:
180+
oknine=1
181+
if interval==10:
182+
okten=1
183+
if interval==11:
184+
okeleven=1
185+
186+
validate_chord()
187+
188+
if clash<=clashes and repeat<=repeats and repeatthree==False:
189+
if firstchord==1:
190+
print ("\n")
191+
print (clashes, " clashes allowed")
192+
print (repeats, " repeated notes allowed")
193+
194+
print ("root= ",notes[root-1])
195+
print ("lowest= ",notes[lowestvalue-1])
196+
print ("Intervals= ",chordnotes)
197+
for items in chord:
198+
chordstring=chordstring+items+" "
199+
print ("chord= ",chordstring)
200+
print ("\n")
201+
if trycheck==1:
202+
"""clashes=clashes_mem
203+
repeats=repeats_mem"""
204+
True
205+
trycheck=0
206+
more=input("Enter for new chord, q to quit ")
207+
if more=="q":
208+
quit()
209+
firstchord=1
210+
configure=input("c to configure, Enter for default parameters: ")
211+
if configure=="c":
212+
clashesyes=-1
213+
while clashesyes<0 or clashesyes>13:
214+
clashesinput=input("How many clashes allowed? (0 to 13, default 1): ")
215+
if clashesinput.isdigit():
216+
clashesyes=int(clashesinput)
217+
clashes=clashesyes
218+
clashes_mem=clashes
219+
if clashesinput=='':
220+
clashesyes=1
221+
clashes=clashesyes
222+
repeats=-1
223+
while repeats<0 or repeats>13:
224+
repeatinput=input("How many repeated notes allowed? (0 to 13, default 0): ")
225+
if repeatinput.isdigit():
226+
repeats=int(repeatinput)
227+
repeats_mem=repeats
228+
if repeatinput=='':
229+
repeats=0
230+
notesnumber=-1
231+
while notesnumber <4 or notesnumber>13:
232+
inputnotesnumber=input("How many notes? (4 to 13, default 6): ")
233+
if inputnotesnumber.isdigit():
234+
notesnumber=int(inputnotesnumber)
235+
if inputnotesnumber=='':
236+
notesnumber=6
237+
lowrange=-1
238+
while lowrange <1 or lowrange>11:
239+
lowrangeinput=input("Lowest interval? (1 to 11, default 2): ")
240+
if lowrangeinput.isdigit():
241+
lowrange=int(lowrangeinput)
242+
if lowrangeinput=='':
243+
lowrange=2
244+
hirange=-1
245+
while hirange <2 or hirange>11:
246+
hirangeinput=input("Highest interval? (2 to 11, default 7): ")
247+
if hirangeinput.isdigit():
248+
hirange=int(hirangeinput)
249+
if hirangeinput=='':
250+
hirange=7
251+
if lowrange>hirange:
252+
low=lowrange
253+
high=highrange
254+
lowrange=high
255+
highrange=low
256+
257+
258+
index=1
259+
index=index+1
260+
if index>10000:
261+
print ("Trying 10.000 combinations")
262+
trycheck=1
263+
if clashes<=repeats:
264+
clashes=clashes+1
265+
print ("Clashes allowed:",clashes)
266+
if clashes>=13:
267+
clashes=13
268+
repeats=repeats+1
269+
print ("Repeated notes allowed:",repeats)
270+
if repeats>=13:
271+
repeats=13
272+
273+
index=1
274+
init()
275+
276+

0 commit comments

Comments
 (0)