Code Monkey home page Code Monkey logo

py_midicsv's People

Contributors

joshnatis avatar snively avatar timwedde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

py_midicsv's Issues

Not enough values on to_TimeSignatureEvent

Hello and thank you for this great library! I am using it to do some processing on midi files, but I am having an issue with the TimeSignature of certain midi files.

Making a csv csv_string = py_midicsv.midi_to_csv(source) gives me the line 1, 0, Time_signature, 4, 2. Then when I try to parse it back to midi (without any processing) midi = py_midicsv.csv_to_midi(csv_string) I get the following error:

File ".../py_midicsv/csvmidi.py", line 46, in parse
    event = csv_to_midi_map[identifier](tr, time, identifier, line[3:])
File ".../py_midicsv/csv_converters.py", line 142, in to_TimeSignatureEvent
    num, denom, click, notesq = map(int, line)
ValueError: not enough values to unpack (expected 4, got 2)

Is this a known issue and how can I prevent it?

Don't work

in https://pypi.org/project/py-midicsv/#description

we have

import py_midicsv

# Load the MIDI file and parse it into CSV format
csv_string = py_midicsv.midi_to_csv("example.mid")

# Parse the CSV output of the previous command back into a MIDI file
midi_object = py_midicsv.csv_to_midi(csv_string)

# Save the parsed MIDI file to disk
with open("example_converted.mid", "wb") as output_file:
    midi_writer = py_midicsv.FileWriter(output_file)
    midi_writer.write(midi_object)

in https://github.com/timwedde/py_midicsv

we have

import py_midicsv as pm

# Load the MIDI file and parse it into CSV format
csv_string = pm.midi_to_csv("example.mid")

# Parse the CSV output of the previous command back into a MIDI file
midi_object = pm.csv_to_midi(csv_string)

# Save the parsed MIDI file to disk
with open("example_converted.mid", "wb") as output_file:
    midi_writer = pm.FileWriter(output_file)
    midi_writer.write(midi_object)

but none of them work or i did something wrong

Traceback (most recent call last):
  File "C:/Users/felipe/PycharmProjects/2020/PORRA.py", line 9, in <module>
    midi_writer.write(midi_object)
NameError: name 'midi_object' is not defined

TypeError: ('Bad header in MIDI file.', b'')

Ran this on Google Colab, I uploaded a midi file and tested multiple and kept getting this error. What's going on?
(Also, IDK why the indentations arent working on the code)
`
#MIDI TO CSV

import py_midicsv as pm
def midi2csv():
save=input('filename\n')
print("Step 1")
owo=open(save,mode='w')
print("Step 2")
owo.write(str(pm.midi_to_csv(str(save)+'.mid')))
print("Step 3")
owo.close
print("Step 4")
messagebox.showinfo('Complete','file saved as {}'.format(save))
print("Step 5")
while 1==1:
x=input('midi to CSV: 0\nend: 2\n')
if x == '0':
midi2csv()
elif x == '2':
break
`

csv export

Can we export a cvs file from MIDI?
Do you have an example? (new to python)

Processing folder? Why not? :)

Tree project

├── csv
│   └── AllBlues.csv
├── mid
│   └── AllBlues.mid
├── midi
│   └── AllBlues.mid

Implementation

import os
import py_midicsv as pm

#MIDI folder
file_list=os.listdir(r"midi")

#Custom Path
path = ''

#Create folders where to save files
try:
    os.mkdir(path +"csv")
    os.mkdir(path +"mid") 

except OSError:
    print ("Creation of the directory %s failed" % path)
else:
    print ("Successfully created the directory %s" % path)
    
for file_name_song in file_list:
    
    name_file_without_ext = file_name_song.rsplit('.', 1)[0]
    
    # Load the MIDI file and parse it into CSV format
    csv_string = pm.midi_to_csv("midi/"+ name_file_without_ext + ".mid")

    with open("csv/" + name_file_without_ext + ".csv", "w") as f:
        f.writelines(csv_string)

    # Parse the CSV output of the previous command back into a MIDI file
    midi_object = pm.csv_to_midi(csv_string)

    # Save the parsed MIDI file to disk
    with open("mid/" + name_file_without_ext + ".mid", "wb") as output_file:
        midi_writer = pm.FileWriter(output_file)
        midi_writer.write(midi_object)
    print("processed file name:",file_name_song)

Unexpected status byte 0x80 and Warning: Unknown Meta MIDI Event: 10

