def draw_tweaks(self, layout, context): scene = context.scene # Create a simple row. row = layout.row() ''' row.context_pointer_set("scene", context.scene) row.context_pointer_set("area", context.screen.areas[0]) row.context_pointer_set("window", context.window) row.context_pointer_set("screen", context.screen) row.context_pointer_set("region", context.screen.areas[0].regions[-1]) op = row.operator("graph.clean") ''' op = row.operator("soundaction.tweak", text="CLEAN") op.type = 'CLEAN' op = row.operator("soundaction.tweak", text="SMOOTH") op.type = 'SMOOTH' row = layout.row() #row.prop(op, "threshold") action = getAction(context.scene.speaker) for xx in action.tweaks: row = layout.row() row.label("[%s] %s " % (xx.channel_name, xx.type)) #row.label("%.4f" % xx.threshold) row.label("%d" % xx.fcurve_count) row.label("%d" % xx.samples_count) row.label("%d" % xx.keyframe_count)
def execute(self, context): action = getAction(context.scene.speaker) c = {} graph = get_context_area(context, c, 'GRAPH_EDITOR') ''' c["area"] = graph c["screen"] = context.screen c["region"] = graph.regions[-1] c["window"] = context.window c["scene"] = context.scene ''' #hs = action.tweaks.add() #hs.type = self.type if self.type == 'CLEAN': bpy.ops.graph.clean(c, threshold=self.threshold) print("clean") #hs.threshold = self.threshold elif self.type == 'SMOOTH': bpy.ops.graph.smooth(c) print("smooth") self.sd_tweak_type = self.type self.add_to_tweaks(action) return {'FINISHED'}
def visualise(self, context): # Override BGLWidget visualise # it's the handle passed to the ScreenArea to draw sp = context.scene.speaker if sp is None: return None action = getAction(sp) # action = context.area.sound_action # NEW IDEA REFACTO if action is None: return None area_settings = self.area_settings(context) if not area_settings: return None region = context.area.regions[-1] self.update(context) y = 0 w = self.frame_width x = interp(action.frame_range[0], self.region_frame_range, [0, region.width]) h = region.height #print("XYWH", x,y,w,h) frames = action.frame_range.length self.draw_sound_action(context, action, x, y, w, h, frames)
def draw(self, context): layout = self.layout layout.enabled = not bpy.types.BakeSoundPanel.baking speaker = getSpeaker(context) action = getAction(speaker) #checks if speaker.sound is None: layout.label("Speaker has No Sound", icon='INFO') return if action is None: layout.label("No Action Baked", icon='INFO') return elif action is None: layout.label("No Action Baked", icon='INFO') return elif action['wavfile'] != speaker.sound.name: layout.label("No Action Baked", icon='INFO') layout.label("for %s" % speaker.sound.name) return ''' layout.label(repr(action)) if action: layout.label(action['wavfile']) ''' if not bpy.types.BakeSoundPanel.baking: if action.vismode == 'SLIDER': self.Sliders(context) elif action.vismode == 'FCURVE': self.FCurveSliders(context) elif action.vismode == 'VERTICAL': self.EBT(context) elif action.vismode == 'TABSTER': self.EBT(context)
def visualise(self, context): # Override BGLWidget visualise # it's the handle passed to the ScreenArea to draw sp = context.scene.speaker if sp is None: return None action = getAction(sp) # action = context.area.sound_action # NEW IDEA REFACTO if action is None: return None area_settings = self.area_settings(context) if not area_settings: return None region = context.area.regions[-1] self.update(context) y = 0 w = self.frame_width x = interp(action.frame_range[0], self.region_frame_range, [0, region.width]) h = region.height # print("XYWH", x,y,w,h) frames = action.frame_range.length self.draw_sound_action(context, action, x, y, w, h, frames)
def visualise(self, context): area = context.area speaker = context.scene.speaker action = getAction(speaker) scene = context.scene frame = scene.frame_current """ print("MHHM") action = context.screen.sound_driver_areas["VIEW_3D_4"].action print("THIS WORKING", action) #action = context.area.sound_action # NEW IDEA REFACTO """ if action is None: return None area_settings = self.area_settings(context) if area_settings is None: return None (x, y) = area_settings.loc fw = context.area.regions[-1].width - (x + 20) fh = context.area.regions[-1].height - 50 area_settings = self.area_settings(context) AMP = area_settings.height * fh / 100 if action.get("MIDI"): bgl.glEnable(bgl.GL_BLEND) self.draw_box(x, y + AMP, 3 * fw, 20, color=self.gridcol) bgl.glDisable(bgl.GL_BLEND) self.draw_action_header_text(x, y + AMP, speaker, action) self.draw_midi_keyboard(x, y, fw, AMP, action=action, frame=frame) else: self.draw_spectrum(context, x, y, speaker, action)
def xxxx(self, context): id_data = self.id_data p = self.path_from_id() p = p[:p.find(".channels")] driver_gui = self.id_data.path_resolve(p) idx = int(driver_gui.name[3:]) dm = context.driver_manager ed = dm.find(idx) if ed is not None: sp = context.scene.speaker a = getAction(sp) a = bpy.data.actions.get(driver_gui.action) if a is None: return None cn = a["channel_name"] cn = driver_gui.channel if not self.value: bpy.ops.dm.remove_driver_var(varname=self.name, dindex=ed.index) # REFACTO else: channel_list = [ ch.name for ch in driver_gui.channels if ch.value and ch.name.startswith(cn) ] main(driver_gui, context, ed, sp, a, channel_list) return None
def draw_sound_widgets(context, wlist): speaker = context.scene.speaker action = getAction(speaker) # action = context.area.sound_action # NEW IDEA REFACTO for w in wlist: w.draw_action_header_text(speaker, action)
def visualise(self, context): area = context.area speaker = context.scene.speaker action = getAction(speaker) scene = context.scene frame = scene.frame_current ''' print("MHHM") action = context.screen.sound_driver_areas["VIEW_3D_4"].action print("THIS WORKING", action) #action = context.area.sound_action # NEW IDEA REFACTO ''' if action is None: return None area_settings = self.area_settings(context) if area_settings is None: return None (x, y) = area_settings.loc fw = (context.area.regions[-1].width - (x + 20)) fh = context.area.regions[-1].height - 50 area_settings = self.area_settings(context) AMP = area_settings.height * fh / 100 if action.get("MIDI"): bgl.glEnable(bgl.GL_BLEND) self.draw_box(x, y + AMP, 3 * fw, 20, color=self.gridcol) bgl.glDisable(bgl.GL_BLEND) self.draw_action_header_text(x, y+AMP, speaker, action) self.draw_midi_keyboard(x, y, fw, AMP, action=action, frame=frame) else: self.draw_spectrum(context, x, y, speaker, action)
def xxxx(self, context): id_data = self.id_data p = self.path_from_id() p = p[:p.find(".channels")] driver_gui = self.id_data.path_resolve(p) idx = int(driver_gui.name[3:]) dm = context.driver_manager ed = dm.find(idx) if ed is not None: sp = context.scene.speaker a = getAction(sp) a = bpy.data.actions.get(driver_gui.action) if a is None: return None cn = a["channel_name"] cn = driver_gui.channel if not self.value: bpy.ops.dm.remove_driver_var(varname=self.name, dindex=ed.index) #REFACTO else: channel_list = [ch.name for ch in driver_gui.channels if ch.value and ch.name.startswith(cn)] main(driver_gui, context, ed, sp, a, channel_list) return None
def Sliders(self, context): layout = self.layout speaker = getSpeaker(context) action = getAction(speaker) if not (action and speaker): return None channel_name = action["channel_name"] start = action["start"] end = action["end"] box = layout.box() #row = box.row() #box.scale_y = 0.4 cf = box.column_flow(columns=1) cf.scale_y = action["row_height"] for i in range(start, end + 1): channel = "%s%d" % (channel_name, i) # TODO ADDED with MIDI if channel not in speaker.keys(): continue cf.prop(speaker, '["%s"]' % channel, slider=True, emboss=True, text="")
def SoundActionMenu(self, context, speaker=None, action=None, has_sound=True): speaker = getSpeaker(context) action = getAction(speaker) layout = self.layout if action is None: layout.label("NO ACTION", icon='INFO') return channel_name = action.get("channel_name") if channel_name is None: return row = layout.row(align=True) if has_sound: sub = row.row() sub.alignment = 'LEFT' #col.alignment = 'LEFT' sub.menu("soundtest.menu", text=channel_name) #sub = row.row() row.prop(action, "name", text="") sub = row.row() sub.alignment = 'RIGHT' sub.prop(action, "use_fake_user", toggle=True, text="F")
def execute(self, context): # rebake action using modifiers scene = context.scene speaker = getSpeaker(context) action = getAction(speaker) name = action.name print("-" * 72) print("Rebake action %s to sampled points" % name) print("-" * 72) rna = speaker["_RNA_UI"] sp_rna = {} pts = [(c, [(sp.co[0], c.evaluate(sp.co[0])) for sp in c.keyframe_points]) for c in action.fcurves if c.select or self.bake_all] action.normalise = 'NONE' action["max"] = -float("inf") action["min"] = float("inf") start, end = action.frame_range[0], action.frame_range[1] for fc, sam in pts: #if self.RGB: fcu.color_mode = 'AUTO_RGB' for i, p in enumerate(sam): frame, v = p fc.keyframe_points[i].co.y = v fc.keyframe_points.update() channel_name = fc.data_path.strip('["]') is_music = False fc_range, points = fc.minmax low = rna[channel_name]['low'] high = rna[channel_name]['high'] (_min, _max) = fc_range if _min < action["min"]: action["min"] = _min if _max > action["max"]: action["max"] = _max set_channel_idprop_rna(channel_name, rna, low, high, fc_range, fc_range, is_music=is_music) sp_rna[channel_name] = rna[channel_name].to_dict() print("%4s %8s %8s %10.4f %10.4f" % (channel_name, f(low), f(high), fc_range[0], fc_range[1])) # ok now bake fc.convert_to_samples(start, end) self.add_to_tweaks(action) return {'FINISHED'}
def poll(cls, context): if not hasattr(context, "speaker"): return False speaker = getSpeaker(context) action = getAction(speaker) return (context.speaker and speaker and action\ and cls.vismode in speaker.vismode)
def execute(self, context): # rebake action using modifiers scene = context.scene speaker = getSpeaker(context) action = getAction(speaker) name = action.name print("-" * 72) print("Rebake action %s to sampled points" % name) print("-" * 72) rna = speaker["_RNA_UI"] sp_rna = {} pts = [(c, [(sp.co[0], c.evaluate(sp.co[0])) for sp in c.keyframe_points]) for c in action.fcurves if c.select or self.bake_all] action.normalise = 'NONE' action["max"] = -float("inf") action["min"] = float("inf") start, end = action.frame_range[0], action.frame_range[1] for fc, sam in pts: #if self.RGB: fcu.color_mode = 'AUTO_RGB' for i, p in enumerate(sam): frame, v = p fc.keyframe_points[i].co.y = v fc.keyframe_points.update() channel_name = fc.data_path.strip('["]') is_music = False fc_range, points = fc.minmax low = rna[channel_name]['low'] high = rna[channel_name]['high'] (_min, _max) = fc_range if _min < action["min"]: action["min"] = _min if _max > action["max"]: action["max"] = _max set_channel_idprop_rna(channel_name, rna, low, high, fc_range, fc_range, is_music=is_music) sp_rna[channel_name] = rna[channel_name].to_dict() print("%4s %8s %8s %10.4f %10.4f" % (channel_name, f(low), f(high), fc_range[0], fc_range[1])) # ok now bake fc.convert_to_samples(start, end) self.add_to_tweaks(action) return{'FINISHED'}
def draw_header(self, context): layout = self.layout speaker = getSpeaker(context) action = getAction(speaker) if not action: layout.label("", icon='SEQ_HISTOGRAM') return op = layout.operator("action.visualiser", icon='SEQ_HISTOGRAM', emboss=False, text="") op.action_name = action.name
def mix_buffer(context): dprint("mix BUff") #make a buffer from the channel mix # set up a buffer with the same dictionary structure as the device = aud.device() scene = context.scene fps = scene.render.fps / scene.render.fps_base if not context: return None if scene.use_preview_range: frame_start = scene.frame_preview_start frame_end = scene.frame_preview_end else: frame_start = scene.frame_start frame_end = scene.frame_end # get g = None for name, value in scene.sound_channels.items(): mix = sound_buffer.get(name) if mix is None: continue speaker_name, action_name = name.split("__@__") speaker = bpy.data.speakers.get(speaker_name) if not speaker: continue action = getAction(speaker) if not speaker.filter_sound \ or action_name != action.name: # using the mute as a flag continue channel_name = action["channel_name"] fs = int(max(frame_start, action.frame_range.x)) fe = min(frame_end, action.frame_range.y) if True: for i in range(action["start"], action["end"]): ch = "channel%02d" % i if value.get(ch): # channel selected for mix f = mix.get(ch) if g: #f = f.join(g) # join f = f.mix(g) g = f if g: #factory_buffered = #aud.Factory.buffer(g.limit((fs-1) / fps, (fe-1) / fps)) bpy.app.driver_namespace["ST_buffer"] = g factory_buffered = aud.Factory.buffer(g) dprint("buffered") return factory_buffered return None
def draw(self, context): wm = context.window_manager scene = context.scene a = getAction(context.scene.speaker) channels = a["Channels"] ob = context.object VisualiserRowsColumns.channels = channels if "VIS" in ob.keys(): self.edit_draw(ob, context) self.retarget_draw(ob, context) row = self.layout.row() row.operator("sounddriver.create_visualiser") return n = channels # rcs = [(x, n/x) for x in range(1, int(sqrt(n))+1) if n % x == 0] rcs = [(x, n / x) for x in range(1, n+1) if n % x == 0] layout = self.layout row = layout.row() row.prop(wm, "visualiser_type") row = layout.row() col = row.column() ''' col.label("TEST") for obj in context.selected_objects: orow = col.row() orow.label(obj.name) ''' col = row.column() row = col.row() scene = context.scene if wm.visualiser_type == "GRID": col.menu("visualiser.rows_columns", text="Rows x Cols") elif wm.visualiser_type == "SOUNDSURFACE": row = layout.row() row.label("NIY: Not Implemented Yet") if wm.visualiser_type == "CURVESURFACE": actions = [a for a in bpy.data.actions if 'wavfile' in a.keys()] for a in actions: row = layout.row() txt = "%s %s channels:%d" % (a.name, a["channel_name"], a["Channels"]) op = row.operator("soundaction.create_visualiser", text=txt) op.type = 'CURVESURFACE' op.action = a.name
def execute(self, context): action = bpy.data.actions.get(self.action) if action is None: action = getAction(context.scene.speaker) if self.area_index > -1: area = context.screen.areas[self.area_index] # s = ScreenAreaAction(context.screen) # REFACTO s = context.sound_vis_areas s.set_action_to_area(area, action) area.type = 'VIEW_3D' return {'FINISHED'} return {'FINISHED'}
def draw(self, context): speaker = getSpeaker(context) layout = self.layout if not speaker: return {'CANCELLED'} soundaction = getAction(speaker) soundaction = bpy.data.actions.get(self.action, None) #soundaction = bpy.data.actions.get(self.action) #layout.enabled = False #layout.menu("soundtest.menu", text=soundaction.get("channel_name", "AA")) layout.enabled = True layout.operator("wm.call_menu", text=soundaction.get("channel_name", "AA"), emboss=True).name = "soundtest.menu"
def drawnormalise(self, context): layout = self.layout action = getAction(getSpeaker(context)) row = layout.row(align=True) row.prop(action, "normalise", expand=True) row = layout.row() row.scale_y = row.scale_x = 0.5 row.label("min: %6.2f" % action["min"]) row.label("max: %6.2f" % action["max"]) sub = layout.row() sub.enabled = action.normalise != 'NONE' sub.prop(action, "normalise_range", text="", expand=True) return
def execute(self, context): action = bpy.data.actions.get(self.action) if action is None: action = getAction(context.scene.speaker) if self.area_index > -1: area = context.screen.areas[self.area_index] # s = ScreenAreaAction(context.screen) # REFACTO s = context.sound_vis_areas s.set_action_to_area(area, action) area.type = "VIEW_3D" return {"FINISHED"} return {"FINISHED"}
def draw(self, context): wm = context.window_manager scene = context.scene a = getAction(context.scene.speaker) channels = a["Channels"] ob = context.object VisualiserRowsColumns.channels = channels if "VIS" in ob.keys(): self.edit_draw(ob, context) self.retarget_draw(ob, context) row = self.layout.row() row.operator("sounddriver.create_visualiser") return n = channels #rcs = [(x, n/x) for x in range(1, int(sqrt(n))+1) if n % x == 0] rcs = [(x, n / x) for x in range(1, n + 1) if n % x == 0] layout = self.layout row = layout.row() row.prop(wm, "visualiser_type") row = layout.row() col = row.column() ''' col.label("TEST") for obj in context.selected_objects: orow = col.row() orow.label(obj.name) ''' col = row.column() row = col.row() scene = context.scene if wm.visualiser_type == "GRID": col.menu("visualiser.rows_columns", text="Rows x Cols") elif wm.visualiser_type == "SOUNDSURFACE": row = layout.row() row.label("NIY: Not Implemented Yet") if wm.visualiser_type == "CURVESURFACE": actions = [a for a in bpy.data.actions if 'wavfile' in a.keys()] for a in actions: row = layout.row() txt = "%s %s channels:%d" % (a.name, a["channel_name"], a["Channels"]) op = row.operator("soundaction.create_visualiser", text=txt) op.type = 'CURVESURFACE' op.action = a.name
def visualise(self, context): """ Override BGLWidget visualise it's the handle passed to the ScreenArea to draw """ sp = context.scene.speaker if sp is None: return None action = getAction(sp) # action = context.area.sound_action # NEW IDEA REFACTO if action is None: return None area_settings = self.area_settings(context) if not area_settings: debug.print("No Area Settings") return None self.draw_strips(action, context)
def visualise(self, context): ''' Override BGLWidget visualise it's the handle passed to the ScreenArea to draw ''' sp = context.scene.speaker if sp is None: return None action = getAction(sp) # action = context.area.sound_action # NEW IDEA REFACTO if action is None: return None area_settings = self.area_settings(context) if not area_settings: debug.print("No Area Settings") return None self.draw_strips(action, context)
def setup_buffer(context): dprint("Setup BUffer") # set up a buffer with the same dictionary structure as the device = aud.device() scene = context.scene fps = scene.render.fps / scene.render.fps_base if not context: return False if scene.use_preview_range: frame_start = scene.frame_preview_start frame_end = scene.frame_preview_end else: frame_start = scene.frame_start frame_end = scene.frame_end # get for name, value in scene.sound_channels.items(): mix = sound_buffer[name] = {} speaker_name, action_name = name.split("__@__") speaker = bpy.data.speakers.get(speaker_name) if speaker is None: continue action = getAction(speaker) if action is None: continue if not speaker.filter_sound \ or action_name != action.name: # using the mute as a flag continue channel_name = action["channel_name"] rna_ui = speaker['_RNA_UI'] fs = int(max(frame_start, action.frame_range.x)) fe = min(frame_end, action.frame_range.y) if True: for i in range(action["start"], action["end"]): if True: low = rna_ui['%s%d' % (channel_name, i)]['low'] high = rna_ui['%s%d' % (channel_name, i)]['high'] f = speaker.sound.factory #f = aud.Factory(speaker.sound.filepath) f = f.lowpass(low).highpass(high).buffer() mix["channel%02d" % i] = f return True
def draw(self, context): scene = context.scene layout = self.layout if context.space_data.use_pin_id: speaker = context.space_data.pin_id else: speaker = context.object.data action = getAction(speaker) area = layout.row() if True: area.prop(context.scene, "frame_current", text="Start") self.layout.operator("anim.loadlipsync") phon = speaker.papagayo_phonemes layout.prop(speaker, "papagayo_phonemes", expand=True) #st = context.object.animation_data.nla_tracks[phon].strips[phon] #layout.template_ID(st, "action", new="action.new") row = layout.row() row.template_ID(context.scene.objects, "active") frame = context.scene.frame_current timemarkers = [ marker for marker in action.pose_markers if marker.frame == frame ] row = layout.row() if True: row.prop(speaker, "papagayo_phonemes", expand=True) row = layout.row() if len(timemarkers) and True: row.label(text="%s" % timemarkers[0].name, icon='MOD_MASK') row.prop(timemarkers[0], "frame", text="") else: timemarkers = [ marker for marker in action.pose_markers if marker.frame > frame ] if len(timemarkers): row.label(text="NEXT %s" % timemarkers[0].name) else: row.label("-") layout.prop(context.scene, "frame_current", emboss=True)
def ColSliders(self, context): layout = self.layout speaker = getSpeaker(context) action = getAction(speaker) if not (action and speaker): return None channel_name = action["channel_name"] start = action["start"] end = action["end"] box = layout.box() #row = box.row() #box.scale_y = 0.4 cf = box.column() cf.scale_y = action["row_height"] for i in range(start, end + 1): channel = "%s%d" % (channel_name, i) cf.prop(speaker, '["%s"]' % channel, slider=True, emboss=True, text="")
def draw(self, context): space = context.space_data if space.use_pin_id: speaker = space.pin_id else: speaker = context.speaker layout = self.layout action = getAction(speaker) layout.label("NOT IMPLEMENTED YET", icon='INFO') layout.separator() layout.label("Spatial Layouts ie (STEREO, 5.1 Surround)") return speakerL = None speakerR = None actionL = None actionR = None '''
def draw(self, context): space = context.space_data if space.use_pin_id: speaker = space.pin_id else: speaker = context.speaker layout = self.layout action = getAction(speaker) layout.label("NOT IMPLEMENTED YET", icon="INFO") layout.separator() layout.label("Spatial Layouts ie (STEREO, 5.1 Surround)") return speakerL = None speakerR = None actionL = None actionR = None """
def draw(self, context): scene = context.scene layout = self.layout if context.space_data.use_pin_id: speaker = context.space_data.pin_id else: speaker = context.object.data action = getAction(speaker) area = layout.row() if True: area.prop(context.scene, "frame_current", text="Start") self.layout.operator("anim.loadlipsync") phon = speaker.papagayo_phonemes layout.prop(speaker, "papagayo_phonemes", expand=True) #st = context.object.animation_data.nla_tracks[phon].strips[phon] #layout.template_ID(st, "action", new="action.new") row = layout.row() row.template_ID(context.scene.objects, "active") frame = context.scene.frame_current timemarkers = [marker for marker in action.pose_markers if marker.frame == frame] row = layout.row() if True: row.prop(speaker, "papagayo_phonemes", expand=True) row = layout.row() if len(timemarkers) and True: row.label(text="%s" % timemarkers[0].name, icon='MOD_MASK') row.prop(timemarkers[0], "frame", text="") else: timemarkers = [marker for marker in action.pose_markers if marker.frame > frame] if len(timemarkers): row.label(text="NEXT %s" % timemarkers[0].name) else: row.label("-") layout.prop(context.scene, "frame_current", emboss=True)
def __init__(self, op, context, areatype): # Calculate scroller width, dpi and pixelsize dependent self.pixel_size = context.user_preferences.system.pixel_size self.dpi = context.user_preferences.system.dpi self.dpi_fac = self.pixel_size * self.dpi / 72 # A normal widget unit is 20, but the scroller is apparently 16 self.scroller_width = 16 * self.dpi_fac self.region = context.area.regions[-1] self.context = context self.op = op self.areatype = areatype speaker = context.scene.speaker a = getAction(speaker) # a = context.area.sound_action # NEW IDEA REFACTO self.handle = self.create_handle(context) theme = context.user_preferences.themes[0] self.gridcol = [getattr(theme.view_3d.grid, c) for c in "rgb"] self.gridcol.append(1.0) self.curfc = [getattr(theme.timeline.frame_current, c) for c in "rgb"] self.curfc.append(1.0) self.theme = theme
def draw(self, context): a = getAction(context.scene.speaker) layout = self.layout row = layout.row() row.label(a["channel_name"]) row.label("%d" % a["Channels"]) col = layout.column() col.prop(self, "offset") row = layout.row() if self.handle: handle = bpy.data.objects.get(self.handle_name) row.prop(handle, "name") row = layout.row() col = row.column() box = col.box() box.label("Scale") box.prop(self, "scale", text="") col = row.column() box = col.box() box.label("Translate") box.prop(self, "translate", text="")
def FCurveSliders(self, context): layout = self.layout speaker = getSpeaker(context) action = getAction(speaker) if not (action and speaker): return None channel_name = action["channel_name"] start = action["start"] end = action["end"] box = layout.box() #row = box.row() #box.scale_y = 0.4 cf = box.column_flow(columns=1) #cf.scale_y = action["row_height"] fcurves = action.fcurves for i in range(start, end + 1): channel = "%s%d" % (channel_name, i) v = speaker[channel] MIN = speaker["_RNA_UI"][channel]['min'] MAX = speaker["_RNA_UI"][channel]['max'] diff = MAX - MIN pc = 0.0 if diff > 0.0000001: pc = (v - MIN) / diff #row = cf.row() #row.scale_y = action["row_height"] if pc < 0.00001: split = cf.split(percentage=0.0001) split.scale_y = action["row_height"] split.label("") continue split = cf.split(percentage=pc) split.scale_y = action["row_height"] split.prop(fcurves[i], "color", text="") row = box.row() row.scale_y = 0.2 row.label(icon='BLANK1')
def wonk(self, context): dm = context.driver_manager sp = context.scene.speaker a = getAction(sp) # REFACTO a = bpy.data.actions.get(self.action) if dm is None or sp is None or a is None: return None p = self.path_from_id() ''' print(p) #REFACTO p = p[:p.find(".channels")] print(p) gui = self.id_data.path_resolve(p) if gui is None: print("NO GUI") return None ''' gui = self idx = int(self.name.split("_")[1]) #ed = dm.find(dm.filter_dic[gui.collection][gui.object][str(gui.array_index)]) d = dm.find(idx) ed = self if ed is None: return None if d._setting_channels: return None #cn = a['channel_name'] cn = self.channel if self.rna_type.identifier.startswith('SoundDriverChannel'): pass elif self.rna_type.identifier.startswith('GUIDriver'): channel_list = [ ch.name for ch in ed.channels if ch.value and ch.name.startswith(cn) ] main(self, context, d, sp, a, channel_list) # do amplify things etc pass
def __init__(self, op, context, areatype): # Calculate scroller width, dpi and pixelsize dependent self.pixel_size = context.user_preferences.system.pixel_size self.dpi = context.user_preferences.system.dpi self.dpi_fac = self.pixel_size * self.dpi / 72 # A normal widget unit is 20, but the scroller is apparently 16 self.scroller_width = 16 * self.dpi_fac self.region = context.area.regions[-1] self.context = context self.op = op self.areatype = areatype speaker = context.scene.speaker a = getAction(speaker) # a = context.area.sound_action # NEW IDEA REFACTO self.handle = self.create_handle(context) theme = context.user_preferences.themes[0] self.gridcol = [getattr(theme.view_3d.grid, c) for c in 'rgb'] self.gridcol.append(1.0) self.curfc = [getattr(theme.timeline.frame_current, c) for c in 'rgb'] self.curfc.append(1.0) self.theme = theme
def draw(self, context): layout = self.layout layout.enabled = not bpy.types.BakeSoundPanel.baking speaker = getSpeaker(context) action = getAction(speaker) self.SoundActionMenu(context) row = layout.row(align=True) self.drawnormalise(context) self.copy_action(context) row = layout.row() enabled = getattr(context.active_object, "data", None) == speaker if enabled: row=layout.row() op = row.operator("soundaction.unbake") if bpy.ops.soundaction.rebake.poll() : col = layout.column() self.draw_tweaks(col, context) row=layout.row() row.operator("soundaction.rebake") else: row = layout.row() row.label("Select Speaker to (un)(re)bake", icon='INFO')
def wonk(self, context): dm = context.driver_manager sp = context.scene.speaker a = getAction(sp) # REFACTO a = bpy.data.actions.get(self.action) if dm is None or sp is None or a is None: return None p = self.path_from_id() ''' print(p) #REFACTO p = p[:p.find(".channels")] print(p) gui = self.id_data.path_resolve(p) if gui is None: print("NO GUI") return None ''' gui = self idx = int(self.name.split("_")[1]) #ed = dm.find(dm.filter_dic[gui.collection][gui.object][str(gui.array_index)]) d = dm.find(idx) ed = self if ed is None: return None if d._setting_channels: return None #cn = a['channel_name'] cn = self.channel if self.rna_type.identifier.startswith('SoundDriverChannel'): pass elif self.rna_type.identifier.startswith('GUIDriver'): channel_list = [ch.name for ch in ed.channels if ch.value and ch.name.startswith(cn)] main(self, context, d, sp, a, channel_list) # do amplify things etc pass
def get_action(self): if self.use_active_action: return getAction(bpy.context.scene.speaker) else: return bpy.data.actions.get(self.action_name)
def EBT(self, context): layout = self.layout speaker = getSpeaker(context) action = getAction(speaker) # max and min of whole action def icon(ch, pc): cn = action["channel_name"] chi = "%s%d" % (cn, ch) mn = speaker['_RNA_UI'][chi]["min"] mx = speaker['_RNA_UI'][chi]["max"] vol_range = Vector((mx, mn)).magnitude mx = max(mn, mx) b = speaker['_RNA_UI'][chi]["b"] a = speaker['_RNA_UI'][chi]["a"] map_range = Vector((a, b)).magnitude v = map_range * abs(speaker[chi]) / vol_range o = 0 # no output if v >= vol_range * pc: o = 3 elif pc * vol_range < (abs(map_range)): o = 1 #return 'CHECKBOX_DEHLT' return o # create a list channels x 10 channels = action["Channels"] #row = layout.row() self.icontable = [[icon(j, (i + 1) / 20.0) for i in range(20)] for j in range(channels)] for l in self.icontable: i = l.count(3) if i: l[i - 1] = 2 ''' # horizontal cf = self.column_flow(columns=10, align=True) cf.scale_y = 0.4 for i in range(10): for j in range(channels): cf.label(text='', icon=icontable[j][i]) ''' row = layout.box() row.scale_x = 0.5 #row = row.row() cf = row.column_flow(columns=channels + 1) cf.scale_y = action["row_height"] cf.scale_x = action["row_height"] for j in range(channels + 1): if j == channels: for i in range(19, -1, -1): cf.label("") continue for i in range(19, -1, -1): #col.label(text='', icon=self.icons[self.icontable[j][i]]) cf.label(text='', icon=self.icons[self.icontable[j][i]])
def get_action(self, context): return getAction(getSpeaker(context), search=True)
def poll(cls, context): sp = context.scene.speaker # need an action to generate this kind from return sp is not None\ and getAction(sp) is not None
def focus_areas(context): #obj = context.object #save_action = obj.animation_data.action #obj["view"] = 0.0 sp = getSpeaker(context) sp["view"] = 0.0 action = getAction(sp) wm = context.window_manager (x, y) = action.frame_range c = context.copy() s = ScreenAreaAction(context) for i, area in enumerate(context.screen.areas): if area.type != 'GRAPH_EDITOR': continue region = area.regions[-1] print("SCREEN:", context.screen.name , "[", i, "]") if action.normalise == 'NONE': (min, max) = (action["min"], action["max"]) else: (min, max) = action.normalise_range c["space_data"] = area.spaces.active c["area"] = area c["region"] = region dummyaction = get_view_action((x, min), (y, max)) #obj.animation_data.action = dummyaction sp.animation_data.action = dummyaction bgl_area = s.get_area(area) bpy.ops.anim.channels_expand(c, all=True) bpy.ops.anim.channels_expand(c, all=True) if (bgl_area is None or not wm.bgl_draw_speaker): bpy.ops.graph.view_all(c) continue if bgl_area is not None: ah = area.height v2d = region.view2d rh = region.height pc = bgl_area.GRAPH_EDITOR.height / 100.0 apc = (bgl_area.GRAPH_EDITOR.loc[1] + (pc * rh)) / ah vis_h = (pc + 2) * rh / 100.0 # plus header box #(m, n) = Vector(v2d.region_to_view(1,1)) - Vector(v2d.region_to_view(0,0)) if action.normalise == 'NONE': (min, max) = (action["min"], action["max"]) else: (min, max) = action.normalise_range range = abs(max-min) newmin = min - (apc / (1.0 - apc)) * range min = newmin print(bgl_area) print("GRAPH RESIZE", pc, apc, vis_h, min) dummyaction = get_view_action((x, min), (y, max)) #bpy.ops.graph.view_selected(c, include_handles=False) bpy.ops.graph.view_all(c) sp.animation_data.action = action
def execute(self, context): #unbake action speaker = getSpeaker(context) action = getAction(speaker) name = action.name print("-" * 72) print("Unbake action %s to keyframe points" % name) print("-" * 72) rna = speaker["_RNA_UI"] save_fcurve_select = [0] * len(action.fcurves) action.fcurves.foreach_get("select", save_fcurve_select) #action["max"] = -float("inf") #action["min"] = float("inf") channel_prefix = action["channel_name"] #keys.normalise = 'NONE' fcurves = [fc for fc in action.fcurves if len(fc.sampled_points)] sp_rna = speaker.get("_RNA_UI").to_dict() pts = [(fc, [(sp.co[0], fc.evaluate(sp.co[0])) for sp in fc.sampled_points]) for fc in fcurves if fc.select or self.bake_all] for fcu, fd in pts: dp = fcu.data_path i = fcu.array_index action.fcurves.remove(fcu) fc = action.fcurves.new(dp, index=i, action_group=channel_prefix) channel_name = dp.strip('["]') #fc.keyframe_points.foreach_set("co", [v for c in fd for v in c]) for p in fd: w = fc.keyframe_points.insert(*p) is_music = False channel_rna = rna[channel_name] fc_range, points = fc.minmax low = channel_rna['low'] high = channel_rna['high'] (_min, _max) = fc_range if _min < action["min"]: action["min"] = _min if _max > action["max"]: action["max"] = _max set_channel_idprop_rna(channel_name, rna, low, high, fc_range, fc_range, is_music=is_music) sp_rna[channel_name] = channel_rna.to_dict() print("%4s %8s %8s %10.4f %10.4f" %\ (channel_name,\ f(low),\ f(high),\ fc_range[0],\ fc_range[1])) action['rna'] = str(sp_rna) action.normalise = 'NONE' action.fcurves.foreach_set("select", save_fcurve_select) #replace_speaker_action(speaker, action, keys) self.add_to_tweaks(speaker.animation_data.action) return{'FINISHED'}
def poll(cls, context): sp = getSpeaker(context) a = getAction(sp) kfps = [1 for fc in a.fcurves if len(fc.keyframe_points)] return len(kfps)