Skip to content
Snippets Groups Projects
operators_extra_actions.py 69.5 KiB
Newer Older
# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

'''
TODO
align strip to the left (shift-s + -lenght)

'''

import bpy

import random
import math
import os, sys

from bpy.props import IntProperty
from bpy.props import FloatProperty
from bpy.props import EnumProperty
from bpy.props import BoolProperty
from bpy.props import StringProperty

from . import functions
from . import exiftool


# Initialization


def initSceneProperties(context, scn):
    try:
        if context.scene.scene_initialized == True:
            return False
    except AttributeError:
        pass

    bpy.types.Scene.default_slide_offset = IntProperty(
        name='Offset',
        description='Number of frames to slide',
        min=-250, max=250,
        default=0)
    scn.default_slide_offset = 0

    bpy.types.Scene.default_fade_duration = IntProperty(
        name='Duration',
        description='Number of frames to fade',
        min=1, max=250,
        default=scn.render.fps)
    scn.default_fade_duration = scn.render.fps

    bpy.types.Scene.default_fade_amount = FloatProperty(
        name='Amount',
        description='Maximum value of fade',
        min=0.0,
        max=100.0,
        default=1.0)
    scn.default_fade_amount = 1.0

    bpy.types.Scene.default_distribute_offset = IntProperty(
        name='Offset',
        description='Number of frames between strip start frames',
        min=1,
        max=250,
        default=2)
    scn.default_distribute_offset = 2

    bpy.types.Scene.default_distribute_reverse = BoolProperty(
        name='Reverse Order',
        description='Reverse the order of selected strips',
        default=False)
    scn.default_distribute_reverse = False

    bpy.types.Scene.default_proxy_suffix = StringProperty(
        name='default proxy suffix',
        description='default proxy filename suffix',
        default="-25")
    scn.default_proxy_suffix = "-25"

    bpy.types.Scene.default_proxy_extension = StringProperty(
        name='default proxy extension',
        description='default proxy file extension',
        default=".mkv")
    scn.default_proxy_extension = ".mkv"

    bpy.types.Scene.default_proxy_path = StringProperty(
        name='default proxy path',
        description='default proxy file path (relative to original file)',
        default="")
    scn.default_proxy_path = ""

    bpy.types.Scene.default_build_25 = BoolProperty(
        name='default_build_25',
        description='default build_25',
        default=True)
    scn.default_build_25 = True

    bpy.types.Scene.default_build_50 = BoolProperty(
        name='default_build_50',
        description='default build_50',
        default=False)
    scn.default_build_50 = False

    bpy.types.Scene.default_build_75 = BoolProperty(
        name='default_build_75',
        description='default build_75',
        default=False)
    scn.default_build_75 = False

    bpy.types.Scene.default_build_100 = BoolProperty(
        name='default_build_100',
        description='default build_100',
        default=False)
    scn.default_build_100 = False
    
    bpy.types.Scene.default_recursive = BoolProperty(
        name='Recursive',
        description='Load in recursive folders',
        default=False)
    scn.default_recursive = False
   
    bpy.types.Scene.default_recursive_proxies = BoolProperty(
        name='Recursive proxies',
        description='Load in recursive folders + proxies',
        default=False)
    scn.default_recursive_proxies = False
    
    bpy.types.Scene.default_recursive_select_by_extension = BoolProperty(
        name='Recursive ext',
        description='Load only clips with selected extension',
        default=False)
    scn.default_recursive_select_by_extension = False
    
    bpy.types.Scene.default_ext = EnumProperty(
        items=functions.movieextdict,
        name="ext enum",
        default="3")
    scn.default_ext = "3"
    
    bpy.types.Scene.scene_initialized = BoolProperty(
        name='Init',
        default=False)
    scn.scene_initialized = True

    return True

   
# TRIM TIMELINE
class Sequencer_Extra_TrimTimeline(bpy.types.Operator):
    bl_label = 'Trim to Timeline Content'
    bl_idname = 'timeextra.trimtimeline'
    bl_description = 'Automatically set start and end frames'
    bl_options = {'REGISTER', 'UNDO'}

    @classmethod
    def poll(self, context):
        scn = context.scene
        if scn and scn.sequence_editor:
            return scn.sequence_editor.sequences
        else:
            return False

    def execute(self, context):
        scn = context.scene
        seq = scn.sequence_editor
        meta_level = len(seq.meta_stack)
        if meta_level > 0:
            seq = seq.meta_stack[meta_level - 1]

        frame_start = 300000
        frame_end = -300000
        for i in seq.sequences:
            try:
                if i.frame_final_start < frame_start:
                    frame_start = i.frame_final_start
                if i.frame_final_end > frame_end:
                    frame_end = i.frame_final_end - 1
            except AttributeError:
                    pass

        if frame_start != 300000:
            scn.frame_start = frame_start
        if frame_end != -300000:
            scn.frame_end = frame_end
        return {'FINISHED'}


Loading
Loading full blame...