def create_midi(m): # Convert to MIDI easyMIDI = EasyMIDI() track1 = Track("Acoustic Guitar (nylon)", tempo=180) unique_x = m[4][0].astype(int) # Keep track of x coordinate chord_counter = 0 chord_notes = [] for i in range(len(m[0]) - 1): next_x = m[4][i + 1].astype(int) if abs(unique_x - next_x) < 5: # Duplicate or possible chord found chord_counter += 1 # Increment counter else: unique_x = next_x if chord_counter > 0: # if False: for j in range(chord_counter + 1): N = Note(m[0][i - j], m[1][i - j].astype(int), m[2][i - j].astype(float)) chord_notes.append(N) chord = Chord(chord_notes) track1.addNote(chord) chord_notes = [] chord_counter = 0 else: N = Note(m[0][i], m[1][i].astype(int), m[2][i].astype(float)) track1.addNote(N) easyMIDI.addTrack(track1) easyMIDI.writeMIDI("output.mid")
def transcribe(file): easyMIDI = EasyMIDI() track1 = Track("acoustic grand piano") num = file[:-4] file = file[:-4] + "_to_chords.txt" f = open(file, "r") lines = f.readlines() #formatted like 'Cdim:\tC\tD#\tF#\tA\t\n' for chord in lines: aList = [] appeared = [] chord = chord.split("\t")[1:-1] for note in chord: if note not in appeared: temp = Note(note, 4, 1 / 4, 100) appeared.append(note) else: temp = Note(note, 5, 1 / 4, 100) aList.append(temp) chord = Chord(aList) track1.addNote(chord) easyMIDI.addTrack(track1) easyMIDI.writeMIDI("output" + "_" + num + ".mid") file = "output" + "_" + num + ".mid" f.close() return file
def planB(track, chordPredict, durat_list): for i, val in enumerate(chordPredict): if i >= len(durat_list): break N = getManyNamedNotes(RomanChord(val).getNotes()) for k, val2 in enumerate(durat_list[i]): if val2 == 0: break m = Note(N[0][:-1], octave=int(N[0][-1]), duration=val2, volume=100) p = Note(N[1][:-1], octave=int(N[1][-1]), duration=val2, volume=100) q = Note(N[2][:-1], octave=int(N[2][-1]), duration=val2, volume=100) mQ = Chord([m, q]) if dna[i * 3 + k] == 'A': track.addNote(m) elif dna[i * 3 + k] == 'T': track.addNote(p) elif dna[i * 3 + k] == 'C': track.addNote(q) elif dna[i * 3 + k] == 'G': track.addChord(mQ)
def run(self): global yinlist global playFlag global endFlag while(endFlag is False): if yinlist != [] and playFlag is True: name = [] vol = 100 easyMIDI = EasyMIDI() track = Track("acoustic grand piano") for item in yinlist: dur = [] octave = [] if item[0] == 1: octave = 1 if item[0] == 1.5: octave = 2 if item[0] == 2: octave = 3 if item[0] == 2.5: octave = 4 if item[0] == 3: octave = 5 if item[0] == 3.5: octave = 6 if item[0] == 4: octave = 7 if item[1] == 0: dur = 1/2 if item[1] == 1: dur = 1/4 if item[1] == 2: dur = 1/8 if item[1] == 3: name = "F" if item[1] == 4: name = "G" if item[1] == 10: name = "C" if name == []: #如果没有谱号 print("name of Note is None!",sys._getframe().f_lineno,sys._getframe().f_code.co_name) else: if dur != [] and octave != []: pitch = Note(name,octave,dur,vol) track.addNotes(pitch) easyMIDI.addTrack(track) easyMIDI.writeMIDI("example.mid") file = r'example.mid' pygame.mixer.init() print("play music") track = pygame.mixer.music.load(file) pygame.mixer.music.play() while pygame.mixer.music.get_busy(): pass pygame.mixer.music.stop() os.remove("example.mid") else: time.sleep(1)
def playRandomNote(): newPitch = EasyMIDI() note = Track("acoustic grand piano") notes = ['A', 'B', 'C', 'D', 'E', 'F', 'G'] i = random.randint(0, 6) singleNote = Note(notes[i], octave=5, duration=1, volume=90) note.addNotes([singleNote]) newPitch.addTrack(note) newPitch.writeMIDI('pitch.mid')
def to_midi(self): easy_midi = EasyMIDI() track1 = Track("acoustic grand piano") notes = [] for i in range(len(self.notes)): note_name = self.notes[i] note_octave = self.octaves[i] duration = self.durations[i] volume = self.volumes[i] note = Note(note_name, octave=note_octave, duration=duration, volume=volume) notes.append(note) track1.addNotes(notes) easy_midi.addTrack(track1) out_str = io.BytesIO() easy_midi.midFile.writeFile(out_str) data = out_str.getvalue() out_str.close() return base64.b64encode(data).decode('ascii')
sequence.append(current_state) n_tracks = len(sequence[0]) - 1 tracks = [[] for i in range(n_tracks)] for state in sequence: for i in range(n_tracks): pitch = state[i] duration = state[-1] if pitch > 0: tracks[i].append([pitch, duration]) else: tracks[i][-1][1] += duration notes = ['C', 'C#', 'D', 'Eb', 'E', 'F', 'F#', 'G', 'Ab', 'A', 'Bb', 'B'] easyMIDI = EasyMIDI() for voice in tracks: track = Track("choir aahs") for note in voice: pitch = note[0] duration = note[1] midi_note = Note(notes[pitch % 12], octave=pitch // 12 - 1, duration=duration / 4, volume=100) track.addNote(midi_note) easyMIDI.addTrack(track) easyMIDI.writeMIDI(sys.argv[2])
def generateNewMusic(MOOD): newSong = EasyMIDI() melody = Track("acoustic grand piano") chords = Track("acoustic grand piano") #creates the key notes = ['A', 'B', 'C', 'D', 'E', 'F', 'G'] majMin = random.randint(0, 1) #0 for minor, 1 for major baseNote = random.randint(0, 6) #ABCDEFG baseScale = generateScale(notes[baseNote], majMin) #generate chord beat baseBeat = generateBaseBeat() #generate melody beat melodyRhyth = generateMelodyRhythm(len(baseBeat[0])) #generate chords getChords = generateChords(baseBeat) #generate melody pitches = generateMelodyPitch(baseScale, melodyRhyth) #add notes to melody for i in range(len(pitches)): if MOOD == 0: vol = random.randint(50, 100) elif MOOD == 1: vol = random.randint(50, 90) elif MOOD == 2: vol = random.randint(90, 100) else: vol = random.randint(50, 80) newNote = Note(pitches[i], octave=5, duration=melodyRhyth[i] / 4, volume=vol) melody.addNotes([newNote]) #formats into boolean for chords if majMin == 0: majMin = False else: majMin = True #flattens chord list and gets durations newGetChords, chordDurations = generateChordDurations(getChords) chordOctave = random.randint(2, 4) #hardcoded chord volumes based on if powerful if MOOD == 2 or MOOD == 0: vol = random.randint(80, 100) else: vol = random.randint(40, 90) for i in range(len(newGetChords)): chords.addNotes( RomanChord(newGetChords[i], octave=chordOctave, duration=chordDurations[i], key=notes[baseNote], major=majMin, volume=vol)) #place tracks into file newSong.addTrack(melody) newSong.addTrack(chords) newSong.writeMIDI('output.mid') #for debugging purposes # print(getChords) # print(melodyRhyth) # print(pitches) # print("MajorBool: " + str(majMin)) # print(newGetChords) # print(chordDurations) chordProgression = getChordProgression(getChords) #returns raw data so it is judged print(notes[baseNote], majMin, chordProgression, melodyRhyth, pitches) return notes[baseNote], majMin, chordProgression, melodyRhyth, pitches
def __init__(self, genre): ### Definition des notes self.c2 = Note('C', octave=3, duration=1 / 4, volume=100) # DO2 self.c2d = Note('C#', octave=3, duration=1 / 4, volume=100) self.d2 = Note('D', octave=3, duration=1 / 4, volume=100) self.d2d = Note('D#', octave=3, duration=1 / 4, volume=100) self.e2 = Note('E', octave=3, duration=1 / 4, volume=100) self.f2 = Note('F', octave=3, duration=1 / 4, volume=100) self.f2d = Note('F#', octave=3, duration=1 / 4, volume=100) self.g2 = Note('G', octave=3, duration=1 / 4, volume=100) self.g2d = Note('G#', octave=3, duration=1 / 4, volume=100) self.a2 = Note('A', octave=3, duration=1 / 4, volume=100) self.a2d = Note('A#', octave=3, duration=1 / 4, volume=100) self.b2 = Note('B', octave=3, duration=1 / 4, volume=100) self.c3 = Note('C', octave=4, duration=1 / 4, volume=100) # DO3 self.c3d = Note('C#', octave=4, duration=1 / 4, volume=100) self.d3 = Note('D', octave=4, duration=1 / 4, volume=100) self.d3d = Note('D#', octave=4, duration=1 / 4, volume=100) self.e3 = Note('E', octave=4, duration=1 / 4, volume=100) self.f3 = Note('F', octave=4, duration=1 / 4, volume=100) self.f3d = Note('F#', octave=4, duration=1 / 4, volume=100) self.g3 = Note('G', octave=4, duration=1 / 4, volume=100) self.g3d = Note('G#', octave=4, duration=1 / 4, volume=100) self.a3 = Note('A', octave=4, duration=1 / 4, volume=100) self.a3d = Note('A#', octave=4, duration=1 / 4, volume=100) self.b3 = Note('B', octave=4, duration=1 / 4, volume=100) self.c4 = Note('C', octave=5, duration=1 / 4, volume=100) # DO4 self.c4d = Note('C#', octave=5, duration=1 / 4, volume=100) self.d4 = Note('D', octave=5, duration=1 / 4, volume=100) self.d4d = Note('D#', octave=5, duration=1 / 4, volume=100) self.e4 = Note('E', octave=5, duration=1 / 4, volume=100) self.f4 = Note('F', octave=5, duration=1 / 4, volume=100) self.f4d = Note('F#', octave=5, duration=1 / 4, volume=100) self.g4 = Note('G', octave=5, duration=1 / 4, volume=100) self.g4d = Note('G#', octave=5, duration=1 / 4, volume=100) self.a4 = Note('A', octave=5, duration=1 / 4, volume=100) self.a4d = Note('A#', octave=5, duration=1 / 4, volume=100) self.b4 = Note('B', octave=5, duration=1 / 4, volume=100) ### Definition des gammes self.doma = Gamme('Do majeur', ['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Si']) self.lami = Gamme('La mineur', ['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Si']) self.solma = Gamme('Sol majeur', ['Do', 'Re', 'Mi', 'Fad', 'Sol', 'La', 'Si']) self.mimi = Gamme('Mi mineur', ['Do', 'Re', 'Mi', 'Fad', 'Sol', 'La', 'Si']) self.rema = Gamme('Re majeur', ['Dod', 'Re', 'Mi', 'Fad', 'Sol', 'La', 'Si']) self.simi = Gamme('Si mineur', ['Dod', 'Re', 'Mi', 'Fad', 'Sol', 'La', 'Si']) self.lama = Gamme('La majeur', ['Dod', 'Re', 'Mi', 'Fad', 'Sold', 'La', 'Si']) self.fadmi = Gamme('Fad mineur', ['Dod', 'Re', 'Mi', 'Fad', 'Sold', 'La', 'Si']) self.mima = Gamme('Mi majeur', ['Dod', 'Red', 'Mi', 'Fad', 'Sold', 'La', 'Si']) self.dodmi = Gamme('Dod mineur', ['Dod', 'Red', 'Mi', 'Fad', 'Sold', 'La', 'Si']) self.sima = Gamme('Si majeur', ['Dod', 'Red', 'Mi', 'Fad', 'Sold', 'Lad', 'Si']) self.soldmi = Gamme('Sold mineur', ['Dod', 'Red', 'Mi', 'Fad', 'Sold', 'Lad', 'Si']) self.fadma = Gamme('Fad majeur', ['Dod', 'Red', 'Fa', 'Fad', 'Sold', 'Lad', 'Si']) self.redmi = Gamme('Red mineur', ['Dod', 'Red', 'Fa', 'Fad', 'Sold', 'Lad', 'Si']) self.dodma = Gamme('Dod majeur', ['Do', 'Dod', 'Red', 'Fa', 'Fad', 'Sold', 'Lad']) self.ladmi = Gamme('Lad mineur', ['Do', 'Dod', 'Red', 'Fa', 'Fad', 'Sold', 'Lad']) self.fama = Gamme('Fa majeur', ['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Lad']) self.remi = Gamme('Re mineur', ['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Lad']) self.ladma = Gamme('Lad majeur', ['Do', 'Re', 'Red', 'Fa', 'Sol', 'La', 'Lad']) self.solmi = Gamme('Sol mineur', ['Do', 'Re', 'Red', 'Fa', 'Sol', 'La', 'Lad']) self.redma = Gamme('Red majeur', ['Do', 'Re', 'Red', 'Fa', 'Sol', 'Sold', 'Lad']) self.domi = Gamme('Do mineur', ['Do', 'Re', 'Red', 'Fa', 'Sol', 'Sold', 'Lad']) self.soldma = Gamme('Sold majeur', ['Do', 'Dod', 'Red', 'Fa', 'Sol', 'Sold', 'Lad']) self.fami = Gamme('Fa mineur', ['Do', 'Dod', 'Red', 'Fa', 'Sol', 'Sold', 'Lad']) self.dissonnance = 0 gamme = genre.chooseGenre() print(gamme) dissonnance = genre.dissonanceMoyenne() - 10 self.generate(gamme, dissonnance)
def __init__(self, genre, markov1, markov2): ### Definition des notes self.c2 = Note('C', octave=3, duration=1 / 4, volume=100) # DO2 self.c2d = Note('C#', octave=3, duration=1 / 4, volume=100) self.d2 = Note('D', octave=3, duration=1 / 4, volume=100) self.d2d = Note('D#', octave=3, duration=1 / 4, volume=100) self.e2 = Note('E', octave=3, duration=1 / 4, volume=100) self.f2 = Note('F', octave=3, duration=1 / 4, volume=100) self.f2d = Note('F#', octave=3, duration=1 / 4, volume=100) self.g2 = Note('G', octave=3, duration=1 / 4, volume=100) self.g2d = Note('G#', octave=3, duration=1 / 4, volume=100) self.a2 = Note('A', octave=3, duration=1 / 4, volume=100) self.a2d = Note('A#', octave=3, duration=1 / 4, volume=100) self.b2 = Note('B', octave=3, duration=1 / 4, volume=100) self.c3 = Note('C', octave=4, duration=1 / 4, volume=100) # DO3 self.c3d = Note('C#', octave=4, duration=1 / 4, volume=100) self.d3 = Note('D', octave=4, duration=1 / 4, volume=100) self.d3d = Note('D#', octave=4, duration=1 / 4, volume=100) self.e3 = Note('E', octave=4, duration=1 / 4, volume=100) self.f3 = Note('F', octave=4, duration=1 / 4, volume=100) self.f3d = Note('F#', octave=4, duration=1 / 4, volume=100) self.g3 = Note('G', octave=4, duration=1 / 4, volume=100) self.g3d = Note('G#', octave=4, duration=1 / 4, volume=100) self.a3 = Note('A', octave=4, duration=1 / 4, volume=100) self.a3d = Note('A#', octave=4, duration=1 / 4, volume=100) self.b3 = Note('B', octave=4, duration=1 / 4, volume=100) self.c4 = Note('C', octave=5, duration=1 / 4, volume=100) # DO4 self.c4d = Note('C#', octave=5, duration=1 / 4, volume=100) self.d4 = Note('D', octave=5, duration=1 / 4, volume=100) self.d4d = Note('D#', octave=5, duration=1 / 4, volume=100) self.e4 = Note('E', octave=5, duration=1 / 4, volume=100) self.f4 = Note('F', octave=5, duration=1 / 4, volume=100) self.f4d = Note('F#', octave=5, duration=1 / 4, volume=100) self.g4 = Note('G', octave=5, duration=1 / 4, volume=100) self.g4d = Note('G#', octave=5, duration=1 / 4, volume=100) self.a4 = Note('A', octave=5, duration=1 / 4, volume=100) self.a4d = Note('A#', octave=5, duration=1 / 4, volume=100) self.b4 = Note('B', octave=5, duration=1 / 4, volume=100) ### Definition des gammes self.doma = Gamme('Do majeur', ['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Si']) self.lami = Gamme('La mineur', ['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Si']) self.solma = Gamme('Sol majeur', ['Do', 'Re', 'Mi', 'Fad', 'Sol', 'La', 'Si']) self.mimi = Gamme('Mi mineur', ['Do', 'Re', 'Mi', 'Fad', 'Sol', 'La', 'Si']) self.rema = Gamme('Re majeur', ['Dod', 'Re', 'Mi', 'Fad', 'Sol', 'La', 'Si']) self.simi = Gamme('Si mineur', ['Dod', 'Re', 'Mi', 'Fad', 'Sol', 'La', 'Si']) self.lama = Gamme('La majeur', ['Dod', 'Re', 'Mi', 'Fad', 'Sold', 'La', 'Si']) self.fadmi = Gamme('Fad mineur', ['Dod', 'Re', 'Mi', 'Fad', 'Sold', 'La', 'Si']) self.mima = Gamme('Mi majeur', ['Dod', 'Red', 'Mi', 'Fad', 'Sold', 'La', 'Si']) self.dodmi = Gamme('Dod mineur', ['Dod', 'Red', 'Mi', 'Fad', 'Sold', 'La', 'Si']) self.sima = Gamme('Si majeur', ['Dod', 'Red', 'Mi', 'Fad', 'Sold', 'Lad', 'Si']) self.soldmi = Gamme('Sold mineur', ['Dod', 'Red', 'Mi', 'Fad', 'Sold', 'Lad', 'Si']) self.fadma = Gamme('Fad majeur', ['Dod', 'Red', 'Fa', 'Fad', 'Sold', 'Lad', 'Si']) self.redmi = Gamme('Red mineur', ['Dod', 'Red', 'Fa', 'Fad', 'Sold', 'Lad', 'Si']) self.dodma = Gamme('Dod majeur', ['Do', 'Dod', 'Red', 'Fa', 'Fad', 'Sold', 'Lad']) self.ladmi = Gamme('Lad mineur', ['Do', 'Dod', 'Red', 'Fa', 'Fad', 'Sold', 'Lad']) self.fama = Gamme('Fa majeur', ['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Lad']) self.remi = Gamme('Re mineur', ['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Lad']) self.ladma = Gamme('Lad majeur', ['Do', 'Re', 'Red', 'Fa', 'Sol', 'La', 'Lad']) self.solmi = Gamme('Sol mineur', ['Do', 'Re', 'Red', 'Fa', 'Sol', 'La', 'Lad']) self.redma = Gamme('Red majeur', ['Do', 'Re', 'Red', 'Fa', 'Sol', 'Sold', 'Lad']) self.domi = Gamme('Do mineur', ['Do', 'Re', 'Red', 'Fa', 'Sol', 'Sold', 'Lad']) self.soldma = Gamme('Sold majeur', ['Do', 'Dod', 'Red', 'Fa', 'Sol', 'Sold', 'Lad']) self.fami = Gamme('Fa mineur', ['Do', 'Dod', 'Red', 'Fa', 'Sol', 'Sold', 'Lad']) self.markov = [] # tableau de markov self.markovtps = [] # tab de markov pour le temps for i in range(36): self.markov.append([0] * 36) self.markov = markov1[:] gamme = genre.chooseGenre() self.generate(gamme)
def generate(dna): DNA = Seq(dna, IUPAC.unambiguous_dna) seq = DNA.translate() seq = str(seq) durat_list = rco(dna) print(durat_list) # Generation easyMIDI = EasyMIDI(numTracks=3) track1 = Track('acoustic grand piano') #track2 = Track('FX 5 (brightness)') track2 = Track('Whistle') track3 = Track('String Ensemble 1') key_input = 'C' c2 = Note('C', octave=2, duration=1 / 8, volume=100) d2 = Note('D', 2, 1 / 8) e2 = Note('E', 2, 1 / 8) eflat2 = Note('Eb', 2, 1 / 8) f2 = Note('F', 2, 1 / 8) fsharp2 = Note('F#', 2, 1 / 8) g2 = Note('G', 2, 1 / 8) a2 = Note('A', 2, 1 / 8) b2 = Note('B', 2, 1 / 8) bflat2 = Note('Bb', 2, 1 / 8) #3rd Octave c = Note('C', octave=3, duration=1 / 8, volume=100) d = Note('D', 3, 1 / 8) e = Note('E', 3, 1 / 8) eflat = Note('Eb', 3, 1 / 8) f = Note('F', 3, 1 / 8) fsharp = Note('F#', 3, 1 / 8) g = Note('G', 3, 1 / 8) a = Note('A', 3, 1 / 8) b = Note('B', 3, 1 / 8) bflat = Note('Bb', 3, 1 / 8) #duration=3/8, 3rd Octave d_38 = Note('D', 3, 3 / 8) fsharp_38 = Note('F#', 3, 3 / 8) a_38 = Note('A', 3, 3 / 8) c4_38 = Note('C', 3, 3 / 8) #duration=1/4, 3rd Octave d_14 = Note('D', 3, 1 / 4) fsharp_14 = Note('F#', 3, 1 / 4) a_14 = Note('A', 3, 1 / 4) c4_14 = Note('C', 3, 1 / 4) #4th Octave c4 = Note('C', octave=4, duration=1 / 8, volume=100) d4 = Note('D', 4, 1 / 8) e4 = Note('E', 4, 1 / 8) eflat4 = Note('Eb', 4, 1 / 8) f4 = Note('F', 4, 1 / 8) fsharp4 = Note('F#', 4, 1 / 8) g4 = Note('G', 4, 1 / 8) a4 = Note('A', 4, 1 / 8) b4 = Note('B', 4, 1 / 8) bflat4 = Note('Bb', 4, 1 / 8) #5th Octave c5 = Note('C', 5, 1 / 8) d5 = Note('D', 5, 1 / 8) e5 = Note('E', 5, 1 / 8) eflat5 = Note('Eb', 5, 1 / 8) f5 = Note('F', 5, 1 / 8) fsharp5 = Note('F#', 5, 1 / 8) g5 = Note('G', 5, 1 / 8) a5 = Note('A', 5, 1 / 8) b5 = Note('B', 5, 1 / 8) bflat5 = Note('Bb', 5, 1 / 8) #6th Octave c6 = Note('C', 6, 1 / 8) d6 = Note('D', 6, 1 / 8) e6 = Note('E', 6, 1 / 8) eflat6 = Note('Eb', 6, 1 / 8) f6 = Note('F', 6, 1 / 8) fsharp6 = Note('F#', 6, 1 / 8) g6 = Note('G', 6, 1 / 8) a6 = Note('A', 6, 1 / 8) b6 = Note('B', 6, 1 / 8) bflat6 = Note('Bb', 6, 1 / 8) #chordC = Chord([c,e,g]) #-- a chord of notes C, E and G # Track3 # abcbcbcb pattern Idiv = [c, e, g, e, g, e, g, e] I6div = [e, g, c4, g, c4, g, c4, g] I64div = [g2, c, e, c, e, c, e, c] Idom7div = [c, g, bflat, g, bflat, g, bflat, g] IIdiv = [d, f, a, f, a, f, a, f] II6div = [f2, a2, d, a2, d, a2, d, a2] II64div = [a2, d, f, d, f, d, f, d] IIIdiv = [e, g, b, g, b, g, b, g] IVdiv = [f, a, c4, a, c4, a, c4, a] IV6div = [a2, c, f, c, f, c, f, c] IV64div = [c, f, a, f, a, f, a, f] IV7div = [f2, c, eflat, c, eflat, c, eflat, c] Vdiv = [g2, b2, d, b2, d, b2, d, b2] V6div = [b2, d, g, d, g, d, g, d] V64div = [c, f, a, f, a, f, a, f] V7div = [g2, d, f, d, f, d, f, d] VofVdiv = [d, fsharp, c4, fsharp, c4, fsharp, c4, fsharp] VIdiv = [a2, c, e, c, e, c, e, c] VI6div = [c, e, a, e, a, e, a, e] def set_Duration(chordname, octave, durat): cd = RomanChord(chordname, octave, durat, key_input, True, 100) return cd #regular roman chords I = RomanChord(numeral='I', octave=4, duration=0.25, key=key_input, major=True, volume=100) II = RomanChord(numeral='II', octave=3, duration=0.25, key=key_input, major=True, volume=100) III = RomanChord(numeral='III', octave=3, duration=0.25, key=key_input, major=True, volume=100) IV = RomanChord(numeral='IV', octave=3, duration=0.25, key=key_input, major=True, volume=100) V = RomanChord(numeral='V', octave=3, duration=0.25, key=key_input, major=True, volume=100) VI = RomanChord(numeral='VI', octave=3, duration=0.25, key=key_input, major=True, volume=100) I6 = RomanChord(numeral='I*', octave=3, duration=0.25, key=key_input, major=True, volume=100) I64 = RomanChord(numeral='I**', octave=3, duration=0.25, key=key_input, major=True, volume=100) Idom7 = RomanChord(numeral='Idom7', octave=3, duration=0.25, key=key_input, major=True, volume=100) II6 = RomanChord(numeral='II*', octave=3, duration=0.25, key=key_input, major=True, volume=100) II64 = RomanChord(numeral='II**', octave=3, duration=0.25, key=key_input, major=True, volume=100) IV6 = RomanChord(numeral='IV*', octave=3, duration=0.25, key=key_input, major=True, volume=100) IV64 = RomanChord(numeral='IV**', octave=3, duration=0.25, key=key_input, major=True, volume=100) IV7 = RomanChord(numeral='IVdom7', octave=3, duration=0.25, key=key_input, major=True, volume=100) V6 = RomanChord(numeral='V*', octave=3, duration=0.25, key=key_input, major=True, volume=100) V64 = RomanChord(numeral='V**', octave=3, duration=0.25, key=key_input, major=True, volume=100) V7 = RomanChord(numeral='V7', octave=3, duration=0.25, key=key_input, major=True, volume=100) # VofV = Chord([d,fsharp,a,c4]) # VofV_38 = Chord([d_38,fsharp_38,a_38,c4_38]) # VofV_14 = Chord([d_14,fsharp_14,a_14,c4_14]) VI6 = RomanChord(numeral='VI*', octave=3, duration=0.25, key=key_input, major=True, volume=100) PAC_cadence = [V6, I] chordPredict = [] def Starting_Chord(track): track.addChord(set_Duration('I', 3, 3 / 8)) track.addChord(set_Duration('I', 3, 1 / 8)) track.addChord(set_Duration('I', 3, 1 / 4)) track.addChord(set_Duration('I', 3, 1 / 4)) for letter in seq: if letter == 'S': #I chordPredict.append('I') track2.addChord(set_Duration('I', 4, 3 / 8)) track2.addChord(set_Duration('I', 4, 1 / 8)) track2.addChord(set_Duration('I', 4, 1 / 4)) track2.addChord(set_Duration('I', 4, 1 / 4)) track3.addNote(Idiv) elif letter == 'L': #V chordPredict.append('V') track2.addChord(set_Duration('V', 3, 3 / 8)) track2.addChord(set_Duration('V', 3, 1 / 8)) track2.addChord(set_Duration('V', 3, 1 / 4)) track2.addChord(set_Duration('V', 3, 1 / 4)) track3.addNote(Vdiv) elif letter == 'A': #IV chordPredict.append('IV') track2.addChord(set_Duration('IV', 3, 3 / 8)) track2.addChord(set_Duration('IV', 3, 1 / 8)) track2.addChord(set_Duration('IV', 3, 1 / 4)) track2.addChord(set_Duration('IV', 3, 1 / 4)) track3.addNote(IVdiv) elif letter == 'G': #V7 chordPredict.append('V7') track2.addChord(set_Duration('V7', 3, 3 / 8)) track2.addChord(set_Duration('V7', 3, 1 / 8)) track2.addChord(set_Duration('V7', 3, 1 / 4)) track2.addChord(set_Duration('V7', 3, 1 / 4)) track3.addNote(V7div) elif letter == 'K': #VI chordPredict.append('VI') track2.addChord(set_Duration('VI', 3, 3 / 8)) track2.addChord(set_Duration('VI', 3, 1 / 8)) track2.addChord(set_Duration('VI', 3, 1 / 4)) track2.addChord(set_Duration('VI', 3, 1 / 4)) track3.addNote(VIdiv) elif letter == 'T': #I6 chordPredict.append('I*') track2.addChord(set_Duration('I*', 3, 3 / 8)) track2.addChord(set_Duration('I*', 3, 1 / 8)) track2.addChord(set_Duration('I*', 3, 1 / 4)) track2.addChord(set_Duration('I*', 3, 1 / 4)) track3.addNote(I6div) elif letter == 'D': #V6 chordPredict.append('V*') track2.addChord(set_Duration('V*', 3, 3 / 8)) track2.addChord(set_Duration('V*', 3, 1 / 8)) track2.addChord(set_Duration('V*', 3, 1 / 4)) track2.addChord(set_Duration('V*', 3, 1 / 4)) track3.addNote(V6div) elif letter == 'E': #IV6 chordPredict.append('IV*') track2.addChord(set_Duration('IV*', 3, 3 / 8)) track2.addChord(set_Duration('IV*', 3, 1 / 8)) track2.addChord(set_Duration('IV*', 3, 1 / 4)) track2.addChord(set_Duration('IV*', 3, 1 / 4)) track3.addNote(IV6div) elif letter == 'P': #Idom7 chordPredict.append('Idom7') track2.addChord(set_Duration('Idom7', 3, 3 / 8)) track2.addChord(set_Duration('Idom7', 3, 1 / 8)) track2.addChord(set_Duration('Idom7', 3, 1 / 4)) track2.addChord(set_Duration('Idom7', 3, 1 / 4)) track3.addNote(Idom7div) elif letter == 'N': #VI6 chordPredict.append('VI*') track2.addChord(set_Duration('VI*', 3, 3 / 8)) track2.addChord(set_Duration('VI*', 3, 1 / 8)) track2.addChord(set_Duration('VI*', 3, 1 / 4)) track2.addChord(set_Duration('VI*', 3, 1 / 4)) track3.addNote(VI6div) elif letter == 'R': #II6 chordPredict.append('II*') track2.addChord(set_Duration('II*', 3, 3 / 8)) track2.addChord(set_Duration('II*', 3, 1 / 8)) track2.addChord(set_Duration('II*', 3, 1 / 4)) track2.addChord(set_Duration('II*', 3, 1 / 4)) track3.addNote(II6div) elif letter == 'F': #VofV #VofV = Chord([d,fsharp,a,c4]) # chordPredict.append('V/V') # track2.addChord(VofV_38) # track2.addChord(VofV) # track2.addChord(VofV_14) # track2.addChord(VofV_14) # track3.addNote(VofVdiv) #V chordPredict.append('V') track2.addChord(set_Duration('V', 3, 3 / 8)) track2.addChord(set_Duration('V', 3, 1 / 8)) track2.addChord(set_Duration('V', 3, 1 / 4)) track2.addChord(set_Duration('V', 3, 1 / 4)) track3.addNote(Vdiv) elif letter == 'I': #I64 chordPredict.append('I**') track2.addChord(set_Duration('I**', 3, 3 / 8)) track2.addChord(set_Duration('I**', 3, 1 / 8)) track2.addChord(set_Duration('I**', 3, 1 / 4)) track2.addChord(set_Duration('I**', 3, 1 / 4)) track3.addNote(I64div) elif letter == 'Q': #V64 chordPredict.append('V**') track2.addChord(set_Duration('V**', 3, 3 / 8)) track2.addChord(set_Duration('V**', 3, 1 / 8)) track2.addChord(set_Duration('V**', 3, 1 / 4)) track2.addChord(set_Duration('V**', 3, 1 / 4)) track3.addNote(V64div) #I chordPredict.append('I') track2.addChord(set_Duration('I', 4, 3 / 8)) track2.addChord(set_Duration('I', 4, 1 / 8)) track2.addChord(set_Duration('I', 4, 1 / 4)) track2.addChord(set_Duration('I', 4, 1 / 4)) track3.addNote(Idiv) elif letter == 'C': #IV7 chordPredict.append('IVdom7') track2.addChord(set_Duration('IVdom7', 3, 3 / 8)) track2.addChord(set_Duration('IVdom7', 3, 1 / 8)) track2.addChord(set_Duration('IVdom7', 3, 1 / 4)) track2.addChord(set_Duration('IVdom7', 3, 1 / 4)) track3.addNote(IV7div) elif letter == 'Y': #IV64 chordPredict.append('IV**') track2.addChord(set_Duration('IV**', 3, 3 / 8)) track2.addChord(set_Duration('IV**', 3, 1 / 8)) track2.addChord(set_Duration('IV**', 3, 1 / 4)) track2.addChord(set_Duration('IV**', 3, 1 / 4)) track3.addNote(IV64div) elif letter == 'H': #I chordPredict.append('I') track2.addChord(set_Duration('I', 4, 3 / 8)) track2.addChord(set_Duration('I', 4, 1 / 8)) track2.addChord(set_Duration('I', 4, 1 / 4)) track2.addChord(set_Duration('I', 4, 1 / 4)) track3.addNote(Idiv) #V6 chordPredict.append('V*') track2.addChord(set_Duration('V*', 3, 3 / 8)) track2.addChord(set_Duration('V*', 3, 1 / 8)) track2.addChord(set_Duration('V*', 3, 1 / 4)) track2.addChord(set_Duration('V*', 3, 1 / 4)) track3.addNote(V6div) #VI chordPredict.append('VI') track2.addChord(set_Duration('VI', 3, 3 / 8)) track2.addChord(set_Duration('VI', 3, 1 / 8)) track2.addChord(set_Duration('VI', 3, 1 / 4)) track2.addChord(set_Duration('VI', 3, 1 / 4)) track3.addNote(VIdiv) #IV6 chordPredict.append('IV*') track2.addChord(set_Duration('IV*', 3, 3 / 8)) track2.addChord(set_Duration('IV*', 3, 1 / 8)) track2.addChord(set_Duration('IV*', 3, 1 / 4)) track2.addChord(set_Duration('IV*', 3, 1 / 4)) track3.addNote(IV6div) #I chordPredict.append('I') track2.addChord(set_Duration('I', 4, 3 / 8)) track2.addChord(set_Duration('I', 4, 1 / 8)) track2.addChord(set_Duration('I', 4, 1 / 4)) track2.addChord(set_Duration('I', 4, 1 / 4)) track3.addNote(Idiv) elif letter == 'M': #II64 chordPredict.append('II**') track2.addChord(set_Duration('II**', 3, 3 / 8)) track2.addChord(set_Duration('II**', 3, 1 / 8)) track2.addChord(set_Duration('II**', 3, 1 / 4)) track2.addChord(set_Duration('II**', 3, 1 / 4)) track3.addNote(II64div) elif letter == 'W': #II6 chordPredict.append('II*') track2.addChord(set_Duration('II*', 3, 3 / 8)) track2.addChord(set_Duration('II*', 3, 1 / 8)) track2.addChord(set_Duration('II*', 3, 1 / 4)) track2.addChord(set_Duration('II*', 3, 1 / 4)) track3.addNote(II6div) #V chordPredict.append('V') track2.addChord(set_Duration('V', 3, 3 / 8)) track2.addChord(set_Duration('V', 3, 1 / 8)) track2.addChord(set_Duration('V', 3, 1 / 4)) track2.addChord(set_Duration('V', 3, 1 / 4)) track3.addNote(Vdiv) #I chordPredict.append('I') track2.addChord(set_Duration('I', 4, 3 / 8)) track2.addChord(set_Duration('I', 4, 1 / 8)) track2.addChord(set_Duration('I', 4, 1 / 4)) track2.addChord(set_Duration('I', 4, 1 / 4)) track3.addNote(Idiv) elif letter == '*': continue getNamedNote = lambda note: note.name + str(note.octave) getManyNamedNotes = lambda notes: list(map(getNamedNote, notes)) # print(chordPredict[0]) # print(getManyNamedNotes(RomanChord(chordPredict[0]).getNotes())) def planB(track, chordPredict, durat_list): for i, val in enumerate(chordPredict): if i >= len(durat_list): break N = getManyNamedNotes(RomanChord(val).getNotes()) for k, val2 in enumerate(durat_list[i]): if val2 == 0: break m = Note(N[0][:-1], octave=int(N[0][-1]), duration=val2, volume=100) p = Note(N[1][:-1], octave=int(N[1][-1]), duration=val2, volume=100) q = Note(N[2][:-1], octave=int(N[2][-1]), duration=val2, volume=100) mQ = Chord([m, q]) if dna[i * 3 + k] == 'A': track.addNote(m) elif dna[i * 3 + k] == 'T': track.addNote(p) elif dna[i * 3 + k] == 'C': track.addNote(q) elif dna[i * 3 + k] == 'G': track.addChord(mQ) # Starting_Chord(track1) # Starting_Chord(track2) # Starting_Chord(track3) track2.addChord(PAC_cadence) planB(track1, chordPredict, durat_list) track3.addChord(PAC_cadence) track1.addChord(PAC_cadence) easyMIDI.addTrack(track1) easyMIDI.addTrack(track2) easyMIDI.addTrack(track3) easyMIDI.writeMIDI('output.mid') fs = FluidSynth(sound_font='SGM.sf2', sample_rate=22050) fs.midi_to_audio('output.mid', 'static/output.wav')