473,387 Members | 1,904 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,387 software developers and data experts.

Python Midi package 0.1

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. It reads and writes midi files! It is *very*
easy to write your own event handlers to make midi files do whatever you
want them to.

It uses the same general ideas as the Sax parser for xml.
#########################################
# example #1

"""
This prints all note_on events on midi channel 0. It's a short example
of creating your own event handler by subclassing the MidiOutStream.
"""

from MidiOutStream import MidiOutStream
from MidiInFile import MidiInFile
class NoteOnPrinter(MidiOutStream):

"Prints all note_on events on channel 0"

def note_on(self, channel=0, note=0x40, velocity=0x40):
if channel == 0:
print channel, note, velocity, self.rel_time()
event_handler = NoteOnPrinter()

in_file = 'midiout/minimal_type0.mid'
midi_in = MidiInFile(event_handler, in_file)
midi_in.read()

#########################################
#########################################
# example #2

"""
This is an example of how to create the smallest possible type 0 midi
file, where all the midi events are in the same track.
"""

from MidiOutFile import MidiOutFile

out_file = 'midiout/minimal_type0.mid'
midi = MidiOutFile(out_file)

# non optional midi framework
midi.header()
midi.start_of_track()

# musical events

midi.update_time(0)
midi.note_on(channel=0, note=0x40)

midi.update_time(192)
midi.note_off(channel=0, note=0x40)

# midi framework

midi.update_time(0)
midi.end_of_track() # not optional!

midi.eof()
#########################################
It cannot read/write midi ports at this point. So no realtime stuff yet.
Get it at:
http://www.mxm.dk/technologies/pythonmidi/
regards Max M

Jul 18 '05 #1
0 2086

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

Similar topics

0
by: Ton K. | last post by:
Folks, I'm planning to build MIDI sysex tools in Python on Windows 98SE. I need a simple read/write to MIDI interface, preferably with a read callback integrated with the Tkinter event loop. I...
52
by: Dick Moores | last post by:
I need to figure out how to compute pi to base 12, to as many digits as possible. I found this reference, <http://mathworld.wolfram.com/Base.html>, but I really don't understand it well enough....
5
by: Francois De Serres | last post by:
Hiho, could somebody please enlighten me about the mechanics of C callbacks to Python? My domain is more specifically callbacks from the win32 API, but I'm not sure that's where the problem...
2
by: James Harris | last post by:
Hi, I am wanting to develop some software that a) Reads existing files of music of a few well known types b) Displays the music in traditional notation - i.e. on a stave c) Displays the same...
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...
5
by: '2+ | last post by:
well maybe am over-advertising .. excuse me ... am new to python but my "algo-comping cs.sco with python" thang kinda got lauched after all so decided to move from java to python to do these...
7
by: Protocol | last post by:
Hello all Is Python suitable for building a multi-track midi sequencer (with a gui), that would run on windows / mac ? I fail to find sufficient information on this, being a newbie and all....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.