From f41a6b570f840dd67f2181e3671e7a7d4cb96f39 Mon Sep 17 00:00:00 2001 From: langolierz Date: Mon, 1 Jul 2019 19:34:14 +0000 Subject: [PATCH] detour almost working now --- actions.py | 78 ++++++++++++++++++++++- data_centre/data.py | 2 + display_centre/display.py | 43 +++++++++++++ json_objects/current_bankslot_number.json | 2 +- json_objects/keypad_action_mapping.json | 20 ++++-- json_objects/midi_action_mapping.json | 12 ++-- 6 files changed, 142 insertions(+), 15 deletions(-) diff --git a/actions.py b/actions.py index 5ddf080..f32c64f 100644 --- a/actions.py +++ b/actions.py @@ -136,10 +136,11 @@ class Actions(object): def cycle_display_mode(self): + display_modes = [["BROWSER",'NAV_BROWSER'],["SETTINGS",'NAV_SETTINGS'],[ "SAMPLER",'PLAYER']] if self.data.settings['conjur']['VIDEO_BACKEND']['value'] == 'openframeworks': - display_modes = [["SETTINGS",'NAV_SETTINGS'],[ "SAMPLER",'PLAYER'],["BROWSER",'NAV_BROWSER'],["SHADERS",'NAV_SHADERS']] - else: - display_modes = [["BROWSER",'NAV_BROWSER'],["SETTINGS",'NAV_SETTINGS'],[ "SAMPLER",'PLAYER']] + display_modes.append(["SHADERS",'NAV_SHADERS']) + if self.data.settings['detour']['TRY_DEMO']['value'] == 'enabled': + display_modes.append(["DETOUR",'NAV_DETOUR']) current_mode_index = [index for index, i in enumerate(display_modes) if self.data.display_mode in i][0] next_mode_index = (current_mode_index + 1) % len(display_modes) @@ -287,6 +288,76 @@ class Actions(object): self.data.detour_active = True self.video_driver.osc_client.send_message("/detour/start", True) + def toggle_detour_play(self): + if self.data.settings['detour']['TRY_DEMO']['value'] == 'enabled': + is_playing = not self.data.detour_settings['is_playing'] + self.data.detour_settings['is_playing'] = is_playing + self.video_driver.osc_client.send_message("/detour/is_playing", is_playing) + + def toggle_detour_record(self): + if self.data.settings['detour']['TRY_DEMO']['value'] == 'enabled': + is_recording = not self.data.detour_settings['is_recording'] + self.data.detour_settings['is_recording'] = is_recording + self.video_driver.osc_client.send_message("/detour/is_recording", is_recording) + + def toggle_detour_record_loop(self): + if self.data.settings['detour']['TRY_DEMO']['value'] == 'enabled': + record_loop = not self.data.detour_settings['record_loop'] + self.data.detour_settings['record_loop'] = record_loop + self.video_driver.osc_client.send_message("/detour/record_loop", record_loop) + + def clear_this_detour(self): + if self.data.settings['detour']['TRY_DEMO']['value'] == 'enabled': + self.video_driver.osc_client.send_message("/detour/clear_this_detour", True) + + def switch_to_detour_0(self): + self.switch_to_this_detour(0) + + def switch_to_detour_1(self): + self.switch_to_this_detour(1) + + def switch_to_detour_2(self): + self.switch_to_this_detour(2) + + def switch_to_detour_3(self): + self.switch_to_this_detour(3) + + def switch_to_this_detour(self, number): + if self.data.settings['detour']['TRY_DEMO']['value'] == 'enabled': + self.data.detour_settings['current_detour'] = number + self.video_driver.osc_client.send_message("/detour/switch_to_detour_number", number) + + + def set_detour_speed_position_continuous(self, amount): + self.video_driver.osc_client.send_message("/detour/set_speed_position", amount) + + def set_detour_start_continuous(self, amount): + self.video_driver.osc_client.send_message("/detour/set_start", amount) + + def set_detour_end_continuous(self, amount): + self.video_driver.osc_client.send_message("/detour/set_end", amount) + + def set_detour_mix_continuous(self, amount): + self.video_driver.osc_client.send_message("/detour/set_mix", amount) + + def receive_detour_info(self, unused_addr, position, start, end, size, speed, mix, memory_full): + self.data.detour_settings['detour_position'] = position + self.data.detour_settings['detour_start'] = start + self.data.detour_settings['detour_end'] = end + self.data.detour_settings['detour_size'] = size + self.data.detour_settings['detour_speed'] = speed + self.data.detour_settings['position_position'] = mix + self.data.detour_settings['memory_full'] = memory_full + + + print(position, start, end, size, speed, mix, memory_full) + + def set_the_detour_mix_0(self): + self.set_detour_mix_continuous(0) + + def set_the_detour_mix_1(self): + self.set_detour_mix_continuous(1) + def set_the_camera_colour_u_continuous(self, amount): self.capture.set_colour(amount*255, None) @@ -546,6 +617,7 @@ class Actions(object): this_dispatcher.map("/player/a/status", self.video_driver.receive_status, "a.a") this_dispatcher.map("/player/b/status", self.video_driver.receive_status, "b.b") this_dispatcher.map("/player/c/status", self.video_driver.receive_status, "c.c") + this_dispatcher.map("/detour/detour_info", self.receive_detour_info) this_dispatcher.map("/shutdown", self.exit_osc_server) #this_dispatcher.map("/player/a/status", self.set_status) diff --git a/data_centre/data.py b/data_centre/data.py index e5c0cc8..f70ecd8 100644 --- a/data_centre/data.py +++ b/data_centre/data.py @@ -1,6 +1,7 @@ import json import xml.etree.ElementTree as ET import os +import collections from random import randint import inspect from itertools import cycle @@ -42,6 +43,7 @@ class Data(object): self.update_screen = True self.player_mode = 'now' self.detour_active = False + self.detour_settings = collections.OrderedDict([('current_detour',0), ('is_playing', False), ('is_recording', False), ('record_loop', False), ('detour_size', False), ('detour_speed', 0), ('memory_full', False), ('mix_position', False), ('is_delay', False), ('detour_position', 0), ('detour_start', 0), ('detour_end', 0), ]) ### persisted data (use default if doesnt exits): self.bank_data = [self.create_empty_bank()] diff --git a/display_centre/display.py b/display_centre/display.py index 2b9fe53..cf6ebc8 100644 --- a/display_centre/display.py +++ b/display_centre/display.py @@ -81,6 +81,8 @@ class Display(object): self._load_sampler() elif self.data.display_mode == 'SHADERS': self._load_shaders() + elif self.data.display_mode == 'DETOUR': + self._load_detour() self.display_text.tag_add("COLUMN_NAME", 5.0, 6.0) @@ -176,6 +178,21 @@ class Display(object): self._highlight_this_param(self.shaders.focused_param) + def _load_detour(self): + line_count = 0 + self.display_text.insert(END, '------------------ ------------------- \n') + self.display_text.tag_add("DISPLAY_MODE", 4.19, 4.28) + +## showing current detour info: + self.display_text.insert(END, '{:^23} {:^22} \n'.format('SETTING', 'VALUE')) + + for index, (key, value) in enumerate(self.data.detour_settings.items()): + if index < 9: + self.display_text.insert(END, '{:>23} {:<22} \n'.format(key, value)) + detour_banner = self.create_detour_display_banner(self.data.detour_settings['detour_size'], self.data.detour_settings['detour_position'], self.data.detour_settings['detour_start'], self.data.detour_settings['detour_end']) + self.display_text.insert(END, '{} \n'.format(detour_banner)) + self.display_text.tag_add("NOW_PLAYER_INFO", 15.0, 15.0 + self.SELECTOR_WIDTH) + def _load_message(self): if self.message_handler.current_message[1]: self.display_text.insert(END, '{:5} {:42} \n'.format( @@ -280,6 +297,32 @@ round(param_row + column_offset + (param_num+1)*param_length, 2)) return ''.join(banner_list) + @staticmethod + def create_detour_display_banner(size, position, start, end): + banner_list = ['|', '-', '-', '-', '-', '-', '-', '-', '-', + '-', '-', '-', '-', '-', '-', '-', '-', '-', + '-', '-', '-', '-', '-', '-', '-', '-', '-', + '-', '-', '-', '-', '-', + '|'] + max = len(banner_list) - 1 + if size == 0: + size = max + #print('start value is {}, end value is {}, position is {}'.format(start, end, position)) + if start > 0: + start = int(math.floor(float(start) / + float(size) * (max - 1)) + 1) + banner_list[start] = '[' + if end > 0: + end = int(math.floor(float(end) / + float(size) * (max - 1)) + 1) + banner_list[end] = ']' + position = int(math.floor(float(position) / + float(size) * (max - 1)) + 1) + banner_list[position] = '*' + + return ''.join(banner_list) + + def _set_colour_from_alpha(self, now_alpha, preview_alpha, next_alpha): upper_bound = 150 if self.capture is not None: diff --git a/json_objects/current_bankslot_number.json b/json_objects/current_bankslot_number.json index 7c1b0ff..a829d46 100644 --- a/json_objects/current_bankslot_number.json +++ b/json_objects/current_bankslot_number.json @@ -1 +1 @@ -"1-1" \ No newline at end of file +"1-4" \ No newline at end of file diff --git a/json_objects/keypad_action_mapping.json b/json_objects/keypad_action_mapping.json index 0402e5e..67a5b49 100644 --- a/json_objects/keypad_action_mapping.json +++ b/json_objects/keypad_action_mapping.json @@ -21,14 +21,16 @@ "NAV_SETTINGS": ["enter_on_settings_selection"], "NAV_SHADERS": ["enter_on_shaders_selection"], "LENGTH_SET": ["record_fixed_length"], - "SHADER_PARAM": ["return_to_default_control_mode"] + "SHADER_PARAM": ["return_to_default_control_mode"], + "NAV_DETOUR": ["toggle_detour_play"] }, "d": { - "DEFAULT": ["switch_to_next_player", "toggle_player_mode"] + "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"] + "SHADER_PARAM": ["decrease_param_focus"] }, "f": { "DEFAULT": ["set_playing_sample_end_to_current_duration", "clear_playing_sample_end_time"], @@ -43,16 +45,20 @@ "DEFAULT": ["toggle_function"] }, "j": { - "DEFAULT": ["load_slot_0_into_next_player","previous_bank"] + "DEFAULT": ["load_slot_0_into_next_player","previous_bank"], + "NAV_DETOUR": ["switch_to_detour_0", "set_the_detour_mix_0"] }, "k": { - "DEFAULT": ["load_slot_1_into_next_player","next_bank"] + "DEFAULT": ["load_slot_1_into_next_player","next_bank"], + "NAV_DETOUR": ["switch_to_detour_1", "set_the_detour_mix_1"] }, "l": { - "DEFAULT": ["load_slot_2_into_next_player","clear_all_slots"] + "DEFAULT": ["load_slot_2_into_next_player","clear_all_slots"], + "NAV_DETOUR": ["switch_to_detour_2", "clear_this_detour"] }, "m": { - "DEFAULT": ["load_slot_3_into_next_player"] + "DEFAULT": ["load_slot_3_into_next_player"], + "NAV_DETOUR": ["switch_to_detour_3"] }, "n": { "DEFAULT": ["load_slot_4_into_next_player"] diff --git a/json_objects/midi_action_mapping.json b/json_objects/midi_action_mapping.json index 4aa9576..959b13e 100644 --- a/json_objects/midi_action_mapping.json +++ b/json_objects/midi_action_mapping.json @@ -3,16 +3,20 @@ "DEFAULT": ["set_the_current_video_alpha_continuous"] }, "control_change 1": { - "DEFAULT": ["set_the_next_video_alpha_continuous"] + "DEFAULT": ["set_the_next_video_alpha_continuous"], + "NAV_DETOUR": ["set_detour_mix_continuous"] }, "control_change 2": { - "DEFAULT": ["set_the_camera_alpha_continuous"] + "DEFAULT": ["set_the_camera_alpha_continuous"], + "NAV_DETOUR": ["set_detour_speed_position_continuous"] }, "control_change 3": { - "DEFAULT": ["set_the_camera_colour_u_continuous"] + "DEFAULT": ["set_the_camera_colour_u_continuous"], + "NAV_DETOUR": ["set_detour_start_continuous"] }, "control_change 4": { - "DEFAULT": ["set_the_camera_colour_v_continuous"] + "DEFAULT": ["set_the_camera_colour_v_continuous"], + "NAV_DETOUR": ["set_detour_end_continuous"] }, "control_change 5": { "DEFAULT": ["set_the_shader_param_0_continuous"]