Contents
. 1. Front Matter  
 
 
Next 1.2. Installing

1.1. Whetting Your Appetite


Let me take you on a quick tour of Midithing. We'll assume that you have something capable of playing MIDI notes hooked to your system's first hardware MIDI port. So let's get at it. Start Python, and play your first note.

$ python
Python 2.0 (#10, Jul 11 2001, 19:41:56)
[GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2

>>> from midithing import *
>>> port = Port ('/dev/midi0') # this usually is the first hardware midi port
>>> port.write (Note())
>>> port.write (NoteOff())
>>>

Want to try a different sound?

>>> port.write (Program (4))
>>>

Now we'll do the first song.

>>> song = Song()
>>> song.add (Part()) # the first part should be used for time and tempo information alone
>>> part = Part()
>>> song.add (part)
>>> quarter = song.division
>>> for i in ('e5', 'g#5', 'b5'):
... part.add (Note (i, length = quarter))
...
>>> for i in ('eb5', 'gb5', 'b5'):
... part.add (Note (i, length = quarter / 2, tick = 2 * quarter))
...
>>> song[1]
Part (
Note ('E5' or 64, velocity=80, channel=0, tick=0, length=192, velocity_off=80, port=0),
Note ('G#5' or 68, velocity=80, channel=0, tick=0, length=192, velocity_off=80, port=0),
Note ('B5' or 71, velocity=80, channel=0, tick=0, length=192, velocity_off=80, port=0),
Note ('D#5' or 63, velocity=80, channel=0, tick=384, length=96, velocity_off=80, port=0),
Note ('F#5' or 66, velocity=80, channel=0, tick=384, length=96, velocity_off=80, port=0),
Note ('B5' or 71, velocity=80, channel=0, tick=384, length=96, velocity_off=80, port=0),
division=192)
>>>

Now how do we play it? We need the IO object to schedule and write the MIDI data:

>>> io=IO()
>>> io.add (port) # this will return 0 as the index of the port
0
>>> io.sync.add (song)
>>> song.play()
>>>

Ok. that was short. Let's find out what our song is doing now.

>>> song.tick, song.beat, song.time
(31077, (40, 1, 165), 80.9296875)
>>> song.stop()
>>> song.tick, song.beat, song.time
(32986, (42, 3, 154), 85.901041666666657)
>>>

So the song never stopped playing until we told it to. Aha. Can we make it loop so we can enjoy our beautiful composition a little longer?

>>> song.loop = (0, 3 * quarter)
>>> song.tick = 0
>>> song.play()
>>>

Let's try a different sound while it's playing ...

>>> part[4].note += 1
>>>

No doubt, this composition needs to be preserved for later generations.

>>> song.write ('foo.mid')
>>>

Ok, here the quick tour ends. We've only scratched the surface of what the midi thing can do, but I hope it is sufficient to get you going. Have fun!

Next is Installing

midithing 0.3.22 documentation © Tim Goetze Nov. 06 2001