Client bugfixs

This commit is contained in:
sam 2020-05-08 18:29:51 +02:00
parent b79a3487eb
commit 8205534a40
6 changed files with 64 additions and 54 deletions

View File

@ -44,6 +44,8 @@ sys.path.append('libs/')
import midi3 import midi3
import types import types
import websocket import websocket
import gstt
#import WScom
try: try:
import _thread import _thread
@ -52,8 +54,6 @@ except ImportError:
import argparse import argparse
debug = 1
print ("") print ("")
print ("Arguments parsing if needed...") print ("Arguments parsing if needed...")
@ -146,7 +146,7 @@ def LoadConfs():
f=open("jamidi.json","r") f=open("jamidi.json","r")
s = f.read() s = f.read()
Confs = json.loads(s) gstt.Confs = json.loads(s)
# return midi confname number for given type # return midi confname number for given type
@ -154,14 +154,16 @@ def findConfs(confname,conftype):
#print("searching", midiconfname,'...') #print("searching", midiconfname,'...')
position = -1 position = -1
for counter in range(len(Confs[conftype])): for counter in range(len(gstt.Confs[conftype])):
if confname == Confs[conftype][counter]['name']: if confname == gstt.Confs[conftype][counter]['name']:
#print(confname, "is ", counter) #print(confname, "is ", counter)
position = counter position = counter
return position return position
def curved(value): def curved(value):
return round(np.sqrt(value)*11.27) return round(np.sqrt(value)*11.27)
@ -191,34 +193,6 @@ def cc(midichannel, ccnumber, value, mididest):
midi3.MidiMsg([CONTROLLER_CHANGE+midichannel-1, ccnumber, value], mididest) midi3.MidiMsg([CONTROLLER_CHANGE+midichannel-1, ccnumber, value], mididest)
'''
# Specials features ?
if len(MidiRules['Specials']) > 0:
for counter in range(len(MidiRules["Specials"])):
# print()
# print("Name", MidiRules["Specials"][counter]["name"])
# print("Song", MidiRules["Specials"][counter]["songname"], songs[song]) # name, "all"
# print("Channel", MidiRules["Specials"][ counter]["chanIN"], MidiChannel) # number, "all"
# print("Note", MidiRules["Specials"][counter]["notes"], MidiNote) # number, "all"
# print("Notetype", MidiRules["Specials"][counter]["notetype"], "on") # "on", "off", "all"
if (MidiRules["Specials"][counter]["songname"] == songs[song] or MidiRules["Specials"][counter]["songname"] == "all") and (MidiRules["Specials"][counter]["chanIN"] == MidiChannel or MidiRules["Specials"][counter]["chanIN"] == "all") and (MidiRules["Specials"][counter]["notes"] == MidiNote or MidiRules["Specials"][counter]["notes"] == "all") and (MidiRules["Specials"][counter]["notetype"] == "off" or MidiRules["Specials"][counter]["notetype"] == "all") :
midirulecode = MidiRules["Specials"][counter]["code"]
print("Specials function :",MidiRules["Specials"][counter]["songname"], ":", MidiRules["Specials"][counter]["name"], midirulecode)
# python function
if midirulecode.count('.') > 0:
#print(midirulecode+"("+str(MidiNote)+')')
eval(midirulecode+"("+str(MidiNote)+')')
# Maxwell function
elif midirulecode.count('/') > 0:
#print("Specials NoteON got :", MidiRules["Specials"][counter]["songname"]," IN Channel :", MidiRules["Specials"][counter]["chanIN"]," Code :", midirulecode, " CC", maxwellccs.FindCC(MidiRules["Specials"][counter]["code"]), " value :",MidiRules["Specials"][counter]["valuetype"], " laser :", MidiRules["ZccLcc"][counter]["laser"] )
midi3.MidiMsg((CONTROLLER_CHANGE, maxwellccs.FindCC(MidiRules["Specials"][counter]["code"]), MidiRules["Specials"][counter]["valuetype"]), mididest, laser = MidiRules["Specials"][counter]["laser"])
'''
# /reset nozoids with "default" values # /reset nozoids with "default" values
def reset(nozoid): def reset(nozoid):
@ -228,12 +202,12 @@ def reset(nozoid):
if nozoid == "mmo3": if nozoid == "mmo3":
for ccnumber in range(0,32): for ccnumber in range(0,32):
midi3.MidiMsg([CONTROLLER_CHANGE+Confs["mmo3"][0]["midichan"]-1, ccnumber, resetMMO3[ccnumber]], Confs["mmo3"][0]["mididevice"]) midi3.MidiMsg([CONTROLLER_CHANGE+gstt.Confs["mmo3"][0]["midichan"]-1, ccnumber, resetMMO3[ccnumber]], gstt.Confs["mmo3"][0]["mididevice"])
sendWSall("/mmo3/cc/"+str(ccnumber)+" "+str(resetMMO3[ccnumber])) sendWSall("/mmo3/cc/"+str(ccnumber)+" "+str(resetMMO3[ccnumber]))
crtvalueMMO3[ccnumber]=resetMMO3[ccnumber] crtvalueMMO3[ccnumber]=resetMMO3[ccnumber]
else: else:
for ccnumber in range(0,32): for ccnumber in range(0,32):
midi3.MidiMsg([CONTROLLER_CHANGE+Confs["ocs2"][0]["midichan"]-1, ccnumber, resetOCS2[ccnumber]], Confs["ocs2"][0]["mididevice"]) midi3.MidiMsg([CONTROLLER_CHANGE+gstt.Confs["ocs2"][0]["midichan"]-1, ccnumber, resetOCS2[ccnumber]], gstt.Confs["ocs2"][0]["mididevice"])
sendWSall("/ocs2/cc/"+str(ccnumber)+" "+str(resetOCS2[ccnumber])) sendWSall("/ocs2/cc/"+str(ccnumber)+" "+str(resetOCS2[ccnumber]))
crtvalueOCS2[ccnumber]=resetOCS2[ccnumber] crtvalueOCS2[ccnumber]=resetOCS2[ccnumber]
print("End of reset for", nozoid) print("End of reset for", nozoid)
@ -282,13 +256,18 @@ def on_message(ws, message):
if len(message) > 200: if len(message) > 200:
message = message[:200]+'..' message = message[:200]+'..'
oscpath = message.split(" ") oscpath = message.split(" ") # ['/ocs2/cc/31', '0'] or ['/players', '(player:1)']
wscommand = oscpath[0].split("/") # print("oscpath", oscpath)
wscommand = oscpath[0].split("/") # ['', 'ocs2', 'cc', '31'] or ['', 'players']
# print("wscommand", wscommand)
device = wscommand[1] device = wscommand[1]
if len(wscommand) == 2:
command = wscommand[1]
else:
command = wscommand[2] command = wscommand[2]
# debug # debug
if debug > 0: if gstt.debug > 0 and command != "status" and command != "players":
print("for device", device, "command :", command) print("for device", device, "command :", command)
# noarg # noarg
@ -301,18 +280,18 @@ def on_message(ws, message):
ccvr=int(wscommand[3]) #cc variable ccvr=int(wscommand[3]) #cc variable
ccvl=int(oscpath[1]) #cc value ccvl=int(oscpath[1]) #cc value
if debug > 0: if gstt.debug > 0:
print("device", device,"ccvr=%d/ccvl=%d"%(ccvr,ccvl)) print("device", device,"ccvr=%d/ccvl=%d"%(ccvr,ccvl))
for mididevice in midi3.findJamDevices(device): for mididevice in midi3.findJamDevices(device):
cc(Confs[device][0]["midichan"], ccvr, ccvl, mididevice) cc(gstt.Confs[device][0]["midichan"], ccvr, ccvl, mididevice)
''' '''
# CC : /device/cc/2 127 # CC : /device/cc/2 127
elif wscommand[1] == "ocs2": elif wscommand[1] == "ocs2":
if wscommand[2] == "cc": if wscommand[2] == "cc":
print("Incoming OCS-2 WS CC", wscommand[3], ":", int(oscpath[1])) print("Incoming OCS-2 WS CC", wscommand[3], ":", int(oscpath[1]))
cc(Confs["ocs2"][0]["midichan"], int(wscommand[3]), int(oscpath[1]), Confs["default"][0]["mididevice"]) cc(gstt.Confs["ocs2"][0]["midichan"], int(wscommand[3]), int(oscpath[1]), gstt.Confs["default"][0]["mididevice"])
if wscommand[2] == "OSC1": if wscommand[2] == "OSC1":
print("Incoming OCS-2 WS OSC1", wscommand[3], ":", int(oscpath[1])) print("Incoming OCS-2 WS OSC1", wscommand[3], ":", int(oscpath[1]))
@ -321,7 +300,7 @@ def on_message(ws, message):
elif wscommand[1] == "mmo3": elif wscommand[1] == "mmo3":
if wscommand[2] == "cc": if wscommand[2] == "cc":
print("Incoming MMO-3 WS CC", wscommand[3], ":", int(oscpath[1])) print("Incoming MMO-3 WS CC", wscommand[3], ":", int(oscpath[1]))
cc(Confs["mmo3"][0]["midichan"], int(wscommand[3]), int(oscpath[1]), Confs["default"][0]["mididevice"]) cc(gstt.Confs["mmo3"][0]["midichan"], int(wscommand[3]), int(oscpath[1]), gstt.Confs["default"][0]["mididevice"])
if wscommand[2] == "OSC1": if wscommand[2] == "OSC1":
print("Incoming MMO-3 WS OSC1", wscommand[3], ":", int(oscpath[1])) print("Incoming MMO-3 WS OSC1", wscommand[3], ":", int(oscpath[1]))
@ -346,6 +325,7 @@ def on_message(ws, message):
midi3.NoteOff(int(oscpath[1]), mididevice) midi3.NoteOff(int(oscpath[1]), mididevice)
# if needed a loop back : WS Client -> server -> WS Client # if needed a loop back : WS Client -> server -> WS Client
# sendWSall(message) # sendWSall(message)
@ -358,9 +338,9 @@ def on_message(ws, message):
LoadMidiRules() LoadMidiRules()
LoadConfs() LoadConfs()
serverIP = Confs[servername][0]["IP"] serverIP = gstt.Confs[servername][0]["IP"]
#serverIP = "10.8.0.46" #serverIP = "10.8.0.46"
wsPORT = Confs[servername][0]["port"] wsPORT = gstt.Confs[servername][0]["port"]
print("Running....") print("Running....")
@ -378,8 +358,8 @@ try:
on_close = on_close) on_close = on_close)
midi3.ws = ws midi3.ws = ws
midi3.clientmode = True gstt.clientmode = True
midi3.Confs = Confs #gstt.Confs = Confs
print("Midi Configuration...") print("Midi Configuration...")
midi3.check() midi3.check()

