mirror of
https://github.com/cyberboy666/r_e_c_u_r.git
synced 2025-12-11 19:00:04 +01:00
branch for the more polished plugins that provide some fancy shader features like automation loop recording and preset recall
This commit is contained in:
@@ -2,7 +2,7 @@ import data_centre.plugin_collection
|
||||
from data_centre.plugin_collection import ActionsPlugin, SequencePlugin
|
||||
|
||||
class MidiActionsTestPlugin(ActionsPlugin,SequencePlugin):
|
||||
disabled = False
|
||||
disabled = True
|
||||
|
||||
def __init__(self, plugin_collection):
|
||||
super().__init__(plugin_collection)
|
||||
|
||||
178
plugins/ShaderLoopRecordPlugin.py
Normal file
178
plugins/ShaderLoopRecordPlugin.py
Normal file
@@ -0,0 +1,178 @@
|
||||
import data_centre.plugin_collection
|
||||
from data_centre.plugin_collection import ActionsPlugin, SequencePlugin
|
||||
|
||||
class ShaderLoopRecordPlugin(ActionsPlugin,SequencePlugin):
|
||||
disabled = False
|
||||
MAX_CLIPS = 8
|
||||
|
||||
def __init__(self, plugin_collection):
|
||||
super().__init__(plugin_collection)
|
||||
|
||||
self.PRESET_FILE_NAME = "ShaderLoopRecordPlugin/frames.json"
|
||||
|
||||
self.frames = self.load_presets()
|
||||
self.reset_ignored()
|
||||
|
||||
def load_presets(self):
|
||||
#try:
|
||||
print("trying load presets? %s " % self.PRESET_FILE_NAME)
|
||||
p = self.pc.read_json(self.PRESET_FILE_NAME)
|
||||
if p:
|
||||
while len(p)<self.MAX_CLIPS:
|
||||
print ("adding clip ")
|
||||
p += self.get_empty_clip(self.duration) #[ [None] ] #*((int(self.duration / self.frequency))-len(p)) ]
|
||||
for i in p:
|
||||
print("got automation clip of duration %s" % len(i))
|
||||
if i and len(i)<(int(self.duration / self.frequency)):
|
||||
print("adding more slots due to size change")
|
||||
i += [None]*((int(self.duration / self.frequency))-len(i))
|
||||
print("len is now %s" % len(i))
|
||||
return p
|
||||
elif p:
|
||||
return p
|
||||
else:
|
||||
return self.get_factory_reset()
|
||||
#except:
|
||||
# return self.clear_frames()
|
||||
|
||||
def save_presets(self):
|
||||
self.pc.update_json(self.PRESET_FILE_NAME, self.frames)
|
||||
|
||||
|
||||
@property
|
||||
def parserlist(self):
|
||||
return [
|
||||
( r"run_automation", self.run_automation ),
|
||||
( r"stop_automation", self.stop_automation ),
|
||||
( r"toggle_pause_automation", self.toggle_pause_automation ),
|
||||
( r"pause_automation", self.pause_automation ),
|
||||
( r"toggle_loop_automation", self.toggle_loop_automation ),
|
||||
( r"set_automation_speed", self.set_speed ),
|
||||
( r"toggle_record_automation", self.toggle_record_automation ),
|
||||
( r"toggle_overdub_automation", self.toggle_overdub_automation ),
|
||||
( r"clear_automation", self.clear_clip ),
|
||||
( r"select_automation_clip_([0-7])", self.select_clip ),
|
||||
( r"toggle_automation_clip_([0-7])", self.toggle_clip )
|
||||
]
|
||||
|
||||
def toggle_overdub_automation(self):
|
||||
self.overdub = not self.overdub
|
||||
if not self.overdub:
|
||||
self.reset_ignored()
|
||||
|
||||
def toggle_record_automation(self):
|
||||
self.recording = not self.recording
|
||||
if self.recording and not self.overdub:
|
||||
self.clear_clip()
|
||||
if not self.recording:
|
||||
self.reset_ignored()
|
||||
self.last_frame = None
|
||||
self.last_saved_index = None
|
||||
self.save_presets()
|
||||
|
||||
def get_empty_clip(self, duration = 2000):
|
||||
return [{}] * (int(duration / self.frequency))
|
||||
|
||||
def get_factory_reset(self):
|
||||
return [ self.get_empty_clip(self.duration) for i in range(self.MAX_CLIPS) ]
|
||||
|
||||
def clear_clip(self,clip = None):
|
||||
if clip is None:
|
||||
clip = self.selected_clip
|
||||
self.frames[clip] = self.get_empty_clip(self.duration) * self.MAX_CLIPS
|
||||
self.reset_ignored()
|
||||
if self.DEBUG_FRAMES: print ("clear_frames set to %s" % (int(self.duration / self.frequency)))
|
||||
return self.frames
|
||||
|
||||
def toggle_clip(self,clip = None):
|
||||
if clip is None:
|
||||
clip = self.selected_clip
|
||||
else:
|
||||
self.selected_clip = clip
|
||||
|
||||
#self.running_clips[clip] = not self.running_clips[clip]
|
||||
if clip in self.running_clips:
|
||||
self.running_clips.remove(clip)
|
||||
else:
|
||||
self.running_clips.append(clip)
|
||||
print("running clips looks like %s" %self.running_clips)
|
||||
|
||||
def reset_ignored(self):
|
||||
# print("!!!!resetting ignored")
|
||||
self.ignored = { 'shader_params': [[None]*4,[None]*4,[None]*4] }
|
||||
|
||||
def is_ignoring(self):
|
||||
return not self.pc.shaders.is_frame_empty(self.ignored)
|
||||
|
||||
def select_clip(self, clip):
|
||||
self.selected_clip = clip
|
||||
|
||||
selected_clip = 0
|
||||
running_clips = [ ] #False ] * self.MAX_CLIPS
|
||||
|
||||
duration = 2000
|
||||
frequency = 10 #25
|
||||
recording = False
|
||||
overdub = True
|
||||
#ignored = None # set in reset_ignored in init - used for tracking what parans have changed since overdub
|
||||
last_frame = None # for tracking what's changed between frames when overdubbing
|
||||
last_saved_index = None # for backfilling
|
||||
DEBUG_FRAMES = False#True
|
||||
def run_sequence(self, position):
|
||||
current_frame_index = int(position * (int(self.duration / self.frequency)))
|
||||
if current_frame_index<0:
|
||||
current_frame_index = (self.duration/self.frequency) - current_frame_index
|
||||
if current_frame_index > self.duration/self.frequency:
|
||||
current_frame_index = self.duration/self.frequency
|
||||
|
||||
if self.DEBUG_FRAMES: print (">>>>>>>>>>>>>>frame at %i%%: %i" % (position*100, current_frame_index))
|
||||
#print("got frame index %s" % current_frame_index)
|
||||
|
||||
current_frame = self.pc.shaders.get_live_frame().copy()
|
||||
|
||||
selected_clip = self.selected_clip
|
||||
if self.DEBUG_FRAMES: print("current_frame copy before recall is %s" % current_frame['shader_params'])
|
||||
#print ("%s clips, looks like %s" % (len(self.frames),self.frames))
|
||||
|
||||
#print("selected_clip is %s "%selected_clip)
|
||||
#clip = self.frames[selected_clip]
|
||||
if self.is_playing() and self.recording and self.selected_clip not in self.running_clips:
|
||||
self.running_clips += [ self.selected_clip ]
|
||||
for selected_clip in self.running_clips:
|
||||
saved_frame = self.frames[selected_clip][current_frame_index]
|
||||
if not self.recording or (selected_clip!=self.selected_clip):
|
||||
self.pc.shaders.recall_frame(saved_frame)
|
||||
if self.recording and selected_clip==self.selected_clip:
|
||||
if self.last_frame is None:
|
||||
self.last_frame = current_frame
|
||||
if self.DEBUG_FRAMES: print("last frame is \t\t%s" % self.last_frame['shader_params'])
|
||||
if self.DEBUG_FRAMES: print("current f is \t\t%s" % current_frame['shader_params'])
|
||||
diff = self.pc.shaders.get_frame_diff(self.last_frame,current_frame)
|
||||
if self.DEBUG_FRAMES: print("diffed frame is \t%s" % diff['shader_params'])
|
||||
|
||||
if self.overdub and saved_frame:
|
||||
# add the params tweaked this frame to the params to be ignored by recall
|
||||
if self.DEBUG_FRAMES: print("saved frame is \t%s" % saved_frame['shader_params'])
|
||||
self.ignored = self.pc.shaders.merge_frames(self.ignored, diff)
|
||||
diff = self.pc.shaders.merge_frames(
|
||||
self.pc.shaders.get_frame_ignored(saved_frame, self.ignored),
|
||||
diff
|
||||
)
|
||||
#diff = self.pc.shaders.merge_frames(self.pc.shaders.get_live_frame(), diff)
|
||||
self.pc.shaders.recall_frame(diff)
|
||||
if self.DEBUG_FRAMES: print("after diff2 is: \t%s" % diff['shader_params'])
|
||||
if self.DEBUG_FRAMES: print("||||saving frame \t%s" % (diff['shader_params']))
|
||||
self.frames[selected_clip][current_frame_index] = diff #self.get_frame_diff(self.last_frame,current_frame)
|
||||
#backfill frames
|
||||
if self.last_saved_index is not None:
|
||||
if self.DEBUG_FRAMES: print ("last_saved_index is %s, current_frame_index is %s" % (self.last_saved_index, current_frame_index))
|
||||
for i in range(current_frame_index - (self.last_saved_index) ):
|
||||
if self.DEBUG_FRAMES:print("backfilling frame %s" % ((self.last_saved_index+i+1)%len(self.frames[selected_clip])))
|
||||
self.frames[selected_clip][(self.last_saved_index+i+1)%len(self.frames[selected_clip])] = diff
|
||||
self.last_saved_index = current_frame_index
|
||||
self.last_frame = self.pc.shaders.get_live_frame() #diff
|
||||
if self.DEBUG_FRAMES: print("<<<<<<<<<<<<<< frame at %s" % current_frame_index)
|
||||
|
||||
"""def recall_frame_index(self, index):
|
||||
self.pc.shaders.recall_frame_params(self.frames[index].copy())"""
|
||||
|
||||
84
plugins/ShaderQuickPresetPlugin.py
Normal file
84
plugins/ShaderQuickPresetPlugin.py
Normal file
@@ -0,0 +1,84 @@
|
||||
import data_centre.plugin_collection
|
||||
from data_centre.plugin_collection import ActionsPlugin, SequencePlugin
|
||||
import copy
|
||||
|
||||
class ShaderQuickPresetPlugin(ActionsPlugin): #,SequencePlugin):
|
||||
disabled = False
|
||||
|
||||
MAX_PRESETS = 8
|
||||
|
||||
def __init__(self, plugin_collection):
|
||||
super().__init__(plugin_collection)
|
||||
self.PRESET_FILE_NAME = 'ShaderQuickPresetPlugin/presets.json'
|
||||
|
||||
self.presets = self.load_presets()
|
||||
print("loaded presets %s" % self.presets)
|
||||
|
||||
self.selected_preset = None
|
||||
self.last_recalled = None
|
||||
|
||||
def load_presets(self):
|
||||
print("trying load presets? %s " % self.PRESET_FILE_NAME)
|
||||
return self.pc.read_json(self.PRESET_FILE_NAME) or ([None]*self.MAX_PRESETS)
|
||||
|
||||
def save_presets(self):
|
||||
self.pc.update_json(self.PRESET_FILE_NAME, self.presets)
|
||||
|
||||
@property
|
||||
def parserlist(self):
|
||||
return [
|
||||
( r"load_presets", self.load_presets ),
|
||||
( r"save_presets", self.save_presets ),
|
||||
( r"store_next_preset", self.store_next_preset ),
|
||||
( r"store_current_preset", self.store_current_preset ),
|
||||
( r"switch_to_preset_([0-%i])"%self.MAX_PRESETS, self.switch_to_preset ),
|
||||
( r"select_preset_([0-%i])"%self.MAX_PRESETS, self.select_preset ),
|
||||
( r"clear_current_preset", self.clear_current_preset ),
|
||||
]
|
||||
|
||||
def store_next_preset(self):
|
||||
res = [i for i, val in enumerate(self.presets) if val == None]
|
||||
if res is None or not res:
|
||||
self.selected_preset += 1
|
||||
self.selected_preset %= self.MAX_PRESETS
|
||||
else:
|
||||
self.selected_preset = res[0]
|
||||
|
||||
self.store_current_preset()
|
||||
|
||||
def clear_current_preset(self):
|
||||
if self.selected_preset is None:
|
||||
return
|
||||
self.presets[self.selected_preset] = None
|
||||
|
||||
self.save_presets()
|
||||
|
||||
def store_current_preset(self):
|
||||
if self.selected_preset is None: self.selected_preset = 0
|
||||
|
||||
insert_position = self.selected_preset
|
||||
self.presets[insert_position] = self.pc.shaders.get_live_frame()
|
||||
#print ("stored %s at position %s" % (self.presets[insert_position], insert_position))
|
||||
self.selected_preset = insert_position
|
||||
self.last_recalled = insert_position
|
||||
|
||||
self.save_presets()
|
||||
|
||||
def select_preset(self, preset):
|
||||
self.selected_preset = preset
|
||||
|
||||
def switch_to_preset(self, preset):
|
||||
#if preset>len(self.presets):
|
||||
if self.presets[preset] is None:
|
||||
print ("no quick shader preset in slot %s!" % preset)
|
||||
self.selected_preset = preset
|
||||
return
|
||||
print ("switching to preset %s" % preset)
|
||||
self.selected_preset = preset
|
||||
|
||||
self.last_recalled = preset
|
||||
preset = self.presets[preset]
|
||||
|
||||
print ("recalled preset %s" % preset)
|
||||
self.pc.shaders.recall_frame(preset)
|
||||
|
||||
@@ -12,6 +12,7 @@ class MidiInput(object):
|
||||
self.data = data
|
||||
self.midi_mappings = data.midi_mappings
|
||||
self.midi_device = None
|
||||
self.midi_feedback_device = None
|
||||
self.midi_setting = None
|
||||
self.port_index = 0
|
||||
self.midi_delay = 40
|
||||
@@ -41,7 +42,13 @@ class MidiInput(object):
|
||||
subport_index = self.port_index % len(midi_device_on_port)
|
||||
self.midi_device = mido.open_input(midi_device_on_port[subport_index])
|
||||
self.data.midi_status = 'connected'
|
||||
self.data.midi_device_name = self.midi_device.name
|
||||
self.message_handler.set_message('INFO', 'connected to midi device {}'.format(self.midi_device.name))
|
||||
self.midi_mappings = self.data.load_midi_mapping_for_device(self.midi_device.name.split(":")[0])
|
||||
self.midi_output = self.find_output_plugin(midi_device_on_port[subport_index])
|
||||
if self.midi_output:
|
||||
#self.midi_feedback_device = mido.open_output(midi_device_on_port[subport_index])
|
||||
self.root.after(self.midi_delay, self.refresh_midi_feedback)
|
||||
self.poll_midi_input()
|
||||
elif self.data.midi_status == 'connected':
|
||||
self.data.midi_status = 'disconnected'
|
||||
@@ -106,14 +113,19 @@ class MidiInput(object):
|
||||
|
||||
def run_action_for_mapped_message(self, message_name, mapped_message_value):
|
||||
this_mapping = self.midi_mappings[message_name]
|
||||
#if self.data.function_on and "FN_%s"%self.data.control_mode in this_mapping:
|
||||
# mode = "FN_%s"%self.data.control_mode
|
||||
#el
|
||||
if self.data.control_mode in this_mapping:
|
||||
mode = self.data.control_mode
|
||||
#elif self.data.function_on and "FN_DEFAULT" in this_mapping:
|
||||
# mode = "FN_DEFAULT"
|
||||
elif 'DEFAULT' in this_mapping:
|
||||
mode = 'DEFAULT'
|
||||
|
||||
if self.data.function_on and len(this_mapping[mode]) > 1:
|
||||
method_name = this_mapping[mode][1]
|
||||
self.data.function_on = False
|
||||
#self.data.function_on = False
|
||||
else:
|
||||
method_name = this_mapping[mode][0]
|
||||
|
||||
@@ -127,4 +139,30 @@ class MidiInput(object):
|
||||
## 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()
|
||||
#self.refresh_midi_feedback()
|
||||
|
||||
# Plugins to support MIDI feedback
|
||||
|
||||
def find_output_plugin(self, midi_device):
|
||||
# loop over the plugins
|
||||
# find one that self.supports_midi_feedback(self.midi_device.name):
|
||||
# open the midi device self.midi_feedback_device = mido.open_output(midi_device_on_port[subport_index])
|
||||
print ("Looking for a MIDI Feedback plugin that supports %s..." % midi_device)
|
||||
from data_centre.plugin_collection import MidiFeedbackPlugin
|
||||
|
||||
for p in self.data.plugins.get_plugins(MidiFeedbackPlugin):
|
||||
if p.supports_midi_feedback(midi_device):
|
||||
print ("Found one! Opening device")
|
||||
p.set_midi_device(mido.open_output(midi_device))
|
||||
return p
|
||||
|
||||
print ("Didn't find one!")
|
||||
|
||||
def refresh_midi_feedback(self):
|
||||
|
||||
self.midi_output.refresh_midi_feedback()
|
||||
|
||||
if self.midi_output and self.data.settings['user_input']['MIDI_INPUT']['value'] == self.midi_setting and self.data.midi_port_index == self.port_index:
|
||||
if self.midi_output.supports_midi_feedback(self.data.midi_device_name):
|
||||
self.root.after(self.midi_delay*5, self.refresh_midi_feedback)
|
||||
|
||||
|
||||
@@ -267,3 +267,203 @@ class Shaders(object):
|
||||
self.osc_client.send_message("/shader/{}/speed".format(str(layer)), amount )
|
||||
self.selected_speed_list[layer] = amount
|
||||
|
||||
# methods for helping dealing with storing and recalling shader parameter frame states
|
||||
def get_live_frame(self):
|
||||
#print("get_live_frame: %s" % self.pc.message_handler.shaders.selected_param_list)
|
||||
import copy #from copy import deepcopy
|
||||
frame = {
|
||||
'selected_shader_slots': [ shader.get('slot',None) for shader in self.selected_shader_list ],
|
||||
'shader_params': copy.deepcopy(self.selected_param_list),
|
||||
'layer_active_status': copy.deepcopy(self.selected_status_list),
|
||||
'feedback_active': self.data.feedback_active,
|
||||
'x3_as_speed': self.data.settings['shader']['X3_AS_SPEED']['value'],
|
||||
'shader_speeds': copy.deepcopy(self.selected_speed_list),
|
||||
'strobe_amount': self.data.settings['shader']['STROBE_AMOUNT']['value'] / 10.0
|
||||
}
|
||||
#print("built frame: %s" % frame['shader_params'])
|
||||
return frame
|
||||
|
||||
def recall_frame_params(self, preset):
|
||||
if preset is None:
|
||||
return
|
||||
#print("recall_frame_params got: %s" % preset.get('shader_params'))
|
||||
for (layer, param_list) in enumerate(preset.get('shader_params',[])):
|
||||
if param_list:
|
||||
for param,value in enumerate(param_list):
|
||||
#if (ignored is not None and ignored['shader_params'][layer][param] is not None):
|
||||
# print ("ignoring %s,%s because value is %s" % (layer,param,ignored['shader_params'][layer][param]))
|
||||
# continue
|
||||
if (value is not None):
|
||||
#print("recalling layer %s param %s: value %s" % (layer,param,value))
|
||||
self.data.plugins.actions.call_method_name('set_the_shader_param_%s_layer_%s_continuous' % (param,layer), value)
|
||||
|
||||
if preset.get('feedback_active') is not None:
|
||||
self.data.feedback_active = preset.get('feedback_active',self.data.feedback_active)
|
||||
if self.data.feedback_active:
|
||||
self.data.plugins.actions.call_method_name('enable_feedback')
|
||||
else:
|
||||
self.data.plugins.actions.call_method_name('disable_feedback')
|
||||
|
||||
if preset.get('x3_as_speed') is not None:
|
||||
self.data.settings['shader']['X3_AS_SPEED']['value'] = preset.get('x3_as_speed',self.data.settings['shader']['X3_AS_SPEED']['value'])
|
||||
"""if self.data.settings['shader']['X3_AS_SPEED']['value']:
|
||||
self.data.plugins.actions.call_method_name('enable_x3_as_speed')
|
||||
else:
|
||||
self.data.plugins.actions.call_method_name('disable_x3_as_speed')"""
|
||||
|
||||
for (layer, speed) in enumerate(preset.get('shader_speeds',[])):
|
||||
if speed is not None:
|
||||
self.data.plugins.actions.call_method_name('set_shader_speed_layer_%s_amount' % layer, speed)
|
||||
|
||||
if preset.get('strobe_amount') is not None:
|
||||
self.data.plugins.actions.set_strobe_amount_continuous(preset.get('strobe_amount'))
|
||||
|
||||
def recall_frame(self, preset):
|
||||
|
||||
self.data.settings['shader']['X3_AS_SPEED']['value'] = preset.get('x3_as_speed')
|
||||
|
||||
# x3_as_speed affects preset recall, so do that first
|
||||
self.recall_frame_params(preset)
|
||||
|
||||
for (layer, slot) in enumerate(preset.get('selected_shader_slots',[])):
|
||||
if slot is not None:
|
||||
#print("setting layer %s to slot %s" % (layer, slot))
|
||||
self.data.plugins.actions.call_method_name('play_shader_%s_%s' % (layer, slot))
|
||||
|
||||
for (layer, active) in enumerate(preset.get('layer_active_status',[])):
|
||||
# print ("got %s layer with status %s " % (layer,active))
|
||||
if active=='▶':
|
||||
self.data.plugins.actions.call_method_name('start_shader_layer_%s' % layer)
|
||||
else:
|
||||
self.data.plugins.actions.call_method_name('stop_shader_layer_%s' % layer)
|
||||
|
||||
DEBUG_FRAMES = False
|
||||
|
||||
# overlay frame2 on frame1
|
||||
def merge_frames(self, frame1, frame2):
|
||||
from copy import deepcopy
|
||||
f = deepcopy(frame1) #frame1.copy()
|
||||
if self.DEBUG_FRAMES: print("merge_frames: got frame1\t%s" % frame1)
|
||||
if self.DEBUG_FRAMES: print("merge_frames: got frame2\t%s" % frame2)
|
||||
for i,f2 in enumerate(frame2['shader_params']):
|
||||
for i2,p in enumerate(f2):
|
||||
if p is not None:
|
||||
f['shader_params'][i][i2] = p
|
||||
|
||||
if frame2['feedback_active'] is not None:
|
||||
f['feedback_active'] = frame2['feedback_active']
|
||||
|
||||
if frame2['x3_as_speed'] is not None:
|
||||
f['x3_as_speed'] = frame2['x3_as_speed']
|
||||
|
||||
if f.get('shader_speeds') is None:
|
||||
f['shader_speeds'] = frame2.get('shader_speeds')
|
||||
else:
|
||||
for i,s in enumerate(frame2['shader_speeds']):
|
||||
if s is not None:
|
||||
f['shader_speeds'][i] = s
|
||||
|
||||
if frame2.get('strobe_amount'):
|
||||
f['strobe_amount'] = frame2.get('strobe_amount')
|
||||
|
||||
if self.DEBUG_FRAMES: print("merge_frames: got return\t%s" % f)
|
||||
return f
|
||||
|
||||
def get_frame_ignored(self, frame, ignored):
|
||||
from copy import deepcopy
|
||||
f = deepcopy(frame) #frame1.copy()
|
||||
if self.DEBUG_FRAMES: print("get_frame_ignored: got frame\t%s" % frame)
|
||||
for i,f2 in enumerate(frame['shader_params']):
|
||||
for i2,p in enumerate(f2):
|
||||
if ignored['shader_params'][i][i2] is not None:
|
||||
f['shader_params'][i][i2] = None
|
||||
if ignored.get('feedback_active') is not None:
|
||||
f['feedback_active'] = None
|
||||
if ignored.get('x3_as_speed') is not None:
|
||||
f['x3_as_speed'] = None
|
||||
if ignored.get('shader_speeds') is not None and frame.get('shader_speeds'):
|
||||
for i,s in enumerate(frame.get('shader_speeds')):
|
||||
if ignored['shader_speeds'][i] is not None:
|
||||
f['shader_speeds'][i] = None
|
||||
if ignored.get('strobe_amount') is not None:
|
||||
f['strobe_amount'] = None
|
||||
if self.DEBUG_FRAMES: print("get_frame_ignored: got return\t%s" % f)
|
||||
return f
|
||||
|
||||
def is_frame_empty(self, frame):
|
||||
#from copy import deepcopy
|
||||
#f = deepcopy(frame) #frame1.copy()
|
||||
if self.DEBUG_FRAMES: print("is_frame_empty: got frame\t%s" % frame)
|
||||
|
||||
if frame.get('feedback_active') is not None:
|
||||
return False
|
||||
if frame.get('x3_as_speed') is not None:
|
||||
return False
|
||||
if frame.get('strobe_amount') is not None:
|
||||
return False
|
||||
|
||||
for i,f in enumerate(frame['shader_params']):
|
||||
for i2,p in enumerate(f):
|
||||
if p is not None: #ignored['shader_params'][i][i2] is not None:
|
||||
return False
|
||||
|
||||
if frame.get('shader_speeds') is not None:
|
||||
for i,f in enumerate(frame['shader_speeds']):
|
||||
if f is not None:
|
||||
return False
|
||||
|
||||
if self.DEBUG_FRAMES: print("is_frame_empty: got return true")
|
||||
return True
|
||||
|
||||
|
||||
def get_frame_diff(self, last_frame, current_frame):
|
||||
if not last_frame: return current_frame
|
||||
|
||||
if self.DEBUG_FRAMES:
|
||||
print(">>>>get_frame_diff>>>>")
|
||||
print("last_frame: \t%s" % last_frame['shader_params'])
|
||||
print("current_frame: \t%s" % current_frame['shader_params'])
|
||||
|
||||
param_values = [[None]*4,[None]*4,[None]*4]
|
||||
for layer,params in enumerate(current_frame.get('shader_params',[[None]*4]*3)):
|
||||
#if self.DEBUG_FRAMES: print("got layer %s params: %s" % (layer, params))
|
||||
for param,p in enumerate(params):
|
||||
if p is not None and p != last_frame.get('shader_params')[layer][param]:
|
||||
if self.DEBUG_FRAMES: print("setting layer %s param %s to %s" % (layer,param,p))
|
||||
param_values[layer][param] = p
|
||||
|
||||
if current_frame['feedback_active'] is not None and last_frame['feedback_active'] != current_frame['feedback_active']:
|
||||
feedback_active = current_frame['feedback_active']
|
||||
else:
|
||||
feedback_active = None
|
||||
|
||||
if current_frame['x3_as_speed'] is not None and last_frame['x3_as_speed'] != current_frame['x3_as_speed']:
|
||||
x3_as_speed = current_frame['x3_as_speed']
|
||||
else:
|
||||
x3_as_speed = None
|
||||
|
||||
speed_values = [None]*3
|
||||
for layer,param in enumerate(current_frame.get('shader_speeds',[None]*3)):
|
||||
if param is not None and param != last_frame['shader_speeds'][layer]:
|
||||
speed_values[layer] = param
|
||||
|
||||
if current_frame['strobe_amount'] is not None and last_frame['strobe_amount'] != current_frame['strobe_amount']:
|
||||
strobe_amount = current_frame['strobe_amount']
|
||||
else:
|
||||
strobe_amount = None
|
||||
|
||||
if self.DEBUG_FRAMES:
|
||||
print("param_values is\t%s" % param_values)
|
||||
print("speed_values is\t%s" % speed_values)
|
||||
|
||||
diff = {
|
||||
'shader_params': param_values,
|
||||
'feedback_active': feedback_active,
|
||||
'x3_as_speed': x3_as_speed,
|
||||
'shader_speeds': speed_values,
|
||||
'strobe_amount': strobe_amount,
|
||||
}
|
||||
if self.DEBUG_FRAMES: print("returning\t%s\n^^^^" % diff['shader_params'])
|
||||
|
||||
return diff
|
||||
|
||||
|
||||
Reference in New Issue
Block a user