Example #1
0
    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 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'}
Example #3
0
    def execute(self, context):
        spk = bpy.data.speakers.new('Speaker')
        base = object_utils.object_data_add(context, spk, operator=self)
        ob = base.object
        context.scene.frame_set(1)
        #return {'FINISHED'}
        if not getattr(ob, "animation_data", None):
            d = context.copy()
            info = None
            nla = None
            #find any area that is not the current area
            ob.animation_data_create()
            soundtrack = ob.animation_data.nla_tracks.new()
            soundtrack.name = "SoundTrack"
            areas = [a for a in context.screen.areas if a != context.area]
            if len(areas):
                area = areas[0]
                t = area.type
                area.type = 'NLA_EDITOR'
                d["area"] = area
                # add an NLA track
                nla = get_context_area(context, d, area_type='NLA_EDITOR')
                bpy.ops.nla.soundclip_add(d)
                soundtrack.select = False  #  Otherwise you get track on track.
                area.type = t
            else:
                # ok no override available.. going to have to flip into NLA_ED
                # draw method unavailable. feck it.
                context.area.type = 'NLA_EDITOR'
                bpy.ops.nla.soundclip_add()
                context.area.type = 'VIEW_3D'

            spk.vismode = {'SOUND'}

            props = get_context_area(context, {},
                                     area_type='PROPERTIES',
                                     context_screen=True)
            if props is not None:
                if getattr(props.spaces.active, "context", None):
                    try:
                        props.spaces.active.context = 'DATA'
                    except:
                        pass

        return {'FINISHED'}