View File

@ -9,6 +9,11 @@ OSCom.Start(serverIP, OSCPORT)
default handler : handler(path, tags, args, source) default handler : handler(path, tags, args, source)
register particular OSC command in Start(): i.e oscserver.addMsgHandler( "/n", Note) register particular OSC command in Start(): i.e oscserver.addMsgHandler( "/n", Note)
Launch
print("Launching OSC Server", serverIP,':', OSCPORT)
OSCom.Start(serverIP, OSCPORT)
''' '''
import midi3 import midi3

View File

@ -8,6 +8,11 @@ UDPcom for jamidi v0.1b
UDPcom.Start(serverIP, UDPORT) UDPcom.Start(serverIP, UDPORT)
Handler : udp_thread() Handler : udp_thread()
Launch :
print("Launching UDP Server", serverIP,':', wsPORT)
UDPcom.Start(serverIP, UDPORT)
Read below for : Read below for :
- MIDI NOTES use ;nmonv - MIDI NOTES use ;nmonv
@ -21,16 +26,20 @@ import midi3
import types, json import types, json
import socket import socket
import _thread, time import _thread, time
import midi3
import WScom, OSCom import WScom, OSCom
import gstt import gstt
import time import time
#base36 = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
def GetTime(): def GetTime():
return time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()) return time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
#
# SERVER part
#
def udp_thread(): def udp_thread():
while True: while True:

