예제 #1
0
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")
예제 #2
0
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
예제 #3
0
 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)
예제 #4
0
파일: main.py 프로젝트: 886yy40/composer
 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)
예제 #5
0
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')
예제 #6
0
 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')
예제 #7
0
    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])
예제 #8
0
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
예제 #9
0
class AleatoireGen:

    # Constructeur
    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)

    # Generation musique
    def generate(self, gamme, dissonnance):
        notes = []
        if gamme == "Do majeur" or gamme == "La mineur":
            notes = self.doma.getNotes()
        if gamme == "Sol majeur" or gamme == "Mi mineur":
            notes = list(self.solma.getNotes())
        if gamme == "Re majeur" or gamme == "Si mineur":
            notes = list(self.redmi.getNotes())
        if gamme == "La majeur" or gamme == "Fa# mineur":
            notes = list(self.lama.getNotes())
        if gamme == "Mi majeur" or gamme == "Do# mineur":
            notes = list(self.mima.getNotes())
        if gamme == "Si majeur" or gamme == "Sol# mineur":
            notes = list(self.sima.getNotes())
        if gamme == "Fa# majeur" or gamme == "Re# mineur":
            notes = list(self.fadma.getNotes())
        if gamme == "Do# majeur" or gamme == "La# mineur":
            notes = list(self.dodma.getNotes())
        if gamme == "Fa majeur" or gamme == "Re mineur":
            notes = list(self.fama.getNotes())
        if gamme == "La# majeur" or gamme == "Sol mineur":
            notes = list(self.ladma.getNotes())
        if gamme == "Re# majeur" or gamme == "Do mineur":
            notes = list(self.redma.getNotes())
        if gamme == "Sol# majeur" or gamme == "Fa mineur":
            notes = list(self.soldma.getNotes())

        counter = 0
        # definition longueur morceau (100 à 200 notes)
        taillemorceau = randrange(100, 200)
        dissonnanceactuelle = 100

        easyMIDI = EasyMIDI()
        track1 = Track("acoustic grand piano")  # oops

        while counter < taillemorceau:
            # On ajoute une note de la gamme
            notesrandom = randrange(0, 7)
            tempsrandom = randrange(0, 5)
            temps = [1, 1 / 2, 1 / 4, 1 / 8, 1 / 16]
            if notes[notesrandom] == "Do":
                hauteur = randrange(1, 4)
                if hauteur == 1:
                    self.c2.setDuration(temps[tempsrandom])
                    track1.addNote(self.c2)
                if hauteur == 2:
                    self.c3.setDuration(temps[tempsrandom])
                    track1.addNote(self.c3)
                if hauteur == 3:
                    self.c4.setDuration(temps[tempsrandom])
                    track1.addNote(self.c4)
            if notes[notesrandom] == "Dod":
                hauteur = randrange(1, 4)
                if hauteur == 1:
                    self.c2d.setDuration(temps[tempsrandom])
                    track1.addNote(self.c2d)
                if hauteur == 2:
                    self.c3d.setDuration(temps[tempsrandom])
                    track1.addNote(self.c3d)
                if hauteur == 3:
                    self.c4d.setDuration(temps[tempsrandom])
                    track1.addNote(self.c4d)
            if notes[notesrandom] == "Re":
                hauteur = randrange(1, 4)
                if hauteur == 1:
                    self.d2.setDuration(temps[tempsrandom])
                    track1.addNote(self.d2)
                if hauteur == 2:
                    self.d3.setDuration(temps[tempsrandom])
                    track1.addNote(self.d3)
                if hauteur == 3:
                    self.d4.setDuration(temps[tempsrandom])
                    track1.addNote(self.d4)
            if notes[notesrandom] == "Red":
                hauteur = randrange(1, 4)
                if hauteur == 1:
                    self.d2d.setDuration(temps[tempsrandom])
                    track1.addNote(self.d2d)
                if hauteur == 2:
                    self.d3d.setDuration(temps[tempsrandom])
                    track1.addNote(self.d3d)
                if hauteur == 3:
                    self.d4d.setDuration(temps[tempsrandom])
                    track1.addNote(self.d4d)
            if notes[notesrandom] == "Mi":
                hauteur = randrange(1, 4)
                if hauteur == 1:
                    self.e2.setDuration(temps[tempsrandom])
                    track1.addNote(self.e2)
                if hauteur == 2:
                    self.e3.setDuration(temps[tempsrandom])
                    track1.addNote(self.e3)
                if hauteur == 3:
                    self.e4.setDuration(temps[tempsrandom])
                    track1.addNote(self.e4)
            if notes[notesrandom] == "Fa":
                hauteur = randrange(1, 4)
                if hauteur == 1:
                    self.f2.setDuration(temps[tempsrandom])
                    track1.addNote(self.f2)
                if hauteur == 2:
                    self.f3.setDuration(temps[tempsrandom])
                    track1.addNote(self.f3)
                if hauteur == 3:
                    self.f4.setDuration(temps[tempsrandom])
                    track1.addNote(self.f4)
            if notes[notesrandom] == "Fad":
                hauteur = randrange(1, 4)
                if hauteur == 1:
                    self.f2d.setDuration(temps[tempsrandom])
                    track1.addNote(self.f2d)
                if hauteur == 2:
                    self.f3d.setDuration(temps[tempsrandom])
                    track1.addNote(self.f3d)
                if hauteur == 3:
                    self.f4d.setDuration(temps[tempsrandom])
                    track1.addNote(self.f4d)
            if notes[notesrandom] == "Sol":
                hauteur = randrange(1, 4)
                if hauteur == 1:
                    self.g2.setDuration(temps[tempsrandom])
                    track1.addNote(self.g2)
                if hauteur == 2:
                    self.g3.setDuration(temps[tempsrandom])
                    track1.addNote(self.g3)
                if hauteur == 3:
                    self.g4.setDuration(temps[tempsrandom])
                    track1.addNote(self.g4)
            if notes[notesrandom] == "Sold":
                hauteur = randrange(1, 4)
                if hauteur == 1:
                    self.g2d.setDuration(temps[tempsrandom])
                    track1.addNote(self.g2d)
                if hauteur == 2:
                    self.g3d.setDuration(temps[tempsrandom])
                    track1.addNote(self.g3d)
                if hauteur == 3:
                    self.g4d.setDuration(temps[tempsrandom])
                    track1.addNote(self.g4d)
            if notes[notesrandom] == "La":
                hauteur = randrange(1, 4)
                if hauteur == 1:
                    self.a2.setDuration(temps[tempsrandom])
                    track1.addNote(self.a2)
                if hauteur == 2:
                    self.a3.setDuration(temps[tempsrandom])
                    track1.addNote(self.a3)
                if hauteur == 3:
                    self.a4.setDuration(temps[tempsrandom])
                    track1.addNote(self.a4)
            if notes[notesrandom] == "Lad":
                hauteur = randrange(1, 4)
                if hauteur == 1:
                    self.a2d.setDuration(temps[tempsrandom])
                    track1.addNote(self.a2d)
                if hauteur == 2:
                    self.a3d.setDuration(temps[tempsrandom])
                    track1.addNote(self.a3d)
                if hauteur == 3:
                    self.a4d.setDuration(temps[tempsrandom])
                    track1.addNote(self.a4d)
            if notes[notesrandom] == "Si":
                hauteur = randrange(1, 4)
                if hauteur == 1:
                    self.b2.setDuration(temps[tempsrandom])
                    track1.addNote(self.b2)
                if hauteur == 2:
                    self.b3.setDuration(temps[tempsrandom])
                    track1.addNote(self.b3)
                if hauteur == 3:
                    self.b4.setDuration(temps[tempsrandom])
                    track1.addNote(self.b4)

            counter = counter + 1
        print("Dissonnance du morceau créé : ", dissonnanceactuelle / 8)
        try:
            os.remove("random.mid")
        except:
            print("N'existe pas encore")
        easyMIDI.addTrack(track1)
        easyMIDI.writeMIDI("random.mid")
        print("Song créé avec succès")