Example #4
0
    def execute(self, context):
        spk = bpy.data.speakers.new('Speaker')
        base = object_utils.object_data_add(context, spk, operator=self)
        ob = base.object
        context.scene.frame_set(1)
        #return {'FINISHED'}
        if not getattr(ob, "animation_data", None):
            d = context.copy()
            info = None
            nla = None
            #find any area that is not the current area
            ob.animation_data_create()
            soundtrack = ob.animation_data.nla_tracks.new()
            soundtrack.name = "SoundTrack"
            areas = [a for a in context.screen.areas if a != context.area]
            if len(areas):
                area = areas[0]
                t =  area.type
                area.type = 'NLA_EDITOR'
                d["area"] = area
                # add an NLA track
                nla = get_context_area(context, d, area_type='NLA_EDITOR')
                bpy.ops.nla.soundclip_add(d)
                soundtrack.select = False #  Otherwise you get track on track.
                area.type = t
            else:
                # ok no override available.. going to have to flip into NLA_ED
                # draw method unavailable. feck it.
                context.area.type = 'NLA_EDITOR'
                bpy.ops.nla.soundclip_add()
                context.area.type = 'VIEW_3D'

            spk.vismode = {'SOUND'}

            props = get_context_area(context, {}, area_type='PROPERTIES',
                                     context_screen = True)
            if props is not None:
                if getattr(props.spaces.active, "context", None):
                    try:
                        props.spaces.active.context = 'DATA'
                    except:
                        pass

        return {'FINISHED'}
    def execute(self, context):
        
        BakeSoundPanel.bake_times = []
        wm = context.window_manager
        wm_rnaui = wm.get("_RNA_UI")
        if wm_rnaui is None:
            wm_rnaui = wm["_RNA_UI"] = {}
            wm["_RNA_UI"]["bake_progress"] = {
                                              "min": 0.0,
                                              "soft_min":0.0,
                                              "hard_min":0.0,
                                              "soft_max":100.0,
                                              "hard_max":100.0,
                                              "max":100.0,
                                              "description": "Baking....",
                                              }
        wm["bake_progress"] = 0.0
        BakeSoundPanel.cancel_baking = False
        self.speaker = bpy.data.speakers.get(self.speaker_name)
        self.c = context.copy()
        self.first_baked = False
        self.last_baked = False
        self.sound = bpy.data.sounds.get(self.sound_name)
        if not (self.sound and self.speaker):
            return {'CANCELLED'}
        bakeoptions = self.sound.bakeoptions
        channels = [c for sp in context.scene.objects if sp.type == 'SPEAKER' for c in sp.data.channels]
        bakeoptions.channel_name = utils.unique_name(channels, "AA") # AAAA
        self.retries = []

        if self.area_index > -1:
            '''
            self.view3d = get_context_area(context, {}, 'VIEW_3D',
                                  context_screen=True)
            '''
            self.view3d = context.screen.areas[self.area_index]
            self._view3d = self.view3d.type
            if self.view3d is not None:
                self.view3d.type = 'GRAPH_EDITOR'

        # NEEDS REFACTO to get BGL Graph Area if there is one
        self.graph = utils.get_context_area(context,
                              self.c,
                              'GRAPH_EDITOR',
                              context_screen=(self.area_index != -1))

        self.context_override = self.graph is not None\
                and self.graph.spaces.active.mode != 'DRIVERS'

        if "_RNA_UI" not in self.speaker.keys():
            self.speaker["_RNA_UI"] = dict()

        context.scene.frame_set(1)
        channels = bakeoptions.channels

        # Create the action # might move this to see if one channel baked
        current_action = None
        if not self.speaker.animation_data:
            self.speaker.animation_data_create()
        elif self.speaker.animation_data.action:
            current_action = self.speaker.animation_data.action

        name = "%s_%s_%s" % (bakeoptions.sound_type, bakeoptions.channel_name, self.sound.name)

        action = bpy.data.actions.new(name)

        if current_action:
            #take some settings from last baked
            action.vismode = current_action.vismode

        action["Channels"] = channels
        action["channel_name"] = bakeoptions.channel_name
        action["minf"] = bakeoptions.minf
        action["maxf"] = bakeoptions.maxf
        action["use_log"] = bakeoptions.use_log
        action["wavfile"] = self.sound.name
        action["min"] = 1000000
        action["max"] = -1000000
        action["start"] = 0
        action["end"] = channels - 1

        #keep some UI stuff here too like the row height of each channel

        # use 0.4 as a default value
        action["row_height"] = 0.4
        action_rna = {}
        action_rna["row_height"] = {"min": 0.001,
                                    "max": 1.0,
                                    "description": "Alter the row height",
                                    "soft_min": 0.0,
                                    "soft_max": 1.0}
        action_rna["start"] = {"min": 0,
                               "max": 1.0,
                               "description": "Clip Start",
                               "soft_min": 0,
                               "soft_max": channels - 1}
        action_rna["end"] = {"min": 1,
                             "max": channels - 1,
                             "description": "Clip End",
                             "soft_min": 1,
                             "soft_max": channels - 1}

        action["_RNA_UI"] = action_rna
        #action["rna"] = str(action_rna)
        # set up the fcurves
        BakeSoundPanel.action = action
        BakeSoundPanel.wait = 0
        BakeSoundPanel.status = [0 for i in range(channels)]
        for i in range(channels):
            p = "%s%d" % (bakeoptions.channel_name, i)
            self.speaker[p] = 0.0
            fc = action.fcurves.new('["%s"]' % p, action_group=bakeoptions.channel_name)
            fc.select = False
            fc.mute = True

        bakeorder = [i for i in range(channels)]
        if channels > 1:
            bakeorder[1], bakeorder[channels - 1] = bakeorder[channels - 1],\
                                                    bakeorder[1]
        self.bakeorder = bakeorder

        self.speaker.animation_data.action = action
        wm = context.window_manager
        self._timer = wm.event_timer_add(0.1, context.window)
        context.window_manager.modal_handler_add(self)
        self.wait = 30
        print("-" * 80)
        print("BAKING %s to action %s" % (self.sound.name, action.name))
        print("-" * 80)

        return {'RUNNING_MODAL'}
