-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkromectl.py
executable file
·63 lines (52 loc) · 1.51 KB
/
kromectl.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
import os
"""
the korg krome synthesizer controller class
tested for combi and sequencer modes
"""
class Krome61:
def __init__(self,mdfl,sndfl):
self.desc='korg krome workstation'
self.midifile=mdfl
self.midifh=None
self.sndfile=sndfl
self.sndmap={}
if self.midifile:
self.midifh=os.open(self.midifile,os.O_WRONLY)
if self.sndfile:
self.loadsounds()
def loadsounds(self):
with open(self.sndfile) as sndf:
sndlns=sndf.readlines()
sndlns=[sndln.strip() for sndln in sndlns]
for sln in sndlns:
lr=sln.split('=')
evtlst=[]
for evt in lr[1].split():
elr=evt.split('/')
evtlst.append((int(elr[0]),int(elr[1])))
self.sndmap[lr[0]]=evtlst
def midion(self,ch,note,velo):
midimsg=[0x90+ch,note,velo]
midiseq=bytearray(midimsg)
if self.midifh:
os.write(self.midifh,midiseq)
def midioff(self,ch,note,velo):
midimsg=[0x80+ch,note,velo]
midiseq=bytearray(midimsg)
if self.midifh:
os.write(self.midifh,midiseq)
def closeio(self):
if self.midifh:
os.close(self.midifh)
# setup krome in seq mode with some drum kit on midi ch 10 (0x09)
def getmidiinfo(self,sndnm,vol):
if sndnm not in self.sndmap:
raise Exception('no such sound %s'%sndnm)
return [(cn[0],cn[1],vol) for cn in self.sndmap[sndnm]]
def __str__(self):
return '[%s] target: %s'%(self.desc,self.midifile)
# program flow
if __name__=='__main__':
kk=Krome61()
print(str(kk))