-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftposc2midi
executable file
·145 lines (118 loc) · 3.75 KB
/
ftposc2midi
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python3
"""
Fishman Triple Play OSC Daemon -> MIDI coversion server
ftposc2midi
Written By:
Shane Hutter
This software:
* Creates an OSC server
* Creates 13 MIDI outputs
This is an interface between ftposcd and Virtual MIDI outputs.
The OSC server listens for /*/tripleplay/output/X OSC paths
The top level "directory" (*) in the OSC Path only indicates the hostname
of the sending client. It is ignored, except maybe for logging
purposes.
The bottom level "directory" (X) represents the channel number.
Only these chanels are accepted
0 to 5
10 to 15
Mono wll send out all 12
Poly will only send out channel 0
When an OSC Midi message is recieved, convert it into a midi message,
and send out an output corresponding to the channel.
Each output sends out channel 0
Midi Output 13 will send all notes, using the original midi channel
"""
from FTP import (
LATENCY , MIDI_PICKUP_NAME ,
)
from FTP.config import load_config
from FTP.midi import (
MIDI_BYTES_INDICES ,
ftp_midi_string_outports ,
)
from FTP.osc import (
OSC_TYPETAGS , OSC_PATH_DELIMITER , FTP_OSC_PATH_INDICES ,
OSCServer ,
)
from mido import (
open_output , Message ,
)
from sys import exit
from time import sleep
alive = True
def osc2midi_convert(
path ,
args ,
typespec ,
function ,
midi_outports ,
):
"""
OSC Server method
uses global midi_outports
parse OSC path
"""
osc_path = path.split( OSC_PATH_DELIMITER )
if osc_path[
FTP_OSC_PATH_INDICES[ "device" ]
] == MIDI_PICKUP_NAME and osc_path[
FTP_OSC_PATH_INDICES[ "direction" ]
] == "output":
midi_outport = midi_outports[
int(
osc_path[
FTP_OSC_PATH_INDICES[ "channel" ]
]
)
]
if midi_outport:
# Convert args into MIDI Message
# ( Note_On(144)/Note_Offmsg2, Note , Velocity, Time(0) )
if args[0][
MIDI_BYTES_INDICES[ "time" ]
]:
# If there is a time byte, use it
midi_outport.send(
Message.from_bytes( args[0] )
)
else:
# Otherwise, take the time byte away
midi_outport.send(
Message.from_bytes( args[0][:-1] )
)
'''
print( midi_outport )
print( args )
print( msg )
'''
return
def main():
"""
Main code block
"""
# Load the OSC Server port from the configuration file
osc_server_port = load_config()[ "ftposc2midi-port" ]
# Create per-string MIDI outports
midi_outports = ftp_midi_string_outports()
print( osc_server_port )
print( midi_outports )
# Start OSC server
with OSCServer( osc_server_port ) as osc_server:
# Register OSC method
osc_server.add_method(
None ,
OSC_TYPETAGS[ "midi" ] ,
osc2midi_convert ,
midi_outports
)
# Main loop
while alive:
sleep( LATENCY )
# Close per-string MIDI outports
for outport in midi_outports:
if outport:
outport.close()
return exit()
if __name__ == "__main__":
main()