New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.9.2: midi kills the application on Linux. #3

Closed
cognot opened this Issue Nov 14, 2011 · 9 comments

Comments

Projects
None yet
2 participants
@cognot
Copy link
Contributor

cognot commented Nov 14, 2011

Hi,

Linux 64 bits, Qt 4.7.1, portmidi 2.1.7 freshly compiled.

Every time I attempt to play the midi output, I get:

File "/dsk/fronsac1/local/users/cognot/workspace/frescobaldi-2.0/frescobaldi_app/qmidi/player.py", line 61, in run
self.timer_start_playing()
File "/dsk/fronsac1/local/users/cognot/workspace/frescobaldi-2.0/frescobaldi_app/midifile/player.py", line 314, in timer_start_playing
self._output.reset()
File "/dsk/fronsac1/local/users/cognot/workspace/frescobaldi-2.0/frescobaldi_app/midifile/output.py", line 54, in reset
self.reset_controllers()
File "/dsk/fronsac1/local/users/cognot/workspace/frescobaldi-2.0/frescobaldi_app/midifile/output.py", line 79, in reset_controllers
send(event.ControllerEvent(c, event.MIDI_CTL_RESET_CONTROLLERS, 0))
File "/usr/lib64/python2.6/contextlib.py", line 23, in exit
self.gen.next()
File "/dsk/fronsac1/local/users/cognot/workspace/frescobaldi-2.0/frescobaldi_app/midifile/output.py", line 113, in sender
self.send_events(l)
File "/dsk/fronsac1/local/users/cognot/workspace/frescobaldi-2.0/frescobaldi_app/midifile/output.py", line 135, in send_events
self.output.write(l)
File "/dsk/fronsac1/local/users/cognot/workspace/frescobaldi-2.0/frescobaldi_app/portmidi/init.py", line 206, in write
self._output.Write(data)
File "/dsk/fronsac1/local/users/cognot/workspace/frescobaldi-2.0/frescobaldi_app/portmidi/ctypes_pypm.py", line 112, in Write
_check_error(err)
File "/dsk/fronsac1/local/users/cognot/workspace/frescobaldi-2.0/frescobaldi_app/portmidi/ctypes_pypm.py", line 189, in _check_error
"PortMIDI-ctypes error [{0}]: {1}".format(err_no, err_msg))
MidiException: PortMIDI-ctypes error [-9994]: PortMidi: `Invalid MIDI message Data'

Trouble is after that, I get a couple of errors due to (a wild guess) the midi player thread accessing things in the Qt Gui thread:

QObject::installEventFilter(): Cannot filter events for objects in a different thread.
QObject::installEventFilter(): Cannot filter events for objects in a different thread.
QObject::setParent: Cannot set parent, new parent is in a different thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QObject::installEventFilter(): Cannot filter events for objects in a different thread.
QObject::installEventFilter(): Cannot filter events for objects in a different thread.
QObject::installEventFilter(): Cannot filter events for objects in a different thread.
QObject::installEventFilter(): Cannot filter events for objects in a different thread.
QObject::installEventFilter(): Cannot filter events for objects in a different thread.
QObject::installEventFilter(): Cannot filter events for objects in a different thread.
QObject::installEventFilter(): Cannot filter events for objects in a different thread.

Later followed by an X error which I assume is a consequence of this, and which kills the application.

I have no such problem on Windows.

Regards,
Richard.

@wbsoft

This comment has been minimized.

Copy link
Collaborator

wbsoft commented Nov 14, 2011

thanks

probably the ctypes embedding code does something wrong in 64bit mode.

It is recommended to install a Python binding to PortMIDI, such as the python-pypm or python-portmidi package.
Also installing PyGame >= 1.9.1 gives a Python binding to PortMidi.

This will work better I think, although the ctypes embedding should work as well.

@cognot

This comment has been minimized.

Copy link
Contributor Author

cognot commented Nov 14, 2011

Hmmm.

Pygame is installed:

[frescobaldi-2.0]$ rpm -qa | grep pygame
pygame-1.9.1-2mdv2010.1

So what you are saying is that it should be picked up instead?

I'll give the other bindings a go and see what happens.

Regards,
Richard.

@wbsoft

This comment has been minimized.

Copy link
Collaborator

wbsoft commented Nov 14, 2011

what happens if you do this? Does Frescobaldi use the same Python as Pygame is installed for?

$ python

from pygame import pypm

@cognot

This comment has been minimized.

Copy link
Contributor Author

cognot commented Nov 14, 2011

Python and Pygame are in sync. BUT:

Type "help", "copyright", "credits" or "license" for more information.

from pygame import pypm
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name pypm

Bingo!

So I guess the default install of pygame on this platform is somehow incomplete.

Recompiling it after minor tweaks to account for the more recent portmidi I installed did the trick. I now have midi playback (with no volume, but that is more than probably another external issue on this machine).

I'll check the other bindings, but the bad news is that none of them is available as installable packages, so again they will require compilation, which is not something your average user is going to do if he can avoid it.

Adding a check at least for now to forbid the usage of the ctype embedding on linux 64 bits is probably a good idea as well though...

Regards,
Richard.

@wbsoft

This comment has been minimized.

Copy link
Collaborator

wbsoft commented Nov 14, 2011

If possible, could you test if portmidi embedding via ctypes now works under 64bit Linux? I changed all c_long to c_int32 in the pm_ctypes module.
You can do this by changing the try_order variable at line 88 in portmidi/init.py in frescobaldi_app. (Put 'ctypes' in front to force usage of the ctypes binding).

@cognot

This comment has been minimized.

Copy link
Contributor Author

cognot commented Nov 14, 2011

Wilbert Berendsen a écrit :

If possible, could you test if portmidi embedding via ctypes now works under 64bit Linux? I changed all c_long to c_int32 in the pm_ctypes module.
Will do in the morning.
You can do this by changing the try_order variable at line 88 in portmidi/init.py in frescobaldi_app. (Put 'ctypes' in front to force usage of the ctypes binding).
I had found that one yes.

Actually, using the ctypes embedding has pros and cons, the major pro
being less things to install, the cons is that it should be included
right into portmidi to make sure it follows the include files there...

But then, it does not seem like portmidi has evolved much in late years.

Out of curiosity: why not using pyrtmidi? It is built on top of rtmidi
and seems relatively active (well at least rtmidi is), and is supported
on linux, windows and macos. Better yet, it is multithreaded on all 3...

(ok maybe you tried and it failed miserably to do the job ;) )

Regards,
Richard.

@wbsoft

This comment has been minimized.

Copy link
Collaborator

wbsoft commented Nov 15, 2011

well at first I was intending to use the real-time features of PortMIDI (i.e. use the latency argument for Output and send timestamped MIDI messages). But later I used a thread myself to play the MIDI and send messages directly, which is also the way pyrtmidi works.

So now it would be very easy to change Frescobaldi to pyrtmidi. I'm even thinking about supporting both backends.

@cognot

This comment has been minimized.

Copy link
Contributor Author

cognot commented Nov 15, 2011

OK, tested with the new ctypes on linux 64 and it works (I took the time to plug a soft synth in, so this time I even got to the point where there was real sound coming out).

Note that if the softsynth dies (taking its midi port down with it) it kills frescobaldi as well.

Regards,
Richard.

@wbsoft

This comment has been minimized.

Copy link
Collaborator

wbsoft commented Nov 15, 2011

Thanks for testing this.

Yes, the problem of midi ports disappearing while portmidi is using them is the next issue, but this also applies to the other portmidi bindings

@wbsoft wbsoft closed this Nov 15, 2011

anthonyfok added a commit to anthonyfok/frescobaldi that referenced this issue Apr 8, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment