#!/usr/bin/python3 # -*- coding: utf-8 -*- """ miredis v0.1 Forward midi events to OSC and redis. by Sam Neurohack from ProtonPhoton """ from libs import log print() log.infog('Miredis v0.1') import argparse import redis from libs import midix import traceback from pathlib import Path #myHostName = socket.gethostname() #print("Name of the localhost is {}".format(myHostName)) #gstt.myIP = socket.gethostbyname(myHostName) #print("IP address of the localhost is {}".format(gstt.myIP)) #gstt.myIP = "127.0.0.1" #print('Used IP', gstt.myIP) argsparser = argparse.ArgumentParser(description="Miredis") # General Args argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose") # Redis Args argsparser.add_argument("-i","--ip",help="IP address of the Redis server ",default="127.0.0.1",type=str) argsparser.add_argument("-p","--port",help="Port of the Redis server ",default="6379",type=str) # OSC Args argsparser.add_argument("-o","--oscip",help="IP address of the OSC server to forward midi events.",default="127.0.0.1",type=str) argsparser.add_argument("-q","--oscport",help="Port of the OSC server ",default="9000",type=str) argsparser.add_argument('-link',help="Enable Ableton Link (disabled by default)", dest='link', action='store_true') argsparser.add_argument("-m","--mode",help="Mode choice : simplex, clitools",default="clitools",type=str) argsparser.set_defaults(link=False) args = argsparser.parse_args() redisIP = args.ip redisPORT = args.port midix.oscIP = args.oscip midix.oscPORT = int(args.oscport) midix.debug = args.verbose midix.mode = args.mode # with Ableton Link if args.link == True: from libs import alink alink.Start() linked = True else: print("Link DISABLED") linked = False r = redis.StrictRedis(host=redisIP , port=redisPORT, db=0) midix.r = r def Osc(): p = r.pubsub() p.subscribe('updates') print("Artnet updates subscribed") while True: # Handle OSC based changed OSCframe() # Handle Artnet change via redis key 'updates' subscription message = p.get_message() if message: messageCC = message['data'] # print(type(messageCC)) #print("Updates said: %s" % messageCC) if messageCC != 1: #if ":" in str(messageCC.decode('utf_8')): messageCC = messageCC.decode('utf_8') artnetCC = messageCC.split(":") if len(artnetCC) > 1: cc(int(artnetCC[0]), round(int(artnetCC[1])/2)) print() #time.sleep(0.0) if __name__ == '__main__': import traceback import time midix.check() midix.loadConf() midix.toKey("/beats","0.0") midix.toKey("/bpm",120) try: while True: time.sleep(0.001) if linked: alink.BeatEvent() except Exception: traceback.print_exc() #finally: