Skip to content

Commit fb7ee81

Browse files
authored
Add files via upload
1 parent 01a5870 commit fb7ee81

File tree

2 files changed

+327
-0
lines changed

2 files changed

+327
-0
lines changed

ReadMe.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
RandomChords 1.2.3
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+
- Improved algorithm
45+
- Modified default parameters to 4 note chords with no clashes and no repeated notes

randomchords_1.2.3.py

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
"""Random Chords 1.2.3 - Generate random chords.
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=0
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=4
28+
trycheck=0
29+
maxrepeats=False
30+
def init():
31+
global oktwo
32+
global okeight
33+
global oknine
34+
global okten
35+
global okeleven
36+
global chordnotes
37+
global counter
38+
global chord
39+
global chordstring
40+
global clash
41+
global repeat
42+
global notelist
43+
global occurrencies
44+
global clash_occ
45+
global repeatthree
46+
47+
oktwo=0
48+
okfive=0
49+
okeight=0
50+
oknine=0
51+
okten=0
52+
okeleven=0
53+
chordnotes=[]
54+
chord=[]
55+
counter=1
56+
octave=4
57+
chordstring=""
58+
clash=0
59+
repeat=0
60+
repeatthree=False
61+
notelist=[]
62+
occurrencies=[]
63+
clash_occ=[0,0,0,0,0,0,0,0,0,0,0,0]
64+
random.seed()
65+
66+
67+
68+
69+
def validate_chord():
70+
global clash
71+
global repeat
72+
global notelist
73+
global occurrencies
74+
global clash_occ
75+
global clashcount
76+
global repeatthree
77+
for note in chord:
78+
#print (note)
79+
for checknote in chord:
80+
pair=note+checknote
81+
for clashtype in clashlist:
82+
if pair==clashtype:
83+
clash_occ[clashlist.index(clashtype)]=clash_occ[clashlist.index(clashtype)]+1
84+
for eachclash in clash_occ:
85+
clash=clash+eachclash
86+
87+
occ_check=0
88+
note_occ=chord[0]
89+
notelist.append(note_occ)
90+
occurrencies.append(0)
91+
for note in chord:
92+
note_occ=note
93+
items=len(notelist)
94+
for x in range (0,items):
95+
if note_occ==notelist[x]:
96+
count=int(occurrencies[x])
97+
occurrencies[x]=count+1
98+
occ_check=1
99+
if occ_check==0:
100+
notelist.append(note_occ)
101+
occurrencies.append(1)
102+
occ_check=0
103+
for value in occurrencies:
104+
if value>1:
105+
repeat=repeat+value
106+
if value>2:
107+
repeatthree=True
108+
109+
init()
110+
111+
while True:
112+
113+
root= randint(1,12)
114+
randomloop=randint(3,15)
115+
for n in range (1,randomloop):
116+
randreset=randint(2,11)
117+
lowest=randint(2,11)
118+
chord.append(notes[root-1])
119+
lowestvalue=root+lowest
120+
if lowestvalue>12:
121+
lowestvalue=lowestvalue-12
122+
chord.append(notes[lowestvalue-1])
123+
124+
notevalue=lowestvalue
125+
126+
while counter<notesnumber-1:
127+
interval=randint(lowrange,hirange)
128+
if interval!=2 and interval<8:
129+
chordnotes.append(interval)
130+
notevalue=notevalue+interval
131+
if notevalue>12:
132+
notevalue=notevalue-12
133+
chord.append(notes[notevalue-1])
134+
counter=counter+1
135+
if interval==2 and oktwo==0:
136+
chordnotes.append(interval)
137+
notevalue=notevalue+interval
138+
if notevalue>12:
139+
notevalue=notevalue-12
140+
chord.append(notes[notevalue-1])
141+
counter=counter+1
142+
if interval==8 and okeight==0:
143+
chordnotes.append(interval)
144+
notevalue=notevalue+interval
145+
if notevalue>12:
146+
notevalue=notevalue-12
147+
chord.append(notes[notevalue-1])
148+
counter=counter+1
149+
if interval==9 and oknine==0:
150+
chordnotes.append(interval)
151+
notevalue=notevalue+interval
152+
if notevalue>12:
153+
notevalue=notevalue-12
154+
chord.append(notes[notevalue-1])
155+
counter=counter+1
156+
if interval==10 and okten==0:
157+
chordnotes.append(interval)
158+
notevalue=notevalue+interval
159+
if notevalue>12:
160+
notevalue=notevalue-12
161+
chord.append(notes[notevalue-1])
162+
counter=counter+1
163+
if interval==11 and okeleven==0:
164+
chordnotes.append(interval)
165+
notevalue=notevalue+interval
166+
if notevalue>12:
167+
notevalue=notevalue-12
168+
chord.append(notes[notevalue-1])
169+
counter=counter+1
170+
if interval==2:
171+
oktwo=1
172+
if interval==5:
173+
okfive=1
174+
if interval==6:
175+
oksix=1
176+
if interval==7:
177+
okseven=1
178+
if interval==8:
179+
okeight=1
180+
if interval==9:
181+
oknine=1
182+
if interval==10:
183+
okten=1
184+
if interval==11:
185+
okeleven=1
186+
187+
validate_chord()
188+
189+
if clash<=clashes and repeat<=repeats and repeatthree==False:
190+
if firstchord==1:
191+
print ("\n")
192+
print (clashes, " clashes allowed")
193+
print (repeats, " repeated notes allowed")
194+
195+
print ("root= ",notes[root-1])
196+
print ("lowest= ",notes[lowestvalue-1])
197+
print ("Intervals= ",chordnotes)
198+
for items in chord:
199+
chordstring=chordstring+items+" "
200+
print ("chord= ",chordstring)
201+
print ("\n")
202+
if trycheck==1:
203+
"""clashes=clashes_mem
204+
repeats=repeats_mem"""
205+
True
206+
trycheck=0
207+
more=input("Enter for new chord, q to quit ")
208+
if more=="q":
209+
quit()
210+
firstchord=1
211+
configure=input("c to configure, Enter for default parameters: ")
212+
if configure=="c":
213+
clashesyes=-1
214+
while clashesyes<0 or clashesyes>13:
215+
clashesinput=input("How many clashes allowed? (0 to 13, default 0): ")
216+
if clashesinput.isdigit():
217+
clashesyes=int(clashesinput)
218+
clashes=clashesyes
219+
clashes_mem=clashes
220+
if clashesinput=='':
221+
clashesyes=0
222+
clashes=clashesyes
223+
repeats=-1
224+
while repeats<0 or repeats>13:
225+
repeatinput=input("How many repeated notes allowed? (0 to 13, default 0): ")
226+
if repeatinput.isdigit():
227+
repeats=int(repeatinput)
228+
repeats_mem=repeats
229+
if repeatinput=='':
230+
repeats=0
231+
notesnumber=-1
232+
while notesnumber <4 or notesnumber>13:
233+
inputnotesnumber=input("How many notes? (4 to 13, default 4): ")
234+
if inputnotesnumber.isdigit():
235+
notesnumber=int(inputnotesnumber)
236+
if inputnotesnumber=='':
237+
notesnumber=4
238+
lowrange=-1
239+
while lowrange <1 or lowrange>11:
240+
lowrangeinput=input("Lowest interval? (1 to 11, default 2): ")
241+
if lowrangeinput.isdigit():
242+
lowrange=int(lowrangeinput)
243+
if lowrangeinput=='':
244+
lowrange=2
245+
hirange=-1
246+
while hirange <3 or hirange>11:
247+
hirangeinput=input("Highest interval? (3 to 11, default 7): ")
248+
if hirangeinput.isdigit():
249+
hirange=int(hirangeinput)
250+
if hirangeinput=='':
251+
hirange=7
252+
if lowrange>hirange:
253+
low=lowrange
254+
high=highrange
255+
lowrange=high
256+
highrange=low
257+
258+
259+
index=1
260+
index=index+1
261+
if index>10000:
262+
print ("Trying 10.000 combinations")
263+
trycheck=1
264+
if clashes==0:
265+
clashes=clashes+1
266+
if maxrepeats==True:
267+
clashes=clashes+1
268+
maxrepeats=False
269+
print ("Clashes allowed:",clashes)
270+
if clashes>=13:
271+
clashes=13
272+
repeats=repeats+1
273+
print ("Repeated notes allowed:",repeats)
274+
if repeats>=13:
275+
maxrepeats=True
276+
repeats=0
277+
278+
279+
index=1
280+
init()
281+
282+

0 commit comments

Comments
 (0)