refactor and fixes for episode handling gav
This commit is contained in:
+114
-18
@@ -9,7 +9,7 @@ from bpy.props import (BoolProperty, StringProperty, FloatProperty,
|
||||
|
||||
from vse_toolbox.sequencer_utils import (get_strips, rename_strips, set_channels,
|
||||
get_channel_index, new_text_strip, get_strip_at, get_channel_name,
|
||||
create_shot_strip)
|
||||
create_shot_strip, update_text_strips)
|
||||
|
||||
from vse_toolbox.scene_cut_detection import detect_scene_change
|
||||
from vse_toolbox.bl_utils import get_scene_settings, get_strip_settings, get_addon_prefs
|
||||
@@ -24,7 +24,11 @@ class VSETB_OT_rename(Operator):
|
||||
|
||||
#template : StringProperty(name="Strip Name", default="")
|
||||
#increment : IntProperty(name="Increment", default=0)
|
||||
selected_only : BoolProperty(name="Selected Only", default=True)
|
||||
selected_only : BoolProperty(
|
||||
name="Selected Only",
|
||||
default=False,
|
||||
description="Rename only selected strips; disabled renames the whole channel",
|
||||
)
|
||||
#start_number : IntProperty(name="Start Number", default=0, min=0)
|
||||
#by_sequence : BoolProperty(
|
||||
# name="Reset By Sequence",
|
||||
@@ -34,9 +38,13 @@ class VSETB_OT_rename(Operator):
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
settings = get_scene_settings()
|
||||
strip = context.active_strip
|
||||
return settings.active_project and get_channel_name(strip) in ('Shots', 'Sequences')
|
||||
if strip is None and context.scene.sequence_editor:
|
||||
strip = next(
|
||||
(s for s in context.scene.sequence_editor.strips if s.select),
|
||||
None,
|
||||
)
|
||||
return strip is not None
|
||||
|
||||
def invoke(self, context, event):
|
||||
scn = context.scene
|
||||
@@ -49,19 +57,29 @@ class VSETB_OT_rename(Operator):
|
||||
scn = context.scene
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
if project is None and settings.projects:
|
||||
project = settings.projects[0]
|
||||
if project is None:
|
||||
self.report({'ERROR'}, 'No VSE Toolbox project is loaded')
|
||||
return
|
||||
|
||||
episode = project.episode_name
|
||||
sequence = str(project.sequence_start_number).zfill(project.sequence_padding)
|
||||
shot = str(project.shot_start_number).zfill(project.shot_padding)
|
||||
|
||||
strip = context.active_strip
|
||||
if strip is None and context.scene.sequence_editor:
|
||||
strip = next(
|
||||
(s for s in context.scene.sequence_editor.strips if s.select),
|
||||
None,
|
||||
)
|
||||
channel_name = get_channel_name(strip)
|
||||
|
||||
col = layout.column()
|
||||
col.use_property_split = True
|
||||
col.use_property_decorate = False
|
||||
|
||||
if channel_name == 'Shots':
|
||||
if channel_name != 'Sequences':
|
||||
col.prop(project, 'shot_template', text='Shot Name')
|
||||
col.prop(project, 'shot_start_number', text='Start Number')
|
||||
col.prop(project, 'shot_increment', text='Increment')
|
||||
@@ -77,9 +95,9 @@ class VSETB_OT_rename(Operator):
|
||||
|
||||
col.prop(self, 'selected_only')
|
||||
|
||||
if channel_name == 'Shots':
|
||||
if channel_name != 'Sequences':
|
||||
label = project.shot_template.format(episode=episode, sequence=sequence, shot=shot)
|
||||
elif channel_name == 'Sequences':
|
||||
else:
|
||||
label = project.sequence_template.format(episode=episode, sequence=sequence)
|
||||
|
||||
col.label(text=f'Renaming {label}')
|
||||
@@ -88,12 +106,30 @@ class VSETB_OT_rename(Operator):
|
||||
scn = context.scene
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
if project is None:
|
||||
# The config path is set during addon registration, but the
|
||||
# project data is only populated when Load Settings is pressed.
|
||||
bpy.ops.vse_toolbox.load_settings()
|
||||
project = settings.active_project
|
||||
if project is None and settings.projects:
|
||||
project = settings.projects[0]
|
||||
if project is None:
|
||||
self.report({'ERROR'}, 'No VSE Toolbox project is loaded')
|
||||
return {'CANCELLED'}
|
||||
# Keep the scene's active project in sync with the fallback project;
|
||||
# rename_strips reads it again from scene settings.
|
||||
settings.project_name = project.name
|
||||
|
||||
strip = context.active_strip
|
||||
if strip is None and context.scene.sequence_editor:
|
||||
strip = next(
|
||||
(s for s in context.scene.sequence_editor.strips if s.select),
|
||||
None,
|
||||
)
|
||||
channel_name = get_channel_name(strip)
|
||||
|
||||
strips = get_strips(channel=channel_name, selected_only=self.selected_only)
|
||||
if channel_name == 'Shots':
|
||||
if channel_name != 'Sequences':
|
||||
rename_strips(strips,
|
||||
template=project.shot_template,
|
||||
increment=project.shot_increment, start_number=project.shot_start_number,
|
||||
@@ -152,8 +188,13 @@ class VSETB_OT_set_sequencer(Operator):
|
||||
movie = movies[0]
|
||||
movie.transform.scale_x = movie.transform.scale_y = 1
|
||||
elem = movie.strip_elem_from_frame(scn.frame_current)
|
||||
scn.render.resolution_x = elem.orig_width
|
||||
scn.render.resolution_y = elem.orig_height
|
||||
if elem is None and movie.elements:
|
||||
elem = movie.elements[0]
|
||||
if elem is not None:
|
||||
scn.render.resolution_x = elem.orig_width
|
||||
scn.render.resolution_y = elem.orig_height
|
||||
else:
|
||||
self.report({'WARNING'}, 'Cannot determine movie resolution.')
|
||||
else:
|
||||
self.report({'INFO'}, f'Cannot set Resolution. No Movie Found.')
|
||||
|
||||
@@ -200,16 +241,32 @@ class VSETB_OT_scene_cut_detection(Operator):
|
||||
movie_type: EnumProperty(
|
||||
items=[('ANIMATED', 'Animated', 'Use select filter from ffmpeg, best for animated frame'),
|
||||
('STILL', 'Still', 'Use freezedetect filter from ffmpeg, best for board or text')],
|
||||
name='Movie Type')
|
||||
name='Movie Type', default='ANIMATED')
|
||||
|
||||
def invoke(self, context, event):
|
||||
|
||||
if context.scene.sequence_editor.channels.get('Shots'):
|
||||
self.destination_channel_name = 'Shots'
|
||||
sequencer = context.scene.sequence_editor
|
||||
channels = sequencer.channels if sequencer else None
|
||||
selected_strip = context.active_strip
|
||||
if selected_strip is None and context.selected_strips:
|
||||
selected_strip = context.selected_strips[0]
|
||||
|
||||
# Select active channel by default
|
||||
if (strip := context.active_strip) and get_channel_name(strip) != 'Shots':
|
||||
self.source_channel_name = get_channel_name(strip)
|
||||
# Prefer the channel containing the selected strip. With no selected
|
||||
# strip, use the first available channel (channel 0 in the UI list).
|
||||
if selected_strip is not None:
|
||||
source_channel = selected_strip.channel
|
||||
self.source_channel_name = get_channel_name(selected_strip)
|
||||
elif channels and len(channels):
|
||||
source_channel = 0
|
||||
self.source_channel_name = channels[0].name
|
||||
else:
|
||||
source_channel = 0
|
||||
|
||||
# Put the result on the immediately following channel when it exists.
|
||||
# Do not overwrite it when that channel is unavailable.
|
||||
if channels and source_channel + 1 < len(channels):
|
||||
destination_channel = channels[source_channel + 1]
|
||||
self.destination_channel_name = destination_channel.name
|
||||
|
||||
self.frame_start = context.scene.frame_start
|
||||
self.frame_end = context.scene.frame_end
|
||||
@@ -251,6 +308,12 @@ class VSETB_OT_scene_cut_detection(Operator):
|
||||
|
||||
def modal(self, context, event):
|
||||
scn = context.scene
|
||||
# Replace the previous detection result instead of mixing it with the
|
||||
# new one. This is especially important when changing thresholds.
|
||||
for old_strip in list(scn.sequence_editor.strips):
|
||||
if old_strip.name.startswith("tmp_shot_"):
|
||||
scn.sequence_editor.strips.remove(old_strip)
|
||||
|
||||
strips = get_strips(channel=self.source_channel_name)
|
||||
|
||||
i = 1
|
||||
@@ -385,7 +448,9 @@ class VSETB_OT_set_stamps(Operator):
|
||||
|
||||
#stamps_strip = scn.sequence_editor.sequences.new_meta('Stamps', scn.frame_start, scn.frame_end)
|
||||
#stamps_strip.channel = get_channel_index('Stamps')
|
||||
scn.frame_set(scn.frame_current) # For update stamps
|
||||
# frame_set() does not trigger frame_change_post when the frame does
|
||||
# not change, so update the stamp text explicitly for the first view.
|
||||
update_text_strips(scn)
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -748,7 +813,7 @@ class VSETB_OT_create_sequence_strip(Operator):
|
||||
sequence_name: StringProperty(
|
||||
name="Sequence Name",
|
||||
description="Name of the sequence (e.g. SC010)",
|
||||
default="SC010",
|
||||
default="SQ010",
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -763,6 +828,37 @@ class VSETB_OT_create_sequence_strip(Operator):
|
||||
return True
|
||||
|
||||
def invoke(self, context, event):
|
||||
selected_shots = sorted(
|
||||
(s for s in context.selected_strips if get_channel_name(s) == 'Shots'),
|
||||
key=lambda s: s.frame_final_start,
|
||||
)
|
||||
if selected_shots:
|
||||
first_frame = selected_shots[0].frame_final_start
|
||||
sequence_channel = get_channel_index('Sequences')
|
||||
previous = None
|
||||
if sequence_channel:
|
||||
previous = max(
|
||||
(
|
||||
s for s in context.scene.sequence_editor.strips
|
||||
if s.channel == sequence_channel
|
||||
and s.frame_final_end <= first_frame
|
||||
),
|
||||
key=lambda s: s.frame_final_end,
|
||||
default=None,
|
||||
)
|
||||
|
||||
if previous:
|
||||
match = re.search(r'(\d+)$', previous.name)
|
||||
if match:
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
increment = project.sequence_increment if project else 10
|
||||
number = int(match.group(1)) + increment
|
||||
self.sequence_name = (
|
||||
previous.name[:match.start()]
|
||||
+ str(number).zfill(len(match.group(1)))
|
||||
)
|
||||
|
||||
return context.window_manager.invoke_props_dialog(self)
|
||||
|
||||
def execute(self, context):
|
||||
|
||||
Reference in New Issue
Block a user