Exemple #1
0
    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 draw(self, context):
        layout = self.layout
        sce = context.scene
        space = context.space_data
        speaker = getSpeaker(context)
        '''
        # Call menu executes the operator...
        row = layout.row()
        row.operator("wm.call_menu").name="speaker.preset_menu"
        row = layout.row()
        row.menu("speaker.preset_menu")

        '''
        nla = False
        action = None
        frame = sce.frame_current
        self.drawvisenum(context)
        '''
        if speaker.vismode == 'BAKE':
            return None
        '''
        self.drawcontextspeaker(context)

        return
        '''
Exemple #3
0
    def nla_tracks(self, context):
        layout = self.layout
        speaker = getSpeaker(context)

        row = layout.row()
        if not getattr(speaker, "animation_data", None):
            row.label("NO ANITION DATA", icon='ERROR')
            return None
        row.prop(speaker.animation_data, "use_nla", toggle=True)
        if not speaker.animation_data.use_nla:
            return None
        l = len(speaker.animation_data.nla_tracks) - 1
        for i in range(l):
            nla_track = speaker.animation_data.nla_tracks[l - i]
            # need to fix for only strips with soundactions.. for R'ON
            row = layout.row()
            row = layout.row(align=True)
            for strip in nla_track.strips:
                action = strip.action
                ch = action.get("channel_name")
                if ch is None:
                    continue
                sub = row.row()
                sub.alignment = 'LEFT'
                op = sub.operator("soundaction.change", text=ch)
                op.action = strip.action.name
                sub.enabled = action != speaker.animation_data.action

                #sub.label(strip.action["channel_name"])
                if not nla_track.mute:
                    icon = "MUTE_IPO_OFF"
                else:
                    icon = "MUTE_IPO_ON"
                row.prop(action, "normalise_range", text="", expand=True)
                row.prop(nla_track, "mute", icon=icon, text="", icon_only=True)
Exemple #4
0
 def poll(cls, context):
     speaker = getSpeaker(context)
     screen_areas = [
         a.type for a in context.screen.areas if a.type in cls.screen_areas
     ]
     return speaker is not None and len(
         screen_areas) and 'VISUAL' in speaker.vismode
Exemple #5
0
 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 draw(self, context):
        layout = self.layout
        speaker = getSpeaker(context)
        #speaker = context.scene.speaker
        #if SoundVisMenu.vismode in ["VISUAL", "SOUND", "DRIVERS"]:
        if True:
            actions = [action for action in bpy.data.actions
                       if "wavfile" in action
                       and action["wavfile"] == speaker.sound.name]

            
            for action in actions:
                if "channels" in action.keys(): # midi atm TODO
                    channels = action["channels"]
                    channels.sort()
                    '''
                    layout.label("MIDI %s" %  action["wavfile"])
                    layout.separator()
                    '''
                    groups = [g.name for g in action.groups]
                    groups.sort()
                    for channel in channels:
                        cn = groups[channels.index(channel)]
                        layout.operator_context = 'EXEC_DEFAULT'
                        op = layout.operator("soundaction.change",
                             text="%s" % (cn))
                        op.action = action.name
                        op.channel = channel
                else:
                    #layout.label("MUSIC %s" % action.name)
                    #layout.separator()
                    channel = action["channel_name"]
                    op = layout.operator("soundaction.change",
                         text="%s" % (channel))
                    op.action = action.name
    def drawcontextspeaker(self, context):
        layout = self.layout
        ob = context.active_object
        speaker = getSpeaker(context)

        space = context.space_data
        row = layout.row(align=True)

        if not space.pin_id:
            row.template_ID(ob, "data")
        else:
            row.template_ID(space, "pin_id")

        if speaker.sound is not None:
            row = layout.row(align=True)
            sub = row.row()
            sub.alignment = 'LEFT'
            #use solo icon to show speaker has context
            if speaker.is_context_speaker:
                sub.prop(speaker, "is_context_speaker",
                         icon='SOLO_ON', text="", emboss=False)
            else:
                sub.prop(speaker, "is_context_speaker",
                         icon='SOLO_OFF', text="", emboss=False)

            row.label(speaker.sound.name)
    def copy_action(self, context):
        speaker = getSpeaker(context)
        sound = speaker.sound
        bakeoptions = sound.bakeoptions
        scene = context.scene
        layout = self.layout
        row = layout.row(align=True)
        sub = row.row()
        sub.scale_x = 2

        channels = [c for sp in scene.objects if sp.type == 'SPEAKER' for c in sp.data.channels]
        new_channel_name = unique_name(channels, bakeoptions.channel_name)
        op = sub.operator("soundaction.copy", text="Copy to Channel %s" % new_channel_name)
        op.new_channel_name = new_channel_name
        col = layout.column()
        col.operator_context = 'INVOKE_DEFAULT'
        op = col.operator("soundaction.copy_to_switches")

        '''
        row = layout.row()
        op = row.operator("sound.bake_animation")
        row = layout.column()
        row.prop(scene, "sync_mode", expand=True)
        '''
        return
    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 copy_action(self, context):
        speaker = getSpeaker(context)
        sound = speaker.sound
        bakeoptions = sound.bakeoptions
        scene = context.scene
        layout = self.layout
        row = layout.row(align=True)
        sub = row.row()
        sub.scale_x = 2

        channels = [c for sp in scene.objects if sp.type == 'SPEAKER' for c in sp.data.channels]
        new_channel_name = unique_name(channels, bakeoptions.channel_name)
        op = sub.operator("soundaction.copy", text="Copy to Channel %s" % new_channel_name)
        op.new_channel_name = new_channel_name
        col = layout.column()
        col.operator_context = 'INVOKE_DEFAULT'
        op = col.operator("soundaction.copy_to_switches")

        '''
        row = layout.row()
        op = row.operator("sound.bake_animation")
        row = layout.column()
        row.prop(scene, "sync_mode", expand=True)
        '''
        return
Exemple #11
0
    def draw(self, context):
        layout = self.layout
        sce = context.scene
        space = context.space_data
        speaker = getSpeaker(context)
        '''
        # Call menu executes the operator...
        row = layout.row()
        row.operator("wm.call_menu").name="speaker.preset_menu"
        row = layout.row()
        row.menu("speaker.preset_menu")

        '''
        nla = False
        action = None
        frame = sce.frame_current
        self.drawvisenum(context)
        '''
        if speaker.vismode == 'BAKE':
            return None
        '''
        self.drawcontextspeaker(context)

        return
        '''
    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 draw(self, context):
        layout = self.layout
        speaker = getSpeaker(context)
        #speaker = context.scene.speaker
        #if SoundVisMenu.vismode in ["VISUAL", "SOUND", "DRIVERS"]:
        if True:
            actions = [
                action for action in bpy.data.actions if "wavfile" in action
                and action["wavfile"] == speaker.sound.name
            ]

            for action in actions:
                if "channels" in action.keys():  # midi atm TODO
                    channels = action["channels"]
                    channels.sort()
                    '''
                    layout.label("MIDI %s" %  action["wavfile"])
                    layout.separator()
                    '''
                    groups = [g.name for g in action.groups]
                    groups.sort()
                    for channel in channels:
                        cn = groups[channels.index(channel)]
                        layout.operator_context = 'EXEC_DEFAULT'
                        op = layout.operator("soundaction.change",
                                             text="%s" % (cn))
                        op.action = action.name
                        op.channel = channel
                else:
                    #layout.label("MUSIC %s" % action.name)
                    #layout.separator()
                    channel = action["channel_name"]
                    op = layout.operator("soundaction.change",
                                         text="%s" % (channel))
                    op.action = action.name
