def connectRavelox(): global gRaveloxClient try: #local_port = 5006 #if len(sys.argv) == 1: # family = socket.AF_INET # connect_tuple = ( 'localhost', local_port ) #else: # details = socket.getaddrinfo( sys.argv[1], local_port, socket.AF_UNSPEC, socket.SOCK_DGRAM) # family = details[0][0] # if family == socket.AF_INET6: # connect_tuple = ( sys.argv[1], local_port, 0, 0) # else: # connect_tuple = ( sys.argv[1], local_port) #s = socket.socket( family, socket.SOCK_DGRAM ) #s.connect( connect_tuple ) connect_tuple = ('localhost', 5006) gRaveloxClient = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) gRaveloxClient.connect(connect_tuple) displayData.setRaveloxmidiStatus(255) displayData.drawScreen() return True except: displayData.setRaveloxmidiStatus(0) displayData.drawScreen() printDebug('<<< exception. connectRavelox >>') # pprint.pprint(sys.exc_info()) return False
def getListOfRaveloxMidiClients(): global gRaveloxClient # Request status bytes = struct.pack('4s', b'LIST') #print(bytes) data = '' result = '' gRaveloxClient.sendall(bytes) x = 0 while True: try: data, addr = gRaveloxClient.recvfrom(8192) if data: result = dataHelper.unicodetoASCII(str(data)) break except: pass sleep(MIN_DELAY) if (x > 5): break x = x + 1 #---- if result.find("Vlad-iPad") > -1: displayData.g_iPadStatus = 255 else: displayData.g_iPadStatus = 0 if result.find("Vlad's MacBook Pro") > -1: displayData.g_MacBookStatus = 255 else: displayData.g_MacBookStatus = 0 displayData.drawScreen() printDebug(result)
def connect(): try: printDebug('SOCKET connection established') displayData.setMessageAPIStatus(255) #displayData.drawScreen() except: printDebug('SOCKET connection can not be established') displayData.setMessageAPIStatus(0) displayData.drawScreen()
def loadAllData(): global gGig global gSongDict global gSongList global gGigSongList global gInstrumentChannelDict global gPresetDict global gInstrumentBankDict global gBankSongList global gSelectedGigId printDebug(' << Load All Data >>') if gGig != None and hasattr('gGig', 'shortSongList'): gGig.shortSongList.clear() gGig = None if gInstrumentChannelDict != None: gInstrumentChannelDict.clear() if gInstrumentBankDict != None: gInstrumentBankDict.clear() if gPresetDict != None: gPresetDict.clear() if gGigSongList != None: gGigSongList.clear() if gSongList != None: gSongList.clear() if gSongDict != None: gSongDict.clear() if gBankSongList != None: gBankSongList.clear() try: gGig = dataHelper.loadScheduledGig() gSelectedGigId = gGig.id #printDebug(gGig.shortSongList) gSongDict = dataHelper.loadSongs() #printDebug(gSongDict) gSongList = dataHelper.initAllSongs(gSongDict) #printDebug(gSongList) gGigSongList = dataHelper.initGigSongs(gGig.shortSongList, gSongDict) gInstrumentChannelDict = dataHelper.initInstruments() gPresetDict = dataHelper.initPresets() gInstrumentBankDict = dataHelper.initInstrumentBanks() displayData.setDataAPIStatus(255) #displayData.drawScreen() except: displayData.setDataAPIStatus(0) displayData.drawScreen() print('<< Exception. loadAllData >>')
def setPreset(program, songPreset): id = songPreset['refpreset'] #print(id) preset = gPresetDict[str(id)] #print(preset) midiProgramChange = int(preset['midipc']) channel = int(gInstrumentChannelDict[str(songPreset['refinstrument'])]) mute = songPreset['muteflag'] if mute: muteChannel(channel, songPreset['volume'], MIN_DELAY, 10) sendRaveloxPCMessage(channel, midiProgramChange) if mute: unmuteChannel(channel, songPreset['volume'], MIN_DELAY, 10) else: sendRaveloxCCMessage(channel, VOLUME_CC, songPreset['volume']) if preset['refinstrument'] == 1: displayData.setProgramName(f"{program['name']}.{preset['name']}") displayData.drawScreen()
def processRaveloxMessageQueue(): global gRaveloxClient global gExitFlag global gMessageQueue global gQueueLock delay = MIN_DELAY while not gExitFlag: gQueueLock.acquire() if not gMessageQueue.empty(): #print (gMessageQueue.qsize()) broadcastMessage = gMessageQueue.get() gMessageQueue.task_done() gQueueLock.release() try: if (broadcastMessage.messageType == 'PC'): sleep(MIN_DELAY * 3.0) gRaveloxClient.send(broadcastMessage.message) #sleep(MIN_DELAY * 2.0) # gRaveloxClient.send( broadcastMessage.message ) if (broadcastMessage.messageType == 'CC'): gRaveloxClient.send(broadcastMessage.message) except: displayData.setRaveloxmidiStatus(0) displayData.drawScreen() printDebug( f'<<< exception. processRaveloxMessageQueue >>{broadcastMessage}' ) delay = MIN_DELAY #printDebug (f'Processed Message ->>> {message}') else: gQueueLock.release() delay = MIN_DELAY * 2.0 sleep(delay)
def disconnect(): printDebug('disconnected from SOCKET server') displayData.setMessageAPIStatus(0) displayData.drawScreen()
displayData.drawScreen() printDebug(result) #---------------------------------------------------------------- #---------------------------------------------------------------- #---------------------------------------------------------------- #Main Module #pygame.init() pygame.midi.init() displayData.initDisplay() displayData.clearScreen() displayData.drawScreen() sleep(3) #displayData.clearScreen() # print(str(sys.argv)) if len(sys.argv) > 1: if str(sys.argv[1]).upper() == 'DEBUG': gMode = 'Debug' #Show the list of available midi devices printDebug(pygame.midi.get_count()) if gMode == 'Debug': for id in range(pygame.midi.get_count()): printDebug("Id=%d Device=%s" % (id, pygame.midi.get_device_info(id))) # sio = socketio.Client()