|
|
""" |
|
|
拡張キーフレーム処理モジュール |
|
|
キーフレーム処理に関する拡張機能を提供します |
|
|
""" |
|
|
|
|
|
import gradio as gr |
|
|
|
|
|
from locales.i18n_extended import translate |
|
|
|
|
|
from eichi_utils.video_mode_settings import ( |
|
|
get_total_sections, |
|
|
get_important_keyframes, |
|
|
get_video_seconds, |
|
|
MODE_TYPE_LOOP |
|
|
) |
|
|
from eichi_utils.keyframe_handler import code_to_ui_index, get_max_keyframes_count |
|
|
from eichi_utils.frame_calculator import calculate_sections_for_mode_and_size |
|
|
|
|
|
def extended_mode_length_change_handler(mode, length, section_number_inputs, section_row_groups=None, frame_size_setting="_KEY_FRAME_SIZE_1SEC", enable_keyframe_copy=None): |
|
|
"""モードと動画長の変更を統一的に処理する関数(セクション行の表示/非表示制御を追加) |
|
|
|
|
|
Args: |
|
|
mode: モード ("通常" or "ループ") |
|
|
length: 動画長 ("6秒", "8秒", "10秒", "12秒", "16秒", "20秒") |
|
|
section_number_inputs: セクション番号入力欄のリスト |
|
|
section_row_groups: セクション行のUIグループリスト(オプション) |
|
|
frame_size_setting: フレームサイズ設定 ("1秒 (33フレーム)" or "0.5秒 (17フレーム)") |
|
|
enable_keyframe_copy: キーフレーム自動コピー機能の有効/無効状態(オプション) |
|
|
|
|
|
Returns: |
|
|
更新リスト: 各UI要素の更新情報のリスト |
|
|
""" |
|
|
|
|
|
is_loop_mode = (mode == MODE_TYPE_LOOP) |
|
|
|
|
|
|
|
|
|
|
|
if is_loop_mode and enable_keyframe_copy is not None: |
|
|
is_copy_enabled = enable_keyframe_copy |
|
|
print(translate("[keyframe_handler_extended] ループモードでキーフレーム自動コピー機能の状態: {state}").format(state=is_copy_enabled)) |
|
|
else: |
|
|
|
|
|
is_copy_enabled = is_loop_mode |
|
|
print(translate("[keyframe_handler_extended] モード変更によるキーフレーム自動コピー機能のデフォルト状態: {state}").format(state=is_copy_enabled)) |
|
|
|
|
|
if not is_loop_mode: |
|
|
print(translate("[keyframe_handler_extended] 通常モードで強制的に赤枠/青枠を非表示に設定")) |
|
|
else: |
|
|
print(translate("[keyframe_handler_extended] ループモードで赤枠/青枠を表示可能に設定")) |
|
|
|
|
|
|
|
|
updates = [gr.update(value=None) for _ in range(2)] |
|
|
|
|
|
|
|
|
section_image_count = get_max_keyframes_count() |
|
|
for _ in range(section_image_count): |
|
|
updates.append(gr.update(value=None, elem_classes="")) |
|
|
|
|
|
|
|
|
for i in range(len(section_number_inputs)): |
|
|
section_number_inputs[i].elem_classes = "" |
|
|
|
|
|
|
|
|
important_kfs = get_important_keyframes(length) |
|
|
for idx in important_kfs: |
|
|
ui_idx = code_to_ui_index(idx) |
|
|
update_idx = ui_idx + 1 |
|
|
if update_idx < len(updates): |
|
|
|
|
|
if not is_loop_mode: |
|
|
updates[update_idx] = gr.update(value=None, elem_classes="") |
|
|
if idx < len(section_number_inputs): |
|
|
section_number_inputs[idx].elem_classes = "" |
|
|
continue |
|
|
|
|
|
|
|
|
if not is_copy_enabled: |
|
|
updates[update_idx] = gr.update(value=None, elem_classes="") |
|
|
if idx < len(section_number_inputs): |
|
|
section_number_inputs[idx].elem_classes = "" |
|
|
continue |
|
|
|
|
|
|
|
|
if idx == 0: |
|
|
|
|
|
updates[update_idx] = gr.update(value=None, elem_classes="highlighted-keyframe-red") |
|
|
if idx < len(section_number_inputs): |
|
|
section_number_inputs[idx].elem_classes = "highlighted-label-red" |
|
|
elif idx == 1: |
|
|
|
|
|
updates[update_idx] = gr.update(value=None, elem_classes="highlighted-keyframe-blue") |
|
|
if idx < len(section_number_inputs): |
|
|
section_number_inputs[idx].elem_classes = "highlighted-label-blue" |
|
|
else: |
|
|
|
|
|
updates[update_idx] = gr.update(value=None, elem_classes="highlighted-keyframe") |
|
|
if idx < len(section_number_inputs): |
|
|
section_number_inputs[idx].elem_classes = "highlighted-label" |
|
|
|
|
|
|
|
|
|
|
|
if is_loop_mode and is_copy_enabled and 0 not in important_kfs: |
|
|
print(translate("[keyframe_handler_extended] ループモードでセクション0に赤枠を適用")) |
|
|
updates[2] = gr.update(value=None, elem_classes="highlighted-keyframe-red") |
|
|
if 0 < len(section_number_inputs): |
|
|
section_number_inputs[0].elem_classes = "highlighted-label-red" |
|
|
elif not (is_loop_mode and is_copy_enabled): |
|
|
print(translate("[keyframe_handler_extended] モードまたはコピー機能状態により、セクション0の赤枠を適用せず")) |
|
|
|
|
|
updates[2] = gr.update(value=None, elem_classes="") |
|
|
|
|
|
|
|
|
video_length = get_video_seconds(length) |
|
|
|
|
|
|
|
|
updates.append(gr.update(value=video_length)) |
|
|
|
|
|
|
|
|
if section_row_groups is not None: |
|
|
|
|
|
required_sections = calculate_sections_for_mode_and_size(length, frame_size_setting) |
|
|
print(translate("動画モード '{length}' とフレームサイズ '{frame_size_setting}' で必要なセクション数: {required_sections}").format(length=length, frame_size_setting=frame_size_setting, required_sections=required_sections)) |
|
|
|
|
|
|
|
|
row_updates = [] |
|
|
for i, _ in enumerate(section_row_groups): |
|
|
if i < required_sections: |
|
|
row_updates.append(gr.update(visible=True)) |
|
|
else: |
|
|
row_updates.append(gr.update(visible=False)) |
|
|
|
|
|
|
|
|
updates.extend(row_updates) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return updates |
|
|
|