I'm trying to get portmidi working with Python on Windows 11/64. I'm able to compile the dll/lib in MSVS without errors, without specifying any changes or options. I'm new to this, so I don't know how to tell the system about the libraries, do I have to put them on some path or something? For now I'm just telling Python their location in the build directory directly.
I'd like to get two approaches working in order to compare them.
First way: ctypes. I stumbled across portmidizero, which looks old and dead, but basically correct. I have to 2to3 it and fix a few tiny errors, but then it almost works. Running testportmidizero.py
, I can Initialize()
, list the devices and get sensible names, open an Output
, and run the Time()
function, all without errors. But then when I try to Pm_write()
, I get OSError: Access Violation
. I am running as administrator. Googling, my best guess is that there's a problem either with calling conventions or pointer sizes. But I don't see any mention of cdecl
or stdcall
anywhere, so I think everything has defaulted to cdecl
, but I don't know how to verify. And I don't see any problem with how the pointer types/sizes are written, but I barely know what I'm doing. What should I do to figure out what's wrong?
Second way: Cython. As far as I understand this approach will give the best performance. pyportmidi used to work well on mac several years ago, but is now out of date. I tried to get pip install
working:
- Remove the
description
related stuff fromsetup.py
because the expectedreadme
is missing. Same for all testing related stuff. - I couldn't figure out how to add a path to the portmidi header files, the compiler couldn't find them when I added the path to
include_dirs
, even though it looked correct in the compiler directive output. I just manually copied the.h
's into thepyportmidi
directory for now. - But then I got all the following errors I have no idea how to solve:
pyportmidi\_pyportmidi.c(399): warning C4244: 'function': conversion from 'Py_ssize_t' to 'long', possible loss of data
pyportmidi\_pyportmidi.c(419): warning C4244: 'function': conversion from 'Py_ssize_t' to 'long', possible loss of data
pyportmidi\_pyportmidi.c(441): warning C4244: 'function': conversion from 'Py_ssize_t' to 'long', possible loss of data
pyportmidi\_pyportmidi.c(2093): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int32_t', possible loss of data
pyportmidi\_pyportmidi.c(2625): warning C4113: 'PtTimestamp (__cdecl *)(void)' differs in parameter lists from 'PmTimeProcPtr'
pyportmidi\_pyportmidi.c(3455): error C2105: '++' needs l-value
pyportmidi\_pyportmidi.c(3458): error C2105: '--' needs l-value
pyportmidi\_pyportmidi.c(3634): error C2105: '++' needs l-value
pyportmidi\_pyportmidi.c(3637): error C2105: '--' needs l-value
pyportmidi\_pyportmidi.c(4554): warning C4996: 'PyUnicode_GET_SIZE': deprecated in 3.3
pyportmidi\_pyportmidi.c(4568): warning C4996: 'PyUnicode_GET_SIZE': deprecated in 3.3
pyportmidi\_pyportmidi.c(5523): warning C4047: 'function': 'PyObject *' differs in levels of indirection from 'int'
pyportmidi\_pyportmidi.c(5523): warning C4024: 'PyCode_New': different types for formal and actual parameter 14
pyportmidi\_pyportmidi.c(5525): warning C4047: 'function': 'int' differs in levels of indirection from 'PyObject *'
pyportmidi\_pyportmidi.c(5524): warning C4024: 'PyCode_New': different types for formal and actual parameter 15
pyportmidi\_pyportmidi.c(5507): error C2198: 'PyCode_New': too few arguments for call
pyportmidi\_pyportmidi.c(5534): error C2037: left of 'f_lineno' specifies undefined struct/union '_frame'
I assume these need to be fixed by editing the .pyx
with knowledge of how the c library has been updated. But I don't know Cython/pyrex, so any guidance would be greatly appreciated!