Skip to content

Commit 6889a98

Browse files
authored
Python3 (#3)
* Python3 port by Marius Gedminas See: - https://github.com/mgedmin/python-midi - vishnubob#130 * Re-applied adaptations for samplerbox * Add buffered writing of 1-track midi files (#2)
1 parent 3d565e5 commit 6889a98

File tree

20 files changed

+225
-127
lines changed

20 files changed

+225
-127
lines changed

examples/example_1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import midi
23
# Instantiate a MIDI Pattern (contains a list of tracks)
34
pattern = midi.Pattern()
@@ -15,6 +16,6 @@
1516
eot = midi.EndOfTrackEvent(tick=1)
1617
track.append(eot)
1718
# Print out the pattern
18-
print pattern
19+
print(pattern)
1920
# Save the pattern to disk
2021
midi.write_midifile("example.mid", pattern)

examples/example_2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import midi
23
pattern = midi.read_midifile("example.mid")
3-
print pattern
4+
print(pattern)

scripts/mididump.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#!/usr/bin/env python
2+
from __future__ import print_function
3+
24
"""
35
Print a description of a MIDI file.
46
"""
57
import midi
68
import sys
79

810
if len(sys.argv) != 2:
9-
print "Usage: {0} <midifile>".format(sys.argv[0])
11+
print("Usage: {0} <midifile>".format(sys.argv[0]))
1012
sys.exit(2)
1113

1214
midifile = sys.argv[1]
1315
pattern = midi.read_midifile(midifile)
14-
print repr(pattern)
16+
print(repr(pattern))

scripts/mididumphw.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"""
33
Print a description of the available devices.
44
"""
5+
from __future__ import print_function
56
import midi.sequencer as sequencer
67

78
s = sequencer.SequencerHardware()
89

9-
print s
10+
print(s)

scripts/midilisten.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
"""
33
Attach to a MIDI device and print events to standard output.
44
"""
5+
from __future__ import print_function
6+
57
import sys
68
import time
79
import midi
810
import midi.sequencer as sequencer
911

1012
if len(sys.argv) != 3:
11-
print "Usage: {0} <client> <port>".format(sys.argv[0])
13+
print("Usage: {0} <client> <port>".format(sys.argv[0]))
1214
exit(2)
1315

1416
client = sys.argv[1]
@@ -21,4 +23,4 @@
2123
while True:
2224
event = seq.event_read()
2325
if event is not None:
24-
print event
26+
print(event)

scripts/midiplay.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
Attach to a MIDI device and send the contents of a MIDI file to it.
44
2019 - HansEhv: adapted to work with modified sequencer.py
55
"""
6+
from __future__ import print_function
7+
68
import sys
79
import time
810
import midi
911
import midi.sequencer as sequencer
1012

1113
if len(sys.argv) != 4:
12-
print "Usage: {0} <client> <port> <file>".format(sys.argv[0])
14+
print("Usage: {0} <client> <port> <file>".format(sys.argv[0]))
1315
exit(2)
1416

1517
client = sys.argv[1]
@@ -47,4 +49,4 @@
4749
seq.drain()
4850
time.sleep(.5)
4951

50-
print 'The end?'
52+
print('The end?')

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22

3+
from __future__ import print_function
34
import os
45
from setuptools import setup, Extension
56
import setuptools.command.install
@@ -62,7 +63,7 @@ def configure_platform():
6263
setup_alsa(ns)
6364
pass
6465
else:
65-
print "No sequencer available for '%s' platform." % platform
66+
print("No sequencer available for '%s' platform." % platform)
6667
return ns
6768

6869
if __name__ == "__main__":

src/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from containers import *
2-
from events import *
31
from struct import unpack, pack
4-
from util import *
5-
from fileio import *
2+
3+
from .containers import *
4+
from .events import *
5+
from .util import *
6+
from .fileio import *

src/constants.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
##
44

55
OCTAVE_MAX_VALUE = 12
6-
OCTAVE_VALUES = range( OCTAVE_MAX_VALUE )
6+
OCTAVE_VALUES = list(range( OCTAVE_MAX_VALUE))
77

8-
NOTE_NAMES = ['C','Cs','D','Ds','E','F','Fs','G','Gs','A','As','B']
8+
NOTE_NAMES = ['C', 'Cs', 'D', 'Ds', 'E', 'F', 'Fs', 'G', 'Gs', 'A', 'As', 'B']
99
WHITE_KEYS = [0, 2, 4, 5, 7, 9, 11]
1010
BLACK_KEYS = [1, 3, 6, 8, 10]
1111
NOTE_PER_OCTAVE = len( NOTE_NAMES )
12-
NOTE_VALUES = range( OCTAVE_MAX_VALUE * NOTE_PER_OCTAVE )
12+
NOTE_VALUES = list(range( OCTAVE_MAX_VALUE * NOTE_PER_OCTAVE))
1313
NOTE_NAME_MAP_FLAT = {}
1414
NOTE_VALUE_MAP_FLAT = []
1515
NOTE_NAME_MAP_SHARP = {}

src/containers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __getitem__(self, item):
2525
if isinstance(item, slice):
2626
indices = item.indices(len(self))
2727
return Pattern(resolution=self.resolution, format=self.format,
28-
tracks=(super(Pattern, self).__getitem__(i) for i in xrange(*indices)))
28+
tracks=(super(Pattern, self).__getitem__(i) for i in range(*indices)))
2929
else:
3030
return super(Pattern, self).__getitem__(item)
3131

@@ -58,7 +58,7 @@ def make_ticks_rel(self):
5858
def __getitem__(self, item):
5959
if isinstance(item, slice):
6060
indices = item.indices(len(self))
61-
return Track((super(Track, self).__getitem__(i) for i in xrange(*indices)))
61+
return Track((super(Track, self).__getitem__(i) for i in range(*indices)))
6262
else:
6363
return super(Track, self).__getitem__(item)
6464

0 commit comments

Comments
 (0)