vishnubob / python-midi

Python MIDI library
MIT License
1.51k stars 370 forks source link

Using `midiplay.py` #78

Closed JPry closed 8 years ago

JPry commented 8 years ago

I'm trying to use the included midiplay.py file on a Raspberry Pi. I have Alsa and Timidity installed, and I'm able to play midi files directly from the command line using the tools provided by those libraries. However, I want to work with the midi data using Python at the same time as the music is playing. I'm trying to use the midiplay.py file to simply play the included mary.mid file, but it doesn't seem to be working.

Here's the output when trying to play using the TiMidity sequencer:

midiplay.py TiMidity 14 mary.mid 
Traceback (most recent call last):
  File "/usr/local/bin/midiplay.py", line 29, in <module>
    seq.subscribe_port(client, port)
  File "/usr/local/lib/python2.7/dist-packages/midi/sequencer/sequencer.py", line 429, in subscribe_port
    dest = self._new_address(client, port)
  File "/usr/local/lib/python2.7/dist-packages/midi/sequencer/sequencer.py", line 126, in _new_address
    addr.client = int(client)
ValueError: invalid literal for int() with base 10: 'TiMidity'

Using the Python console to examine the sequencer object, I can see that TiMidity should indeed be a valid sequencer:

>>> hard = seq.SequencerHardware()
>>> hard
<midi.sequencer.sequencer.SequencerHardware object at 0xb6c95250>
>>> hard._clients
{'__sequencer__': <midi.sequencer.sequencer.Client object at 0xb6a43890>, 'Midi Through': <midi.sequencer.sequencer.Client object at 0xb6a39bf0>, 'System': <midi.sequencer.sequencer.Client object at 0xb6a39570>, 'TiMidity': <midi.sequencer.sequencer.Client object at 0xb6a39d50>}

It appears that the sequencer library is attempting to convert the TiMidity string to an int for some reason. Am I doing something wrong here, or is this a bug?

vishnubob commented 8 years ago

ALSA MIDI endpoints are identified using two integers. If you use this script, it will show you the address pair that maps to your TiMidity endpoint. Please see the documentation for more information.

JPry commented 8 years ago

Thanks for the guidance @vishnubob! I didn't realize at first that "port" referred to the ports within a MIDI endpoint instead of the endpoint itself. I was able to get it working!