import data_centre.plugin_collection from data_centre.plugin_collection import ActionsPlugin, SequencePlugin, DisplayPlugin from plugins.frame_manager import Frame class ShaderLoopRecordPlugin(ActionsPlugin,SequencePlugin,DisplayPlugin): MAX_CLIPS = 8 frames = [] def __init__(self, plugin_collection): super().__init__(plugin_collection) self.PRESET_FILE_NAME = "ShaderLoopRecordPlugin/frames.json" for clip in self.load_presets(): c = [] for frame in clip: c.append(Frame(self.pc).store_copy(frame)) self.frames.append(c) 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.duration: # self.duration/self.frequency: current_frame_index = "(self.duration/self.frequency) +""" (current_frame_index%self.duration) if self.DEBUG_FRAMES: print (">>>>>>>>>>>>>>frame at %i%%: %i" % (position*100, current_frame_index)) #print("got frame index %s" % current_frame_index) if self.recording: current_frame = self.pc.fm.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 ] if self.recording: current_frame = self.pc.fm.get_live_frame() #.copy() if self.DEBUG_FRAMES: print("current_frame copy before recall is %s" % current_frame['shader_params']) 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.fm.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.fm.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.fm.merge_frames(self.ignored, diff) if self.DEBUG_FRAMES: print("about to call get_ignored_frames with %s\n and\n %s" % (saved_frame.f, self.ignored.f)) """print("got self.ignored:\n\t%s\n" % self.ignored.f) print("diff is currently:\n\t%s\n" % diff.f) print("saved_frame is currently:\n\t%s\n" % saved_frame.f)""" diff = self.pc.fm.merge_frames( self.pc.fm.get_frame_ignored(saved_frame, self.ignored), diff ) #print("got merged:\n\t%s\n" % diff.f) #diff = self.pc.shaders.merge_frames(self.pc.shaders.get_live_frame(), diff) self.pc.fm.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.fm.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())"""