예제 #10
0
    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)
예제 #11
0
 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)
예제 #12
0
class MarkovGen:

    # Constructeur
    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)

    # Generation avec Markov
    def generate(self, gamme):
        noteactuelle = ""
        notes = []
        if gamme == "Do majeur" or gamme == "La mineur":
            notes = self.doma.getNotes()
        if gamme == "Sol majeur" or gamme == "Mi mineur":
            notes = list(self.solma.getNotes())
        if gamme == "Re majeur" or gamme == "Si mineur":
            notes = list(self.redmi.getNotes())
        if gamme == "La majeur" or gamme == "Fa# mineur":
            notes = list(self.lama.getNotes())
        if gamme == "Mi majeur" or gamme == "Do# mineur":
            notes = list(self.mima.getNotes())
        if gamme == "Si majeur" or gamme == "Sol# mineur":
            notes = list(self.sima.getNotes())
        if gamme == "Fa# majeur" or gamme == "Re# mineur":
            notes = list(self.fadma.getNotes())
        if gamme == "Do# majeur" or gamme == "La# mineur":
            notes = list(self.dodma.getNotes())
        if gamme == "Fa majeur" or gamme == "Re mineur":
            notes = list(self.fama.getNotes())
        if gamme == "La# majeur" or gamme == "Sol mineur":
            notes = list(self.ladma.getNotes())
        if gamme == "Re# majeur" or gamme == "Do mineur":
            notes = list(self.redma.getNotes())
        if gamme == "Sol# majeur" or gamme == "Fa mineur":
            notes = list(self.soldma.getNotes())
        total = 0
        for i in range(36):
            for j in range(36):
                total += self.markov[i][j]
            for x in range(36):
                self.markov[i][x] = self.markov[i][x] / total
            total = 0
        for i in range(36):
            print(i, "|", self.markov[i])

        markovtps = ([[0.1, 0.3, 0.6, 0, 0], [0.2, 0.2, 0.5, 0.1, 0],
                      [0.1, 0.1, 0.5, 0.2, 0.1], [0, 0.05, 0.3, 0.6, 0.05],
                      [0, 0.05, 0.3, 0.35, 0.3]])
        print("Gamme du morceau généré : ", gamme)
        Genre.gamme = gamme
        easyMIDI = EasyMIDI()
        track1 = Track("acoustic grand piano")
        temps = [1, 1 / 2, 1 / 4, 1 / 8, 1 / 16]
        tempsrandom = randrange(0, 5)
        # Premiere note aléatoire dans la gamme
        notesrandom = randrange(0, 7)
        tempsactuelle = ""
        if notes[notesrandom] == "Do":
            hauteur = randrange(1, 4)
            if hauteur == 1:
                self.c2.setDuration(temps[tempsrandom])
                track1.addNote(self.c2)
                noteactuelle = 0
                tempsactuelle = tempsrandom
            if hauteur == 2:
                self.c3.setDuration(temps[tempsrandom])
                track1.addNote(self.c3)
                noteactuelle = 12
                tempsactuelle = tempsrandom
            if hauteur == 3:
                self.c4.setDuration(temps[tempsrandom])
                track1.addNote(self.c4)
                noteactuelle = 24
                tempsactuelle = tempsrandom
        if notes[notesrandom] == "Dod":
            hauteur = randrange(1, 4)
            if hauteur == 1:
                self.c2d.setDuration(temps[tempsrandom])
                track1.addNote(self.c2d)
                noteactuelle = 1
                tempsactuelle = tempsrandom
            if hauteur == 2:
                self.c3d.setDuration(temps[tempsrandom])
                track1.addNote(self.c3d)
                noteactuelle = 13
                tempsactuelle = tempsrandom
            if hauteur == 3:
                self.c4d.setDuration(temps[tempsrandom])
                track1.addNote(self.c4d)
                noteactuelle = 25
                tempsactuelle = tempsrandom
        if notes[notesrandom] == "Re":
            hauteur = randrange(1, 4)
            if hauteur == 1:
                self.d2.setDuration(temps[tempsrandom])
                track1.addNote(self.d2)
                noteactuelle = 2
                tempsactuelle = tempsrandom
            if hauteur == 2:
                self.d3.setDuration(temps[tempsrandom])
                track1.addNote(self.d3)
                noteactuelle = 14
                tempsactuelle = tempsrandom
            if hauteur == 3:
                self.d4.setDuration(temps[tempsrandom])
                track1.addNote(self.d4)
                noteactuelle = 26
                tempsactuelle = tempsrandom
        if notes[notesrandom] == "Red":
            hauteur = randrange(1, 4)
            if hauteur == 1:
                self.d2d.setDuration(temps[tempsrandom])
                track1.addNote(self.d2d)
                noteactuelle = 3
                tempsactuelle = tempsrandom
            if hauteur == 2:
                self.d3d.setDuration(temps[tempsrandom])
                track1.addNote(self.d3d)
                noteactuelle = 15
                tempsactuelle = tempsrandom
            if hauteur == 3:
                self.d4d.setDuration(temps[tempsrandom])
                track1.addNote(self.d4d)
                noteactuelle = 27
                tempsactuelle = tempsrandom
        if notes[notesrandom] == "Mi":
            hauteur = randrange(1, 4)
            if hauteur == 1:
                self.e2.setDuration(temps[tempsrandom])
                track1.addNote(self.e2)
                noteactuelle = 4
                tempsactuelle = tempsrandom
            if hauteur == 2:
                self.e3.setDuration(temps[tempsrandom])
                track1.addNote(self.e3)
                noteactuelle = 16
                tempsactuelle = tempsrandom
            if hauteur == 3:
                self.e4.setDuration(temps[tempsrandom])
                track1.addNote(self.e4)
                noteactuelle = 28
                tempsactuelle = tempsrandom
        if notes[notesrandom] == "Fa":
            hauteur = randrange(1, 4)
            if hauteur == 1:
                self.f2.setDuration(temps[tempsrandom])
                track1.addNote(self.f2)
                noteactuelle = 5
                tempsactuelle = tempsrandom
            if hauteur == 2:
                self.f3.setDuration(temps[tempsrandom])
                track1.addNote(self.f3)
                noteactuelle = 17
                tempsactuelle = tempsrandom
            if hauteur == 3:
                self.f4.setDuration(temps[tempsrandom])
                track1.addNote(self.f4)
                noteactuelle = 29
                tempsactuelle = tempsrandom
        if notes[notesrandom] == "Fad":
            hauteur = randrange(1, 4)
            if hauteur == 1:
                self.f2d.setDuration(temps[tempsrandom])
                track1.addNote(self.f2d)
                noteactuelle = 6
                tempsactuelle = tempsrandom
            if hauteur == 2:
                self.f3d.setDuration(temps[tempsrandom])
                track1.addNote(self.f3d)
                noteactuelle = 18
                tempsactuelle = tempsrandom
            if hauteur == 3:
                self.f4d.setDuration(temps[tempsrandom])
                track1.addNote(self.f4d)
                noteactuelle = 30
                tempsactuelle = tempsrandom
        if notes[notesrandom] == "Sol":
            hauteur = randrange(1, 4)
            if hauteur == 1:
                self.g2.setDuration(temps[tempsrandom])
                track1.addNote(self.g2)
                noteactuelle = 7
                tempsactuelle = tempsrandom
            if hauteur == 2:
                self.g3.setDuration(temps[tempsrandom])
                track1.addNote(self.g3)
                noteactuelle = 19
                tempsactuelle = tempsrandom
            if hauteur == 3:
                self.g4.setDuration(temps[tempsrandom])
                track1.addNote(self.g4)
                noteactuelle = 31
                tempsactuelle = tempsrandom
        if notes[notesrandom] == "Sold":
            hauteur = randrange(1, 4)
            if hauteur == 1:
                self.g2d.setDuration(temps[tempsrandom])
                track1.addNote(self.g2d)
                noteactuelle = 8
                tempsactuelle = tempsrandom
            if hauteur == 2:
                self.g3d.setDuration(temps[tempsrandom])
                track1.addNote(self.g3d)
                noteactuelle = 20
                tempsactuelle = tempsrandom
            if hauteur == 3:
                self.g4d.setDuration(temps[tempsrandom])
                track1.addNote(self.g4d)
                noteactuelle = 32
                tempsactuelle = tempsrandom
        if notes[notesrandom] == "La":
            hauteur = randrange(1, 4)
            if hauteur == 1:
                self.a2.setDuration(temps[tempsrandom])
                track1.addNote(self.a2)
                noteactuelle = 9
                tempsactuelle = tempsrandom
            if hauteur == 2:
                self.a3.setDuration(temps[tempsrandom])
                track1.addNote(self.a3)
                noteactuelle = 21
                tempsactuelle = tempsrandom
            if hauteur == 3:
                self.a4.setDuration(temps[tempsrandom])
                track1.addNote(self.a4)
                noteactuelle = 33
                tempsactuelle = tempsrandom
        if notes[notesrandom] == "Lad":
            hauteur = randrange(1, 4)
            if hauteur == 1:
                self.a2d.setDuration(temps[tempsrandom])
                track1.addNote(self.a2d)
                noteactuelle = 10
                tempsactuelle = tempsrandom
            if hauteur == 2:
                self.a3d.setDuration(temps[tempsrandom])
                track1.addNote(self.a3d)
                noteactuelle = 22
                tempsactuelle = tempsrandom
            if hauteur == 3:
                self.a4d.setDuration(temps[tempsrandom])
                track1.addNote(self.a4d)
                noteactuelle = 34
                tempsactuelle = tempsrandom
        if notes[notesrandom] == "Si":
            hauteur = randrange(1, 4)
            if hauteur == 1:
                self.b2.setDuration(temps[tempsrandom])
                track1.addNote(self.b2)
                noteactuelle = 11
                tempsactuelle = tempsrandom
            if hauteur == 2:
                self.b3.setDuration(temps[tempsrandom])
                track1.addNote(self.b3)
                noteactuelle = 23
                tempsactuelle = tempsrandom
            if hauteur == 3:
                self.b4.setDuration(temps[tempsrandom])
                track1.addNote(self.b4)
                noteactuelle = 35
                tempsactuelle = tempsrandom

        taillemorceau = randrange(100, 200)
        counter = 0
        # on se base sur la premiere note pour generer les suivantes :
        while taillemorceau > counter:
            # selectionne la bonne ligne
            tab = np.array(self.markov[noteactuelle])
            tabtps = np.array(markovtps[tempsactuelle])

            # suit la loi de probabilité et selectionne une valeur
            notesuivantetab = np.random.choice(36, 1, p=tab)
            tempssuivanttab = np.random.choice(5, 1, p=tabtps)

            # récupération de la valeur
            notesuivante = int(notesuivantetab[0])
            tempssuivant = int(tempssuivanttab[0])

            if notesuivante == 0 and "Do" in notes:
                self.c2.setDuration(temps[tempssuivant])
                track1.addNote(self.c2)
                counter += 1
            if notesuivante == 1 and "Dod" in notes:
                self.c2d.setDuration(temps[tempssuivant])
                track1.addNote(self.c2d)
                counter += 1
            if notesuivante == 2 and "Re" in notes:
                self.d2.setDuration(temps[tempssuivant])
                track1.addNote(self.d2)
                counter += 1
            if notesuivante == 3 and "Red" in notes:
                self.d2d.setDuration(temps[tempssuivant])
                track1.addNote(self.d2d)
                counter += 1
            if notesuivante == 4 and "Mi" in notes:
                self.e2.setDuration(temps[tempssuivant])
                track1.addNote(self.e2)
                counter += 1
            if notesuivante == 5 and "Fa" in notes:
                self.f2.setDuration(temps[tempssuivant])
                track1.addNote(self.f2)
                counter += 1
            if notesuivante == 6 and "Fad" in notes:
                self.f2d.setDuration(temps[tempssuivant])
                track1.addNote(self.f2d)
                counter += 1
            if notesuivante == 7 and "Sol" in notes:
                self.g2.setDuration(temps[tempssuivant])
                track1.addNote(self.g2)
                counter += 1
            if notesuivante == 8 and "Sold" in notes:
                self.g2d.setDuration(temps[tempssuivant])
                track1.addNote(self.g2d)
                counter += 1
            if notesuivante == 9 and "La" in notes:
                self.a2.setDuration(temps[tempssuivant])
                track1.addNote(self.a2)
                counter += 1
            if notesuivante == 10 and "Lad" in notes:
                self.a2d.setDuration(temps[tempssuivant])
                track1.addNote(self.a2d)
                counter += 1
            if notesuivante == 11 and "Si" in notes:
                self.b2.setDuration(temps[tempssuivant])
                track1.addNote(self.b2)
                counter += 1
            if notesuivante == 12 and "Do" in notes:
                self.c3.setDuration(temps[tempssuivant])
                track1.addNote(self.c3)
                counter += 1
            if notesuivante == 13 and "Dod" in notes:
                self.c3d.setDuration(temps[tempssuivant])
                track1.addNote(self.c3d)
                counter += 1
            if notesuivante == 14 and "Re" in notes:
                self.d3.setDuration(temps[tempssuivant])
                track1.addNote(self.d3)
                counter += 1
            if notesuivante == 15 and "Red" in notes:
                self.d3d.setDuration(temps[tempssuivant])
                track1.addNote(self.d3d)
                counter += 1
            if notesuivante == 16 and "Mi" in notes:
                self.e3.setDuration(temps[tempssuivant])
                track1.addNote(self.e3)
                counter += 1
            if notesuivante == 17 and "Fa" in notes:
                self.f3.setDuration(temps[tempssuivant])
                track1.addNote(self.f3)
                counter += 1
            if notesuivante == 18 and "Fad" in notes:
                self.f3d.setDuration(temps[tempssuivant])
                track1.addNote(self.f3d)
                counter += 1
            if notesuivante == 19 and "Sol" in notes:
                self.g3.setDuration(temps[tempssuivant])
                track1.addNote(self.g3)
                counter += 1
            if notesuivante == 20 and "Sold" in notes:
                self.g3d.setDuration(temps[tempssuivant])
                track1.addNote(self.g3d)
                counter += 1
            if notesuivante == 21 and "La" in notes:
                self.a3.setDuration(temps[tempssuivant])
                track1.addNote(self.a3)
                counter += 1
            if notesuivante == 22 and "Lad" in notes:
                self.a3d.setDuration(temps[tempssuivant])
                track1.addNote(self.a3d)
                counter += 1
            if notesuivante == 23 and "Si" in notes:
                self.b3.setDuration(temps[tempssuivant])
                track1.addNote(self.b3)
                counter += 1
            if notesuivante == 24 and "Do" in notes:
                self.c4.setDuration(temps[tempssuivant])
                track1.addNote(self.c4)
                counter += 1
            if notesuivante == 25 and "Dod" in notes:
                self.c4d.setDuration(temps[tempssuivant])
                track1.addNote(self.c4d)
                counter += 1
            if notesuivante == 26 and "Re" in notes:
                self.d4.setDuration(temps[tempssuivant])
                track1.addNote(self.d4)
                counter += 1
            if notesuivante == 27 and "Red" in notes:
                self.d4d.setDuration(temps[tempssuivant])
                track1.addNote(self.d4d)
                counter += 1
            if notesuivante == 28 and "Mi" in notes:
                self.e4.setDuration(temps[tempssuivant])
                track1.addNote(self.e4)
                counter += 1
            if notesuivante == 29 and "Fa" in notes:
                self.f4.setDuration(temps[tempssuivant])
                track1.addNote(self.f4)
                counter += 1
            if notesuivante == 30 and "Fad" in notes:
                self.f4d.setDuration(temps[tempssuivant])
                track1.addNote(self.f4d)
                counter += 1
            if notesuivante == 31 and "Sol" in notes:
                self.g4.setDuration(temps[tempssuivant])
                track1.addNote(self.g4)
                counter += 1
            if notesuivante == 32 and "Sold" in notes:
                self.g4d.setDuration(temps[tempssuivant])
                track1.addNote(self.g4d)
                counter += 1
            if notesuivante == 33 and "La" in notes:
                self.a4.setDuration(temps[tempssuivant])
                track1.addNote(self.a4)
                counter += 1
            if notesuivante == 34 and "Lad" in notes:
                self.a4d.setDuration(temps[tempssuivant])
                track1.addNote(self.a4d)
                counter += 1
            if notesuivante == 35 and "Si" in notes:
                self.b4.setDuration(temps[tempssuivant])
                track1.addNote(self.b4)
                counter += 1
            noteactuelle = notesuivante
            tempsactuelle = tempssuivant

        try:
            os.remove("markov.mid")
        except:
            print("N'existe pas encore")
        easyMIDI.addTrack(track1)
        easyMIDI.writeMIDI("markov.mid")
        print("Song créé avec succès")
예제 #13
0
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')