Exemple #14
0
    def drawcontextspeaker(self, context):
        layout = self.layout
        ob = context.active_object
        speaker = getSpeaker(context)

        space = context.space_data
        row = layout.row(align=True)

        if not space.pin_id:
            row.template_ID(ob, "data")
        else:
            row.template_ID(space, "pin_id")

        if speaker.sound is not None:
            row = layout.row(align=True)
            sub = row.row()
            sub.alignment = 'LEFT'
            #use solo icon to show speaker has context
            if speaker.is_context_speaker:
                sub.prop(speaker, "is_context_speaker",
                         icon='SOLO_ON', text="", emboss=False)
            else:
                sub.prop(speaker, "is_context_speaker",
                         icon='SOLO_OFF', text="", emboss=False)

            row.label(speaker.sound.name)
Exemple #15
0
    def draw(self, context):
        sp = getSpeaker(context)
        #sound = sp.sound

        layout = self.layout

        #layout.prop(sound, "midi_file")
        op = layout.operator("sound_drivers.import_midi")
 def draw_area_operator(self, context, layout, index):
     speaker = utils.getSpeaker(context)
     sound = speaker.sound
     op = layout.operator("wm.bake_sound_to_action", text="BAKE",
                          icon='FCURVE')
     op.sound_name = sound.name
     op.speaker_name = speaker.name
     op.area_index = index