Example #6
0
    def execute(self, context):

        BakeSoundPanel.bake_times = []
        wm = context.window_manager
        wm_rnaui = wm.get("_RNA_UI")
        if wm_rnaui is None:
            wm_rnaui = wm["_RNA_UI"] = {}
            wm["_RNA_UI"]["bake_progress"] = {
                "min": 0.0,
                "soft_min": 0.0,
                "hard_min": 0.0,
                "soft_max": 100.0,
                "hard_max": 100.0,
                "max": 100.0,
                "description": "Baking....",
            }
        wm["bake_progress"] = 0.0
        BakeSoundPanel.cancel_baking = False
        self.speaker = bpy.data.speakers.get(self.speaker_name)
        self.c = context.copy()
        self.first_baked = False
        self.last_baked = False
        self.sound = bpy.data.sounds.get(self.sound_name)
        if not (self.sound and self.speaker):
            return {'CANCELLED'}
        bakeoptions = self.sound.bakeoptions
        channels = [
            c for sp in context.scene.objects if sp.type == 'SPEAKER'
            for c in sp.data.channels
        ]
        bakeoptions.channel_name = utils.unique_name(channels, "AA")  # AAAA
        self.retries = []

        if self.area_index > -1:
            '''
            self.view3d = get_context_area(context, {}, 'VIEW_3D',
                                  context_screen=True)
            '''
            self.view3d = context.screen.areas[self.area_index]
            self._view3d = self.view3d.type
            if self.view3d is not None:
                self.view3d.type = 'GRAPH_EDITOR'

        # NEEDS REFACTO to get BGL Graph Area if there is one
        self.graph = utils.get_context_area(
            context,
            self.c,
            'GRAPH_EDITOR',
            context_screen=(self.area_index != -1))

        self.context_override = self.graph is not None\
                and self.graph.spaces.active.mode != 'DRIVERS'

        if "_RNA_UI" not in self.speaker.keys():
            self.speaker["_RNA_UI"] = dict()

        context.scene.frame_set(1)
        channels = bakeoptions.channels

        # Create the action # might move this to see if one channel baked
        current_action = None
        if not self.speaker.animation_data:
            self.speaker.animation_data_create()
        elif self.speaker.animation_data.action:
            current_action = self.speaker.animation_data.action

        name = "%s_%s_%s" % (bakeoptions.sound_type, bakeoptions.channel_name,
                             self.sound.name)

        action = bpy.data.actions.new(name)

        if current_action:
            #take some settings from last baked
            action.vismode = current_action.vismode

        action["Channels"] = channels
        action["channel_name"] = bakeoptions.channel_name
        action["minf"] = bakeoptions.minf
        action["maxf"] = bakeoptions.maxf
        action["use_log"] = bakeoptions.use_log
        action["wavfile"] = self.sound.name
        action["min"] = 1000000
        action["max"] = -1000000
        action["start"] = 0
        action["end"] = channels - 1

        #keep some UI stuff here too like the row height of each channel

        # use 0.4 as a default value
        action["row_height"] = 0.4
        action_rna = {}
        action_rna["row_height"] = {
            "min": 0.001,
            "max": 1.0,
            "description": "Alter the row height",
            "soft_min": 0.0,
            "soft_max": 1.0
        }
        action_rna["start"] = {
            "min": 0,
            "max": 1.0,
            "description": "Clip Start",
            "soft_min": 0,
            "soft_max": channels - 1
        }
        action_rna["end"] = {
            "min": 1,
            "max": channels - 1,
            "description": "Clip End",
            "soft_min": 1,
            "soft_max": channels - 1
        }

        action["_RNA_UI"] = action_rna
        #action["rna"] = str(action_rna)
        # set up the fcurves
        BakeSoundPanel.action = action
        BakeSoundPanel.wait = 0
        BakeSoundPanel.status = [0 for i in range(channels)]
        for i in range(channels):
            p = "%s%d" % (bakeoptions.channel_name, i)
            self.speaker[p] = 0.0
            fc = action.fcurves.new('["%s"]' % p,
                                    action_group=bakeoptions.channel_name)
            fc.select = False
            fc.mute = True

        bakeorder = [i for i in range(channels)]
        if channels > 1:
            bakeorder[1], bakeorder[channels - 1] = bakeorder[channels - 1],\
                                                    bakeorder[1]
        self.bakeorder = bakeorder

        self.speaker.animation_data.action = action
        wm = context.window_manager
        self._timer = wm.event_timer_add(0.1, context.window)
        context.window_manager.modal_handler_add(self)
        self.wait = 30
        print("-" * 80)
        print("BAKING %s to action %s" % (self.sound.name, action.name))
        print("-" * 80)

        return {'RUNNING_MODAL'}