View File

@ -9,6 +9,19 @@ WScom.Start(serverIP, wsPORT)
WScom.runforever() WScom.runforever()
handler : message_received(client, wserver, message) handler : message_received(client, wserver, message)
Launch :
print("Launching WS Server", serverIP,':', UDPORT)
WScom.Start(serverIP, wsPORT)
try:
WScom.runforever()
except Exception:
traceback.print_exc()
''' '''
import midi3 import midi3
@ -21,6 +34,10 @@ from websocket_server import WebsocketServer
import gstt import gstt
import UDPcom, OSCom import UDPcom, OSCom
#
# Server part
#
def Start(serverIP, wsPORT): def Start(serverIP, wsPORT):
global wserver global wserver
@ -140,7 +157,7 @@ def message_received(client, wserver, message):
def send(message): def send(message):
if gstt.clientmode == True: if gstt.clientmode == True:
send(message) midi3.ws.send(message)
else: else:
wserver.send_message_to_all(msg = message) wserver.send_message_to_all(msg = message)

View File

@ -1,4 +1,3 @@
#!/usr/bin/python3 #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-

View File

@ -237,10 +237,10 @@ print(GetTime(),"Launching servers...")
print(GetTime(),"Launching OSC Server", serverIP,':', OSCPORT) print(GetTime(),"Launching OSC Server", serverIP,':', OSCPORT)
OSCom.Start(serverIP, OSCPORT) OSCom.Start(serverIP, OSCPORT)
print(GetTime(),"Launching WS Server", serverIP,':', wsPORT) print(GetTime(),"Launching UDP Server", serverIP,':', wsPORT)
UDPcom.Start(serverIP, UDPORT) UDPcom.Start(serverIP, UDPORT)
print(GetTime(),"Launching UDP Server", serverIP,':', UDPORT) print(GetTime(),"Launching WS Server", serverIP,':', UDPORT)
WScom.Start(serverIP, wsPORT) WScom.Start(serverIP, wsPORT)