Exemple #17
0
    def draw(self, context):
        sp = getSpeaker(context)
        # sound = sp.sound

        layout = self.layout

        # layout.prop(sound, "midi_file")
        op = layout.operator("sound_drivers.import_midi")
Exemple #18
0
    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'}
Exemple #19
0
 def draw_area_operator(self, context, layout, index):
     speaker = utils.getSpeaker(context)
     sound = speaker.sound
     op = layout.operator("wm.bake_sound_to_action",
                          text="BAKE",
                          icon='FCURVE')
     op.sound_name = sound.name
     op.speaker_name = speaker.name
     op.area_index = index
    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'}
Exemple #21
0
    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 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)
Exemple #23
0
    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 draw(self, context):
        layout = self.layout
        from sound_drivers.sound_bake import BakeSoundPanel
        layout.enabled = not BakeSoundPanel.baking
        # get speaker returns the PROPERTIES PANEL speaker
        speaker = getSpeaker(context)
        # refactored code
        box = layout
        has_sound = (speaker.sound is not None)
        if not has_sound:
            row = box.row()
            row.template_ID(speaker, "sound", open="sound.open_mono")
            return

        row = box.row(align=True)

        if 'SOUND' in speaker.vismode:
            soundbox = box.box()
            row = soundbox.row(align=True)
            row.template_ID(speaker, "sound", open="sound.open_mono")
            sub = row.row()
            sub.alignment = 'RIGHT'
            sub.prop(speaker, "muted", text="")
            row = soundbox.row()
            row.prop(speaker, "volume")
            row.prop(speaker, "pitch")

            box.label("Distance", icon='ARROW_LEFTRIGHT')
            distancebox = box.box()
            split = distancebox.split()

            col = split.column()
            col.label("Volume:")
            col.prop(speaker, "volume_min", text="Minimum")
            col.prop(speaker, "volume_max", text="Maximum")
            col.prop(speaker, "attenuation")

            col = split.column()
            col.label("Distance:")
            col.prop(speaker, "distance_max", text="Maximum")
            col.prop(speaker, "distance_reference", text="Reference")

            box.label("Cone", icon='MESH_CONE')
            conebox = box.box()
            split = conebox.split()
            col = split.column()

            col.label("Angle:")
            col.prop(speaker, "cone_angle_outer", text="Outer")
            col.prop(speaker, "cone_angle_inner", text="Inner")

            col = split.column()

            col.label("Volume:")
            col.prop(speaker, "cone_volume_outer", text="Outer")
    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(self, context):
        layout = self.layout
        from sound_drivers.sound_bake import BakeSoundPanel
        layout.enabled = not BakeSoundPanel.baking
        # get speaker returns the PROPERTIES PANEL speaker
        speaker = getSpeaker(context)
        # refactored code
        box = layout
        has_sound = (speaker.sound is not None)
        if not has_sound:
            row = box.row()
            row.template_ID(speaker, "sound", open="sound.open_mono")
            return

        row = box.row(align=True)

        if 'SOUND' in speaker.vismode:
            soundbox = box.box()
            row = soundbox.row(align=True)
            row.template_ID(speaker, "sound", open="sound.open_mono")
            sub = row.row()
            sub.alignment = 'RIGHT'
            sub.prop(speaker, "muted", text="")
            row = soundbox.row()
            row.prop(speaker, "volume")
            row.prop(speaker, "pitch")

            box.label("Distance", icon='ARROW_LEFTRIGHT')
            distancebox = box.box()
            split = distancebox.split()

            col = split.column()
            col.label("Volume:")
            col.prop(speaker, "volume_min", text="Minimum")
            col.prop(speaker, "volume_max", text="Maximum")
            col.prop(speaker, "attenuation")

            col = split.column()
            col.label("Distance:")
            col.prop(speaker, "distance_max", text="Maximum")
            col.prop(speaker, "distance_reference", text="Reference")

            box.label("Cone", icon='MESH_CONE')
            conebox = box.box()
            split = conebox.split()
            col = split.column()

            col.label("Angle:")
            col.prop(speaker, "cone_angle_outer", text="Outer")
            col.prop(speaker, "cone_angle_inner", text="Inner")

            col = split.column()

            col.label("Volume:")
            col.prop(speaker, "cone_volume_outer", text="Outer")
    def poll(cls, context):
        speaker = getSpeaker(context)
        if speaker is None:
            return False

        if context.space_data.pin_id is not None:
            if context.space_data.pin_id == speaker:
                return cls.vismode in speaker.vismode

        return (context.object.data == speaker and cls.vismode
                in speaker.vismode)
    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 poll(cls, context):
        speaker = getSpeaker(context)
        if speaker is None:
            return False

        if context.space_data.pin_id is not None:
            if context.space_data.pin_id == speaker:
                return cls.vismode in speaker.vismode

        return (context.object.data == speaker
                and cls.vismode in speaker.vismode)
    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
