midiOSCesp/main.py

105 lines
1.8 KiB
Python
Executable File

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
midiOSCesp v0.1b Computer side
Hook to all midi ports, forward in OSC these midi events :
/noteon MidiChannel, note, velocity
/noteoff MidiChannel, note
/rawcc MidiChannel, CCnumber, CCvalue
/clock
/start
/stop
'''
print("")
print("")
print("midiOSCesp Server")
print("v0.1b")
import sys
import traceback
import os
import time
from rtmidi.midiconstants import (CHANNEL_PRESSURE, CONTROLLER_CHANGE, NOTE_ON, NOTE_OFF,
PITCH_BEND, POLY_PRESSURE, PROGRAM_CHANGE)
#sys.path.append('libs/')
import midix
#import socket
import types, json
import argparse
import _thread, time
print ("")
print ("Arguments parsing if needed...")
argsparser = argparse.ArgumentParser(description="MidiOSCesp v0.1b commands help mode")
argsparser.add_argument('-verbose',help="Enable debug mode (disabled by default)", dest='verbose', action='store_true')
argsparser.set_defaults(verbose=False)
args = argsparser.parse_args()
# Debug/verbose mode ?
if args.verbose == False:
print("Debug mode disabled")
debug = 0
else:
print("Debug mode enabled")
debug = 1
#
# Midi part
#
print("Midi Configuration...")
# print("Midi Destination", nozmidi)
midix.check()
def GetTime():
return time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
# /cc cc number value
def cc(midichannel, ccnumber, value, mididest):
if gstt.debug>0:
print(GetTime(),"Jamidi Sending Midi channel", midichannel, "cc", ccnumber, "value", value, "to", mididest)
midix.MidiMsg([CONTROLLER_CHANGE+midichannel-1, ccnumber, value], mididest)
#
# Running...
#
try:
print(GetTime(),"midi2osc running forever...")
while True:
time.sleep(1)
except Exception:
traceback.print_exc()
# Gently stop on CTRL C
print("Fin de midiOSCesp.")