def finished(self, context): # return to view3d if self.view3d is not None: self.view3d.type = self._view3d print("TOTAL BAKE TIME: %02d:%02d:%02d" % utils.splittime(sum(BakeSoundPanel.bake_times))) BakeSoundPanel.report = "Finished Baking" #context.area.header_text_set() # set up the rnas sp = self.speaker sound = self.sound action = sp.animation_data.action bakeoptions = sound.bakeoptions boo = bakeoptions.bake_operator # save non defaults to an ID prop. action['boo'] = bakeoptions.sound_type action['_RNA_UI']['boo'] = dict(boo.items()) channel_name = action['channel_name'] vcns = [ "%s%d" % (channel_name, i) for i in range(bakeoptions.channels) ] sp_rna = { k: sp['_RNA_UI'][k].to_dict() for k in sp['_RNA_UI'].keys() if k in vcns } action['rna'] = str(sp_rna) BakeSoundPanel.baking = False # drop the action into the NLA utils.nla_drop(sp, action, 1, "%s %s" % (channel_name, channel_name)) # normalise to action. This will set the action.normalise = 'ACTION' if context.scene.speaker is None: sp.is_context_speaker = True context.window_manager.event_timer_remove(self._timer) bpy.ops.graph.view_all_with_bgl_graph() self.add_to_tweaks(action) return {'FINISHED'}
def finished(self, context): # return to view3d if self.view3d is not None: self.view3d.type = self._view3d print("TOTAL BAKE TIME: %02d:%02d:%02d" % utils.splittime(sum(BakeSoundPanel.bake_times))) BakeSoundPanel.report = "Finished Baking" #context.area.header_text_set() # set up the rnas sp = self.speaker sound = self.sound action = sp.animation_data.action bakeoptions = sound.bakeoptions boo = bakeoptions.bake_operator # save non defaults to an ID prop. action['boo'] = bakeoptions.sound_type action['_RNA_UI']['boo'] = dict(boo.items()) channel_name = action['channel_name'] vcns = ["%s%d" % (channel_name, i) for i in range(bakeoptions.channels)] sp_rna = {k: sp['_RNA_UI'][k].to_dict() for k in sp['_RNA_UI'].keys() if k in vcns} action['rna'] = str(sp_rna) BakeSoundPanel.baking = False # drop the action into the NLA utils.nla_drop(sp, action, 1, "%s %s" %(channel_name, channel_name)) # normalise to action. This will set the action.normalise = 'ACTION' if context.scene.speaker is None: sp.is_context_speaker = True context.window_manager.event_timer_remove(self._timer) bpy.ops.graph.view_all_with_bgl_graph() self.add_to_tweaks(action) return {'FINISHED'}
def modal(self, context, event): if getattr(context, "area", None): context.area.tag_redraw() wm = context.window_manager ''' if BakeSoundPanel.wait > 0: debug.print("waiting", BakeSoundPanel.wait) ''' def confirm_cancel(self, context): layout = self.layout layout.operator("sounddrivers.cancel_baking") layout.operator("sounddrivers.continue_baking") if BakeSoundPanel.cancel_baking: self.clean() return self.cancel(context) BakeSoundPanel.baking = True bakeoptions = self.sound.bakeoptions channels = bakeoptions.channels bake_operator = bakeoptions.bake_operator sound = self.sound speaker = self.speaker action = speaker.animation_data.action if event.type == 'ESC' or not BakeSoundPanel.baking: context.window_manager.popup_menu(confirm_cancel, title="Baking", icon='SOUND') BakeSoundPanel.wait = 1000000 return {'PASS_THROUGH'} self.clean() return self.cancel(context) if BakeSoundPanel.wait > 0: BakeSoundPanel.wait -= 1 return {'PASS_THROUGH'} if self.count >= bakeoptions.channels: # Success do PostPro # return {'PASS_THROUGH'} return self.finished(context) if self.baking: return {'PASS_THROUGH'} if event.type == 'TIMER': if self.baking: return {'PASS_THROUGH'} #context.scene.frame_set(1) self.baking = True fc = action.fcurves[self.bakeorder[self.count]] channel = self.bakeorder[self.count] wm["bake_progress"] = 100 * self.count / channels setattr(BakeSoundPanel, "channel", channel) BakeSoundPanel.report = "[%s%d]" % (bakeoptions.channel_name, channel) fc.select = True #FIXME FIXME FIXME fp = bpy.path.abspath(sound.filepath) low, high = self.channel_range() if not self.context_override or not self.graph: context.area.type = 'GRAPH_EDITOR' context.area.spaces.active.mode = 'FCURVES' self.c = context.copy() context.scene.frame_set(1) #context.area.type = 'GRAPH_EDITOR' t0 = time.clock() try: #x = bpy.ops.graph.sound_bake( x = bpy.ops.graph.sound_bake(self.c, filepath=fp, low=low, high=high, attack=bake_operator.attack, release=bake_operator.release, threshold=bake_operator.threshold, use_accumulate=bake_operator.use_accumulate, use_additive=bake_operator.use_additive, use_square=bake_operator.use_square, sthreshold=bake_operator.sthreshold) except: print("ERROR IN BAKE OP") ''' for k in self.c.keys(): print(k, ":", self.c[k]) ''' return self.cancel(context) ''' if self.graph: #bpy.ops.graph.view_all(self.c) bpy.ops.graph.view_all_with_bgl_graph() ''' context.area.type = 'PROPERTIES' t1 = time.clock() BakeSoundPanel.bake_times.append(t1 - t0) fc_range, points = fc.minmax vol_range = abs(fc_range[1] - fc_range[0]) # FIXME make retry count an addon var. if self.retries.count(channel) > channels // 5: print("TOO MANY RETRIES") self.clean() return self.cancel(context) if bakeoptions.auto_adjust\ and (vol_range < 0.0001 or vol_range > 1e10): print("NO RANGE", vol_range) self.retries.append(channel) BakeSoundPanel.status[channel] = 99 if channel == 0: BakeSoundPanel.report = "[%s%d] NO Lo RANGE.. adjusting" \ % (bakeoptions.channel_name, channel) bakeoptions.minf = high elif channel == (bakeoptions.channels - 1): BakeSoundPanel.report = "[%s%d] NO Hi RANGE .. adjusting" \ % (bakeoptions.channel_name, channel) self.change_last == True bakeoptions.maxf = low else: BakeSoundPanel.wait = 20 # wait 2 seconds to continue BakeSoundPanel.report = "[%s%d] NO Mid RANGE\ .. continuing" % (bakeoptions.channel_name,\ channel) self.count += 1 bpy.ops.graph.view_all_with_bgl_graph() #need to set count down one else: BakeSoundPanel.status[channel] = 1 # set up the rna rna = speaker["_RNA_UI"] channel_name = "%s%d" % (bakeoptions.channel_name, channel) is_music = bakeoptions.sound_type == 'MUSIC' utils.set_channel_idprop_rna(channel_name, rna, low, high, fc_range, fc_range, is_music=is_music) print("%4s %8s %8s %10.4f %10.4f" %\ (channel_name,\ utils.f(low),\ utils.f(high),\ fc_range[0],\ fc_range[1]),\ end="") print(" %02d:%02d:%02d" % (utils.splittime(t1 - t0))) BakeSoundPanel.report = rna[channel_name]["description"]\ .replace("Frequency", "") if channel == (bakeoptions.channels - 1)\ and self.change_last: self.change_last = False action.fcurves[0].mute = True bakeorder[0], bakeorder[channels - 1] =\ bakeorder[channels - 1], bakeorder[0] # need to swap n clear first fcurve # mute the first fcurve _min, _max = fc_range if _min < action["min"]: action["min"] = _min if _max > action["max"]: action["max"] = _max self.count += 1 fc.mute = not bool(BakeSoundPanel.status[channel]) fc.select = False self.baking = False self.baked = True return {'PASS_THROUGH'}
def draw(self, context): space = context.space_data layout = self.layout if self.baking: action = self.action #self.draw_progress_slider(context) row = layout.row() row.label("[%s] %s" % (action["channel_name"], action.name), icon='ACTION') self.draw_progress_slider(context) ''' if channels > 24: i = getattr(self, "channel", 0) self.draw_current_fcurve_slider(context, i=i) else: self.draw_fcurve_slider(context) ''' box = layout.box() if len(action.fcurves): row = box.row(align=False) i = getattr(self, "channel", 0) fc = action.fcurves[i] sub = row.row() sub.alignment = 'LEFT' sub.label(fc.data_path.strip('["]')) color = [c for c in fc.color] color.append(1.0) row.label("Baking...") sub = row.row() sub.alignment = 'RIGHT' sub.template_node_socket(color=color) box = layout.box() if len(self.bake_times): row = box.row(align=False) i = getattr(self, "channel", 0) fc = action.fcurves[i] sub = row.row() sub.alignment = 'LEFT' sub.label(fc.data_path.strip('["]')) color = [c for c in fc.color] color.append(1.0) row.label("Baked") sub = row.row() sub.alignment = 'RIGHT' sub.template_node_socket(color=color) row = box.row(align=False) row.label(BakeSoundPanel.report) row = box.row() row.label("Baked in: %02d:%02d.%02d" % utils.splittime(self.bake_times[-1])) row = box.row() te = sum(self.bake_times) abt = te / len(self.bake_times) channels = self.action.get("Channels", 0) tr = (channels - len(self.bake_times)) * abt row.label("Elapsed: %02d:%02d.%02d" % utils.splittime(te)) row.label("Remaining: %02d:%02d.%02d" % utils.splittime(tr)) #row.column_flow(columns=10, align=True) return None speaker = utils.getSpeaker(context) sound = speaker.sound if sound is None: row = layout.row() row.label("No Sound to Bake", icon='INFO') return None scene = context.scene bakeoptions = sound.bakeoptions bake_operator = bakeoptions.bake_operator # Settings for bake sound to fcurve Operator if not self.baking: areas = [a.type for a in context.screen.areas] if 'GRAPH_EDITOR' in areas: area_index = areas.index('GRAPH_EDITOR') op = layout.operator("wm.bake_sound_to_action", text="BAKE", icon='FCURVE') op.area_index = area_index op.sound_name = sound.name op.speaker_name = speaker.name elif len(areas) > 1: self.draw_area_buttons(context) else: op = layout.operator("wm.bake_sound_to_action", text="BAKE", icon='FCURVE') op.sound_name = sound.name op.speaker_name = speaker.name ### TEST FOR SQUIZ action = None channels = 0 if speaker.animation_data: action = speaker.animation_data.action if action is not None: channels = action["Channels"] #row.operator(self.bl_idname).preset = "FOOBAR" row = layout.row() col = layout.column_flow(align=True) col.label("Bake Options") row = col.row(align=True) row.menu("speaker.preset_menu", text=getattr(bpy.types, "speaker.preset_menu").bl_label) row.operator("wm.soundtool_operator_preset_add", text="", icon='ZOOMIN') row.operator("wm.soundtool_operator_preset_add", text="", icon='ZOOMOUT').remove_active = True #row.prop(bakeoptions, "show_graph_editor", toggle=True, emboss=True) ''' preset_box = row.box() row = preset_box.row() if len(bakeoptions.preset) == 0: txt = "Select Preset" else: txt = bakeoptions.preset row.menu("speaker.preset_menu", text=txt) row = preset_box.row() #row.prop(bakeoptions, "save_preset") preset_row = preset_box.row() preset_row.prop(bakeoptions, "preset") row = layout.row() row.menu("sound.music_notes") ''' channels = [c for sp in context.scene.objects if sp.type == 'SPEAKER' for c in sp.data.channels] channel_name = utils.unique_name(channels, "AA") row = layout.row() row.label("%s_%s_%s" % (bakeoptions.sound_type, channel_name, sound.name), icon='ACTION') abox = layout.box() arow = abox.row(align=True) arow.prop(bakeoptions, "sound_type", text="") arow.label(channel_name) #arow.prop(bakeoptions, "channel_name", text="") arow.label(sound.name) #arow.prop(bakeoptions, "action_name", text="") # REFACTO OUT row = layout.row() ''' if not validate_channel_name(context): row.label("Channel in USE or INVALID", icon='ERROR') row.alert = True row = layout.row() ''' #col.scale_x = row.scale_y = 2 row.label("Channel") row = layout.row() box = row.box() #col.scale_x = row.scale_y = 2 brow = box.row(align=True) #brow.prop(bakeoptions, "channel_name", text="Name") sub = brow.row() sub.prop(bakeoptions, "channels", text="") sub.enabled = bakeoptions.sound_type != 'MUSIC' row = layout.row() self.draw_freqs(layout, bakeoptions) row = layout.row() row.label("Bake Sound to F-Curves", icon='IPO') box = layout.box() #box.operator("graph.sound_bake", icon='IPO') box.prop(bake_operator, "threshold") box.prop(bake_operator, "release") box.prop(bake_operator, 'attack') box.prop(bake_operator, "use_additive", icon="PLUS") box.prop(bake_operator, "use_accumulate", icon="PLUS") row = box.row() split = row.split(percentage=0.20) split.prop(bake_operator, "use_square") split.prop(bake_operator, "sthreshold")
def modal(self, context, event): if getattr(context, "area", None): context.area.tag_redraw() wm = context.window_manager ''' if BakeSoundPanel.wait > 0: debug.print("waiting", BakeSoundPanel.wait) ''' def confirm_cancel(self, context): layout = self.layout layout.operator("sounddrivers.cancel_baking") layout.operator("sounddrivers.continue_baking") if BakeSoundPanel.cancel_baking: self.clean() return self.cancel(context) BakeSoundPanel.baking = True bakeoptions = self.sound.bakeoptions channels = bakeoptions.channels bake_operator = bakeoptions.bake_operator sound = self.sound speaker = self.speaker action = speaker.animation_data.action if event.type == 'ESC' or not BakeSoundPanel.baking: context.window_manager.popup_menu(confirm_cancel, title="Baking", icon='SOUND') BakeSoundPanel.wait = 1000000 return {'PASS_THROUGH'} self.clean() return self.cancel(context) if BakeSoundPanel.wait > 0: BakeSoundPanel.wait -= 1 return {'PASS_THROUGH'} if self.count >= bakeoptions.channels: # Success do PostPro # return {'PASS_THROUGH'} return self.finished(context) if self.baking: return {'PASS_THROUGH'} if event.type == 'TIMER': if self.baking: return {'PASS_THROUGH'} #context.scene.frame_set(1) self.baking = True fc = action.fcurves[self.bakeorder[self.count]] channel = self.bakeorder[self.count] wm["bake_progress"] = 100 * self.count / channels setattr(BakeSoundPanel, "channel", channel) BakeSoundPanel.report = "[%s%d]" % (bakeoptions.channel_name, channel) fc.select = True #FIXME FIXME FIXME fp = bpy.path.abspath(sound.filepath) low, high = self.channel_range() if not self.context_override or not self.graph: context.area.type = 'GRAPH_EDITOR' context.area.spaces.active.mode = 'FCURVES' self.c = context.copy() context.scene.frame_set(1) #context.area.type = 'GRAPH_EDITOR' t0 = time.clock() try: #x = bpy.ops.graph.sound_bake( x = bpy.ops.graph.sound_bake( self.c, filepath=fp, low=low, high=high, attack=bake_operator.attack, release=bake_operator.release, threshold=bake_operator.threshold, use_accumulate=bake_operator.use_accumulate, use_additive=bake_operator.use_additive, use_square=bake_operator.use_square, sthreshold=bake_operator.sthreshold) except: print("ERROR IN BAKE OP") ''' for k in self.c.keys(): print(k, ":", self.c[k]) ''' return self.cancel(context) ''' if self.graph: #bpy.ops.graph.view_all(self.c) bpy.ops.graph.view_all_with_bgl_graph() ''' context.area.type = 'PROPERTIES' t1 = time.clock() BakeSoundPanel.bake_times.append(t1 - t0) fc_range, points = fc.minmax vol_range = abs(fc_range[1] - fc_range[0]) # FIXME make retry count an addon var. if self.retries.count(channel) > channels // 5: print("TOO MANY RETRIES") self.clean() return self.cancel(context) if bakeoptions.auto_adjust\ and (vol_range < 0.0001 or vol_range > 1e10): print("NO RANGE", vol_range) self.retries.append(channel) BakeSoundPanel.status[channel] = 99 if channel == 0: BakeSoundPanel.report = "[%s%d] NO Lo RANGE.. adjusting" \ % (bakeoptions.channel_name, channel) bakeoptions.minf = high elif channel == (bakeoptions.channels - 1): BakeSoundPanel.report = "[%s%d] NO Hi RANGE .. adjusting" \ % (bakeoptions.channel_name, channel) self.change_last == True bakeoptions.maxf = low else: BakeSoundPanel.wait = 20 # wait 2 seconds to continue BakeSoundPanel.report = "[%s%d] NO Mid RANGE\ .. continuing" % (bakeoptions.channel_name,\ channel) self.count += 1 bpy.ops.graph.view_all_with_bgl_graph() #need to set count down one else: BakeSoundPanel.status[channel] = 1 # set up the rna rna = speaker["_RNA_UI"] channel_name = "%s%d" % (bakeoptions.channel_name, channel) is_music = bakeoptions.sound_type == 'MUSIC' utils.set_channel_idprop_rna(channel_name, rna, low, high, fc_range, fc_range, is_music=is_music) print("%4s %8s %8s %10.4f %10.4f" %\ (channel_name,\ utils.f(low),\ utils.f(high),\ fc_range[0],\ fc_range[1]),\ end="") print(" %02d:%02d:%02d" % (utils.splittime(t1 - t0))) BakeSoundPanel.report = rna[channel_name]["description"]\ .replace("Frequency", "") if channel == (bakeoptions.channels - 1)\ and self.change_last: self.change_last = False action.fcurves[0].mute = True bakeorder[0], bakeorder[channels - 1] =\ bakeorder[channels - 1], bakeorder[0] # need to swap n clear first fcurve # mute the first fcurve _min, _max = fc_range if _min < action["min"]: action["min"] = _min if _max > action["max"]: action["max"] = _max self.count += 1 fc.mute = not bool(BakeSoundPanel.status[channel]) fc.select = False self.baking = False self.baked = True return {'PASS_THROUGH'}
def draw(self, context): space = context.space_data layout = self.layout if self.baking: action = self.action #self.draw_progress_slider(context) row = layout.row() row.label("[%s] %s" % (action["channel_name"], action.name), icon='ACTION') self.draw_progress_slider(context) ''' if channels > 24: i = getattr(self, "channel", 0) self.draw_current_fcurve_slider(context, i=i) else: self.draw_fcurve_slider(context) ''' box = layout.box() if len(action.fcurves): row = box.row(align=False) i = getattr(self, "channel", 0) fc = action.fcurves[i] sub = row.row() sub.alignment = 'LEFT' sub.label(fc.data_path.strip('["]')) color = [c for c in fc.color] color.append(1.0) row.label("Baking...") sub = row.row() sub.alignment = 'RIGHT' sub.template_node_socket(color=color) box = layout.box() if len(self.bake_times): row = box.row(align=False) i = getattr(self, "channel", 0) fc = action.fcurves[i] sub = row.row() sub.alignment = 'LEFT' sub.label(fc.data_path.strip('["]')) color = [c for c in fc.color] color.append(1.0) row.label("Baked") sub = row.row() sub.alignment = 'RIGHT' sub.template_node_socket(color=color) row = box.row(align=False) row.label(BakeSoundPanel.report) row = box.row() row.label("Baked in: %02d:%02d.%02d" % utils.splittime(self.bake_times[-1])) row = box.row() te = sum(self.bake_times) abt = te / len(self.bake_times) channels = self.action.get("Channels", 0) tr = (channels - len(self.bake_times)) * abt row.label("Elapsed: %02d:%02d.%02d" % utils.splittime(te)) row.label("Remaining: %02d:%02d.%02d" % utils.splittime(tr)) #row.column_flow(columns=10, align=True) return None speaker = utils.getSpeaker(context) sound = speaker.sound if sound is None: row = layout.row() row.label("No Sound to Bake", icon='INFO') return None scene = context.scene bakeoptions = sound.bakeoptions bake_operator = bakeoptions.bake_operator # Settings for bake sound to fcurve Operator if not self.baking: areas = [a.type for a in context.screen.areas] if 'GRAPH_EDITOR' in areas: area_index = areas.index('GRAPH_EDITOR') op = layout.operator("wm.bake_sound_to_action", text="BAKE", icon='FCURVE') op.area_index = area_index op.sound_name = sound.name op.speaker_name = speaker.name elif len(areas) > 1: self.draw_area_buttons(context) else: op = layout.operator("wm.bake_sound_to_action", text="BAKE", icon='FCURVE') op.sound_name = sound.name op.speaker_name = speaker.name ### TEST FOR SQUIZ action = None channels = 0 if speaker.animation_data: action = speaker.animation_data.action if action is not None: channels = action["Channels"] #row.operator(self.bl_idname).preset = "FOOBAR" row = layout.row() col = layout.column_flow(align=True) col.label("Bake Options") row = col.row(align=True) row.menu("speaker.preset_menu", text=getattr(bpy.types, "speaker.preset_menu").bl_label) row.operator("wm.soundtool_operator_preset_add", text="", icon='ZOOMIN') row.operator("wm.soundtool_operator_preset_add", text="", icon='ZOOMOUT').remove_active = True #row.prop(bakeoptions, "show_graph_editor", toggle=True, emboss=True) ''' preset_box = row.box() row = preset_box.row() if len(bakeoptions.preset) == 0: txt = "Select Preset" else: txt = bakeoptions.preset row.menu("speaker.preset_menu", text=txt) row = preset_box.row() #row.prop(bakeoptions, "save_preset") preset_row = preset_box.row() preset_row.prop(bakeoptions, "preset") row = layout.row() row.menu("sound.music_notes") ''' channels = [ c for sp in context.scene.objects if sp.type == 'SPEAKER' for c in sp.data.channels ] channel_name = utils.unique_name(channels, "AA") row = layout.row() row.label("%s_%s_%s" % (bakeoptions.sound_type, channel_name, sound.name), icon='ACTION') abox = layout.box() arow = abox.row(align=True) arow.prop(bakeoptions, "sound_type", text="") arow.label(channel_name) #arow.prop(bakeoptions, "channel_name", text="") arow.label(sound.name) #arow.prop(bakeoptions, "action_name", text="") # REFACTO OUT row = layout.row() ''' if not validate_channel_name(context): row.label("Channel in USE or INVALID", icon='ERROR') row.alert = True row = layout.row() ''' #col.scale_x = row.scale_y = 2 row.label("Channel") row = layout.row() box = row.box() #col.scale_x = row.scale_y = 2 brow = box.row(align=True) #brow.prop(bakeoptions, "channel_name", text="Name") sub = brow.row() sub.prop(bakeoptions, "channels", text="") sub.enabled = bakeoptions.sound_type != 'MUSIC' row = layout.row() self.draw_freqs(layout, bakeoptions) row = layout.row() row.label("Bake Sound to F-Curves", icon='IPO') box = layout.box() #box.operator("graph.sound_bake", icon='IPO') box.prop(bake_operator, "threshold") box.prop(bake_operator, "release") box.prop(bake_operator, 'attack') box.prop(bake_operator, "use_additive", icon="PLUS") box.prop(bake_operator, "use_accumulate", icon="PLUS") row = box.row() split = row.split(percentage=0.20) split.prop(bake_operator, "use_square") split.prop(bake_operator, "sthreshold")