Exemple #31
0
 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 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
Exemple #34
0
    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 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="")
Exemple #36
0
    def execute(self, context):
        #speaker = context.scene.speaker
        speaker = getSpeaker(context)
        if not speaker:
            return {'CANCELLED'}
        soundaction = bpy.data.actions.get(self.action)
        if soundaction is not None:
            from sound_drivers.sound import SoundVisMenu
            SoundVisMenu.bl_label = soundaction["channel_name"]
            speaker.animation_data.action = soundaction
            if self.channel:
                # set channel for now TODO
                soundaction["channel_name"] = self.channel
            action_normalise_set(soundaction, context)

        dm = bpy.app.driver_namespace.get('DriverManager')
        if dm is not None:
            dm.set_edit_driver_gui(context)
        return {'FINISHED'}
    def execute(self, context):
        #speaker = context.scene.speaker
        speaker = getSpeaker(context)
        if not speaker:
            return {'CANCELLED'}
        soundaction = bpy.data.actions.get(self.action)
        if soundaction is not None:
            from sound_drivers.sound import SoundVisMenu
            SoundVisMenu.bl_label = soundaction["channel_name"]
            speaker.animation_data.action = soundaction
            if self.channel:
                # set channel for now TODO
                soundaction["channel_name"] = self.channel
            action_normalise_set(soundaction, context)

        dm = bpy.app.driver_namespace.get('DriverManager')
        if dm is not None:
            dm.set_edit_driver_gui(context)
        return {'FINISHED'}
Exemple #38
0
    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'}
    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'}
    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')
Exemple #41
0
    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')
Exemple #42
0
    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 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 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 nla_tracks(self, context):
        layout = self.layout
        speaker = getSpeaker(context)

        row = layout.row()
        if not getattr(speaker, "animation_data", None):
            row.label("NO ANITION DATA", icon='ERROR')
            return None
        row.prop(speaker.animation_data, "use_nla", toggle=True)
        if not speaker.animation_data.use_nla:
            return None
        l = len(speaker.animation_data.nla_tracks) - 1
        for i in range(l):
            nla_track = speaker.animation_data.nla_tracks[l - i]
            # need to fix for only strips with soundactions.. for R'ON
            row = layout.row()
            row = layout.row(align=True)
            for strip in nla_track.strips:
                action = strip.action
                ch = action.get("channel_name")
                if ch is None:
                    continue
                sub = row.row()
                sub.alignment = 'LEFT'
                op = sub.operator("soundaction.change", text=ch)
                op.action = strip.action.name
                sub.enabled = action != speaker.animation_data.action

                #sub.label(strip.action["channel_name"])
                if not nla_track.mute:
                    icon = "MUTE_IPO_OFF"
                else:
                    icon = "MUTE_IPO_ON"
                row.prop(action, "normalise_range", text="", expand=True)
                row.prop(nla_track, "mute",  icon=icon,
                         text="", icon_only=True)
Exemple #46
0
    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)
Exemple #47
0
 def drawvisenum(self, context):
     speaker = getSpeaker(context)
     layout = self.layout
     row = layout.row()
     row.prop(speaker, 'vismode', expand=True, icon_only=True)
Exemple #48
0
 def poll(cls, context):
     return getattr(context, "speaker", None) is not None\
            and getSpeaker(context) is not None
Exemple #49
0
    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 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")
Exemple #51
0
 def poll(cls, context):
     return getattr(context, "speaker", None) is not None\
            and getSpeaker(context) is not None
Exemple #52
0
 def drawvisenum(self, context):
     speaker = getSpeaker(context)
     layout = self.layout
     row = layout.row()
     row.prop(speaker, 'vismode', expand=True, icon_only=True)
    def poll(cls, context):
        speaker = utils.getSpeaker(context)
        if speaker is not None and 'BAKE' in speaker.vismode:
            return True

        return False
 def poll(cls, context):
     speaker = getSpeaker(context)
     screen_areas = [a.type for a in context.screen.areas if a.type in cls.screen_areas]
     return speaker is not None and len(screen_areas) and "VISUAL" in speaker.vismode
