s2 = stream.Stream()
for n in range(len(list(testNotesDict))):
noteMidi = testNotesDict[n][0]
noteLength=testNotesDict[n][1]
n = note.Note(midi=noteMidi,quarterLength = noteLength)
s2.append(n)
print("Score of testMidi.mid")
s2.show()
StreamPlayer=midi.realtime.StreamPlayer(s2)
StreamPlayer.play()
python
testPredictions = {1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: []}
for i in range(len(list(testNotesDict))):
pitchBits = encPitch.encode(testNotesDict[i][0])
lengthBits = encLength.encode(testNotesDict[i][1])
inputSDR = SDR( dimensions = (48, ) ).concatenate([pitchBits, lengthBits])
sp.compute(inputSDR, True, activeSDR)
tm.compute( activeSDR, learn=True)
pdf = predictor.infer( tm.getActiveCells() )
for n in (1,2,3,4,5,6,7):
if pdf[n]:
testPredictions[n]=notesDict[list(notesDict)[np.argmax( pdf[n] )] ]
else:
testPredictions[n]=float('nan')
print(testPredictions)
python
s3 = stream.Stream()
for n in range(len(predictions)):
noteMidi = testPredictions[n+1][0]
noteLength=testPredictions[n+1][1]
n = note.Note(midi=noteMidi,quarterLength = noteLength)
s3.append(n)
s3.show()
StreamPlayer=midi.realtime.StreamPlayer(s3)
StreamPlayer.play()