-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmidi.py
More file actions
29 lines (19 loc) · 760 Bytes
/
midi.py
File metadata and controls
29 lines (19 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import sys
import mido
from pstep_base import PipelineStepBase
class MidiParser(PipelineStepBase):
def __init__(self, filename: str):
print("Ingesting midi", file=sys.stderr)
midi = mido.MidiFile(filename)
def do_i_want_this(x: mido.Message):
return 'velocity' in x.dict() and x.dict()['velocity'] > 0
self.left = list(filter(do_i_want_this, midi.tracks[1]))
self.right = list(filter(do_i_want_this, midi.tracks[0]))
def has_left(self) -> bool:
return len(self.left) > 0
def has_right(self) -> bool:
return len(self.right) > 0
def pop_left(self):
return self.left.pop(0)
def pop_right(self):
return self.right.pop(0)