From ca6fd137ca2a2365313fad9cdc77c845526d8599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8E=9F=E3=80=80=E9=A2=AF=E7=99=BB?= Date: Wed, 4 Nov 2026 22:43:30 +0900 Subject: [PATCH] =?UTF-8?q?refactor(musicvideo):=20=E3=83=97=E3=83=AC?= =?UTF-8?q?=E3=83=93=E3=83=A5=E3=83=BC=E3=81=A83=E3=81=A4=E3=81=AE?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E3=83=91=E3=83=8D=E3=83=AB=E3=81=AB=E7=94=BB?= =?UTF-8?q?=E9=9D=A2=E3=82=92=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/MusicVideoTuningSections.swift | 432 +++++++++++++----- .../MusicVideo/Views/MusicVideoView.swift | 379 ++++++++++----- 2 files changed, 587 insertions(+), 224 deletions(-) diff --git a/ArkServer/Features/MusicVideo/Views/MusicVideoTuningSections.swift b/ArkServer/Features/MusicVideo/Views/MusicVideoTuningSections.swift index f712f01..720da68 100644 --- a/ArkServer/Features/MusicVideo/Views/MusicVideoTuningSections.swift +++ b/ArkServer/Features/MusicVideo/Views/MusicVideoTuningSections.swift @@ -2,90 +2,95 @@ import SwiftUI +/// 表示する操作のまとまり。映像を作るための設定値は持たない。 +enum MusicVideoInspectorPane: String, CaseIterable, Identifiable { + case inputs = "曲と素材" + case rhythm = "リズム" + case finish = "仕上げ" + + var id: String { rawValue } +} + /// 「カット割り」「見た目と音」「書き出し」の調整項目。 /// /// 映像ができているときは、項目を変えると、すぐにプレビューとタイムラインが変わる(乱数の種は変えないので、 /// 変えた項目だけの違いが出る)。各項目の説明には、いまの曲での秒数や、いまのカット割りの結果を数値で添える。 struct MusicVideoTuningSections: View { @ObservedObject var viewModel: MusicVideoViewModel + let pane: MusicVideoInspectorPane var body: some View { - VStack(alignment: .leading, spacing: 28) { - cutSection - lookSection - exportSection + VStack(alignment: .leading, spacing: 24) { + switch pane { + case .inputs: + EmptyView() + case .rhythm: + cutSection + case .finish: + lookSection + exportSection + } } + .disabled(viewModel.isWorking) } // MARK: - カット割り private var cutSection: some View { - SettingsSection( - title: "カット割り", - footer: viewModel.plan == nil - ? "映像を作ると、ここを変えるたびにプレビューが変わります." - : "変えるとすぐに映像へ反映されます.気に入らなければ「元に戻す」で戻せます." - ) { - SettingsGroup { - SettingsRow(title: "カットの細かさ", detail: cutStyleDetail) { - FlatSegmentedControl( - options: MusicVideoCutStyle.allCases, - title: \.displayName, - selection: $viewModel.cutStyle, - width: 210 - ) - } - SettingsRow(title: "最短のカット", detail: minimumDetail) { - Picker("最短のカット", selection: minimumBinding) { - ForEach(MusicVideoCutTuning.minimumChoices, id: \.self) { value in - Text(Self.seconds(value)).tag(value) - } - } - .labelsHidden() - .fixedSize() - } - SettingsRow(title: "最長のカット", detail: maximumDetail) { - Picker("最長のカット", selection: maximumBinding) { - Text("制限なし").tag(Double?.none) - ForEach(MusicVideoCutTuning.maximumChoices, id: \.self) { value in - Text(Self.seconds(value)).tag(Double?.some(value)) - } + VStack(alignment: .leading, spacing: 24) { + MusicVideoField(title: "カットの細かさ", detail: cutStyleDetail) { + HStack(spacing: 8) { + ForEach(MusicVideoCutStyle.allCases, id: \.self) { style in + MusicVideoChoiceButton( + title: style.displayName, + isSelected: viewModel.cutStyle == style, + rhythmMarks: rhythmMarks(for: style) + ) { viewModel.cutStyle = style } } - .labelsHidden() - .fixedSize() } - SettingsRow(title: "動きの合わせ方", detail: motionDetail) { - FlatSegmentedControl( - options: MotionMatching.allCases, - title: \.displayName, - selection: $viewModel.cutTuning.motionMatching, - width: 300 - ) + } + + MusicVideoField(title: "動きの合わせ方", detail: motionDetail) { + MusicVideoChoices(options: MotionMatching.allCases, title: \.displayName, selection: $viewModel.cutTuning.motionMatching) + } + MusicVideoField(title: "拍への合わせ込み", detail: hitSyncDetail) { + MusicVideoChoices(options: HitSync.allCases, title: \.displayName, selection: $viewModel.cutTuning.hitSync) + } + MusicVideoField(title: "動画のばらけ具合", detail: varietyDetail) { + MusicVideoChoices(options: VideoVariety.allCases, title: \.displayName, selection: $viewModel.cutTuning.variety, minimumWidth: 100) + } + + MusicVideoFoldout(title: "カットの長さとタイミング", summary: cutLengthSummary) { + MusicVideoField(title: "最短のカット", detail: minimumDetail) { + MusicVideoChoices(options: MusicVideoCutTuning.minimumChoices, title: Self.seconds, selection: minimumBinding) } - SettingsRow(title: "拍への合わせ込み", detail: hitSyncDetail) { - FlatSegmentedControl( - options: HitSync.allCases, - title: \.displayName, - selection: $viewModel.cutTuning.hitSync, - width: 240 + MusicVideoField(title: "最長のカット", detail: maximumDetail) { + MusicVideoChoices( + options: [Double?.none] + MusicVideoCutTuning.maximumChoices.map { Double?.some($0) }, + title: { $0.map(Self.seconds) ?? "制限なし" }, + selection: maximumBinding ) } - SettingsRow(title: "動画のばらけ具合", detail: varietyDetail) { - Picker("動画のばらけ具合", selection: $viewModel.cutTuning.variety) { - ForEach(VideoVariety.allCases, id: \.self) { Text($0.displayName).tag($0) } - } - .labelsHidden() - .fixedSize() - } - SettingsRow(title: "切り替えのタイミング", detail: viewModel.cutTuning.alignment.summary) { - Picker("切り替えのタイミング", selection: $viewModel.cutTuning.alignment) { - ForEach(CutAlignment.allCases, id: \.self) { Text($0.displayName).tag($0) } - } - .labelsHidden() - .fixedSize() + MusicVideoField(title: "切り替えのタイミング", detail: viewModel.cutTuning.alignment.summary) { + MusicVideoChoices(options: CutAlignment.allCases, title: \.displayName, selection: $viewModel.cutTuning.alignment, minimumWidth: 120) } } - .disabled(viewModel.isWorking) + + Text(viewModel.plan == nil ? "映像を作ったあとも,ここで調整できます" : "変更はプレビューへ反映されます.カットの編集から元に戻せます") + .font(.appCaption) + .foregroundStyle(NeomorphicTheme.muted) + } + } + + private var cutLengthSummary: String { + "\(Self.seconds(viewModel.cutTuning.minimumCutDuration))〜\(viewModel.cutTuning.maximumCutDuration.map(Self.seconds) ?? "上限なし")" + } + + private func rhythmMarks(for style: MusicVideoCutStyle) -> Int { + switch style { + case .relaxed: return 3 + case .standard: return 5 + case .energetic: return 8 } } @@ -153,44 +158,29 @@ struct MusicVideoTuningSections: View { // MARK: - 見た目と音 private var lookSection: some View { - SettingsSection(title: "見た目と音") { - SettingsGroup { - SettingsRow(title: "画面サイズ", detail: renderDetail) { - Picker("画面サイズ", selection: $viewModel.renderPreset) { - ForEach(MusicVideoRenderPreset.allCases, id: \.self) { preset in - Text(preset.displayName).tag(preset) - } + VStack(alignment: .leading, spacing: 24) { + MusicVideoField(title: "画面サイズ", detail: renderDetail) { + LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())], spacing: 8) { + ForEach(MusicVideoRenderPreset.allCases, id: \.self) { preset in + MusicVideoChoiceButton( + title: preset.displayName, + isSelected: viewModel.renderPreset == preset, + frameAspect: preset.isPortrait ? 9.0 / 16 : 16.0 / 9 + ) { viewModel.renderPreset = preset } } - .labelsHidden() - .fixedSize() - } - SettingsRow(title: "画面の合わせ方", detail: viewModel.lookTuning.fitMode.summary) { - FlatSegmentedControl( - options: MusicVideoFitMode.allCases, - title: \.displayName, - selection: $viewModel.lookTuning.fitMode, - width: 230 - ) } - SettingsRow(title: "切り替え効果", detail: viewModel.lookTuning.transition.summary) { - FlatSegmentedControl( - options: MusicVideoTransition.allCases, - title: \.displayName, - selection: $viewModel.lookTuning.transition, - width: 300 - ) - } - SettingsRow(title: "最初と最後のフェード", detail: fadeDetail) { - Picker("最初と最後のフェード", selection: $viewModel.lookTuning.fadeSeconds) { - ForEach(MusicVideoLookTuning.fadeChoices, id: \.self) { value in - Text(value == 0 ? "なし" : Self.seconds(value)).tag(value) - } - } - .labelsHidden() - .fixedSize() + } + MusicVideoField(title: "画面の合わせ方", detail: viewModel.lookTuning.fitMode.summary) { + MusicVideoChoices(options: MusicVideoFitMode.allCases, title: \.displayName, selection: $viewModel.lookTuning.fitMode, minimumWidth: 120) + } + MusicVideoField(title: "切り替え効果", detail: viewModel.lookTuning.transition.summary) { + MusicVideoChoices(options: MusicVideoTransition.allCases, title: \.displayName, selection: $viewModel.lookTuning.transition, minimumWidth: 100) + } + MusicVideoFoldout(title: "映像と音のフェード", summary: viewModel.lookTuning.fadeSeconds == 0 ? "なし" : Self.seconds(viewModel.lookTuning.fadeSeconds)) { + MusicVideoField(title: "最初と最後のフェード", detail: fadeDetail) { + MusicVideoChoices(options: MusicVideoLookTuning.fadeChoices, title: { $0 == 0 ? "なし" : Self.seconds($0) }, selection: $viewModel.lookTuning.fadeSeconds) } } - .disabled(viewModel.isWorking) } } @@ -212,19 +202,8 @@ struct MusicVideoTuningSections: View { // MARK: - 書き出し private var exportSection: some View { - SettingsSection(title: "書き出し") { - SettingsGroup { - SettingsRow(title: "書き出しの画質", detail: exportSizeText) { - Picker("書き出しの画質", selection: $viewModel.exportQuality) { - ForEach(MusicVideoExportQuality.allCases, id: \.self) { quality in - Text(quality.displayName).tag(quality) - } - } - .labelsHidden() - .fixedSize() - } - } - .disabled(viewModel.isWorking) + MusicVideoField(title: "書き出しの画質", detail: exportSizeText) { + MusicVideoChoices(options: MusicVideoExportQuality.allCases, title: \.displayName, selection: $viewModel.exportQuality) } } @@ -244,6 +223,235 @@ struct MusicVideoTuningSections: View { } } +// MARK: - ミュージックビデオ画面の操作部品 + +/// 項目名・選択肢・説明の順に並べ,狭いパネルでも操作の幅を確保する。 +struct MusicVideoField: View { + let title: String + var detail: String? = nil + @ViewBuilder var content: Content + + var body: some View { + VStack(alignment: .leading, spacing: 8) { + Text(title) + .font(.appBodyStrong) + .foregroundStyle(NeomorphicTheme.ink) + content + if let detail { + Text(detail) + .font(.appCaption) + .foregroundStyle(NeomorphicTheme.muted) + .fixedSize(horizontal: false, vertical: true) + } + } + .frame(maxWidth: .infinity, alignment: .leading) + .accessibilityElement(children: .contain) + .accessibilityLabel(title) + } +} + +/// 選択肢は幅が足りないときに折り返す。値の変更は既存のBindingへそのまま渡す。 +struct MusicVideoChoices: View { + let options: [Option] + let title: (Option) -> String + @Binding var selection: Option + var minimumWidth: CGFloat = 64 + + var body: some View { + ViewThatFits(in: .horizontal) { + HStack(spacing: 8) { + ForEach(options, id: \.self) { option in + optionButton(option) + .frame(minWidth: minimumWidth) + } + } + LazyVGrid(columns: [GridItem(.adaptive(minimum: minimumWidth), spacing: 8)], spacing: 8) { + ForEach(options, id: \.self) { option in + optionButton(option) + } + } + } + } + + private func optionButton(_ option: Option) -> some View { + MusicVideoChoiceButton(title: title(option), isSelected: selection == option) { + selection = option + } + } +} + +/// 明るさの差と短い青線で選択中を示す。図は設定の意味を表す場合だけ付ける。 +struct MusicVideoChoiceButton: View { + let title: String + let isSelected: Bool + var rhythmMarks: Int? = nil + var frameAspect: CGFloat? = nil + let action: () -> Void + + @Environment(\.isEnabled) private var isEnabled + @State private var isHovering = false + @FocusState private var isFocused: Bool + + private let cornerRadius: CGFloat = 8 + + var body: some View { + Button(action: action) { + VStack(spacing: 12) { + if let rhythmMarks { + HStack(spacing: 4) { + ForEach(0..: View { + let title: String + var summary: String = "" + var selectedCutIndex: Int? = nil + @ViewBuilder var content: Content + @State private var isExpanded = false + + var body: some View { + VStack(alignment: .leading, spacing: 16) { + Button { + isExpanded.toggle() + } label: { + HStack(spacing: 8) { + Image(systemName: isExpanded ? "chevron.down" : "chevron.right") + .font(.system(size: 10, weight: .medium)) + .frame(width: 12) + Text(title) + .font(.appCaptionStrong) + Spacer(minLength: 4) + Text(summary) + .font(.appMicro.monospacedDigit()) + .foregroundStyle(NeomorphicTheme.muted) + .lineLimit(1) + } + .foregroundStyle(NeomorphicTheme.ink) + .frame(maxWidth: .infinity, minHeight: 24) + .contentShape(Rectangle()) + } + .buttonStyle(.plain) + .accessibilityLabel(title) + .accessibilityValue(isExpanded ? "展開中" : "折りたたみ中") + .accessibilityHint("押すと詳細設定を開閉します") + + if isExpanded { content } + } + .padding(16) + .background(GlassCardSurface()) + .onAppear { + if selectedCutIndex != nil { isExpanded = true } + } + .onChange(of: selectedCutIndex) { _, selected in + if selected != nil { isExpanded = true } + } + } +} + +/// チェック操作を画面のタイルと同じ線・面で描く。 +struct MusicVideoCheckStyle: ToggleStyle { + func makeBody(configuration: Configuration) -> some View { + Button { + configuration.isOn.toggle() + } label: { + HStack(spacing: 8) { + ZStack { + RoundedRectangle(cornerRadius: 4) + .fill(configuration.isOn ? NeomorphicTheme.ink : NeomorphicTheme.control) + RoundedRectangle(cornerRadius: 4) + .strokeBorder(NeomorphicTheme.cardBorder, lineWidth: 1) + if configuration.isOn { + Image(systemName: "checkmark") + .font(.system(size: 10, weight: .semibold)) + .foregroundStyle(NeomorphicTheme.canvas) + } + } + .frame(width: 20, height: 20) + configuration.label + .font(.appCaption) + .foregroundStyle(NeomorphicTheme.ink) + } + .contentShape(Rectangle()) + } + .buttonStyle(.plain) + .accessibilityValue(configuration.isOn ? "オン" : "オフ") + } +} + +/// 作成ボタンを最も明るくし,保存などの操作は控えめな面にする。 +struct MusicVideoActionStyle: ButtonStyle { + var isPrimary = false + @Environment(\.isEnabled) private var isEnabled + + func makeBody(configuration: Configuration) -> some View { + configuration.label + .font(.appCaptionStrong) + .foregroundStyle(isPrimary ? NeomorphicTheme.canvas : NeomorphicTheme.ink) + .padding(.horizontal, 16) + .padding(.vertical, 12) + .background( + RoundedRectangle(cornerRadius: 8) + .fill(isPrimary ? NeomorphicTheme.ink : NeomorphicTheme.control) + ) + .overlay { + RoundedRectangle(cornerRadius: 8) + .strokeBorder(NeomorphicTheme.cardBorder, lineWidth: 1) + } + .opacity(isEnabled ? (configuration.isPressed ? 0.75 : 1) : 0.4) + } +} + // MARK: - いまの結果 /// プレビューの下に出す、いまのカット割りの結果。調整項目を変えるたびに数値が変わる。 @@ -295,7 +503,7 @@ struct MusicRangeControl: View { let range = viewModel.musicRange let start = range?.start ?? 0 let end = range?.end ?? duration - SettingsRow(title: "使う範囲", detail: detail(start: start, end: end, duration: duration, isPartial: range != nil)) { + MusicVideoField(title: "使う範囲", detail: detail(start: start, end: end, duration: duration, isPartial: range != nil)) { VStack(alignment: .trailing, spacing: 6) { sliderRow(label: "開始", value: start, bounds: 0...(duration - MusicRange.minimumLength)) { viewModel.setMusicRange(start: $0, end: max(end, $0 + MusicRange.minimumLength)) @@ -324,7 +532,7 @@ struct MusicRangeControl: View { .font(.appMicro) .foregroundStyle(NeomorphicTheme.muted) Slider(value: Binding(get: { value }, set: onChange), in: bounds) - .frame(width: 170) + .frame(minWidth: 100, maxWidth: .infinity) Text(Self.clock(value)) .font(.appCaption.monospacedDigit()) .foregroundStyle(NeomorphicTheme.muted) diff --git a/ArkServer/Features/MusicVideo/Views/MusicVideoView.swift b/ArkServer/Features/MusicVideo/Views/MusicVideoView.swift index a6105df..6367ebd 100644 --- a/ArkServer/Features/MusicVideo/Views/MusicVideoView.swift +++ b/ArkServer/Features/MusicVideo/Views/MusicVideoView.swift @@ -7,8 +7,8 @@ import UniformTypeIdentifiers /// 曲を選ぶと、ライブラリの動画から曲に合わせた映像を自動で作る画面。 /// -/// 設定画面のように、中央の1列に「セクション名 + 行をまとめた面」を縦に並べる。 -/// 結果ができたら、プレビューとカットの編集を一番上に出す。実行ボタンは下に固定して常に見せる。 +/// プレビューと操作パネルを並べ,作成に必要な入力と細かな調整を分ける。 +/// 狭い窓では上下に積み,実行ボタンは下に固定して常に見せる。 struct MusicVideoView: View { @ObservedObject var viewModel: MusicVideoViewModel @ObservedObject var dataManager: LibraryViewModel @@ -19,6 +19,7 @@ struct MusicVideoView: View { @State private var returnAnchor: String? @State private var isShowingMusicPicker = false @State private var isShowingExportAlbumPicker = false + @State private var inspectorPane: MusicVideoInspectorPane = .inputs /// プレビューを全画面で開く。 @State private var fullScreen = MusicVideoFullScreenPresenter() /// プレビューの高さが、窓の高さに占める割合。境目をドラッグして変える。次回も保つ。 @@ -38,6 +39,9 @@ struct MusicVideoView: View { private static let stackedPreviewExtras: CGFloat = 150 /// プレビューをスクロールの中に置くとき(窓が低いとき)の中身の高さ。 private static let inlinePreviewContentHeight: CGFloat = 480 + private static let workspaceMinimumWidth: CGFloat = 1_040 + private static let inspectorWidth: CGFloat = 400 + private static let workspaceMaximumWidth: CGFloat = 1_440 var body: some View { Group { @@ -102,68 +106,179 @@ struct MusicVideoView: View { /// ミュージックビデオの本体(プレビュー・曲・素材・調整項目)。 private var mainContent: some View { GeometryReader { geometry in - // 調整項目を変えたときの変化をその場で見られるよう、窓が十分に高ければ、プレビューを上に固定する。 - let pinsPreview = viewModel.plan != nil && geometry.size.height >= Self.pinnedPreviewMinimumHeight - let pinnedHeight = pinnedRegionHeight(windowHeight: geometry.size.height) VStack(spacing: 0) { - if pinsPreview { - VStack(spacing: 0) { - previewSection(contentHeight: pinnedHeight - Self.pinnedPreviewChrome, showsCaption: false) - .frame(maxWidth: settingsColumnWidth) - .frame(maxWidth: .infinity) - .padding(.horizontal, 24) - .padding(.top, 14) - .padding(.bottom, 8) - .frame(height: pinnedHeight - 10, alignment: .top) - .clipped() - previewResizeHandle(windowHeight: geometry.size.height) - } - .background(NeomorphicTheme.canvas) - } - - ScrollViewReader { proxy in - ScrollView { - VStack(alignment: .leading, spacing: 28) { - // 見出しは列の左端にそろえる(LibraryPageHeader は左右に24の余白を持つ)。 - LibraryPageHeader( - title: "ミュージックビデオ", - subtitle: "曲を選ぶと,ライブラリの動画を曲の盛り上がりに合わせて自動で編集します" - ) - .padding(.horizontal, -24) - .id(Self.topAnchor) - - if viewModel.plan != nil { - if !pinsPreview { - previewSection(contentHeight: Self.inlinePreviewContentHeight, showsCaption: true) + workspaceHeader + Divider().overlay(NeomorphicTheme.separator) + + if geometry.size.width >= Self.workspaceMinimumWidth { + HStack(alignment: .top, spacing: 0) { + ScrollView { + VStack(alignment: .leading, spacing: 20) { + if viewModel.plan != nil { + previewSection(contentHeight: max(320, geometry.size.height - 240), showsCaption: true) + cutEditor + } else { + previewPlaceholder + .frame(minHeight: max(360, geometry.size.height - 240)) } - MusicVideoCutEditorView(viewModel: viewModel, dataManager: dataManager) } - musicSection - .id(Self.musicAnchor) - sourceSection - .id(Self.sourceAnchor) - MusicVideoTuningSections(viewModel: viewModel) + .padding(24) } + .frame(maxWidth: .infinity, maxHeight: .infinity) + Divider().overlay(NeomorphicTheme.separator) + inspector(includesPreview: false) + .frame(width: Self.inspectorWidth) + } + .frame(maxWidth: Self.workspaceMaximumWidth) + .frame(maxWidth: .infinity) + } else { + compactWorkspace(height: max(0, geometry.size.height - 140)) + } + + actionBar + } + } + } + + private var workspaceHeader: some View { + HStack(alignment: .center, spacing: 16) { + VStack(alignment: .leading, spacing: 4) { + Text("ミュージックビデオ") + .font(.appTitle) + .foregroundStyle(NeomorphicTheme.ink) + Text("曲と素材を選んで,映像をつくる") + .font(.appCaption) + .foregroundStyle(NeomorphicTheme.muted) + } + Spacer(minLength: 8) + VStack(alignment: .trailing, spacing: 4) { + Text(viewModel.renderPreset.displayName) + .font(.appCaptionStrong) + if let duration = viewModel.targetDuration { + Text(formatTime(duration)) + .font(.appMonoCaption) + } + } + .foregroundStyle(NeomorphicTheme.muted) + } + .padding(.horizontal, 24) + .padding(.vertical, 16) + } + + /// 高さのある窓ではプレビューを固定し,境目のドラッグによるサイズ変更も残す。 + private func compactWorkspace(height: CGFloat) -> some View { + let pinsPreview = viewModel.plan != nil && height >= Self.pinnedPreviewMinimumHeight + let pinnedHeight = pinnedRegionHeight(windowHeight: height) + return VStack(spacing: 0) { + if pinsPreview { + VStack(spacing: 0) { + previewSection(contentHeight: pinnedHeight - Self.pinnedPreviewChrome, showsCaption: false) .frame(maxWidth: settingsColumnWidth) .frame(maxWidth: .infinity) .padding(.horizontal, 24) - .padding(.bottom, 28) + .padding(.top, 14) + .padding(.bottom, 8) + .frame(height: pinnedHeight - 10, alignment: .top) + .clipped() + previewResizeHandle(windowHeight: height) + } + } + inspector(includesPreview: !pinsPreview, showsCutEditor: true) + } + } + + private func inspector(includesPreview: Bool, showsCutEditor: Bool = false) -> some View { + VStack(spacing: 0) { + HStack(spacing: 8) { + ForEach(MusicVideoInspectorPane.allCases) { pane in + MusicVideoChoiceButton(title: pane.rawValue, isSelected: inspectorPane == pane) { + inspectorPane = pane } - // 映像ができたら、一番上のプレビューが見えるようにする。 - .onChange(of: viewModel.plan != nil) { _, hasPlan in - if hasPlan { withAnimation { proxy.scrollTo(Self.topAnchor, anchor: .top) } } + .accessibilityIdentifier("musicvideo.pane.\(pane.id)") + } + } + .frame(maxWidth: settingsColumnWidth) + .padding(16) + + ScrollViewReader { proxy in + ScrollView { + VStack(alignment: .leading, spacing: 24) { + if includesPreview, viewModel.plan != nil { + previewSection(contentHeight: Self.inlinePreviewContentHeight, showsCaption: true) + .id(Self.topAnchor) + } + if viewModel.plan != nil, showsCutEditor { + cutEditor + } + if inspectorPane == .inputs { + musicSection.id(Self.musicAnchor) + sourceSection.id(Self.sourceAnchor) + } else { + MusicVideoTuningSections(viewModel: viewModel, pane: inspectorPane) + } } - // 素材・曲を選ぶ画面から戻ったときは、その欄を見せる。 - .onAppear { - guard let anchor = returnAnchor else { return } - returnAnchor = nil - proxy.scrollTo(anchor, anchor: .top) + .frame(maxWidth: settingsColumnWidth) + .frame(maxWidth: .infinity, alignment: .top) + .padding(20) + .padding(.bottom, 12) + } + .id(inspectorPane) + .onAppear { + guard let anchor = returnAnchor else { return } + returnAnchor = nil + proxy.scrollTo(anchor, anchor: .top) + } + .onChange(of: viewModel.plan != nil) { _, hasPlan in + if hasPlan, includesPreview { + proxy.scrollTo(Self.topAnchor, anchor: .top) } } + } + } + } - actionBar + private var cutEditor: some View { + MusicVideoFoldout( + title: "カットの編集", + summary: viewModel.selectedCutIndex.map { "カット \($0 + 1)" } ?? "差し替え・履歴", + selectedCutIndex: viewModel.selectedCutIndex + ) { + MusicVideoCutEditorView(viewModel: viewModel, dataManager: dataManager) + } + } + + private var previewPlaceholder: some View { + VStack(spacing: 24) { + Spacer(minLength: 24) + Image(systemName: "play.rectangle") + .font(.system(size: 48, weight: .ultraLight)) + .foregroundStyle(NeomorphicTheme.muted) + .accessibilityHidden(true) + VStack(spacing: 8) { + Text("ここで仕上がりを確認") + .font(.appHeadline) + .foregroundStyle(NeomorphicTheme.ink) + Text("曲と素材を選んで「映像を作る」を押してください") + .font(.appCaption) + .foregroundStyle(NeomorphicTheme.muted) + .multilineTextAlignment(.center) } + Spacer(minLength: 24) + HStack(spacing: 16) { + Label(viewModel.musicTitle ?? "曲を選択", systemImage: viewModel.musicURL == nil ? "circle" : "checkmark.circle") + .lineLimit(1) + .truncationMode(.middle) + Spacer(minLength: 0) + Text("素材 \(viewModel.candidateCount.formatted())本") + .monospacedDigit() + .fixedSize() + } + .font(.appCaption) + .foregroundStyle(NeomorphicTheme.muted) } + .padding(24) + .frame(maxWidth: .infinity) + .background(GlassCardSurface()) } // MARK: - プレビュー @@ -282,14 +397,33 @@ struct MusicVideoView: View { // MARK: - 曲 private var musicSection: some View { - SettingsSection(title: "曲") { - SettingsGroup { - SettingsRow(title: viewModel.musicTitle ?? "曲を選んでください", detail: musicDetail) { - HStack(spacing: 8) { + VStack(alignment: .leading, spacing: 16) { + MusicVideoField(title: "使う曲", detail: musicDetail) { + VStack(alignment: .leading, spacing: 16) { + HStack(spacing: 12) { + Image(systemName: "music.note") + .font(.system(size: 20, weight: .light)) + .foregroundStyle(NeomorphicTheme.muted) + .frame(width: 28) + VStack(alignment: .leading, spacing: 4) { + Text(viewModel.musicTitle ?? "曲を選んでください") + .font(.appBodyStrong) + .foregroundStyle(NeomorphicTheme.ink) + .lineLimit(2) + .truncationMode(.middle) + if let analysis = viewModel.fullAnalysis { + Text("\(formatTime(analysis.duration)) · \(Int(analysis.tempo.rounded())) BPM · 拍 \(analysis.beats.count)個") + .font(.appMicro.monospacedDigit()) + .foregroundStyle(NeomorphicTheme.muted) + } + } + Spacer(minLength: 0) if viewModel.phase == .analyzingMusic { ProgressView().controlSize(.small) } if let url = viewModel.musicURL { MusicPreviewButton(preview: viewModel.preview, url: url) { viewModel.togglePreview(url) } } + } + HStack(spacing: 8) { Button("フォルダから…") { returnAnchor = Self.musicAnchor isShowingMusicPicker = true @@ -303,25 +437,26 @@ struct MusicVideoView: View { .accessibilityIdentifier("musicvideo.musicFile") if !viewModel.recentMusicURLs.isEmpty { recentMenu } } - .disabled(viewModel.isWorking) } - if viewModel.musicURL == nil, let last = viewModel.lastMusicURL { - SettingsRow(title: "前回の曲", detail: last.deletingPathExtension().lastPathComponent) { - HStack(spacing: 8) { - MusicPreviewButton(preview: viewModel.preview, url: last) { viewModel.togglePreview(last) } - Button("開く") { viewModel.chooseMusic(last) } - .buttonStyle(.quiet) - .disabled(viewModel.isWorking) - .accessibilityIdentifier("musicvideo.openLastMusic") - } + .padding(16) + .frame(maxWidth: .infinity, alignment: .leading) + .background(GlassCardSurface()) + .disabled(viewModel.isWorking) + } + + if viewModel.musicURL == nil, let last = viewModel.lastMusicURL { + MusicVideoField(title: "前回の曲", detail: last.deletingPathExtension().lastPathComponent) { + HStack(spacing: 8) { + MusicPreviewButton(preview: viewModel.preview, url: last) { viewModel.togglePreview(last) } + Button("開く") { viewModel.chooseMusic(last) } + .buttonStyle(.quiet) + .disabled(viewModel.isWorking) + .accessibilityIdentifier("musicvideo.openLastMusic") } } - if let analysis = viewModel.fullAnalysis { - SettingsRow(title: "テンポと拍") { - Text("\(formatTime(analysis.duration))・\(Int(analysis.tempo.rounded())) BPM・拍 \(analysis.beats.count)個") - .font(.appBody.monospacedDigit()) - .foregroundStyle(NeomorphicTheme.muted) - } + } + if viewModel.fullAnalysis != nil { + MusicVideoFoldout(title: "曲の使う範囲", summary: viewModel.musicRange == nil ? "曲全体" : (viewModel.targetDuration.map(formatTime) ?? "")) { MusicRangeControl(viewModel: viewModel) } } @@ -381,40 +516,49 @@ struct MusicVideoView: View { } private var sourceSection: some View { - SettingsSection(title: "素材") { - SettingsGroup { - SettingsRow( - title: viewModel.candidateCount == 0 ? "素材がまだ選ばれていません" : "使える動画 \(viewModel.candidateCount.formatted())本", - detail: sourceDetail - ) { + VStack(alignment: .leading, spacing: 16) { + MusicVideoField(title: "素材の動画") { + VStack(alignment: .leading, spacing: 16) { + HStack(alignment: .firstTextBaseline, spacing: 8) { + Text(viewModel.candidateCount.formatted()) + .font(.system(size: 32, weight: .medium, design: .monospaced)) + .foregroundStyle(NeomorphicTheme.ink) + Text("本の動画") + .font(.appCaption) + .foregroundStyle(NeomorphicTheme.muted) + Spacer(minLength: 0) + Button("選ぶ…") { + returnAnchor = Self.sourceAnchor + isShowingSourcePicker = true + } + .buttonStyle(.quiet) + .accessibilityIdentifier("musicvideo.chooseSource") + } + Text(sourceDetail ?? "アルバムや動画を選んでください") + .font(.appCaption) + .foregroundStyle(NeomorphicTheme.muted) + .fixedSize(horizontal: false, vertical: true) HStack(spacing: 8) { + Toggle("お気に入りを含める", isOn: $viewModel.includeFavorites) + .toggleStyle(MusicVideoCheckStyle()) + Spacer(minLength: 0) if !(viewModel.selectedAlbumIDs.isEmpty && viewModel.selectedVideoIDs.isEmpty) { Button("解除") { viewModel.clearSourceSelection() } .buttonStyle(.quiet) .help("アルバムと動画の選択をすべて外します") } - Button("選ぶ…") { - returnAnchor = Self.sourceAnchor - isShowingSourcePicker = true - } - .buttonStyle(.quiet) - .accessibilityIdentifier("musicvideo.chooseSource") } - .disabled(viewModel.isWorking) - } - SettingsRow(title: "お気に入りを含める", detail: "お気に入りにした動画も素材に加えます.") { - SettingsSwitch(title: "お気に入りを含める", isOn: $viewModel.includeFavorites) - .disabled(viewModel.isWorking) } - SettingsRow(title: "解析に使う動画の本数", detail: sourceLimitDetail) { - Picker("解析に使う動画の本数", selection: $viewModel.sourceLimit) { - ForEach(MusicVideoSourceLimit.choices, id: \.self) { Text("\($0)本").tag($0) } - } - .labelsHidden() - .fixedSize() - .disabled(viewModel.isWorking) - .accessibilityIdentifier("musicvideo.sourceLimit") + .padding(16) + .background(GlassCardSurface()) + .disabled(viewModel.isWorking) + } + MusicVideoFoldout(title: "素材の解析本数", summary: "最大\(viewModel.sourceLimit)本") { + MusicVideoField(title: "解析に使う動画の本数", detail: sourceLimitDetail) { + MusicVideoChoices(options: MusicVideoSourceLimit.choices, title: { "\($0)本" }, selection: $viewModel.sourceLimit) + .accessibilityIdentifier("musicvideo.sourceLimit") } + .disabled(viewModel.isWorking) } } } @@ -455,25 +599,42 @@ struct MusicVideoView: View { private var actionBar: some View { VStack(spacing: 0) { Divider().overlay(NeomorphicTheme.separator) - HStack(spacing: 12) { - statusView - .frame(maxWidth: .infinity, alignment: .leading) + ViewThatFits(in: .horizontal) { + HStack(spacing: 24) { + statusView + .frame(maxWidth: .infinity, alignment: .leading) + actionButtons + } + VStack(alignment: .leading, spacing: 12) { + statusView + HStack { + Spacer(minLength: 0) + actionButtons + } + } + } + .frame(maxWidth: Self.workspaceMaximumWidth) + .frame(maxWidth: .infinity) + .padding(.horizontal, 24) + .padding(.vertical, 16) + } + .background(NeomorphicTheme.canvas) + } + private var actionButtons: some View { + HStack(spacing: 8) { if viewModel.isWorking { Button("中止") { viewModel.cancelWork() } - .buttonStyle(.bordered) - .controlSize(.large) + .buttonStyle(MusicVideoActionStyle()) .accessibilityIdentifier("musicvideo.cancel") } else { if viewModel.plan != nil { Button("ファイルに保存…") { saveToFile() } - .buttonStyle(.bordered) - .controlSize(.large) + .buttonStyle(MusicVideoActionStyle()) .disabled(!viewModel.canExport) .accessibilityIdentifier("musicvideo.saveFile") Button("ライブラリに追加…") { isShowingExportAlbumPicker = true } - .buttonStyle(.bordered) - .controlSize(.large) + .buttonStyle(MusicVideoActionStyle()) .disabled(!viewModel.canExport) .help("追加するアルバムを選んで,書き出してライブラリに追加します") .accessibilityIdentifier("musicvideo.exportLibrary") @@ -481,19 +642,13 @@ struct MusicVideoView: View { Button(viewModel.plan == nil ? "映像を作る" : "作り直す") { viewModel.generate(dataManager: dataManager) } - .buttonStyle(.borderedProminent) - .controlSize(.large) + .buttonStyle(MusicVideoActionStyle(isPrimary: true)) .disabled(!viewModel.canGenerate) .help(viewModel.plan == nil ? "曲に合わせて映像を作ります" : "別のカット割りで作り直します") .accessibilityIdentifier("musicvideo.generate") } - } - .frame(maxWidth: settingsColumnWidth) - .frame(maxWidth: .infinity) - .padding(.horizontal, 24) - .padding(.vertical, 14) } - .background(NeomorphicTheme.canvas) + .fixedSize(horizontal: true, vertical: false) } @ViewBuilder