Contents . 1. Front Matter |
Next 1.2. Installing |
$ 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())
>>>
>>> port.write (Program (4))
>>>
>>> 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)
>>>
>>> io=IO()
>>> io.add (port) # this will return 0 as the index of the port
0
>>> io.sync.add (song)
>>> song.play()
>>>
>>> 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)
>>>
>>> song.loop = (0, 3 * quarter)
>>> song.tick = 0
>>> song.play()
>>>
>>> part[4].note += 1
>>>
>>> song.write ('foo.mid')
>>>
midithing 0.3.22 documentation | © Tim Goetze | Nov. 06 2001 |