lucasnfe / music-sentneuron

Controlling a LSTM to generate music with given sentiment (positive or negative).
36 stars 10 forks source link

Hello, when I changed version 0.1 of "vigimidi", this error occurred. Before using your latest version of "vigimidi", there was no error. What is the reason? #5

Open ymm-youbaba opened 2 years ago

ymm-youbaba commented 2 years ago

T {{87ZO6B}O VJUONYKK00

sashulyak commented 2 years ago

Hi! I faced the same error. It looks like some midi-files are corrupted or the encoding algorithm has a bug. For a while I solved this problem by moving the statement midi_fp.close() near the place where the object was created.

if(os.path.isfile(midi_txt_name)):
        midi_fp = open(midi_txt_name, "r")
        encoded_midi = midi_fp.read()
        midi_fp.close()
    else:
        # Create a music21 stream and open the midi file
        midi = m21.midi.MidiFile()
        midi.open(file_path)
        midi.read()
        midi.close()

        # Translate midi to stream of notes and chords
        encoded_midi = midi2encoding(midi, sample_freq, piano_range, transpose_range, stretching_range)

        if len(encoded_midi) > 0:
            midi_fp = open(midi_txt_name, "w+")
            midi_fp.write(encoded_midi)
            midi_fp.flush()
            midi_fp.close()

Kinda works. But the reason for the error is not clear still.