473,766 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(M idiOutStream):

"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.m id'
midi_in = MidiInFile(even t_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.m id'
midi = MidiOutFile(out _file)

# non optional midi framework
midi.header()
midi.start_of_t rack()

# musical events

midi.update_tim e(0)
midi.note_on(ch annel=0, note=0x40)

midi.update_tim e(192)
midi.note_off(c hannel=0, note=0x40)

# midi framework

midi.update_tim e(0)
midi.end_of_tra ck() # 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 2106

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

Similar topics

0
1477
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 don't need timestamps, sequencing etc... please advise on how to proceed... thanks Ton K.
52
5886
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. Could someone show me how to do what I need? Thanks, Dick Moores rdm@rcblue.com
5
4175
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 lies. Here's a description... I want a callback-based MIDI input/processing, so PortMidi was not an alternative. I have written a C extension module that links to the mmsys MIDI API. I separated the win32-dependant code from the Python extension...
2
1803
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 music in my own notation that I am playing with d) Allows both to be printed I guess I can use Python with Tk for the display part but there seems to
1
2104
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 at the beginning of the midifile (because I want to be able to make those dependant on what notes were just written)
4
2698
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 managed to make it work to the level of reading a text file with appropriate notes, octaves, transposing, volume, aftertouch, polyphony, channeltouch etc.
6
2748
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 from 2003 or 2005. Some packages don't seem to be really used, for instance portmidi doesn't even support installing it system-wide; you can compile it and... no make install for you. What I've found so far: -...
5
1328
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 thangs completly platform independently oh .. am just curious who are the guys over here composing weird music with python as my self-introduction...
7
2425
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. Furthermore, i found references on Python not being really able of multi-threading, that further adds to the confusion. Please assist.
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9837
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.