File "midiToText.py", line 10, in convertMidiFile csv_string = pm.midi_to_csv(midiName) File "/home/user/anaconda3/lib/python3.8/site-packages/py_midicsv/midicsv.py", line 22, in parse pattern = read_midifile(file) File "/home/user/anaconda3/lib/python3.8/site-packages/py_midicsv/midi/fileio.py", line 221, in read_midifile return read_midifile(inp) File "/home/user/anaconda3/lib/python3.8/site-packages/py_midicsv/midi/fileio.py", line 223, in read_midifile return reader.read(midifile) File "/home/user/anaconda3/lib/python3.8/site-packages/py_midicsv/midi/fileio.py", line 45, in read self.parse_track(midifile, track) File "/home/user/anaconda3/lib/python3.8/site-packages/py_midicsv/midi/fileio.py", line 87, in parse_track event = self.parse_midi_event(trackdata) File "/home/user/anaconda3/lib/python3.8/site-packages/py_midicsv/midi/fileio.py", line 133, in parse_midi_event data = [trackdata.get_data_byte() for _ in range(cls.length)] File "/home/user/anaconda3/lib/python3.8/site-packages/py_midicsv/midi/fileio.py", line 133, in <listcomp> data = [trackdata.get_data_byte() for _ in range(cls.length)] File "/home/user/anaconda3/lib/python3.8/site-packages/py_midicsv/midi/fileio.py", line 36, in get_data_byte self.assert_data_byte(byte) File "/home/user/anaconda3/lib/python3.8/site-packages/py_midicsv/midi/fileio.py", line 29, in assert_data_byte assert data & 0x80 == 0, self.errmsg("Unexpected status byte", data) AssertionError: Unexpected status byte 0x80 at position 35078

https://easyupload.io/zz2wf6 midi file that causes the issue

when i comment out the assert the conversion passes, though i get a different error later with a different midi

Traceback (most recent call last): File "midiToText.py", line 35, in <module> convertMidiFolderOfFolders(midiName) File "midiToText.py", line 20, in convertMidiFolderOfFolders convertMidiFolder(path + "/" + midiName) File "midiToText.py", line 16, in convertMidiFolder convertMidiFile(path + "/" + midiName) File "midiToText.py", line 10, in convertMidiFile csv_string = pm.midi_to_csv(midiName) File "/home/user/anaconda3/lib/python3.8/site-packages/py_midicsv/midicsv.py", line 22, in parse pattern = read_midifile(file) File "/home/user/anaconda3/lib/python3.8/site-packages/py_midicsv/midi/fileio.py", line 221, in read_midifile return read_midifile(inp) File "/home/user/anaconda3/lib/python3.8/site-packages/py_midicsv/midi/fileio.py", line 223, in read_midifile return reader.read(midifile) File "/home/user/anaconda3/lib/python3.8/site-packages/py_midicsv/midi/fileio.py", line 45, in read self.parse_track(midifile, track) File "/home/user/anaconda3/lib/python3.8/site-packages/py_midicsv/midi/fileio.py", line 87, in parse_track event = self.parse_midi_event(trackdata) File "/home/user/anaconda3/lib/python3.8/site-packages/py_midicsv/midi/fileio.py", line 103, in parse_midi_event raise Warning("Unknown Meta MIDI Event: " + repr(cmd)) Warning: Unknown Meta MIDI Event: 10
https://easyupload.io/8y3mz2

file that causes the issue

IndexError while Parsing MIDI

First of all, congrats for this Python library, which makes easier and integrable the parsing from MIDI files to CSV in Python. I'm encountering a problem while parsing a certain file, which gives the following error:

Traceback (most recent call last):
File "/Users/josepdecidrodriguez/Google Drive/IU/AML/Project/BachPropagation/src/dataset/parser.py", line 27, in
data = py_midicsv.midi_to_csv(file)
File "/Users/josepdecidrodriguez/Envs/BachPropagation-L4F7V3ER/lib/python3.7/site-packages/py_midicsv/midicsv.py", line 31, in parse
csv_file.append(midi_to_csv_map[type(event)](index + 1, abstime, event))
File "/Users/josepdecidrodriguez/Envs/BachPropagation-L4F7V3ER/lib/python3.7/site-packages/py_midicsv/midi_converters.py", line 117, in from_KeySignatureEvent
return write_event(track, time, "Key_signature", [event.get_alternatives(), '"major"' if event.data[1] == 0 else '"minor"'])
IndexError: list index out of range

This is given by the following file BWV_809____piano.txt (I've changed the extension to .txt to be able to upload it here).

name conflict

you should rename the command line midicsv and csvmidi scripts that you included. When I did the pip install, it overwrote my existing binaries from John Walker that were already located in /user/local/bin...

Secondly, if you're going to overwrite, then the pip installer should prompt me to make sure that is what I really want to do

thirdly, you should try to make your version of midicsv and csvmidi use the same command line options as the original binary so that if for some reason it does get overwritten and maybe I would even prefer to use your version for the Latin decoding...but if I have other scripts elsewhere based on using the binary midicsv, I don't want to break all those scripts.

Removing track from midi file

Hi timwedde. I'm trying to build a dataset of midi-files for use in a machine learning project. I've been using py_midicsv to try and remove the drum track from my files. I've tried looking for "Program_c, 9" in the file after conversion to CSV, deleting that whole section and converting back to MIDI, but something is breaking. Could you maybe suggest a better way to do this?
Thanks for the cool module!

Track meta-events—ignored?

I've used your library to successfully convert a midi file (or twelve) into .csv, with the exact same results as the unix midicsv functions. I was hoping your library would also handle meta-events for simplicity and convenience. The simplicity and convenience factors may be fairly limited for general use, so I will not be surprised if you feel it unnecessary.

My midi files definitely contain the information—Musescore 4 identifies the instruments correctly from the same file. Ideally I would like to have it available to any parsing scripts I pass over the .csv.

Is this a feature that is out of scope for the library?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.