depstein / midiutil Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/midiutil
License: Other
Automatically exported from code.google.com/p/midiutil
License: Other
======== MIDIUtil ======== ------------ Introduction ------------ MIDIUtil is a pure Python library that allows one to write muti-track Musical Instrument Digital Interface (MIDI) files from within Python programs. It is object-oriented and allows one to create and write these files with a minimum of fuss. MIDIUtil isn't a full implementation of the MIDI specification. The actual specification is a large, sprawling document which has organically grown over the course of decades. I have selectively implemented some of the more useful and common aspects of the specification. The choices have been somewhat idiosyncratic; I largely implemented what I needed. When I decided that it could be of use to other people I fleshed it out a bit, but there are still things missing. Regardless, the code is fairly easy to understand and well structured. Additions can be made to the library by anyone with a good working knowledge of the MIDI file format and a good, working knowledge of Python. Documentation for extending the library is provided. This software was originally developed with Python 2.5.2 and it makes use of some features that were introduced in 2.5. I have used it extensively in Python 2.6. Included in this version is an intitial port to Python 3 (but which should work in 2.6.X also). The file is called MidiFile3.py. To use it, use the following import line in your code: from midiutil.MidiFile3 import MIDIFile (This assumes that the code has been installed into your system path or that the midiutil directory is copied into your script's working directory.) This software is distributed under an Open Source license and you are free to use it as you see fit, provided that attribution is maintained. See License.txt in the source distribution for details. ------------ Installation ------------ To use the library one can either install it on one's system or copy the midiutil directory of the source distribution to your project's directory (or to any directory pointed to by the PYTHONPATH environment variable). For the Windows platforms an executable installer is provided. Alternately the source distribution can be downloaded, un-zipped (or un-tarred), and installed in the standard way: python setup.py install On non-Windows platforms (Linux, MacOS, etc.) the software should be installed in this way. MIDIUtil is pure Python and should work on any platform to which Python has been ported. If you do not wish to install in on your system, just copy the src/midiutil directory to your project's directory or elsewhere on your PYTHONPATH. If you're using this software in your own projects you may want to consider distributing the library bundled with yours; the library is small and self-contained, and such bundling makes things more convenient for your users. The best way of doing this is probably to copy the midiutil directory directly to your package directory and then refer to it with a fully qualified name. This will prevent it from conflicting with any version of the software that may be installed on the target system. ----------- Quick Start ----------- Using the software is easy: o The package must be imported into your namespace o A MIDIFile object is created o Events (notes, tempo-changes, etc.) are added to the object o The MIDI file is written to disk. Detailed documentation is provided; what follows is a simple example to get you going quickly. In this example we'll create a one track MIDI File, assign a name and tempo to the track, add a one beat middle-C to the track, and write it to disk. #Import the library from midiutil.MidiFile import MIDIFile # Create the MIDIFile Object with 1 track MyMIDI = MIDIFile(1) # Tracks are numbered from zero. Times are measured in beats. track = 0 time = 0 # Add track name and tempo. MyMIDI.addTrackName(track,time,"Sample Track") MyMIDI.addTempo(track,time,120) # Add a note. addNote expects the following information: track = 0 channel = 0 pitch = 60 time = 0 duration = 1 volume = 100 # Now add the note. MyMIDI.addNote(track,channel,pitch,time,duration,volume) # And write it to disk. binfile = open("output.mid", 'wb') MyMIDI.writeFile(binfile) binfile.close() There are several additional event types that can be added and there are various options available for creating the MIDIFile object, but the above is sufficient to begin using the library and creating note sequences. The above code is found in machine-readable form in the examples directory. A detailed class reference and documentation describing how to extend the library is provided in the documentation directory. Have fun! --------- Thank You --------- I'd like to mention the following people who have given feedback, but fixes, and suggestions on the library: Bram de Jong Mike Reeves-McMillan Egg Syntax Nils Gey Francis G.
What steps will reproduce the problem?
1. Try to add many beats to track by addNote will generate this error:
"midiutil\MidiFile.py", line 619
self.MIDIEventList.sort(lambda x, y: int( 1000 * (x.time - y.time)))
TypeError: comparison function must return int, not long
2. May be only Win7 issue?
3. Ive fixed it changing line 619 (and 385 and 411 for thet matter):
self.MIDIEventList.sort(lambda x, y: cmp(x.time*1000 , y.time*1000))
What is the expected output? What do you see instead?
Not to see the error, with the fix above no more problems encoutered
What version of the product are you using? On what operating system?
Version 0.89
Please provide any additional information below.
Thanks for sharing your excellent work!
Original issue reported on code.google.com by [email protected]
on 2 Sep 2014 at 4:21
The documentation would make it seem like you can specify any number for
"param1" in midi.addControllerEvent.
Attempting to add a controller event with paramValue > 255 results in the
following error:
File "/Library/Python/2.7/site-packages/midiutil/MidiFile.py", line 540, in
writeEventsToStream
self.MIDIdata = self.MIDIdata + struct.pack('>B',event.paramerter1)
struct.error: ubyte format requires 0 <= number <= 255
Would be great if we could either extend the lib to support 14-bit messages
like Pan and Pitch-Wheel. Or maybe there's another way to specify these
messages and I'm missing something ...
Original issue reported on code.google.com by [email protected]
on 14 Dec 2013 at 5:04
Hi,
I'm using Python 3, and there's an issue with the use of struct.pack() in
MIDIHeader. Any help would be greatly appreciated. Thanks!
---
Traceback (most recent call last):
File "I:/pm/start.py", line 299, in <module>
pm = PerpetualMotion()
File "I:/pm/start.py", line 98, in __init__
self.score = MIDIFile(9)
File "I:\pm\midiutil\MidiFile3.py", line 695, in __init__
self.header = MIDIHeader(numTracks)
File "I:\pm\midiutil\MidiFile3.py", line 649, in __init__
self.headerString = struct.pack('cccc','M','T','h','d')
struct.error: char format requires a bytes object of length 1
Original issue reported on code.google.com by mikestopcontinues
on 7 Sep 2013 at 3:44
What steps will reproduce the problem?
1. Install your code
2. copy your example into a file
3. run it
What is the expected output? What do you see instead?
Traceback (most recent call last):
File "miditest.py", line 7, in <module>
MyMIDI = MIDIFile(1)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/midiutil/MidiFile3.py", line 695, in __init__
self.header = MIDIHeader(numTracks)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/midiutil/MidiFile3.py", line 649, in __init__
self.headerString = struct.pack('cccc','M','T','h','d')
struct.error: char format requires a bytes object of length 1
What version of the product are you using? On what operating system?
Current version, OSX ML
Original issue reported on code.google.com by [email protected]
on 5 Oct 2013 at 12:21
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.