python-midi
python-midi copied to clipboard
add a class to convert from absolute MIDI tick to milliseconds
it seems to work for me, maybe it's also interesting for you
I've implemented it as a wrapper class to avoid messing up the existing code base and to avoid making the system slower if this functionality is not needed.
Looks awesome, was looking for this. Thanks!
I am have trouble implementing your wrapper class. It gives me an error saying no such attribute "TimeResolver" using example_3.py.
I have installed it using sudo python setup.py install.
@billybob71a to the best of my knowledge the TimeResolver class was never added into the official code. You'd need to get the code from github directly by cloning my fork https://github.com/shimpe/python-midi
Hi, Actually, the TimeResolver class was never included in the sequencer.py installed in "python2.7/dist-packages/midi/sequencer/". I had to concatenate it into the sequencer.py from your git repository. Afterwards, I discovered some traceback messages. First it was : last = SetTempoEvent() so I changed it to: last = midi.SetTempoEvent()
Now, it is: AttributeError: 'SetTempoEvent' object has not attribute 'msdelay'
I was just using your sample script example_3.py for event in track: name = event.name tick = event.tick milliseconds = time_resolver.tick2ms(tick) print ("event {0} with MIDI tick {1} happens after {2} milliseconds.".format(name, tick, milliseconds))
But it cannot even retrieve the milliseconds.
Peter
@billybob71a better check the changes in https://github.com/shimpe/python-midi/commit/9aa092e653684c871b9ee2293ee8e640bb1cab34 to see that you need to change some other things beside just appending the class. You could try to replace your version of sequencer.py with the one from my fork.
Sorry, maybe I am a little bit new to using GIT. I did a git clone https://github.com/shimpe/python-midi.git. How, do I only get the changes in shimpe/python-midi@9aa092e ?
@billybob71a If you cloned my fork, you should be able to install it as described in the readme file (sudo python setup.py install). My code is identical to the code here except for my changes related to TimeResolver. To be certain that we don't mix different versions of python-midi, you could remove the "pip install"-ed one first.
Yes, I git cloned it from your fork. As follows: git clone https://github.com/shimpe/python-midi.git
I ran : sudo python setup.py install It installed: running install running build_ext running build running build_py creating build/lib.linux-x86_64-2.7/src copying src/init.py -> build/lib.linux-x86_64-2.7/src copying src/sequencer.py -> build/lib.linux-x86_64-2.7/src running build_scripts running install_lib creating /usr/local/lib/python2.7/dist-packages/midi copying build/lib.linux-x86_64-2.7/midi/constants.py -> /usr/local/lib/python2.7/dist-packages/midi copying build/lib.linux-x86_64-2.7/midi/containers.py -> /usr/local/lib/python2.7/dist-packages/midi copying build/lib.linux-x86_64-2.7/midi/events.py -> /usr/local/lib/python2.7/dist-packages/midi copying build/lib.linux-x86_64-2.7/midi/util.py -> /usr/local/lib/python2.7/dist-packages/midi creating /usr/local/lib/python2.7/dist-packages/midi/sequencer copying build/lib.linux-x86_64-2.7/midi/sequencer/sequencer.py -> /usr/local/lib/python2.7/dist-packages/midi/sequencer copying build/lib.linux-x86_64-2.7/midi/sequencer/sequencer_alsa.py -> /usr/local/lib/python2.7/dist-packages/midi/sequencer copying build/lib.linux-x86_64-2.7/midi/sequencer/_sequencer_alsa.so -> /usr/local/lib/python2.7/dist-packages/midi/sequencer copying build/lib.linux-x86_64-2.7/midi/sequencer/init.py -> /usr/local/lib/python2.7/dist-packages/midi/sequencer copying build/lib.linux-x86_64-2.7/midi/fileio.py -> /usr/local/lib/python2.7/dist-packages/midi copying build/lib.linux-x86_64-2.7/midi/init.py -> /usr/local/lib/python2.7/dist-packages/midi creating /usr/local/lib/python2.7/dist-packages/src copying build/lib.linux-x86_64-2.7/src/sequencer.py -> /usr/local/lib/python2.7/dist-packages/src copying build/lib.linux-x86_64-2.7/src/init.py -> /usr/local/lib/python2.7/dist-packages/src byte-compiling /usr/local/lib/python2.7/dist-packages/midi/constants.py to constants.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/midi/containers.py to containers.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/midi/events.py to events.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/midi/util.py to util.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/midi/sequencer/sequencer.py to sequencer.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/midi/sequencer/sequencer_alsa.py to sequencer_alsa.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/midi/sequencer/init.py to init.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/midi/fileio.py to fileio.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/midi/init.py to init.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/src/sequencer.py to sequencer.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/src/init.py to init.pyc running install_egg_info running egg_info writing midi.egg-info/PKG-INFO writing top-level names to midi.egg-info/top_level.txt writing dependency_links to midi.egg-info/dependency_links.txt reading manifest file 'midi.egg-info/SOURCES.txt' writing manifest file 'midi.egg-info/SOURCES.txt' Copying midi.egg-info to /usr/local/lib/python2.7/dist-packages/midi-v0.2.3.egg-info running install_scripts changing mode of /usr/local/bin/mididumphw.py to 755 changing mode of /usr/local/bin/midiplay.py to 755 changing mode of /usr/local/bin/mididump.py to 755
And I ran it in ipython, however, you can see that there is no "TimeResolver" option in "sequencer" module.
In [1]: import midi
In [2]: import midi.sequencer as sequencer
In [3]: sequencer. sequencer.S sequencer.SequencerDuplex sequencer.SequencerRead sequencer.midi sequencer.sequencer sequencer.stringify sequencer.Sequencer sequencer.SequencerHardware sequencer.SequencerWrite sequencer.select sequencer.sequencer_alsa
In [3]: sequencer.
The TimeResolver class is part of the sequencer.py file. If you open the sequencer.py file in a text editor, you should be able to locate it. Is it possible the autocompletion in ipython is still using some (outdated) cached information?
There is no outdated cache information. I checked the .local directory and I removed the packages in /usr/local/lib/python2.7/dist-packages/mid and I re-installed it. This is the first time that I have installed it. Have you tried to install it on a new computer recently? Is it working for you?
Thanks a lot for this feature! However I get this error:
milliseconds = time_resolver.tick2ms(tick) File "build/bdist.macosx-10.13-intel/egg/midi/sequencer.py", line 83, in tick2ms AttributeError: 'SetTempoEvent' object has no attribute 'msdelay'
Could you help?
Pfff what a mess. It seems something is very wrong indeed. Let me see if there's a way to make some progress.
Ok here's something to try (python 3 only - hope that's not too inconvenient). This is based on a more recent version of python-midi for python3 found here: https://github.com/mgedmin/python-midi (a pull request from them exists for this project as well, but I'm not sure if this one is still very active)
cd ~ mkdir workingfolder cd workingfolder git clone https://github.com/shimpe/python-midi.git cd python-midi git checkout py3_timeresolver sudo python setup.py install python examples/example_3.py
(on my system python activates python3, on your system, you may need to explicitly call python3 instead)