473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

midi with ctypes

Recently there has been a lot of progress concerning the integration
of midi into python. A midipy.cpp for Python20 is found and various
compiling efforts having been undertaken to compile it for Python23.
See the other threads about midipy.cpp for more info.

However, seeing that the resulting midipy.pyd is only 48 kilobyte long
and seeing that midipy.cpp exports only 14 functions, most of which
are inside winmm.dll (for W98 and W2000 at least) I decided to start
another effort, which I'm presenting below and for which I hope kind
people will add some functions since I doesn't seem to be too hard.

first create a winmm.def like this:

pexports winmm.dll > winmm.def

Now open winmm.def and find the relevant functions, compare them with
what's inside midipy.cpp and try to reproduce them using ctypes. The
file "mmedia.hlp" from Borland C++ Builder for example, contains
detailed info about midi functions, most of which seem to be direct
wrappers around the functions inside winmm.dll .

Now to get started try this:

#ctypesmidipy.py

from ctypes import *

def getNumMidiInDevices():
return windll.winmm.midiInGetNumDevs()

def getNumMidiOutDevices():
return windll.winmm.midiOutGetNumDevs()

def test():
print getNumMidiInDevices()
print getNumMidiOutDevices()

if __name__=='__main__':
test()

Please note that after importing this file every function should work
the same as if midipy.pyd had been imported. Not being very familiar
with midi programming I succeeded only to get 2 of the 14 functions
working. Getting more functions to work should be harder, but not very
hard. Please, anybody reading this, add a function if there's a sudden
insight into how it should be done. By and by ctypesmidipy.py will be
put together like a little pypy-alike project replacing midipy.cpp :-)
Any feasibility studies and remarks about possible legal objections to
this are very welcome too.

Anton
Jul 18 '05 #1
3 2692
da*******@yahoo.com (dan) topposted:
Interesting idea, but frankly it seems like alot of extra overhead.
Now that midipy is compiling, I'm more inclined to add features in C
than using ctypes.
The microsoft visual C compiler is about half a gigabyte size, the
soundfont SDK from creative labs is about 20 megabyte size, the OSC
toolkit is about 3 megabyte size, the midipy.cpp is a few kilobyte
size.

Compare this with the ctypes solution: ctypes itself is about half a
megabyte size and the ctypesmidipy.py is taking a few kilobytes.

From this comparison one could conclude that the overhead is largely
on the side of the current solution using C.
What advantages can we expect from doing it this way?


The ctypes solution is cheaper, there are less license issues because
there are less parties involved, it's a lot less code so it's easier
to understand and maintain, programming this module in Python gives
extra flexibility, and most importantly this could be a platform
independent solution for MIDI programming. That would earn Python
extra kudos from music programmers.

Anton

Jul 18 '05 #2
da*******@yahoo.com (dan) wrote:
One point worth thinking about: a serious MIDI library would include a
method for scheduling low-level routines at exact times (similar to a
sound output buffer). This would almost by definition require some C
code.


At some level these samples must be computed by the hardware, but MIDI
is about controlling this hardware at a higher level. Maybe we can get
away with less exact timing for which Python would be fast enough.

Anton

Jul 18 '05 #3
an***@vredegoor.doge.nl (Anton Vredegoor) writes:
da*******@yahoo.com (dan) topposted:
Interesting idea, but frankly it seems like alot of extra overhead.
Now that midipy is compiling, I'm more inclined to add features in C
than using ctypes.


The microsoft visual C compiler is about half a gigabyte size, the
soundfont SDK from creative labs is about 20 megabyte size, the OSC
toolkit is about 3 megabyte size, the midipy.cpp is a few kilobyte
size.

Compare this with the ctypes solution: ctypes itself is about half a
megabyte size and the ctypesmidipy.py is taking a few kilobytes.

From this comparison one could conclude that the overhead is largely
on the side of the current solution using C.
What advantages can we expect from doing it this way?


The ctypes solution is cheaper, there are less license issues because
there are less parties involved, it's a lot less code so it's easier
to understand and maintain, programming this module in Python gives
extra flexibility, and most importantly this could be a platform
independent solution for MIDI programming. That would earn Python
extra kudos from music programmers.


There may even be another advantage (in the future): the ctypes solution
may be more portable. Bradley Schatz has started porting ctypes to Java,
and so it seems also usable from Jython. Not to speak of pypy...

Thomas
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Max M | last post by:
If anybody is interrested in Midi, but are not on the Python Midi list, I will just notify that I have released the first version of a high level midi package for Python. It is fully functional....
2
by: Mad Scientist Jr | last post by:
any sample code or information would be most appreciated i have been wanting to learn MIDI programming but would rather learn it in my current language (either vb.net or c#)
11
by: Kuba Araszkiewicz | last post by:
Hello! I have to write a program, which would convert midi files to notes, notes to midi files and which would make one MIDI file from two different. I'm totally lame in C (and any other...
2
by: david | last post by:
1.I am considering doing a midi file generator for my 4th year project in B.SC. 2.I would do it using c language, but i'm not sure abou t the level of difficulyt involved 3.Basically, the...
0
by: tom | last post by:
Hallo, I need help on MIDI file, and precisely about retrieving few note values (mainly the "Velocity" value, corrisponding to the intensity of a played note) while the MIDI is playing.
1
by: tim | last post by:
Someone using Python Midi Package from http://www.mxm.dk/products/public/ lately? I want to do the following : write some note events in a midi file then after doing that, put some controllers...
4
by: sreekant | last post by:
Hi folks I hope someone here might be able to help. I scavenged some info and even code from the net and am trying to write a module that reads a text file and spits out a midi file. So far I...
6
by: =?ISO-8859-2?Q?Maciej_Blizi=F1ski?= | last post by:
For the last couple of days, I've been looking for a Python midi library. I'm generally interested in sending MIDI events via ALSA. It seems like everything out there is pretty old; packages are...
6
by: Massi | last post by:
Hi everyone, I'm searching for "something" which allows me to write scripts which handle midi files. I'm totally a newbie in audio manipulation, therefore any suggestion or link related to this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.