mirror of
https://github.com/cyberboy666/r_e_c_u_r.git
synced 2025-12-08 09:20:13 +01:00
wip osc and node server
This commit is contained in:
@@ -17,6 +17,7 @@ class Data(object):
|
||||
SETTINGS_JSON = 'settings.json'
|
||||
DEFAULT_SETTINGS_JSON = 'settings_default.json'
|
||||
KEYPAD_MAPPING_JSON = 'keypad_action_mapping.json'
|
||||
OSC_MAPPING_JSON = 'osc_action_mapping.json'
|
||||
MIDI_MAPPING_JSON = 'midi_action_mapping.json'
|
||||
ANALOG_MAPPING_JSON = 'analog_action_mapping.json'
|
||||
EMPTY_SLOT = dict(name='', location='', length=-1, start=-1, end=-1, rate=1)
|
||||
@@ -73,6 +74,7 @@ class Data(object):
|
||||
self.settings = self._read_json(self.SETTINGS_JSON)
|
||||
|
||||
self.key_mappings = self._read_json(self.KEYPAD_MAPPING_JSON)
|
||||
self.osc_mappings = self._read_json(self.OSC_MAPPING_JSON)
|
||||
self.midi_mappings = self._read_json(self.MIDI_MAPPING_JSON)
|
||||
self.analog_mappings = self._read_json(self.ANALOG_MAPPING_JSON)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import argparse
|
||||
def setup_osc_client():
|
||||
client_parser = argparse.ArgumentParser()
|
||||
client_parser.add_argument("--ip", default="127.0.0.1", help="the ip")
|
||||
client_parser.add_argument("--port", type=int, default=9000, help="the port")
|
||||
client_parser.add_argument("--port", type=int, default=5433, help="the port")
|
||||
|
||||
client_args = client_parser.parse_args()
|
||||
|
||||
|
||||
105
json_objects/osc_action_mapping.json
Normal file
105
json_objects/osc_action_mapping.json
Normal file
@@ -0,0 +1,105 @@
|
||||
{
|
||||
"a": {
|
||||
"NAV_BROWSER": ["move_browser_selection_up"],
|
||||
"DEFAULT": ["seek_back_on_player", "decrease_seek_time"],
|
||||
"NAV_SETTINGS": ["move_settings_selection_up"],
|
||||
"NAV_SHADERS": ["move_shaders_selection_up"],
|
||||
"LENGTH_SET": ["return_to_default_control_mode"],
|
||||
"CONFIRM": ["return_to_default_control_mode"],
|
||||
"SHADER_PARAM": ["decrease_this_param", "decrease_shader_param"],
|
||||
"PLAY_SHADER": ["decrease_this_param", "decrease_shader_param"]
|
||||
},
|
||||
"b": {
|
||||
"NAV_BROWSER": ["move_browser_selection_down"],
|
||||
"DEFAULT": ["seek_forward_on_player", "increase_seek_time"],
|
||||
"NAV_SETTINGS": ["move_settings_selection_down"],
|
||||
"NAV_SHADERS": ["move_shaders_selection_down"],
|
||||
"LENGTH_SET": ["return_to_default_control_mode"],
|
||||
"CONFIRM": ["return_to_default_control_mode"],
|
||||
"SHADER_PARAM": ["increase_this_param", "increase_shader_param"],
|
||||
"PLAY_SHADER": ["increase_this_param", "increase_shader_param"]
|
||||
|
||||
},
|
||||
"c": {
|
||||
"NAV_BROWSER": ["enter_on_browser_selection"],
|
||||
"DEFAULT": ["toggle_action_on_player","toggle_show_on_player"],
|
||||
"NAV_SETTINGS": ["enter_on_settings_selection"],
|
||||
"NAV_SHADERS": ["enter_on_shaders_selection", "map_on_shaders_selection"],
|
||||
"LENGTH_SET": ["record_fixed_length"],
|
||||
"SHADER_PARAM": ["return_to_default_control_mode"],
|
||||
"CONFIRM": ["perform_confirm_action"],
|
||||
"NAV_DETOUR": ["toggle_detour_play"],
|
||||
"PLAY_SHADER": ["toggle_shaders", "toggle_shader_speed"]
|
||||
},
|
||||
"d": {
|
||||
"DEFAULT": ["switch_to_next_player", "toggle_player_mode"],
|
||||
"NAV_DETOUR": ["toggle_detour_record", "toggle_detour_record_loop"]
|
||||
},
|
||||
"e": {
|
||||
"DEFAULT": ["set_playing_sample_start_to_current_duration", "clear_playing_sample_start_time"],
|
||||
"SHADER_PARAM": ["decrease_param_focus"],
|
||||
"PLAY_SHADER": ["decrease_param_focus"],
|
||||
"NAV_DETOUR": ["decrease_mix_shader"]
|
||||
},
|
||||
"f": {
|
||||
"DEFAULT": ["set_playing_sample_end_to_current_duration", "clear_playing_sample_end_time"],
|
||||
"SHADER_PARAM": ["increase_param_focus"],
|
||||
"PLAY_SHADER": ["increase_param_focus"],
|
||||
"NAV_DETOUR": ["increase_mix_shader"]
|
||||
},
|
||||
"g": {
|
||||
"DEFAULT": ["toggle_capture_preview", "toggle_capture_recording"]},
|
||||
"h": {
|
||||
"DEFAULT": ["cycle_display_mode", "cycle_display_mode_back"]
|
||||
},
|
||||
"i": {
|
||||
"DEFAULT": ["toggle_function"]
|
||||
},
|
||||
"j": {
|
||||
"DEFAULT": ["load_slot_0_into_next_player","previous_bank"],
|
||||
"PLAY_SHADER": ["play_shader_0","previous_shader_layer"],
|
||||
"NAV_SHADERS": ["play_shader_0","previous_shader_layer"],
|
||||
"NAV_DETOUR": ["switch_to_detour_0", "set_the_detour_mix_0"]
|
||||
},
|
||||
"k": {
|
||||
"DEFAULT": ["load_slot_1_into_next_player","next_bank"],
|
||||
"PLAY_SHADER": ["play_shader_1","next_shader_layer"],
|
||||
"NAV_SHADERS": ["play_shader_1","next_shader_layer"],
|
||||
"NAV_DETOUR": ["switch_to_detour_1", "set_the_detour_mix_1"]
|
||||
},
|
||||
"l": {
|
||||
"DEFAULT": ["load_slot_2_into_next_player","clear_all_slots"],
|
||||
"PLAY_SHADER": ["play_shader_2","clear_shader_bank"],
|
||||
"NAV_SHADERS": ["play_shader_2","clear_shader_bank"],
|
||||
"NAV_DETOUR": ["switch_to_detour_2", "clear_this_detour"]
|
||||
},
|
||||
"m": {
|
||||
"DEFAULT": ["load_slot_3_into_next_player"],
|
||||
"PLAY_SHADER": ["play_shader_3"],
|
||||
"NAV_DETOUR": ["switch_to_detour_3"]
|
||||
},
|
||||
"n": {
|
||||
"DEFAULT": ["load_slot_4_into_next_player"],
|
||||
"PLAY_SHADER": ["play_shader_4"]
|
||||
},
|
||||
"o": {
|
||||
"DEFAULT": ["load_slot_5_into_next_player","toggle_screen_mirror"],
|
||||
"PLAY_SHADER": ["play_shader_5", "toggle_screen_mirror"]
|
||||
},
|
||||
"p": {
|
||||
"DEFAULT": ["load_slot_6_into_next_player","toggle_shaders"],
|
||||
"PLAY_SHADER": ["play_shader_6","toggle_shaders"]
|
||||
},
|
||||
"q": {
|
||||
"DEFAULT": ["load_slot_7_into_next_player", "toggle_detour_mode"],
|
||||
"PLAY_SHADER": ["play_shader_7","toggle_detour_mode"]
|
||||
},
|
||||
"r": {
|
||||
"DEFAULT": ["load_slot_8_into_next_player", "toggle_feedback"],
|
||||
"PLAY_SHADER": ["play_shader_8", "toggle_feedback"]
|
||||
},
|
||||
"s": {
|
||||
"DEFAULT": ["load_slot_9_into_next_player","confirm_shutdown"],
|
||||
"PLAY_SHADER": ["play_shader_9","confirm_shutdown"]
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ from data_centre.data import Data
|
||||
from display_centre.display import Display
|
||||
from display_centre.messages import MessageHandler
|
||||
from user_input.numpad_input import NumpadInput
|
||||
from user_input.osc_input import OscInput
|
||||
from user_input.midi_input import MidiInput
|
||||
from user_input.analog_input import AnalogInput
|
||||
from video_centre.video_driver import VideoDriver
|
||||
@@ -53,6 +54,7 @@ display = Display(tk, video_driver, shaders, message_handler, data)
|
||||
actions = Actions(tk, message_handler, data, video_driver, shaders, display, osc_client)
|
||||
|
||||
numpad_input = NumpadInput(tk, message_handler, display, actions, data)
|
||||
osc_input = OscInput(tk, message_handler, display, actions, data)
|
||||
midi_input = MidiInput(tk, message_handler, display, actions, data)
|
||||
analog_input = AnalogInput(tk, message_handler, display, actions, data)
|
||||
|
||||
|
||||
67
user_input/osc_input.py
Normal file
67
user_input/osc_input.py
Normal file
@@ -0,0 +1,67 @@
|
||||
import string
|
||||
import sys
|
||||
|
||||
|
||||
from pythonosc import dispatcher
|
||||
from pythonosc import dispatcher
|
||||
from pythonosc import osc_server
|
||||
import threading
|
||||
import argparse
|
||||
|
||||
|
||||
class OscInput(object):
|
||||
def __init__(self, root, message_handler, display, actions, data):
|
||||
self.root = root
|
||||
self.message_handler = message_handler
|
||||
self.display = display
|
||||
self.actions = actions
|
||||
self.data = data
|
||||
self.osc_mappings = data.osc_mappings
|
||||
self.osc_server = self.setup_osc_server()
|
||||
|
||||
def setup_osc_server(self):
|
||||
server_parser = argparse.ArgumentParser()
|
||||
server_parser.add_argument("--ip", default="127.0.0.1", help="the ip")
|
||||
server_parser.add_argument("--port", type=int, default=5433, help="the port")
|
||||
|
||||
server_args = server_parser.parse_args()
|
||||
|
||||
this_dispatcher = dispatcher.Dispatcher()
|
||||
this_dispatcher.map("/recurOsc", self.on_osc_input)
|
||||
this_dispatcher.map("/shutdown", self.exit_osc_server)
|
||||
|
||||
server = osc_server.ThreadingOSCUDPServer((server_args.ip, server_args.port), this_dispatcher)
|
||||
server_thread = threading.Thread(target=server.serve_forever)
|
||||
server_thread.start()
|
||||
return server
|
||||
|
||||
def exit_osc_server(self, unused_addr, args):
|
||||
self.osc_server.shutdown()
|
||||
|
||||
def on_osc_input(self, unused_addr, args):
|
||||
print("!!!!!!!!!!!!!!!!" + args)
|
||||
numpad = list(string.ascii_lowercase[0:19])
|
||||
|
||||
if args in numpad:
|
||||
self.run_action_for_osc_channel(args)
|
||||
else:
|
||||
print('{} is not in keypad map'.format(args))
|
||||
|
||||
def run_action_for_osc_channel(self, channel):
|
||||
this_mapping = self.osc_mappings[channel]
|
||||
if self.data.control_mode in this_mapping:
|
||||
mode = self.data.control_mode
|
||||
elif 'DEFAULT' in this_mapping:
|
||||
mode = 'DEFAULT'
|
||||
|
||||
if self.data.function_on and len(this_mapping[mode]) > 1:
|
||||
print('the action being called is {}'.format(this_mapping[mode][1]))
|
||||
getattr(self.actions, this_mapping[mode][1])()
|
||||
if self.data.settings['sampler']['FUNC_GATED']['value'] == 'off':
|
||||
self.data.function_on = False
|
||||
else:
|
||||
print('the action being called is {}'.format(this_mapping[mode][0]))
|
||||
getattr(self.actions, this_mapping[mode][0])()
|
||||
|
||||
self.display.refresh_display()
|
||||
|
||||
Reference in New Issue
Block a user