Exemple #55
0
def action_normalise_set(self, context):
    # add normal envelope
    '''
    NONE : No normalisation  # all modifiers off
    ACTION: Normalised to ACTION  always modifier 0
    CHANNEL: Normalised to CHANNEL  always modifier 1
             (Note could make this
             one use previous, and factor or TOGGLE)
    '''
    scene = context.scene
    speaker = getSpeaker(context, action=self)
    # boo (bakeoptions) change. Add if doesn't exist.
    if "boo" not in self.keys():
        # set to default.
        self["boo"] = 'SOUND'
    if speaker is None:
        print("SPEAKER IS NONE")
        return None
    speaker_rna = self.get('rna')
    speaker_rna = eval(speaker_rna)

    def add_normal_envelope(fcurve, type):
        #print("RNA", self.speaker_rna)
        '''
        mods = [m for m in fcurve.modifiers if m.type == 'ENVELOPE']
        # remove mods (shouldn't be any)
        for m in mods:
            fcurve.modifiers.remove(m)
        '''
        m = fcurve.modifiers.new(type='ENVELOPE')
        # add a control point at start end
        for f in self.frame_range:
            cp = m.control_points.add(f)
            cp.min = self.normalise_range[0]
            cp.max = self.normalise_range[1]
        m.mute = True
        m.show_expanded = False
        return m

    def set_modifiers(type='ENVELOPE'):
        scene = context.scene
        #speaker = getSpeaker(context)
        for f in self.fcurves:
            channel = f.data_path.strip('[""]')
            touched = False
            while len(f.modifiers) < 2:
            # add muted envelope modifiers
                add_normal_envelope(f, type='ENVELOPE')
                touched = True
            for i, m in enumerate(f.modifiers):
                m.mute = True
                if self.normalise == 'NONE':
                    continue
                m.reference_value = 0.0
                m.default_min = self["min"]\
                                if i == 0 else speaker_rna[channel]["min"]
                m.default_max = self["max"]\
                                if i == 0 else speaker_rna[channel]["max"]

            low = speaker_rna[channel]["low"]
            high = speaker_rna[channel]["high"]
            sp_rna = speaker['_RNA_UI']

            map_range = Vector((self['min'], self['max']))
            if self.normalise == 'NONE':
                fc_range = Vector((speaker_rna[channel]['a'],
                                  speaker_rna[channel]['b']))
                '''
                speaker['_RNA_UI'][channel] = speaker_rna[channel]
                speaker['_RNA_UI']['a'] = self['min']
                speaker['_RNA_UI']['b'] = self['max']
                '''
                pass
            else:
                # could use the mods ID prop to get indexes
                if self.normalise == 'ACTION':
                    m = f.modifiers[0]
                    b = Vector(self.normalise_range).magnitude
                    fc_range = Vector((speaker_rna[channel]['a'],
                                      speaker_rna[channel]['b']))
                    a = map_range.magnitude
                    fc_range *= b / a
                    map_range = Vector(self.normalise_range)
                if self.normalise == 'CHANNEL':
                    m = f.modifiers[1]
                    fc_range = map_range = self.normalise_range
                for cp in m.control_points:
                    cp.min = self.normalise_range[0]
                    cp.max = self.normalise_range[1]

                m.mute = False

            set_channel_idprop_rna(channel,
                                   sp_rna,
                                   low,
                                   high,
                                   fc_range,
                                   map_range,
                                   is_music=(self["boo"] == 'MUSIC'))

        # flag the mods are added
        self["mods"] = True

    def change_range(self):
        pass

    def check_range(self):
        '''
        Check Envelope Modifier Range
        '''
        # check range
        if self.normalise_range[0] == self.normalise_range[1]:
            self.normalise_range[1] += 0.0000001
            return None
        if self.normalise_range[0] > self.normalise_range[1]:
            self.normalise_range[0] = self.normalise_range[1]
            return None

        elif self.normalise_range[1] < self.normalise_range[0]:
            self.normalise_range[1] = self.normalise_range[0]
            return None

    if True or not self.get('mods', False):
        set_modifiers(type='EVELOPE')

    #check_range(self)
    #normalise_action(speaker)
    bpy.ops.graph.view_all_with_bgl_graph()
    return None
