Merge pull request #127 from doctea/feature_plugins

Feature plugins
This commit is contained in:
langolierz
2020-03-12 22:18:39 +01:00
committed by GitHub
6 changed files with 84 additions and 68 deletions

View File

@@ -231,14 +231,14 @@ class Actions(object):
def increase_seek_time(self):
options = self.data.settings['sampler']['SEEK_TIME']['options']
current_index = [index for index, item in enumerate(options) if item == self.data.settings['sampler']['SEEK_TIME']['value'] ][0]
self.data.settings['sampler']['SEEK_TIME']['value'] = options[(current_index + 1) % len(options) ]
self.data.update_setting_value('sampler', 'SEEK_TIME', options[(current_index + 1) % len(options) ])
self.message_handler.set_message('INFO', 'The Seek Time is now ' + str(self.data.settings['sampler']['SEEK_TIME']['value']) + 's')
def decrease_seek_time(self):
options = self.data.settings['sampler']['SEEK_TIME']['options']
current_index = [index for index, item in enumerate(options) if item == self.data.settings['sampler']['SEEK_TIME']['value'] ][0]
self.data.settings['sampler']['SEEK_TIME']['value'] = options[(current_index - 1) % len(options) ]
self.data.update_setting_value('sampler', 'SEEK_TIME', options[(current_index - 1) % len(options) ])
self.message_handler.set_message('INFO', 'The Seek Time is now ' + str(self.data.settings['sampler']['SEEK_TIME']['value']) + 's')
@@ -580,7 +580,7 @@ class Actions(object):
if self.data.settings['shader']['STROBE_AMOUNT']['value'] != scaled_amount:
print(scaled_amount)
self.video_driver.osc_client.send_message("/set_strobe", scaled_amount)
self.data.settings['shader']['STROBE_AMOUNT']['value'] = scaled_amount
self.data.update_setting_value('shader', 'STROBE_AMOUNT', scaled_amount)
def get_midi_status(self):
device_name = 'none' if not hasattr(self.data,'midi_device_name') else self.data.midi_device_name
@@ -794,16 +794,15 @@ class Actions(object):
def increase_shader_param(self):
options = self.data.settings['shader']['SHADER_PARAM']['options']
current_index = [index for index, item in enumerate(options) if item == self.data.settings['shader']['SHADER_PARAM']['value'] ][0]
self.data.settings['shader']['SHADER_PARAM']['value'] = options[(current_index + 1) % len(options) ]
self.data.update_setting_value('shader', 'SHADER_PARAM', options[(current_index + 1) % len(options) ])
self.message_handler.set_message('INFO', 'The Param amount is now ' + str(self.data.settings['shader']['SHADER_PARAM']['value']))
def decrease_shader_param(self):
options = self.data.settings['shader']['SHADER_PARAM']['options']
current_index = [index for index, item in enumerate(options) if item == self.data.settings['shader']['SHADER_PARAM']['value'] ][0]
self.data.settings['shader']['SHADER_PARAM']['value'] = options[(current_index - 1) % len(options) ]
self.data.update_setting_value('shader', 'SHADER_PARAM', options[(current_index - 1) % len(options) ])
self.message_handler.set_message('INFO', 'The Param amount is now ' + str(self.data.settings['shader']['SHADER_PARAM']['value']))
def set_fixed_length(self, value):
self.data.control_mode = 'LENGTH_SET'
self.message_handler.set_message('INFO', 'tap: ■ ; < > : back')
@@ -875,19 +874,22 @@ class Actions(object):
self.server.shutdown()
def create_client_and_shutdown_osc_server(self):
from pythonosc import udp_client
client_parser = argparse.ArgumentParser()
client_parser.add_argument("--ip", default=self.data.get_ip_for_osc_client(), help="the ip")
client_parser.add_argument("--port", type=int, default=8080, help="the port")
try:
from pythonosc import udp_client
client_parser = argparse.ArgumentParser()
client_parser.add_argument("--ip", default=self.data.get_ip_for_osc_client(), help="the ip")
client_parser.add_argument("--port", type=int, default=8080, help="the port")
client_args = client_parser.parse_args()
client_args = client_parser.parse_args()
client = udp_client.SimpleUDPClient(client_args.ip, client_args.port)
client.send_message("/shutdown", True)
client = udp_client.SimpleUDPClient(client_args.ip, client_args.port)
client.send_message("/shutdown", True)
except:
pass
def toggle_access_point(self, setting_value):
osc_setting_state = self.data.settings['user_input']['OSC_INPUT']['value']
self.data.settings['user_input']['OSC_INPUT']['value'] = 'disabled'
self.data.update_setting_value('user_input', 'OSC_INPUT', 'disabled')
self.tk.after(2000, self.toggle_access_point_delay, setting_value, osc_setting_state)
def toggle_access_point_delay(self, setting_value, osc_setting_state ):
@@ -899,7 +901,7 @@ class Actions(object):
def toggle_remote_server(self, setting_value):
osc_setting_state = self.data.settings['user_input']['OSC_INPUT']['value']
self.data.settings['user_input']['OSC_INPUT']['value'] = 'disabled'
self.data.update_setting_value('user_input', 'OSC_INPUT', 'disabled')
self.tk.after(2000, self.toggle_remote_server_delay, setting_value, osc_setting_state)
def toggle_remote_server_delay(self, setting_value, osc_setting_state):
@@ -907,10 +909,10 @@ class Actions(object):
self.remote_process = subprocess.Popen(['node', '/home/pi/r_e_m_o_t_e/webserver.js'])
else:
self.stop_remote_process()
self.data.settings['user_input']['OSC_INPUT']['value'] = osc_setting_state
self.data.update_setting_value('user_input', 'OSC_INPUT', osc_setting_state)
def enable_osc(self, osc_setting_state):
self.data.settings['user_input']['OSC_INPUT']['value'] = osc_setting_state
self.data.update_setting_value('user_input', 'OSC_INPUT', osc_setting_state)
def show_ip(self, *args):

