Clean-up add set stamps
This commit is contained in:
+99
-33
@@ -8,12 +8,39 @@ from pathlib import Path
|
||||
from vse_toolbox.bl_utils import get_scene_settings, get_strip_settings
|
||||
from vse_toolbox.constants import SOUND_SUFFIXES
|
||||
|
||||
def new_text_strip(name='Text', channel=0, start=0, end=50, text='Text', font_size=48,
|
||||
x=0.5, y=0.5, align_x='CENTER', align_y='CENTER', select=False,
|
||||
box_color=None, box_margin=0.005):
|
||||
|
||||
sequences = bpy.context.scene.sequence_editor.sequences
|
||||
strip = sequences.new_effect(name, 'TEXT', channel, frame_start=start, frame_end=end)
|
||||
strip.select = select
|
||||
strip.text = text
|
||||
strip.location.x = x
|
||||
strip.location.y = y
|
||||
strip.align_y = align_y
|
||||
strip.align_x = align_x
|
||||
strip.channel = channel
|
||||
strip.font_size = font_size
|
||||
|
||||
if box_color:
|
||||
strip.use_box = True
|
||||
strip.box_color = box_color
|
||||
strip.box_margin = box_margin
|
||||
|
||||
return strip
|
||||
|
||||
def is_strip_at(strip, frame=None):
|
||||
if frame is None:
|
||||
frame = bpy.context.scene.frame_current
|
||||
|
||||
return (strip.frame_final_start <= frame < strip.frame_final_end)
|
||||
|
||||
def get_strips(channel=0, selected_only=False):
|
||||
scn = bpy.context.scene
|
||||
|
||||
if isinstance(channel, str):
|
||||
channel = get_channel(channel)
|
||||
channel = get_channel_index(channel)
|
||||
|
||||
strips = [s for s in scn.sequence_editor.sequences_all if s.channel==channel]
|
||||
|
||||
@@ -22,7 +49,11 @@ def get_strips(channel=0, selected_only=False):
|
||||
|
||||
return sorted(strips, key=lambda x : x.frame_final_start)
|
||||
|
||||
def get_channel(name):
|
||||
def get_strip_at(channel=0, frame=None):
|
||||
strips = get_strips(channel=channel)
|
||||
return next((s for s in strips if is_strip_at(s, frame)), None)
|
||||
|
||||
def get_channel_index(name):
|
||||
scn = bpy.context.scene
|
||||
|
||||
channel_id = 0
|
||||
@@ -32,9 +63,19 @@ def get_channel(name):
|
||||
|
||||
return channel_id
|
||||
|
||||
def get_shot_sequence(shot):
|
||||
sequences = get_strips(channel='Sequences')
|
||||
return next((s.name for s in sequences if s.frame_final_start<=shot.frame_final_start<s.frame_final_end), '')
|
||||
def get_channel_name(strip):
|
||||
if not strip:
|
||||
return
|
||||
|
||||
scn = bpy.context.scene
|
||||
return scn.sequence_editor.channels[strip.channel].name
|
||||
|
||||
def get_strip_sequence_name(strip):
|
||||
sequence_strip = get_strip_at(channel='Sequences', frame=strip.frame_final_start)
|
||||
if sequence_strip:
|
||||
return sequence_strip.name
|
||||
else:
|
||||
return 'NoSequence'
|
||||
|
||||
def rename_strips(
|
||||
strips, template, increment=10, start_number=0, by_sequence=False):
|
||||
@@ -42,20 +83,23 @@ def rename_strips(
|
||||
settings = get_scene_settings()
|
||||
|
||||
project = settings.active_project
|
||||
episode = settings.active_episode
|
||||
episode_name = ''
|
||||
if settings.active_episode:
|
||||
episode_name = episode.name
|
||||
|
||||
previous_sequence = None
|
||||
prev_sequence_name = None
|
||||
strip_number = 0
|
||||
|
||||
for strip in strips:
|
||||
sequence = get_shot_sequence(strip)
|
||||
sequence_name = get_strip_sequence_name(strip)
|
||||
|
||||
if (by_sequence and previous_sequence and
|
||||
sequence and sequence != previous_sequence):
|
||||
if (by_sequence and prev_sequence_name and
|
||||
sequence_name and sequence != prev_sequence_name):
|
||||
strip_number = 0
|
||||
|
||||
name = template.format(
|
||||
episode=episode.name,
|
||||
sequence=sequence_name,
|
||||
episode=episode_name,
|
||||
index=strip_number*increment+start_number
|
||||
)
|
||||
|
||||
@@ -66,7 +110,7 @@ def rename_strips(
|
||||
print(f'Renaming {strip.name} -> {name}')
|
||||
strip.name = name
|
||||
|
||||
previous_sequence = sequence
|
||||
prev_sequence_name = sequence_name
|
||||
strip_number += 1
|
||||
|
||||
def set_channels():
|
||||
@@ -126,10 +170,10 @@ def import_edit(filepath, adapter="cmx_3600", clean_sequencer=False):
|
||||
|
||||
# FIXME Exclude Audio for now
|
||||
if any(child.name.lower().endswith(ext) for ext in SOUND_SUFFIXES):
|
||||
channel = get_channel('Audio')
|
||||
channel = get_channel_index('Audio')
|
||||
continue
|
||||
|
||||
channel = get_channel('Shots')
|
||||
channel = get_channel_index('Shots')
|
||||
frame_start = otio.opentime.to_frames(
|
||||
child.range_in_parent().start_time)
|
||||
|
||||
@@ -164,7 +208,7 @@ def import_movie(filepath):
|
||||
strip = scn.sequence_editor.sequences.new_movie(
|
||||
name=filepath.stem,
|
||||
filepath=str(filepath),
|
||||
channel=get_channel('Movie'),
|
||||
channel=get_channel_index('Movie'),
|
||||
frame_start=scn.frame_start
|
||||
)
|
||||
|
||||
@@ -187,7 +231,7 @@ def import_sound(filepath):
|
||||
strip = scn.sequence_editor.sequences.new_sound(
|
||||
name=filepath.stem,
|
||||
filepath=str(filepath),
|
||||
channel=get_channel('Audio'),
|
||||
channel=get_channel_index('Audio'),
|
||||
frame_start=scn.frame_start
|
||||
)
|
||||
|
||||
@@ -212,30 +256,52 @@ def clean_sequencer(edit=False, movie=False, sound=False):
|
||||
scn.sequence_editor.sequences.remove(sequence)
|
||||
|
||||
@persistent
|
||||
def get_active_strip(scene):
|
||||
scn = bpy.context.scene
|
||||
def set_active_strip(scene):
|
||||
#scn = bpy.context.scene
|
||||
settings = get_scene_settings()
|
||||
|
||||
if settings.auto_select_strip == False:
|
||||
if not settings.auto_select_strip:
|
||||
return
|
||||
|
||||
screen = bpy.context.screen
|
||||
|
||||
bpy.ops.sequencer.select_all(action="DESELECT")
|
||||
#scene.sequence_editor.active_strip = None
|
||||
|
||||
strip = None
|
||||
frame_current = scn.frame_current
|
||||
shot_strip = get_strip_at('Shots')
|
||||
if shot_strip:
|
||||
shot_strip.select = True
|
||||
scene.sequence_editor.active_strip = shot_strip
|
||||
|
||||
strips = bpy.context.sequences
|
||||
strips = sorted(strips,key=lambda x: (x.channel, x.frame_final_start))
|
||||
@persistent
|
||||
def update_text_strips(scene):
|
||||
#scn = bpy.context.scene
|
||||
format_data = {
|
||||
'scene': scene,
|
||||
'active_shot_name': 'None',
|
||||
'active_shot_frame': 0,
|
||||
'active_shot_duration': 0,
|
||||
'active_shot_start': 0,
|
||||
'active_shot_end': 0
|
||||
}
|
||||
|
||||
for strip in strips:
|
||||
#FIXME Pas propre de mettre le channel name en dur
|
||||
if strip.channel != get_channel('Shots') or 0:
|
||||
shot_strip = get_strip_at('Shots', frame=scene.frame_current)
|
||||
if shot_strip:
|
||||
format_data.update({
|
||||
'active_shot_name': shot_strip.name,
|
||||
'active_shot_duration': shot_strip.frame_final_duration,
|
||||
'active_shot_frame': scene.frame_current - shot_strip.frame_final_start + 1,
|
||||
'active_shot_start': shot_strip.frame_final_start,
|
||||
'active_shot_end': shot_strip.frame_final_end,
|
||||
})
|
||||
|
||||
for strip in scene.sequence_editor.sequences_all:
|
||||
if not strip.type == 'TEXT':
|
||||
continue
|
||||
if (not strip.lock
|
||||
and strip.frame_final_end >= frame_current
|
||||
and strip.frame_final_start <= frame_current):
|
||||
|
||||
strip.select = True
|
||||
scn.sequence_editor.active_strip = strip
|
||||
if not is_strip_at(strip):
|
||||
continue
|
||||
|
||||
if '{' in strip.text:
|
||||
strip['text_pattern'] = strip.text
|
||||
|
||||
if 'text_pattern' in strip.keys():
|
||||
strip.text = strip['text_pattern'].format(**format_data)
|
||||
Reference in New Issue
Block a user