Exemple #56
0
 def get_action(self, context):
     return getAction(getSpeaker(context), search=True)
Exemple #57
0
def action_normalise_set(self, context):
    # add normal envelope
    '''
    NONE : No normalisation  # all modifiers off
    ACTION: Normalised to ACTION  always modifier 0
    CHANNEL: Normalised to CHANNEL  always modifier 1
             (Note could make this
             one use previous, and factor or TOGGLE)
    '''
    scene = context.scene
    speaker = getSpeaker(context, action=self)
    # boo (bakeoptions) change. Add if doesn't exist.
    if "boo" not in self.keys():
        # set to default.
        self["boo"] = 'SOUND'
    if speaker is None:
        print("SPEAKER IS NONE")
        return None
    speaker_rna = self.get('rna')
    speaker_rna = eval(speaker_rna)

    def add_normal_envelope(fcurve, type):
        '''
        mods = [m for m in fcurve.modifiers if m.type == 'ENVELOPE']
        # remove mods (shouldn't be any)
        for m in mods:
            fcurve.modifiers.remove(m)
        '''
        m = fcurve.modifiers.new(type='ENVELOPE')
        # add a control point at start end
        for f in self.frame_range:
            cp = m.control_points.add(f)
            cp.min = self.normalise_range[0]
            cp.max = self.normalise_range[1]
        m.mute = True
        m.show_expanded = False
        return m

    def set_modifiers(type='ENVELOPE'):
        scene = context.scene
        #speaker = getSpeaker(context)
        for f in self.fcurves:
            channel = f.data_path.strip('[""]')
            touched = False
            while len(f.modifiers) < 2:
            # add muted envelope modifiers
                add_normal_envelope(f, type='ENVELOPE')
                touched = True
            for i, m in enumerate(f.modifiers):
                m.mute = True
                if self.normalise == 'NONE':
                    continue
                m.reference_value = 0.0
                m.default_min = self["min"]\
                                if not i else speaker_rna[channel]["min"]
                m.default_max = self["max"]\
                                if not i else speaker_rna[channel]["max"]

            low = speaker_rna[channel]["low"]
            high = speaker_rna[channel]["high"]
            sp_rna = speaker['_RNA_UI']

            map_range = Vector((self['min'], self['max']))
            if self.normalise == 'NONE':
                fc_range = Vector((speaker_rna[channel]['a'],
                                  speaker_rna[channel]['b']))
                '''
                speaker['_RNA_UI'][channel] = speaker_rna[channel]
                speaker['_RNA_UI']['a'] = self['min']
                speaker['_RNA_UI']['b'] = self['max']
                '''
                pass
            else:
                # could use the mods ID prop to get indexes
                if self.normalise == 'ACTION':
                    m = f.modifiers[0]
                    b = Vector(self.normalise_range).magnitude
                    fc_range = Vector((speaker_rna[channel]['a'],
                                      speaker_rna[channel]['b']))
                    a = map_range.magnitude
                    fc_range *= b / a
                    map_range = Vector(self.normalise_range)
                if self.normalise == 'CHANNEL':
                    m = f.modifiers[1]
                    fc_range = map_range = self.normalise_range
                for cp in m.control_points:
                    cp.min = self.normalise_range[0]
                    cp.max = self.normalise_range[1]

                m.mute = False

            set_channel_idprop_rna(channel,
                                   sp_rna,
                                   low,
                                   high,
                                   fc_range,
                                   map_range,
                                   is_music=(self["boo"] == 'MUSIC'))

        # flag the mods are added
        self["mods"] = True

    def change_range(self):
        pass

    def check_range(self):
        '''
        Check Envelope Modifier Range
        '''
        # check range
        if self.normalise_range[0] == self.normalise_range[1]:
            self.normalise_range[1] += 0.0000001
            return None
        if self.normalise_range[0] > self.normalise_range[1]:
            self.normalise_range[0] = self.normalise_range[1]
            return None

        elif self.normalise_range[1] < self.normalise_range[0]:
            self.normalise_range[1] = self.normalise_range[0]
            return None

    if True or not self.get('mods', False):
        set_modifiers(type='EVELOPE')

    #check_range(self)
    #normalise_action(speaker)
    bpy.ops.graph.view_all_with_bgl_graph()
    return 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
Exemple #59
0
 def poll(cls, context):
     speaker = getSpeaker(context)
     return speaker is not None and 'SPEAKER' in speaker.vismode and hasattr(
         context, "speaker")
    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]])