View File

@@ -473,6 +473,8 @@ class Display(object):
if value is None:
return " "
value = abs(value / max_value) # abs() so negative values make some sense
if value>1.0: value = 1.0
elif value<0.0: value = 0.0
bar = u"_\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588"
g = '%s'%bar[int(value*(len(bar)-1))]
return g

View File

@@ -184,6 +184,8 @@ class WJSendPlugin(ActionsPlugin, SequencePlugin, DisplayPlugin, ModulationRecei
import threading
serial_lock = threading.Lock()
def send_serial_string(self, string):
if not self.active:
return
try:
if self.DEBUG:
print("WJSendPlugin>> sending string %s " % string)
@@ -192,10 +194,10 @@ class WJSendPlugin(ActionsPlugin, SequencePlugin, DisplayPlugin, ModulationRecei
#self.ser.write(b'\2\2\2\2\3\3\3\3')
self.ser.write(output) #.encode())
# TODO: sleeping here seems to help serial response lag problem?
self.sleep = 0.25 #self.pc.get_variable('A')
print ("got sleep %s" % self.sleep)
self.sleep = 0.2 #self.pc.get_variable('A')
#print ("got sleep %s" % self.sleep)
if self.sleep>=0.1:
print("using sleep %s" % self.sleep)
#print("using sleep %s" % self.sleep)
import time
time.sleep(self.sleep/10.0)
#yield from self.ser.drain()
@@ -214,19 +216,18 @@ class WJSendPlugin(ActionsPlugin, SequencePlugin, DisplayPlugin, ModulationRecei
if not self.ser or self.ser is None:
self.open_serial()
if self.active:
try:
try:
# sorting the commands that are sent seems to fix jerk and lag that is otherwise pretty horrendous
with self.queue_lock:
for queue, command in sorted(self.queue.items()):
# TODO: modulate the parameters
self.send_buffered(queue, command[0], command[1])
#self.queue.clear()
except Exception:
except Exception:
print ("WJSendPlugin>>> !!! CAUGHT EXCEPTION running queue %s!!!" % queue)
import traceback
print(traceback.format_exc())
finally:
finally:
with self.queue_lock:
self.queue.clear()

View File

@@ -59,38 +59,30 @@ class MidiInput(object):
def poll_midi_input(self):
i = 0
cc_dict = dict()
for message in self.midi_device.iter_pending():
i = i + 1
message_dict = message.dict()
midi_channel = midi_setting = self.data.settings['user_input']['MIDI_CHANNEL']['value'] - 1
midi_channel = self.data.settings['user_input']['MIDI_CHANNEL']['value'] - 1
if not message_dict.get('channel', None) == midi_channel:
pass
## turning off noisey clock messages for now - may want to use them at some point
elif message_dict['type'] == 'clock':
pass
## trying to only let through step cc messages to increase response time
elif message_dict['type'] == 'control_change':
control_number = message_dict['control']
print('control number is {} , cc_dict.keys is {}'.format(control_number, cc_dict.keys() ))
if not control_number in cc_dict.keys():
cc_dict[control_number] = message_dict['value']
self.on_midi_message(message_dict)
else:
step_size = 3
ignore_range = range(cc_dict[control_number] - step_size,cc_dict[control_number] + step_size)
#print('value is {} and ignore range is {}'.format(message_dict['value'], ignore_range ))
if not message_dict['value'] in ignore_range:
cc_dict[control_number] = message_dict['value']
#print(message_dict)
self.on_midi_message(message_dict)
#print(cc_dict)
current_message_buffer = [i.dict() for i in self.midi_device.iter_pending()]
refined_buffer = []
#refine buffer from lastest messages first
current_message_buffer.reverse()
for message in current_message_buffer:
# discard notes from wrong channel
if message.get('channel') != midi_channel:
pass
# process all note messages (in order)
if 'note' in message['type']:
refined_buffer.append(message)
# only take the latest cc message per cc_channel
elif message['type'] == 'control_change':
if not message['control'] in [i.get('control') for i in refined_buffer]:
refined_buffer.append(message)
# process buffer from oldest messages first
refined_buffer.reverse()
for message in refined_buffer:
self.on_midi_message(message)
else:
print(message_dict)
self.on_midi_message(message_dict)
if i > 0:
pass
#print('the number processed {}'.format(i))
if self.data.settings['user_input']['MIDI_INPUT']['value'] == self.midi_setting and self.data.midi_port_index == self.port_index:
self.root.after(self.midi_delay, self.poll_midi_input)
@@ -140,7 +132,12 @@ class MidiInput(object):
else:
norm_message_value = None
self.actions.call_method_name(method_name, norm_message_value)
try:
self.actions.call_method_name(method_name, norm_message_value)
except TypeError:
## to support using cc-0 as button presses
if norm_message_value == 0:
self.actions.call_method_name(method_name, None)
## only update screen if not continuous - seeing if cc can respond faster if not refreshing screen on every action
if 'continuous' not in message_name:
self.display.refresh_display()

View File

@@ -36,7 +36,9 @@ class OscInput(object):
def setup_osc_server(self):
ip_address = self.data.get_ip_for_osc_client()
if ip_address == 'none':
self.message_handler.set_message('INFO', 'osc failed - could not find ip')
return
print('%%%%%%%%%%%%%%%%%%%%% setting up external_osc on ', ip_address)
server_parser = argparse.ArgumentParser()
server_parser.add_argument("--ip", default=ip_address, help="the ip")
@@ -46,28 +48,40 @@ class OscInput(object):
this_dispatcher = dispatcher.Dispatcher()
this_dispatcher.map("/keyboard/*", self.on_osc_input)
this_dispatcher.map("/shaderparam0", self.on_param_osc_input)
this_dispatcher.map("/shaderparam1", self.on_param_osc_input)
this_dispatcher.map("/shaderparam2", self.on_param_osc_input)
this_dispatcher.map("/shaderparam3", self.on_param_osc_input)
this_dispatcher.map("/shutdown", self.exit_osc_server)
# this is for accepting any old osc message to allow binding of modulation to osc messages
# TODO: make configurable?
#this_dispatcher.map("/*", self.on_param_osc_input)
# this_dispatcher.map("/keyboard/*", self.on_osc_input)
# this_dispatcher.map("/shaderparam0", self.on_param_osc_input)
# this_dispatcher.map("/shaderparam1", self.on_param_osc_input)
# this_dispatcher.map("/shaderparam2", self.on_param_osc_input)
# this_dispatcher.map("/shaderparam3", self.on_param_osc_input)
# this_dispatcher.map("/shutdown", self.exit_osc_server)
this_dispatcher.map("/*", self.on_osc_input)
osc_server.ThreadingOSCUDPServer.allow_reuse_address = True
server = osc_server.ThreadingOSCUDPServer((server_args.ip, server_args.port), this_dispatcher)
server_thread = threading.Thread(target=server.serve_forever)
server_thread.start()
self.osc_server = server
self.message_handler.set_message('INFO', 'osc active on ' + ip_address)
def exit_osc_server(self, unused_addr, args):
print('%%%%%%%%%%%%%%%%%%%%% exiting external_osc')
self.osc_server.shutdown()
try:
self.osc_server.shutdown()
self.message_handler.set_message('INFO', 'osc deactive')
except:
self.message_handler.set_message('INFO', 'osc shutdown failed')
def on_osc_input(self, addr, args):
if 'keyboard' in addr:
self.on_key_osc_input(addr, args)
elif 'shutdown' in addr:
self.exit_osc_server(addr, args)
else:
self.on_param_osc_input(addr,args)
def on_key_osc_input(self, addr, args):
args = str(args)
print("!!!!!!!!!!!!!!!!" + args)
print("the address", addr)