def execute(self, context): def evaluate(co, channel, mx): #co = p.co x, y = co.x, 1 if co.y > self.threshold / 100 * mx else 0 #p.co = (x, y) return (x, y) speaker = getSpeaker(context) original_action = speaker.animation_data.action self.new_channel_name = unique_name(speaker.channels, original_action.get("channel_name", "AA")) newaction = copy_sound_action(speaker, self.new_channel_name) ch = newaction["channel_name"] channels = [c for sp in context.scene.objects if sp.type == 'SPEAKER' for c in sp.data.channels] if newaction is None: return {'CANCELLED'} start, end = newaction.frame_range speaker.animation_data.action = newaction speaker.sound.bakeoptions.channel_name =\ unique_name(channels, self.new_channel_name) rna = eval(newaction["rna"]) fcurves = [f for f in newaction.fcurves] for fcurve in fcurves: dp = fcurve.data_path channel = fcurve.data_path.strip("\"'[]") #print(rna[channel]) pts = [x for p in fcurve.sampled_points for x in evaluate(p.co, channel, rna[channel]["b"])] #print(pts) rna[channel]["a"] = 0 rna[channel]["b"] = 1 newaction["min"] = rna[channel]["min"] = rna[channel]["soft_min"] = 0 newaction["max"] = rna[channel]["max"] = rna[channel]["soft_max"] = 1 newaction.fcurves.remove(fcurve) new_fcurve = newaction.fcurves.new(dp, action_group=ch) new_fcurve.extrapolation = 'CONSTANT' new_fcurve.keyframe_points.add(len(pts) // 2) new_fcurve.keyframe_points.foreach_set("co", pts) for p in new_fcurve.keyframe_points: p.interpolation = 'CONSTANT' new_fcurve.convert_to_samples(start, end) newaction["rna"] = str(rna) speaker['_RNA_UI'].update(rna) if self.nla_drop: # need to override context to use.. cbf'd nla_drop(speaker, newaction, 1, self.new_channel_name) # testcode TODO self.add_to_tweaks(newaction) newaction.normalise = 'NONE' #tw.type = "COPIED FROM %s" % original_action.name return {'FINISHED'}
def execute(self, context): speaker = getSpeaker(context) original_action = speaker.animation_data.action newaction = copy_sound_action(speaker, self.new_channel_name) channels = [c for sp in context.scene.objects if sp.type == 'SPEAKER' for c in sp.data.channels] if newaction is not None: speaker.animation_data.action = newaction speaker.sound.bakeoptions.channel_name =\ unique_name(channels, "AA") #unique_name(channels, self.new_channel_name) if self.nla_drop: # need to override context to use.. cbf'd nla_drop(speaker, newaction, 1, self.new_channel_name) self.add_to_tweaks(newaction) #tw.type = "COPIED FROM %s" % original_action.name return {'FINISHED'} return {'CANCELLED'}