-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTropical.py
More file actions
1171 lines (966 loc) · 36.2 KB
/
Tropical.py
File metadata and controls
1171 lines (966 loc) · 36.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import time
import fluidsynth
import numpy
from playsound import playsound
#import threading
import concurrent.futures
#import pygame
import sys
import serial
from serial.tools import list_ports
import matplotlib.pyplot as plt
import statsmodels.api as sm
import scipy.signal
import scipy.fftpack
import pylab
from pylab import *
from numpy import ma
from pylab import polyfit
from matplotlib.colors import LogNorm
import matplotlib.ticker as mticker
import os
import matplotlib.cm as cm
Scale = [67, 69, 72, 74, 76, 79, 81]
SoloScale = [60,62,64,67,69,72,74,75,76,79,81,84]
ScaleRoot = 72
SoloAccentIdx = [0,3,6,9,12]
RNGfreq = 200
PluckSpd = 0.02
NoteSpeed = 0.115
ChordPluck = False
#MTrials = 1000
FreeRhythm = False
UseTrueRNG = False
ThresholdZ = 1.85
SoloZ = 0.5#Threshold of Z-score in bitstream that triggers a piano solo
ModAmount = 2#Key changes that will be triggered, in number of semitones
Rmks = sys.argv[1]
OutPath = os.getcwd()
UnivFreq = 1.0/(PluckSpd+NoteSpeed)
starttime = int(time.time()*1000)
print(starttime)
outfile = open('%s/Trop_%d_%s.txt'%(OutPath,starttime,Rmks),'w')
if UseTrueRNG == True:
# Create ports variable as dictionary
ports=dict()
# Call list_ports to get com port info
ports_avaiable = list(list_ports.comports())
# Set default of None for com port
rng_com_port = None
# Loop on all available ports to find TrueRNG
for temp in ports_avaiable:
if temp[1].startswith("TrueRNG"):
#print('Found: ' + str(temp))
if rng_com_port == None: # always chooses the 1st TrueRNG found
rng_com_port=str(temp[0])
# Print which port we're using
#print('Using com port: ' + str(rng_com_port))
# Print block size and number of loops
#print('==================================================')
sys.stdout.flush()
# Try to setup and open the comport
ser = serial.Serial(port=rng_com_port,timeout=10) # timeout set at 10 seconds in case the read fails
# Open the serial port if it isn't open
if(ser.isOpen() == False):
ser.open()
# Set Data Terminal Ready to start flow
ser.setDTR(True)
# This clears the receive buffer so we aren't using buffered data
ser.flushInput()
fs = fluidsynth.Synth()
fs.start(driver = 'dsound') # use DirectSound driver
sfid0 = fs.sfload(r'Timbres Of Heaven (XGM) 3.94.sf2') # replace path as needed
fs1 = fluidsynth.Synth()
fs1.start(driver = 'dsound') # use DirectSound driver
sfid1 = fs1.sfload(r'Timbres Of Heaven (XGM) 3.94.sf2') # replace path as needed
fs2 = fluidsynth.Synth()
fs2.start(driver = 'dsound') # use DirectSound driver
sfid2 = fs2.sfload(r'Timbres Of Heaven (XGM) 3.94.sf2') # replace path as needed
fs3 = fluidsynth.Synth()
fs3.start(driver = 'dsound') # use DirectSound driver
sfid3 = fs3.sfload(r'Timbres Of Heaven (XGM) 3.94.sf2') # replace path as needed
fs4 = fluidsynth.Synth()
fs4.start(driver = 'dsound') # use DirectSound driver
sfid4 = fs4.sfload(r'Timbres Of Heaven (XGM) 3.94.sf2') # replace path as needed
#NoteSeq = [60,62,64,65,67,65,64,62,60]
#
lib=[]
readFile = open('%s\Conversion.txt'%(OutPath), 'r')
sepfile = readFile.read().split('\n')
for b in range (0,len(sepfile)):
xandy = sepfile[b].split('\t')
lib.append(float(xandy[0]))
#getting around this for now by threading io multiprocess
def RNG_Bulk():
bulk=[]
if UseTrueRNG==True:
ser.flushInput()
#ser.flushInput()
rc=0
for a in range (0,RNGfreq):
if UseTrueRNG==True:
x = ser.read(64)
else:
x = numpy.random.randint(0,256,64)
for b in range (0,64):
rc+=lib[x[b]]
bulk.append(x[b])
outfile.write('%d,'%(x[b]))
outfile.write('\n')
outfile.write('%d\n'%(int(time.time()*1000)))
return rc,bulk
def PlayClap():
playsound('snap3.wav')
#print('clap')
#pygame.mixer.Sound.play(clap_sound)
def PlayKick():
playsound('kick5.wav')
#print('kick')
def PlayHat():
playsound('hat1.wav')
#print('hat')
def ChordID(Cstr,octave,inversion):
if Cstr.startswith('A'):
idx=57
if Cstr.startswith('B'):
idx=59
if Cstr.startswith('C'):
idx=60
if Cstr.startswith('D'):
idx=62
if Cstr.startswith('E'):
idx=64
if Cstr.startswith('F'):
idx=65
if Cstr.startswith('G'):
idx=67
if '#' in Cstr:
idx+= 1
if 'b' in Cstr:
idx+= -1
idx += (octave*12)
if 'm' in Cstr:
Carr = [idx,idx+3,idx+7]
else:
Carr = [idx,idx+4,idx+7]
if inversion==2:
Carr[0] += 12
if inversion==3:
Carr[0] += 12
Carr[1] += 12
return Carr
def AbsDist(note_arr):#just pull in scale as arg if not work
x_use=[]
u_scale = numpy.array(Scale)
for a in range (0,len(note_arr)):
if (note_arr[a]>0):
x_use.append(numpy.where(u_scale==note_arr[a])[0][0])
x_arr=[]
RepeatCt=0
for a in range (1,len(x_use)):
xx_use = numpy.abs(x_use[a]-x_use[a-1])
x_arr.append(xx_use)
if (xx_use==0):
RepeatCt+=1
return numpy.nanmean(x_arr),RepeatCt/(len(x_use)-1)
def MaxJump(NoteSeqS,NoteDurS):
x_jump=[]
for a in range (1,len(NoteSeqS)):
x_jump.append((numpy.abs(NoteSeqS[a]-NoteSeqS[a-1]))/NoteDurS[a-1])
return numpy.nanmean(x_jump)
def FFTdist(NoteSeqS,NoteDurS,Hz,det):
FFT_seq=[]
for a in range (0,len(NoteSeqS)):#helps that 64 IS a valid multiple...not sure how to construct
for b in range (0,NoteDurS[a]):
if (NoteSeqS[a]==-1):
FFT_seq.append(ScaleRoot)
else:
FFT_seq.append(NoteSeqS[a])
#FFT_seq.append(NoteSeqS[a])
FFT_seq = FFT_seq#*64 # streatches length...so no trend
if det==True:
FFT_det=scipy.signal.detrend(FFT_seq)
else:
FFT_det = FFT_seq
U_fft = scipy.fftpack.rfft(FFT_det)
U_psd = U_fft * U_fft.conjugate()
N = len(FFT_det)
fs = Hz#Hz
df = fs/float(N)
freq = numpy.arange(0,fs,df)
Nfi = numpy.intc(numpy.floor(N/2))
testfreq = freq[1:Nfi+1]
xU_psd = U_psd/df/N**2
sU_psd = numpy.real(xU_psd[1:Nfi+1])
Log_testfreq = numpy.log10(testfreq)
Log_sU_psd = numpy.log10(sU_psd)
m1,b1 = numpy.polyfit(Log_testfreq,Log_sU_psd,1)
return m1*-1
def GetMelody(Sc,NumNotes,rnum,rests=None,C_lock=None,M_lock=None):
#print(Sc,NumNotes,rnum,'\n')
buildM=[]
for a in range (0,NumNotes):
if rests:
if a in rests:
buildM.append(-1)
else:
buildM.append(Sc[rnum[a]%len(Sc)])
else:
buildM.append(Sc[rnum[a]%len(Sc)])
if C_lock:
for a in range (0,len(C_lock)):
idx = C_lock[a][0]
ModSc = C_lock[a][1:]
#buildM[idx] = ModSc[numpy.random.randint(0,len(ModSc))]
buildM[idx] = ModSc[rnum[idx]%len(ModSc)]
if M_lock:
for a in range (0,len(M_lock)):
ll = M_lock[a][0]
ul = M_lock[a][1]
paste = M_lock[a][2:]
base = buildM[ll:ul]#remember the +1 aspect when putting this in
for b in range (0,len(paste)):
dx = paste[b]
for c in range (0,len(base)):
buildM[dx+c] = base[c]
return buildM
def GetNotes(Progression,MTrials,numbers):
if Progression==1:
PxCloud = [1,1,4,1,4,3,2,4,1,2,1,3,3,0,4,0]#/4
#RtmPre = numpy.random.randint(0,4,16)
RtmPre = numpy.array(numbers[0:16])%4
Rtm=[]
for a in range (0,len(PxCloud)):
if RtmPre[a]<PxCloud[a]:
Rtm.append(1)
else:
Rtm.append(0)
for a in range (0,16):
Rtm.append(Rtm[a])
PxCloud = [1,1,4,1,4,3,2,4,1,3,1,3,3,1,3,0,2,1,4,2,4,4,1,4,0,3,3,1,4,2,4,2]#/4
#RtmPre = numpy.random.randint(0,4,32)
RtmPre = numpy.array(numbers[16:48])%4
for a in range (0,len(PxCloud)):
if RtmPre[a]<PxCloud[a]:
Rtm.append(1)
else:
Rtm.append(0)
pNoteDur = []
InRests = None
if Rtm[0]==0:
InRests = [0]
LenR = 0; found = 0
for a in range (0,len(Rtm)):
if (Rtm[a]==0) and (found==0):
LenR +=1
else:
found +=1
pNoteDur.append(LenR)
for a in range (0,len(Rtm)):
if Rtm[a]==1:
LenR = 1; found = 0
if (a<len(Rtm)-1):
for b in range (a+1,len(Rtm)):
if (Rtm[b]==0) and (found==0):
LenR +=1
else:
found +=1
pNoteDur.append(LenR)
MelLock=[[]]
CumDur=0
CpyList=[]
found=0
for a in range(0,len(pNoteDur)):
if CumDur<8:
CpyList.append(a)
if CumDur>=16 and found==0:
PastePt = a
found += 1
CumDur+=pNoteDur[a]
if InRests:
MelLock[0].append(1)
else:
MelLock[0].append(0)
#MelLock[0].append(numpy.amin(CpyList))
MelLock[0].append(numpy.amax(CpyList)+1)
MelLock[0].append(PastePt)
ChLock = [[],[],[],[]]
if InRests:
ChLock[0].append(1)
else:
ChLock[0].append(0)
ChLock[0].append(69)
ChLock[0].append(72)
ChLock[0].append(81)
CumDur=0
found=0
for a in range (0,len(pNoteDur)):
if CumDur>=16 and found==0:
ChLock[1].append(a)
ChLock[1].append(69)
ChLock[1].append(72)
ChLock[1].append(81)
found += 1
CumDur += pNoteDur[a]
CumDur=0
found=0
for a in range (0,len(pNoteDur)):
if CumDur>=32 and found==0:
ChLock[2].append(a)
ChLock[2].append(72)
ChLock[2].append(76)
ChLock[2].append(79)
found += 1
CumDur += pNoteDur[a]
ChLock[3].append(len(pNoteDur)-1)
ChLock[3].append(72)
if Progression==2:
PxCloud = [1,1,4,1,4,3,2,4,1,2,1,3,3,0,4,0]#/4
#RtmPre = numpy.random.randint(0,4,16)
RtmPre = numpy.array(numbers[0:16])%4
Rtm=[]
for a in range (0,len(PxCloud)):
if RtmPre[a]<PxCloud[a]:
Rtm.append(1)
else:
Rtm.append(0)
for a in range (0,16):
Rtm.append(Rtm[a])
PxCloud = [1,1,4,1,4,3,2,4,1,3,1,3,3,1,3,0,2,1,4,2,4,4,1,4,0,3,3,1,4,2,4,2]#/4
#RtmPre = numpy.random.randint(0,4,32)
RtmPre = numpy.array(numbers[16:48])%4
for a in range (0,len(PxCloud)):
if RtmPre[a]<PxCloud[a]:
Rtm.append(1)
else:
Rtm.append(0)
pNoteDur = []
InRests = None
if Rtm[0]==0:
InRests = [0]
LenR = 0; found = 0
for a in range (0,len(Rtm)):
if (Rtm[a]==0) and (found==0):
LenR +=1
else:
found +=1
pNoteDur.append(LenR)
for a in range (0,len(Rtm)):
if Rtm[a]==1:
LenR = 1; found = 0
if (a<len(Rtm)-1):
for b in range (a+1,len(Rtm)):
if (Rtm[b]==0) and (found==0):
LenR +=1
else:
found +=1
pNoteDur.append(LenR)
MelLock=[[]]
CumDur=0
CpyList=[]
found=0
for a in range(0,len(pNoteDur)):
if CumDur<8:
CpyList.append(a)
if CumDur>=16 and found==0:
PastePt = a
found += 1
CumDur+=pNoteDur[a]
if InRests:
MelLock[0].append(1)
else:
MelLock[0].append(0)
#MelLock[0].append(numpy.amin(CpyList))
MelLock[0].append(numpy.amax(CpyList)+1)
MelLock[0].append(PastePt)
ChLock = [[],[],[],[]]
if InRests:
ChLock[0].append(1)
else:
ChLock[0].append(0)
ChLock[0].append(72)
ChLock[0].append(74)
ChLock[0].append(79)
CumDur=0
found=0
for a in range (0,len(pNoteDur)):
if CumDur>=16 and found==0:
ChLock[1].append(a)
ChLock[1].append(72)
ChLock[1].append(74)
ChLock[1].append(79)
found += 1
CumDur += pNoteDur[a]
CumDur=0
found=0
for a in range (0,len(pNoteDur)):
if CumDur>=32 and found==0:
ChLock[2].append(a)
ChLock[2].append(69)
ChLock[2].append(72)
ChLock[2].append(81)
found += 1
CumDur += pNoteDur[a]
ChLock[3].append(len(pNoteDur)-1)
ChLock[3].append(72)
if Progression==3:
#Rtm = numpy.random.randint(0,2,64)
Rtm = numpy.array(numbers[0:64])%2
pNoteDur = []
InRests = None
if Rtm[0]==0:
InRests = [0]
LenR = 0; found = 0
for a in range (0,len(Rtm)):
if (Rtm[a]==0) and (found==0):
LenR +=1
else:
found +=1
pNoteDur.append(LenR)
for a in range (0,len(Rtm)):
if Rtm[a]==1:
LenR = 1; found = 0
if (a<len(Rtm)-1):
for b in range (a+1,len(Rtm)):
if (Rtm[b]==0) and (found==0):
LenR +=1
else:
found +=1
pNoteDur.append(LenR)
if Progression==4:
pNoteDur = [2,2,1,1,1,1,3,3,2,2,2,1,1,1,1,2,2,2,2,2,2,1,1,1,1,1,2,2,3,2,2,1,1,1,3,2,2,2]
Mx_save = 999999
save_Dist=[]; save_Rep=[]
ChangeCdtn=0
found=0
for mm in range (0,MTrials):
#if FreeRhythm==True:
# notes_save = GetMelody(Scale,len(pNoteDur),InRests)
#else:
# notes_save = GetMelody(Scale,38,[0,9,19,29],[[1,69,72,81],[20,72,74,76],[37,72]],[[1,6,10]])
llim=mm*64
ulim=llim+len(pNoteDur)
#print(mm,pNoteDur,'\n')
notes_save = GetMelody(Scale,len(pNoteDur),numbers[llim:ulim],InRests,ChLock,MelLock)
#MusDist = FFTdist(notes_save,pNoteDur,UnivFreq,False)
#AbsFFT = numpy.abs(MusDist-1.3)
AbsFFT = MaxJump(notes_save,pNoteDur)
if AbsFFT<Mx_save:
pNoteSeq = notes_save
Mx_save = AbsFFT
return pNoteDur,pNoteSeq
def SoloBuild(Sc,numbers):
BuildM=[]
sNote = numbers[0]%len(Sc)
sDir = numbers[0]%2
Inflections = [numbers[1]%64,numbers[3]%64,numbers[5]%64]
Breaks = [15,47]
TopNoteAllowed=1
used=0
for a in range (0,64):
if a in Breaks:
BuildM.append(-1)
else:
BuildM.append(Sc[sNote])
if a in Inflections:
sDir = (sDir+1)%2
if (sDir==1 and sNote==0) or (sNote==(len(Sc)-1) and sDir==0):
sDir = (sDir+1)%2
if sDir==0:
sNote += 1
if sDir==1:
sNote += -1
if (TopNoteAllowed<2 and sNote==(len(Sc)-1)):
sNote += -3
sDir = (sDir+1)%2
used+=1
if (TopNoteAllowed==2 and sNote==(len(Sc)-1)) or used==1:
TopNoteAllowed = (TopNoteAllowed+1)%3
used=0
return BuildM
def SuperSoloBuild(Sc,idx,rnum):
Breaks = [15,47]
Mx_save = 999999
x_dur=[]
for a in range (0,64):
x_dur.append(1)
Save_FFT=[]
for mm in range (0,idx):
x_solo=[]
xf_solo=[]
llim=mm*64
ulim=llim+64
numbers = rnum[llim:ulim]
sNote = numbers[0]%len(Sc)
sDir = numbers[0]%2
Inflections = [numbers[1]%64,numbers[3]%64,numbers[5]%64]
TopNoteAllowed=1
used=0
for a in range (0,64):
if a in Breaks:
x_solo.append(-1)
xf_solo.append(saveval)
else:
saveval = Sc[sNote]
x_solo.append(Sc[sNote])
xf_solo.append(saveval)
if a in Inflections:
sDir = (sDir+1)%2
if (sDir==1 and sNote==0) or (sNote==(len(Sc)-1) and sDir==0):
sDir = (sDir+1)%2
if sDir==0:
sNote += 1
if sDir==1:
sNote += -1
if (TopNoteAllowed<2 and sNote==(len(Sc)-1)):
sNote += -3
sDir = (sDir+1)%2
used+=1
if (TopNoteAllowed==2 and sNote==(len(Sc)-1)) or used==1:
TopNoteAllowed = (TopNoteAllowed+1)%3
used=0
SoloFFT = FFTdist(xf_solo,x_dur,UnivFreq,False)
#Save_FFT.append(SoloFFT)
AbsFFT = numpy.abs(SoloFFT-1.5)
if AbsFFT<Mx_save:
pNoteSeq = x_solo
Mx_save = AbsFFT
#print(numpy.nanmin(Save_FFT),numpy.nanmax(Save_FFT))
return pNoteSeq
def SuperBuild(Sc,idx,rnum):
Mx_save = -999999
x_dur=[]
ChangeSeq = [-2,-1,1,2]
Breaks = [15,47]
for a in range (0,64):
x_dur.append(1)
for mm in range (0,idx):
x_solo=[]
xf_solo=[]
llim=mm*64
ulim=llim+64
numbers = rnum[llim:ulim]
CurrIdx = 66# = 72 in midi numbers[0]%len(Sc)
for a in range (0,64):
if a in Breaks:
x_solo.append(-1)
xf_solo.append(saveval)
else:
saveval = Sc[CurrIdx]
x_solo.append(saveval)
xf_solo.append(saveval)
CurrIdx += ChangeSeq[int(numbers[a]/64)]
#x_solo.append(Sc[numbers[a]%len(Sc)])
#x_dur = numpy.ones(64)
SoloFFT = FFTdist(xf_solo,x_dur,UnivFreq,False)
if SoloFFT>Mx_save:
pNoteSeq = x_solo
Mx_save = SoloFFT
return pNoteSeq
#more trials but also limit jumps strictly and still include the breaks longer pan flute sustain 30 io 0. **suspend before chord transition by knowing 1 ahead and doing a sequence of 4 claps
#second starting position for each "riff"???
#scale width proportional to coherence also...!!!!!
#can add notes to the solo possibility like 2 notes at once maybe
#key up and generate new each time
#swingy style in drums and stuff as alternate version
#do solo WHEN hits coherence...only permitted on certain cycles
#limit number of times highest note can be reached
#could also use beta for solo calculation here and do many simulations...may be overkill. actually yeah...do this every time event triggers "solo"
#spir type celtic mus
#still chi sq of the actual z scores means that come out ea song chg
ChordSeqStrings = ['C','Bb','F','F']
ChordInvStrings = [2,2,3,3]
ChordOctStrings = [-1,-1,-2,-2]
#ChordOctStrings = [0,0,-1,-1]
ChordDurStrings = [16,16,16,16]
ChordSeqPiano = ['C','C','C','C','C','Bb','Bb','Bb','Bb','Bb','F','F','F','F','F','F','F','F','F','F']
ChordInvPiano = [1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2]
ChordOctPiano = [1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0]
ChordDurPiano = [3,3,4,3,3,3,3,4,3,3,3,3,4,3,3,3,3,4,3,3]
#ChordSeqStrings = ChordSeqStrings*2
#ChordInvStrings = ChordInvStrings*2
#ChordOctStrings = ChordOctStrings*2
#ChordDurStrings = ChordDurStrings*2
#ChordSeqPiano = ChordSeqPiano*2
#ChordInvPiano = ChordInvPiano*2
#ChordOctPiano = ChordOctPiano*2
#ChordDurPiano = ChordDurPiano*2
#Mtrials,(scale),(pxcloud),progression_type,Numbers!!! -> noteDur noteSeq
"""
ScaleMods = [0,2,3,4,7,9]
ScaleFull = []
for a in range (-5,15):
ll=a*12
for b in range (0,len(ScaleMods)):
ScaleFull.append(ll+ScaleMods[b])
"""
ScaleMods = [60,62,64,67,69,72,74,75,76,79,81,84,81,79,76,75,74,72,69,67,64,62]
ScaleFull = ScaleMods*20
stoRC,stoB = RNG_Bulk()
NoteDur, NoteSeq = GetNotes(1,RNGfreq,stoB)#initializing with trails=1000
#Solo = SoloBuild(SoloScale,stoB)
Solo = SuperSoloBuild(ScaleFull,RNGfreq,stoB)
fs.program_select(0, sfid0, 0, 99)
#fs.cc(0, 1, 0)
#fs.cc(0, 7, 127)
fs.cc(0, 91, 127)
fs.cc(0, 64, 0)
fs1.program_select(0, sfid1, 0, 75)
#fs1.cc(0, 1, 0)
#fs1.cc(0, 7, 127)
fs1.cc(0, 91, 127)
fs1.cc(0, 64, 60)
fs2.program_select(0, sfid2, 0, 50)#50 89
#fs1.cc(0, 1, 0)
#fs1.cc(0, 7, 127)
fs2.cc(0, 91, 127)
fs2.cc(0, 64, 0)
fs3.program_select(0, sfid3, 24, 0)
#fs1.cc(0, 1, 0)
#fs1.cc(0, 7, 127)
fs3.cc(0, 91, 127)
fs3.cc(0, 64, 0)
fs4.program_select(0, sfid4, 0, 0)
#fs1.cc(0, 1, 0)
#fs1.cc(0, 7, 127)
fs4.cc(0, 91, 127)
fs4.cc(0, 64, 100)
#https://bspaans.github.io/python-mingus/doc/wiki/refMingusMidiPyfluidsynth.html
LoopInf=True
#while LoopInf==True:
ChordOn=False
ChordOnP=False
ModCount=0
cyc=0
Mcyc = None
FutureType = 2
MeanDev = []
SoloCyc = [-1]
#concurrent.futures.ProcessPoolExecutor().submit(RNG_Bulk, 0)
#time.sleep(30)
concurrent.futures.ThreadPoolExecutor().submit(PlayHat)
concurrent.futures.ThreadPoolExecutor().submit(PlayKick)
concurrent.futures.ThreadPoolExecutor().submit(PlayClap)
time.sleep(3)
while LoopInf==True:
cntr=0
scnt=0
Mcnt=0
cntrC=0
scntC=0
McntC=0
cntrCp=0
scntCp=0
McntCp=0
p1 = concurrent.futures.ThreadPoolExecutor().submit(RNG_Bulk)
for a in range (0,numpy.sum(NoteDur)):
if cyc in SoloCyc:
if a%16 in SoloAccentIdx:
ivolume = 127
else:
ivolume = 100
sid = Solo[a]+ModCount
fs4.noteon(0, sid, ivolume)
if (cntr==Mcnt):
if NoteSeq[scnt]>=0:
if 0<=cyc<=3:
fs4.noteon(0, NoteSeq[scnt],100)
fs.noteon(0, NoteSeq[scnt], 80)
if (cyc>=4) and (cyc not in SoloCyc):
fs.noteon(0, NoteSeq[scnt], 50)
fs1.noteon(0, NoteSeq[scnt], 127)
Mcnt=NoteDur[scnt]
scnt+=1
cntr=0
cntr+=1
if cyc>3:
if (a%4==2):
concurrent.futures.ThreadPoolExecutor().submit(PlayHat)
if (a%4==0):
concurrent.futures.ThreadPoolExecutor().submit(PlayKick)
if cyc>1:
if (a%8==4):
concurrent.futures.ThreadPoolExecutor().submit(PlayClap)
if (cntrC==McntC):
if (ChordOn==True) and (ChordPluck==False):
fs2.noteoff(0, AN[0])
fs2.noteoff(0, AN[1])
fs2.noteoff(0, AN[2])
#print(AN,ModCount)
AN = ChordID(ChordSeqStrings[scntC],ChordOctStrings[scntC],ChordInvStrings[scntC])
AN = numpy.array(AN)+ModCount
fs2.noteon(0, AN[0], 50)
fs2.noteon(0, AN[1], 50)
fs2.noteon(0, AN[2], 50)
ChordOn=True
McntC=ChordDurStrings[scntC]
scntC+=1
cntrC=0
cntrC+=1
if (cntrCp==McntCp):
if (ChordOnP==True) and (ChordPluck==False):
fs3.noteoff(0, ANpiano[0])
fs3.noteoff(0, ANpiano[1])
fs3.noteoff(0, ANpiano[2])
#print(ANpiano)
ANpiano = ChordID(ChordSeqPiano[scntCp],ChordOctPiano[scntCp],ChordInvPiano[scntCp])
ANpiano = numpy.array(ANpiano)+ModCount
if numpy.amax(ANpiano)>=82:
ANpiano = numpy.array(ANpiano)-12
if numpy.amax(ANpiano)>=82:
print(numpy.amax(ANpiano))
if (cyc>1) and (cyc not in SoloCyc):
fs3.noteon(0, ANpiano[0], 55)
fs3.noteon(0, ANpiano[1], 55)
fs3.noteon(0, ANpiano[2], 55)
ChordOnP=True
McntCp=ChordDurPiano[scntCp]
scntCp+=1
cntrCp=0
cntrCp+=1
time.sleep(PluckSpd)
fs.noteoff(0, NoteSeq[scnt-1])
fs1.noteoff(0, NoteSeq[scnt-1])
fs4.noteoff(0, NoteSeq[scnt-1])
#fs1.noteoff(0, NoteSeq[scnt-1]+12)
if (ChordOn==True) and (ChordPluck==True):
fs2.noteoff(0, AN[0])
fs2.noteoff(0, AN[1])
fs2.noteoff(0, AN[2])
fs3.noteoff(0, ANpiano[0])
fs3.noteoff(0, ANpiano[1])
fs3.noteoff(0, ANpiano[2])
#time.sleep((NoteDur[a]*NoteSpeed)+((NoteDur[a]-1)*PluckSpd))
time.sleep(NoteSpeed)
#time.sleep(0.2)
stoRC,stoB = p1.result()
MeanDev.append(stoRC)
ActionZ = (stoRC-(256*RNGfreq))/((512*RNGfreq*0.25)**0.5)
TotalDev = numpy.sum(MeanDev)
NDev = len(MeanDev)
MeanZ = (TotalDev-(NDev*256*RNGfreq)) / ((NDev*512*RNGfreq*0.25)**0.5)
if (numpy.abs(MeanZ)>=SoloZ) and ((cyc-SoloCyc[-1])>8):
SoloCyc = [cyc+1,cyc+2,cyc+3,cyc+4]
cyc+=1
if ActionZ >= ThresholdZ:
if cyc not in SoloCyc:
cntr=0
scnt=0
Mcnt=0
cntrC=0
scntC=0
McntC=0
cntrCp=0
scntCp=0
McntCp=0
for a in range (0,numpy.sum(NoteDur)):
#if cyc in SoloCyc:
# sid = Solo[a]+ModCount
# fs4.noteon(0, sid, 100)
if (cntr==Mcnt):
if NoteSeq[scnt]>=0:
if 0<=cyc<=3:
fs4.noteon(0, NoteSeq[scnt],100)
fs.noteon(0, NoteSeq[scnt], 80)
if (cyc>=4) and (cyc not in SoloCyc):
fs.noteon(0, NoteSeq[scnt], 50)
fs1.noteon(0, NoteSeq[scnt], 127)
Mcnt=NoteDur[scnt]
scnt+=1
cntr=0
cntr+=1
if a<32:
if (a%4==2):
concurrent.futures.ThreadPoolExecutor().submit(PlayHat)
if (a%4==0):
concurrent.futures.ThreadPoolExecutor().submit(PlayKick)
if (a%8==4):
concurrent.futures.ThreadPoolExecutor().submit(PlayClap)
else:
if (a%4==0):
concurrent.futures.ThreadPoolExecutor().submit(PlayKick)
if (cntrC==McntC) and (a<32):
fs2.noteoff(0, AN[0])
fs2.noteoff(0, AN[1])
fs2.noteoff(0, AN[2])
AN = ChordID(ChordSeqStrings[scntC],ChordOctStrings[scntC],ChordInvStrings[scntC])
AN = numpy.array(AN)+ModCount
fs2.noteon(0, AN[0], 50)
fs2.noteon(0, AN[1], 50)
fs2.noteon(0, AN[2], 50)
McntC=ChordDurStrings[scntC]
scntC+=1
cntrC=0
cntrC+=1
if (cntrCp==McntCp):
fs3.noteoff(0, ANpiano[0])
fs3.noteoff(0, ANpiano[1])
fs3.noteoff(0, ANpiano[2])
ANpiano = ChordID(ChordSeqPiano[scntCp],ChordOctPiano[scntCp],ChordInvPiano[scntCp])
ANpiano = numpy.array(ANpiano)+ModCount
if numpy.amax(ANpiano)>=82:
ANpiano = numpy.array(ANpiano)-12
if numpy.amax(ANpiano)>=82:
print(numpy.amax(ANpiano))
if (cyc>1) and (cyc not in SoloCyc):
fs3.noteon(0, ANpiano[0], 55)
fs3.noteon(0, ANpiano[1], 55)
fs3.noteon(0, ANpiano[2], 55)
ChordOnP=True
McntCp=ChordDurPiano[scntCp]
scntCp+=1
cntrCp=0
cntrCp+=1
time.sleep(PluckSpd)
fs.noteoff(0, NoteSeq[scnt-1])
fs1.noteoff(0, NoteSeq[scnt-1])
fs4.noteoff(0, NoteSeq[scnt-1])
#fs1.noteoff(0, NoteSeq[scnt-1]+12)
if (ChordOn==True) and (ChordPluck==True):
fs2.noteoff(0, AN[0])
fs2.noteoff(0, AN[1])
fs2.noteoff(0, AN[2])
fs3.noteoff(0, ANpiano[0])
fs3.noteoff(0, ANpiano[1])
fs3.noteoff(0, ANpiano[2])
#time.sleep((NoteDur[a]*NoteSpeed)+((NoteDur[a]-1)*PluckSpd))
time.sleep(NoteSpeed)
if numpy.amax(NoteSeq)>=85:
NoteSeq = numpy.array(NoteSeq)+(ModAmount-12)
else:
NoteSeq = numpy.array(NoteSeq)+ModAmount
ModCount += ModAmount
fs2.noteoff(0, AN[0])
fs2.noteoff(0, AN[1])
fs2.noteoff(0, AN[2])
fs3.noteoff(0, ANpiano[0])
fs3.noteoff(0, ANpiano[1])