Skip to content
Snippets Groups Projects
operators_extra_actions.py 69.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
    # ##### 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'}
    
    
    # TRIM TIMELINE TO SELECTION
    class Sequencer_Extra_TrimTimelineToSelection(bpy.types.Operator):
        bl_label = 'Trim to Selection'
        bl_idname = 'timeextra.trimtimelinetoselection'
        bl_description = 'Set start and end frames to selection'
        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 and i.select == True:
                        frame_start = i.frame_final_start
                    if i.frame_final_end > frame_end and i.select == True:
                        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'}
    
    
    # SLIDE STRIP
    class Sequencer_Extra_SlideStrip(bpy.types.Operator):
        bl_label = 'Slide'
        bl_idname = 'sequencerextra.slide'
        bl_description = 'Alter in and out points but not duration of a strip'
        mode = EnumProperty(
            name='Mode',
            items=(
            ('TOSTART', 'Current Frame to Strip Start', ''),
            ('TOEND', 'Current Frame to Strip End', ''),
            ('INPUT', 'Input...', '')),
            default='INPUT',
            options={'HIDDEN'})
        bl_options = {'REGISTER', 'UNDO'}
        
        slide_offset = IntProperty(
            name='Offset',
            description='Number of frames to slide',
            min=-250, max=250,
            default=0)
    
        @classmethod
        def poll(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                return strip.type in ('MOVIE', 'IMAGE', 'META', 'SCENE')
            else:
                return False
    
        def execute(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
            cf = scn.frame_current
    
            if self.mode == 'TOSTART':
                sx = strip.frame_final_start - cf
            elif self.mode == 'TOEND':
                sx = strip.frame_final_end - cf
            else:
                sx = self.slide_offset
    
            frame_end = strip.frame_start + strip.frame_duration
            pad_left = strip.frame_final_start - strip.frame_start
            pad_right = (frame_end - strip.frame_final_end) * -1
    
            if sx > pad_left:
                sx = pad_left
            elif sx < pad_right:
                sx = pad_right
    
            strip.frame_start += sx
            strip.frame_final_start -= sx
            strip.frame_final_end -= sx
    
            self.report({'INFO'}, 'Strip slid %d frame(s)' % (sx))
            scn.default_slide_offset = sx
            bpy.ops.sequencer.reload()
            return {'FINISHED'}
    
        def invoke(self, context, event):
            scn = context.scene
            initSceneProperties(context,scn)
            self.slide_offset = scn.default_slide_offset
            if self.mode == 'INPUT':
                return context.window_manager.invoke_props_dialog(self)
            else:
                return self.execute(context)
    
    
    # SLIDE GRAB
    class Sequencer_Extra_SlideGrab(bpy.types.Operator):
        bl_label = 'Slide Grab'
        bl_idname = 'sequencerextra.slidegrab'
        bl_description = 'Alter in and out points but not duration of a strip'
        bl_options = {'REGISTER', 'UNDO'}
    
        @classmethod
        def poll(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                return strip.type in ('MOVIE', 'IMAGE', 'META', 'SCENE')
            else:
                return False
    
        def execute(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
    
            diff = self.prev_x - self.x
            self.prev_x = self.x
            sx = int(diff / 2)
    
            frame_end = strip.frame_start + strip.frame_duration
            pad_left = strip.frame_final_start - strip.frame_start
            pad_right = (frame_end - strip.frame_final_end) * -1
    
            if sx > pad_left:
                sx = pad_left
            elif sx < pad_right:
                sx = pad_right
    
            strip.frame_start += sx
            strip.frame_final_start -= sx
            strip.frame_final_end -= sx
    
        def modal(self, context, event):
            if event.type == 'MOUSEMOVE':
                self.x = event.mouse_x
                self.execute(context)
            elif event.type == 'LEFTMOUSE':
                return {'FINISHED'}
            elif event.type in ('RIGHTMOUSE', 'ESC'):
                return {'CANCELLED'}
    
            return {'RUNNING_MODAL'}
    
        def invoke(self, context, event):
            scn = context.scene
            self.x = event.mouse_x
            self.prev_x = event.mouse_x
            self.execute(context)
            context.window_manager.modal_handler_add(self)
            return {'RUNNING_MODAL'}
    
    
    # FILE NAME TO STRIP NAME
    class Sequencer_Extra_FileNameToStripName(bpy.types.Operator):
        bl_label = 'File Name to Selected Strips Name'
        bl_idname = 'sequencerextra.striprename'
        bl_description = 'Set strip name to input file name'
        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]
            selection = False
            for i in seq.sequences:
                if i.select == True:
                    if i.type == 'IMAGE' and not i.mute:
                        selection = True
                        i.name = i.elements[0].filename
                    if (i.type == 'SOUND' or i.type == 'MOVIE') and not i.mute:
                        selection = True
                        i.name = bpy.path.display_name_from_filepath(i.filepath)
            if selection == False:
                self.report({'ERROR_INVALID_INPUT'},
                'No image or movie strip selected')
                return {'CANCELLED'}
            return {'FINISHED'}
    
    
    # NAVIGATE UP
    class Sequencer_Extra_NavigateUp(bpy.types.Operator):
        bl_label = 'Navigate Up'
        bl_idname = 'sequencerextra.navigateup'
        bl_description = 'Move to Parent Timeline'
    
        @classmethod
        def poll(self, context):
            strip = functions.act_strip(context)
            try:
                if context.scene.sequence_editor.meta_stack:
                    return True
                else:
                    return False
            except:
                return False
    
        def execute(self, context):
            if (functions.act_strip(context)):
                strip = functions.act_strip(context)
                seq_type = strip.type
                if seq_type == 'META':
                    context.scene.sequence_editor.active_strip = None
    
            bpy.ops.sequencer.meta_toggle()
            return {'FINISHED'}
    
    
    # RIPPLE DELETE
    class Sequencer_Extra_RippleDelete(bpy.types.Operator):
        bl_label = 'Ripple Delete'
        bl_idname = 'sequencerextra.rippledelete'
        bl_description = 'Delete a strip and shift back following ones'
        bl_options = {'REGISTER', 'UNDO'}
    
        @classmethod
        def poll(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                return True
            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]
            #strip = functions.act_strip(context)
            for strip in context.selected_editable_sequences:
                cut_frame = strip.frame_final_start
                next_edit = 300000
                bpy.ops.sequencer.select_all(action='DESELECT')
                strip.select = True
                bpy.ops.sequencer.delete()
                striplist = []
                for i in seq.sequences:
                    try:
                        if (i.frame_final_start > cut_frame
                        and not i.mute):
                            if i.frame_final_start < next_edit:
                                next_edit = i.frame_final_start
                        if not i.mute:
                            striplist.append(i)
                    except AttributeError:
                            pass
    
                if next_edit == 300000:
                    return {'FINISHED'}
                ripple_length = next_edit - cut_frame
                for i in range(len(striplist)):
                    str = striplist[i]
                    try:
                        if str.frame_final_start > cut_frame:
                            str.frame_start = str.frame_start - ripple_length
                    except AttributeError:
                            pass
                bpy.ops.sequencer.reload()
            return {'FINISHED'}
    
    
    # RIPPLE CUT
    class Sequencer_Extra_RippleCut(bpy.types.Operator):
        bl_label = 'Ripple Cut'
        bl_idname = 'sequencerextra.ripplecut'
        bl_description = 'Move a strip to buffer and shift back following ones'
        bl_options = {'REGISTER', 'UNDO'}
    
        @classmethod
        def poll(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                return True
            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]
            strip = functions.act_strip(context)
            bpy.ops.sequencer.select_all(action='DESELECT')
            strip.select = True
            temp_cf = scn.frame_current
            scn.frame_current = strip.frame_final_start
            bpy.ops.sequencer.copy()
            scn.frame_current = temp_cf
    
            bpy.ops.sequencerextra.rippledelete()
            return {'FINISHED'}
    
    
    # INSERT
    class Sequencer_Extra_Insert(bpy.types.Operator):
        bl_label = 'Insert'
        bl_idname = 'sequencerextra.insert'
        bl_description = 'Move active strip to current frame and shift '\
        'forward following ones'
        singlechannel = BoolProperty(
        name='Single Channel',
        default=False)
        bl_options = {'REGISTER', 'UNDO'}
    
        @classmethod
        def poll(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                return True
            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]
            strip = functions.act_strip(context)
            gap = strip.frame_final_duration
            bpy.ops.sequencer.select_all(action='DESELECT')
            current_frame = scn.frame_current
    
            striplist = []
            for i in seq.sequences:
                try:
                    if (i.frame_final_start >= current_frame
                    and not i.mute):
                        if self.singlechannel == True:
                            if i.channel == strip.channel:
                                striplist.append(i)
                        else:
                            striplist.append(i)
                except AttributeError:
                        pass
            try:
                bpy.ops.sequencerextra.selectcurrentframe('EXEC_DEFAULT',
                mode='AFTER')
            except:
                self.report({'ERROR_INVALID_INPUT'}, 'Execution Error, '\
                'check your Blender version')
                return {'CANCELLED'}
    
            for i in range(len(striplist)):
                str = striplist[i]
                try:
                    if str.select == True:
                        str.frame_start += gap
                except AttributeError:
                        pass
            try:
                diff = current_frame - strip.frame_final_start
                strip.frame_start += diff
            except AttributeError:
                    pass
    
            strip = functions.act_strip(context)
            scn.frame_current += strip.frame_final_duration
            bpy.ops.sequencer.reload()
    
            return {'FINISHED'}
    
    
    # PLACE FROM FILE BROWSER
    class Sequencer_Extra_PlaceFromFileBrowser(bpy.types.Operator):
        bl_label = 'Place'
        bl_idname = 'sequencerextra.placefromfilebrowser'
        bl_description = 'Place or insert active file from File Browser'
        insert = BoolProperty(
        name='Insert',
        default=False)
        bl_options = {'REGISTER', 'UNDO'}
    
        def execute(self, context):
            scn = context.scene
            for a in context.window.screen.areas:
                if a.type == 'FILE_BROWSER':
                    params = a.spaces[0].params
                    break
            try:
                params
            except UnboundLocalError:
                self.report({'ERROR_INVALID_INPUT'}, 'No visible File Browser')
                return {'CANCELLED'}
    
            if params.filename == '':
                self.report({'ERROR_INVALID_INPUT'}, 'No file selected')
                return {'CANCELLED'}
    
            path = os.path.join(params.directory, params.filename)
            frame = context.scene.frame_current
            strip_type = functions.detect_strip_type(params.filename)
    
            try:
                if strip_type == 'IMAGE':
                    image_file = []
                    filename = {"name": params.filename}
                    image_file.append(filename)
                    f_in = scn.frame_current
                    f_out = f_in + scn.render.fps - 1
                    bpy.ops.sequencer.image_strip_add(files=image_file,
                    directory=params.directory, frame_start=f_in,
                    frame_end=f_out, relative_path=False)
                elif strip_type == 'MOVIE':
                    bpy.ops.sequencer.movie_strip_add(filepath=path,
                    frame_start=frame, relative_path=False)
                elif strip_type == 'SOUND':
                    bpy.ops.sequencer.sound_strip_add(filepath=path,
                    frame_start=frame, relative_path=False)
                else:
                    self.report({'ERROR_INVALID_INPUT'}, 'Invalid file format')
                    return {'CANCELLED'}
            except:
                self.report({'ERROR_INVALID_INPUT'}, 'Error loading file')
                return {'CANCELLED'}
    
            if self.insert == True:
                try:
                    striplist = []
                    for i in bpy.context.selected_editable_sequences:
                        if (i.select == True and i.type == "SOUND"):
                            striplist.append(i)
                    bpy.ops.sequencerextra.insert()
                    if striplist[0]:
                        striplist[0].frame_start = frame
                except:
                    self.report({'ERROR_INVALID_INPUT'}, 'Execution Error, '\
                    'check your Blender version')
                    return {'CANCELLED'}
            else:
                strip = functions.act_strip(context)
                scn.frame_current += strip.frame_final_duration
                bpy.ops.sequencer.reload()
    
            return {'FINISHED'}
    
    
    # SELECT BY TYPE
    class Sequencer_Extra_SelectAllByType(bpy.types.Operator):
        bl_label = 'All by Type'
        bl_idname = 'sequencerextra.select_all_by_type'
        bl_description = 'Select all the strips of the same type'
        type = EnumProperty(
                name='Strip Type',
                items=(
                ('ACTIVE', 'Same as Active Strip', ''),
                ('IMAGE', 'Image', ''),
                ('META', 'Meta', ''),
                ('SCENE', 'Scene', ''),
                ('MOVIE', 'Movie', ''),
                ('SOUND', 'Sound', ''),
                ('TRANSFORM', 'Transform', ''),
                ('COLOR', 'Color', '')),
                default='ACTIVE',
                )
        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):
            strip_type = self.type
            scn = context.scene
            seq = scn.sequence_editor
            meta_level = len(seq.meta_stack)
            if meta_level > 0:
                seq = seq.meta_stack[meta_level - 1]
            active_strip = functions.act_strip(context)
            if strip_type == 'ACTIVE':
                if active_strip == None:
                    self.report({'ERROR_INVALID_INPUT'},
                    'No active strip')
                    return {'CANCELLED'}
                strip_type = active_strip.type
    
            striplist = []
            for i in seq.sequences:
                try:
                    if (i.type == strip_type
                    and not i.mute):
                        striplist.append(i)
                except AttributeError:
                        pass
            for i in range(len(striplist)):
                str = striplist[i]
                try:
                    str.select = True
                except AttributeError:
                        pass
    
            return {'FINISHED'}
    
    
    # CURRENT-FRAME-AWARE SELECT
    class Sequencer_Extra_SelectCurrentFrame(bpy.types.Operator):
        bl_label = 'Current-Frame-Aware Select'
        bl_idname = 'sequencerextra.selectcurrentframe'
        bl_description = 'Select strips according to current frame'
        mode = EnumProperty(
                name='Mode',
                items=(
                ('BEFORE', 'Before Current Frame', ''),
                ('AFTER', 'After Current Frame', ''),
                ('ON', 'On Current Frame', '')),
                default='BEFORE',
                )
        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):
            mode = self.mode
            scn = context.scene
            seq = scn.sequence_editor
            cf = scn.frame_current
            meta_level = len(seq.meta_stack)
            if meta_level > 0:
                seq = seq.meta_stack[meta_level - 1]
    
            if mode == 'AFTER':
                for i in seq.sequences:
                    try:
                        if (i.frame_final_start >= cf
                        and not i.mute):
                            i.select = True
                    except AttributeError:
                            pass
            elif mode == 'ON':
                for i in seq.sequences:
                    try:
                        if (i.frame_final_start <= cf
                        and i.frame_final_end > cf
                        and not i.mute):
                            i.select = True
                    except AttributeError:
                            pass
            else:
                for i in seq.sequences:
                    try:
                        if (i.frame_final_end < cf
                        and not i.mute):
                            i.select = True
                    except AttributeError:
                            pass
    
            return {'FINISHED'}
    
    
    # SELECT STRIPS ON SAME CHANNEL
    class Sequencer_Extra_SelectSameChannel(bpy.types.Operator):
        bl_label = 'Select Strips on the Same Channel'
        bl_idname = 'sequencerextra.selectsamechannel'
        bl_description = 'Select strips on the same channel as active one'
        bl_options = {'REGISTER', 'UNDO'}
    
        @classmethod
        def poll(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                return True
            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]
            bpy.ops.sequencer.select_active_side(side="LEFT")
            bpy.ops.sequencer.select_active_side(side="RIGHT")
    
            return {'FINISHED'}
    
    
    # OPEN IMAGE WITH EXTERNAL EDITOR
    class Sequencer_Extra_EditExternally(bpy.types.Operator):
        bl_label = 'Open with External Editor'
        bl_idname = 'sequencerextra.editexternally'
        bl_description = 'Open with the default external image editor'
    
        @classmethod
        def poll(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                return strip.type == 'IMAGE'
            else:
                return False
    
        def execute(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
            base_dir = bpy.path.abspath(strip.directory)
            strip_elem = strip.strip_elem_from_frame(scn.frame_current)
            path = base_dir + strip_elem.filename
    
            try:
                bpy.ops.image.external_edit(filepath=path)
            except:
                self.report({'ERROR_INVALID_INPUT'},
                'Please specify an Image Editor in Preferences > File')
                return {'CANCELLED'}
    
            return {'FINISHED'}
    
    
    # OPEN IMAGE WITH EDITOR
    class Sequencer_Extra_Edit(bpy.types.Operator):
        bl_label = 'Open with Editor'
        bl_idname = 'sequencerextra.edit'
        bl_description = 'Open with Movie Clip or Image Editor'
    
        @classmethod
        def poll(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                return strip.type in ('MOVIE', 'IMAGE')
            else:
                return False
    
        def execute(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
            data_exists = False
    
            if strip.type == 'MOVIE':
                path = strip.filepath
    
                for i in bpy.data.movieclips:
                    if i.filepath == path:
                        data_exists = True
                        data = i
    
                if data_exists == False:
                    try:
                        data = bpy.data.movieclips.load(filepath=path)
                    except:
                        self.report({'ERROR_INVALID_INPUT'}, 'Error loading file')
                        return {'CANCELLED'}
    
            elif strip.type == 'IMAGE':
                base_dir = bpy.path.abspath(strip.directory)
                strip_elem = strip.strip_elem_from_frame(scn.frame_current)
                elem_name = strip_elem.filename
                path = base_dir + elem_name
    
                for i in bpy.data.images:
                    if i.filepath == path:
                        data_exists = True
                        data = i
    
                if data_exists == False:
                    try:
                        data = bpy.data.images.load(filepath=path)
                    except:
                        self.report({'ERROR_INVALID_INPUT'}, 'Error loading file')
                        return {'CANCELLED'}
    
            if strip.type == 'MOVIE':
                for a in context.window.screen.areas:
                    if a.type == 'CLIP_EDITOR':
                        a.spaces[0].clip = data
            elif strip.type == 'IMAGE':
                for a in context.window.screen.areas:
                    if a.type == 'IMAGE_EDITOR':
                        a.spaces[0].image = data
    
            return {'FINISHED'}
    
    
    # COPY STRIP PROPERTIES
    class Sequencer_Extra_CopyProperties(bpy.types.Operator):
        bl_label = 'Copy Properties'
        bl_idname = 'sequencerextra.copyproperties'
        bl_description = 'Copy properties of active strip to selected strips'
        bl_options = {'REGISTER', 'UNDO'}
    
        prop = EnumProperty(
        name='Property',
        items=[
        # COMMON
        ('name', 'Name', ''),
        ('blend_alpha', 'Opacity', ''),
        ('blend_type', 'Blend Mode', ''),
        ('animation_offset', 'Input - Trim Duration', ''),
        # NON-SOUND
        ('use_translation', 'Input - Image Offset', ''),
        ('crop', 'Input - Image Crop', ''),
        ('proxy', 'Proxy / Timecode', ''),
        ('strobe', 'Filter - Strobe', ''),
        ('color_multiply', 'Filter - Multiply', ''),
        ('color_saturation', 'Filter - Saturation', ''),
        ('deinterlace', 'Filter - De-Interlace', ''),
        ('flip', 'Filter - Flip', ''),
        ('float', 'Filter - Convert Float', ''),
        ('alpha_mode', 'Filter - Alpha Mode', ''),
        ('reverse', 'Filter - Backwards', ''),
        # SOUND
        ('pan', 'Sound - Pan', ''),
        ('pitch', 'Sound - Pitch', ''),
        ('volume', 'Sound - Volume', ''),
        ('cache', 'Sound - Caching', ''),
        # IMAGE
        ('directory', 'Image - Directory', ''),
        # MOVIE
        ('mpeg_preseek', 'Movie - MPEG Preseek', ''),
        ('stream_index', 'Movie - Stream Index', ''),
        # WIPE
        ('wipe', 'Effect - Wipe', ''),
        # TRANSFORM
        ('transform', 'Effect - Transform', ''),
        # COLOR
        ('color', 'Effect - Color', ''),
        # SPEED
        ('speed', 'Effect - Speed', ''),
        # MULTICAM
        ('multicam_source', 'Effect - Multicam Source', ''),
        # EFFECT
        ('effect_fader', 'Effect - Effect Fader', ''),
        ],
        default='blend_alpha')
    
        @classmethod
        def poll(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                return True
            else:
                return False
    
        def execute(self, context):
            strip = functions.act_strip(context)
            selectedstrips = context.selected_editable_sequences
    
            for i in selectedstrips:
                if (i.select == True and not i.mute) and i != strip:
                    try:
                        if self.prop == 'name':
                            i.name = strip.name
                        elif self.prop == 'blend_alpha':
                            i.blend_alpha = strip.blend_alpha
                        elif self.prop == 'blend_type':
                            i.blend_type = strip.blend_type
                        elif self.prop == 'animation_offset':
                            i.animation_offset_start = strip.animation_offset_start
                            i.animation_offset_end = strip.animation_offset_end
                        elif self.prop == 'use_translation':
                            i.use_translation = strip.use_translation
                            i.transform.offset_x = strip.transform.offset_x
                            i.transform.offset_y = strip.transform.offset_y
                        elif self.prop == 'crop':
                            i.use_crop = strip.use_crop
                            i.crop.min_x = strip.crop.min_x
                            i.crop.min_y = strip.crop.min_y
                            i.crop.max_x = strip.crop.max_x
                            i.crop.max_y = strip.crop.max_y