| 1 | |
| 2 | |
| 3 | use crate::*; |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 15 | pub(crate) enum Enable { |
| 16 | Yes, |
| 17 | No(&'static str), |
| 18 | Hidden(&'static str), |
| 19 | } |
| 20 | |
| 21 | impl Enable { |
| 22 | |
| 23 | pub(crate) fn yes(self) -> bool { |
| 24 | self == Enable::Yes |
| 25 | } |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | pub(crate) fn listed(self) -> bool { |
| 31 | !matches!(self, Enable::Hidden(_)) |
| 32 | } |
| 33 | |
| 34 | |
| 35 | pub(crate) fn why(self) -> Option<&'static str> { |
| 36 | match self { |
| 37 | Enable::Yes => None, |
| 38 | Enable::No(why) | Enable::Hidden(why) => Some(why), |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | #[derive(Clone, Default)] |
| 48 | pub(crate) struct Ctx { |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | pub(crate) clip: Option<(Clip, Lane)>, |
| 54 | |
| 55 | |
| 56 | pub(crate) gap: bool, |
| 57 | |
| 58 | pub(crate) gap_here: bool, |
| 59 | |
| 60 | pub(crate) clip_here: bool, |
| 61 | |
| 62 | pub(crate) words: bool, |
| 63 | |
| 64 | pub(crate) rendering: bool, |
| 65 | |
| 66 | pub(crate) asset: bool, |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | pub(crate) caption: bool, |
| 73 | |
| 74 | |
| 75 | |
| 76 | pub(crate) image: bool, |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | pub(crate) no_sound: bool, |
| 83 | pub(crate) playhead: u32, |
| 84 | |
| 85 | pub(crate) timeline: bool, |
| 86 | |
| 87 | pub(crate) clipboard: bool, |
| 88 | |
| 89 | |
| 90 | pub(crate) subtitles: bool, |
| 91 | |
| 92 | |
| 93 | |
| 94 | pub(crate) playable: bool, |
| 95 | pub(crate) exporting: bool, |
| 96 | |
| 97 | |
| 98 | |
| 99 | pub(crate) picks: usize, |
| 100 | pub(crate) pick_lanes: usize, |
| 101 | |
| 102 | |
| 103 | pub(crate) caption_link: Option<u32>, |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | pub(crate) locked: bool, |
| 109 | |
| 110 | |
| 111 | |
| 112 | pub(crate) nothing_to_undo: bool, |
| 113 | pub(crate) nothing_to_redo: bool, |
| 114 | |
| 115 | |
| 116 | |
| 117 | pub(crate) alone: bool, |
| 118 | |
| 119 | |
| 120 | pub(crate) no_join: bool, |
| 121 | |
| 122 | |
| 123 | pub(crate) no_partner: bool, |
| 124 | |
| 125 | pub(crate) compound: bool, |
| 126 | |
| 127 | pub(crate) multicam: bool, |
| 128 | |
| 129 | pub(crate) media_picks: usize, |
| 130 | pub(crate) monitor: bool, |
| 131 | |
| 132 | pub(crate) angles_here: usize, |
| 133 | |
| 134 | |
| 135 | pub(crate) sequences: usize, |
| 136 | pub(crate) sequence_used: bool, |
| 137 | |
| 138 | pub(crate) parent: bool, |
| 139 | } |
| 140 | |
| 141 | |
| 142 | |
| 143 | pub(crate) const LOCKED_REASON: &str = "The track is locked"; |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | fn edits_placement(action: ActionId) -> bool { |
| 149 | matches!( |
| 150 | action, |
| 151 | ActionId::Cut |
| 152 | | ActionId::Regroup |
| 153 | | ActionId::Detach |
| 154 | | ActionId::Group |
| 155 | | ActionId::Delete |
| 156 | | ActionId::Lift |
| 157 | | ActionId::Paste |
| 158 | | ActionId::PasteAttributes |
| 159 | | ActionId::PasteColor |
| 160 | | ActionId::PasteEffects |
| 161 | | ActionId::PasteTransform |
| 162 | | ActionId::PasteSpeed |
| 163 | | ActionId::PasteAudio |
| 164 | | ActionId::NudgeBack |
| 165 | | ActionId::NudgeForward |
| 166 | | ActionId::NudgeBack10 |
| 167 | | ActionId::NudgeForward10 |
| 168 | | ActionId::ExtendAudio |
| 169 | | ActionId::ExtendVideo |
| 170 | | ActionId::Crossfade |
| 171 | | ActionId::Dissolve |
| 172 | | ActionId::TransitionDissolve |
| 173 | | ActionId::TransitionDipBlack |
| 174 | | ActionId::TransitionDipWhite |
| 175 | | ActionId::TransitionWipeLeft |
| 176 | | ActionId::TransitionWipeRight |
| 177 | | ActionId::TransitionWipeUp |
| 178 | | ActionId::TransitionWipeDown |
| 179 | | ActionId::TransitionSlideLeft |
| 180 | | ActionId::TransitionSlideRight |
| 181 | | ActionId::TransitionSlideUp |
| 182 | | ActionId::TransitionSlideDown |
| 183 | | ActionId::TransitionPushLeft |
| 184 | | ActionId::TransitionPushRight |
| 185 | | ActionId::TransitionPushUp |
| 186 | | ActionId::TransitionPushDown |
| 187 | | ActionId::TransitionZoom |
| 188 | | ActionId::Color |
| 189 | | ActionId::Fit |
| 190 | | ActionId::Reframe |
| 191 | | ActionId::TrackMask |
| 192 | | ActionId::NestClips |
| 193 | | ActionId::BreakApart |
| 194 | | ActionId::Transform |
| 195 | | ActionId::Effects |
| 196 | | ActionId::KeyPlacement |
| 197 | | ActionId::KeyOpacity |
| 198 | | ActionId::KeyColor |
| 199 | | ActionId::KeyEasing |
| 200 | | ActionId::Equalizer |
| 201 | | ActionId::Silence |
| 202 | | ActionId::Reverse |
| 203 | | ActionId::SpeedRampUp |
| 204 | | ActionId::SpeedRampDown |
| 205 | | ActionId::SpeedRampSlowFastSlow |
| 206 | | ActionId::SpeedRampFastSlowFast |
| 207 | | ActionId::SpeedRampKey |
| 208 | | ActionId::SpeedRampClear |
| 209 | | ActionId::Mix |
| 210 | | ActionId::CleanVoice |
| 211 | | ActionId::VoiceDynamics |
| 212 | | ActionId::TrimIn |
| 213 | | ActionId::TrimOut |
| 214 | | ActionId::TrimInToPlayhead |
| 215 | | ActionId::TrimOutToPlayhead |
| 216 | | ActionId::RippleTrimInToPlayhead |
| 217 | | ActionId::RippleTrimOutToPlayhead |
| 218 | | ActionId::RollBack |
| 219 | | ActionId::RollForward |
| 220 | | ActionId::SlipBack |
| 221 | | ActionId::SlipForward |
| 222 | | ActionId::SlideBack |
| 223 | | ActionId::SlideForward |
| 224 | | ActionId::LoopTrim |
| 225 | ) |
| 226 | } |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { |
| 234 | if action == ActionId::CancelRender && !ctx.rendering { |
| 235 | return Enable::No("nothing is rendering"); |
| 236 | } |
| 237 | if action == ActionId::CutSelectedWords && !ctx.words { |
| 238 | return Enable::No("no transcript words picked"); |
| 239 | } |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | if action == ActionId::Theme |
| 258 | || action == ActionId::AccentColour |
| 259 | || action == ActionId::Fullscreen |
| 260 | || action == ActionId::SubtitleStyle |
| 261 | |
| 262 | |
| 263 | |
| 264 | || action == ActionId::FocusPanels |
| 265 | |
| 266 | |
| 267 | || action == ActionId::ShowKeys |
| 268 | || action == ActionId::About |
| 269 | |
| 270 | || action == ActionId::ViewZoom |
| 271 | || action == ActionId::PlaybackQuality |
| 272 | || action == ActionId::GuideStyle |
| 273 | || action == ActionId::GuideMask |
| 274 | |
| 275 | || action == ActionId::ToggleOutputWindow |
| 276 | || action == ActionId::OutputDisplay |
| 277 | { |
| 278 | return Enable::Yes; |
| 279 | } |
| 280 | if action == ActionId::Settings { |
| 281 | return match ctx.exporting { |
| 282 | true => Enable::No("an export is running"), |
| 283 | false => Enable::Yes, |
| 284 | }; |
| 285 | } |
| 286 | if action == ActionId::ShowActions { |
| 287 | return match ctx.exporting { |
| 288 | true => Enable::No("an export is running"), |
| 289 | false => Enable::Yes, |
| 290 | }; |
| 291 | } |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | if matches!( |
| 302 | action, |
| 303 | ActionId::ToggleSnap |
| 304 | | ActionId::ToggleMute |
| 305 | | ActionId::VolumeUp |
| 306 | | ActionId::VolumeDown |
| 307 | | ActionId::ToggleProxies |
| 308 | | ActionId::ToggleAutoProxies |
| 309 | |
| 310 | |
| 311 | |
| 312 | | ActionId::Resolution |
| 313 | |
| 314 | |
| 315 | |
| 316 | | ActionId::AddFiles |
| 317 | | ActionId::PasteFilePath |
| 318 | |
| 319 | | ActionId::NewProject |
| 320 | |
| 321 | | ActionId::OpenProject |
| 322 | ) { |
| 323 | return match ctx.exporting { |
| 324 | true => Enable::No("an export is running"), |
| 325 | false => Enable::Yes, |
| 326 | }; |
| 327 | } |
| 328 | |
| 329 | |
| 330 | if action == ActionId::Export && !ctx.exporting && !ctx.playable { |
| 331 | return Enable::No("the timeline is empty"); |
| 332 | } |
| 333 | if !ctx.timeline { |
| 334 | return Enable::No("no timeline open"); |
| 335 | } |
| 336 | |
| 337 | |
| 338 | if ctx.exporting { |
| 339 | return match action { |
| 340 | ActionId::CancelExport => Enable::Yes, |
| 341 | _ => Enable::No("an export is running"), |
| 342 | }; |
| 343 | } |
| 344 | |
| 345 | |
| 346 | |
| 347 | if ctx.locked && edits_placement(action) { |
| 348 | return Enable::No(LOCKED_REASON); |
| 349 | } |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | if ctx.caption |
| 368 | && matches!( |
| 369 | action, |
| 370 | ActionId::Copy |
| 371 | | ActionId::Delete |
| 372 | | ActionId::Lift |
| 373 | | ActionId::Equalizer |
| 374 | | ActionId::NestClips |
| 375 | | ActionId::BreakApart |
| 376 | | ActionId::OpenCompound |
| 377 | ) |
| 378 | { |
| 379 | return match action { |
| 380 | ActionId::Delete => Enable::Yes, |
| 381 | _ => Enable::Hidden("this is a caption"), |
| 382 | }; |
| 383 | } |
| 384 | |
| 385 | |
| 386 | if ctx.compound |
| 387 | && ctx.clip.is_some() |
| 388 | && matches!( |
| 389 | action, |
| 390 | ActionId::Speed |
| 391 | | ActionId::SpeedRampUp |
| 392 | | ActionId::SpeedRampDown |
| 393 | | ActionId::SpeedRampSlowFastSlow |
| 394 | | ActionId::SpeedRampFastSlowFast |
| 395 | | ActionId::SpeedRampKey |
| 396 | | ActionId::SpeedRampClear |
| 397 | | ActionId::Reverse |
| 398 | | ActionId::Color |
| 399 | | ActionId::AutoColour |
| 400 | | ActionId::SaveLook |
| 401 | | ActionId::Transform |
| 402 | | ActionId::Effects |
| 403 | | ActionId::KeyPlacement |
| 404 | | ActionId::KeyOpacity |
| 405 | | ActionId::KeyColor |
| 406 | | ActionId::KeyEasing |
| 407 | | ActionId::Fit |
| 408 | | ActionId::Equalizer |
| 409 | | ActionId::Silence |
| 410 | | ActionId::Visualizer |
| 411 | | ActionId::Reframe |
| 412 | | ActionId::TrackMask |
| 413 | | ActionId::Mix |
| 414 | | ActionId::CleanVoice |
| 415 | | ActionId::VoiceDynamics |
| 416 | ) |
| 417 | { |
| 418 | return Enable::Hidden("a compound clip plays a sequence"); |
| 419 | } |
| 420 | match action { |
| 421 | ActionId::Undo if ctx.nothing_to_undo => return Enable::No("nothing to undo"), |
| 422 | ActionId::Redo if ctx.nothing_to_redo => return Enable::No("nothing to redo"), |
| 423 | _ => {} |
| 424 | } |
| 425 | match action { |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | ActionId::Equalizer | ActionId::Crossfade => match ctx.clip { |
| 432 | Some((_, lane)) if lane.kind != LaneKind::Audio => { |
| 433 | Enable::Hidden("this clip is picture") |
| 434 | } |
| 435 | _ => Enable::Yes, |
| 436 | }, |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | a if matches!( |
| 442 | a, |
| 443 | ActionId::Color |
| 444 | | ActionId::Fit |
| 445 | | ActionId::Transform |
| 446 | | ActionId::Effects |
| 447 | | ActionId::KeyPlacement |
| 448 | | ActionId::KeyOpacity |
| 449 | | ActionId::KeyColor |
| 450 | | ActionId::KeyEasing |
| 451 | | ActionId::Dissolve |
| 452 | ) || a.transition_kind().is_some() => |
| 453 | { |
| 454 | match ctx.clip { |
| 455 | Some((_, lane)) if lane.kind != LaneKind::Video => { |
| 456 | Enable::Hidden("this clip is sound") |
| 457 | } |
| 458 | _ => Enable::Yes, |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | ActionId::MarkBeats if ctx.image || ctx.no_sound => Enable::No("Pick a clip with sound"), |
| 469 | ActionId::Silence | ActionId::Mix | ActionId::CleanVoice | ActionId::VoiceDynamics |
| 470 | if ctx.image => Enable::Hidden("this clip is a still"), |
| 471 | |
| 472 | ActionId::Reverse if ctx.image => Enable::Hidden("this clip is a still"), |
| 473 | |
| 474 | |
| 475 | ActionId::NewSequence | ActionId::DuplicateSequence if ctx.sequences >= engine::project::MAX_SEQUENCES => { |
| 476 | Enable::No("the project holds as many sequences as it can") |
| 477 | } |
| 478 | ActionId::NewSequence | ActionId::DuplicateSequence | ActionId::RenameSequence => Enable::Yes, |
| 479 | ActionId::DeleteSequence if ctx.sequences <= 1 => Enable::No("this is the only sequence"), |
| 480 | ActionId::DeleteSequence if ctx.sequence_used => Enable::No("a compound clip plays this sequence"), |
| 481 | ActionId::DeleteSequence => Enable::Yes, |
| 482 | ActionId::CloseCompound if !ctx.parent => Enable::No("this sequence was not opened from a compound clip"), |
| 483 | ActionId::CloseCompound => Enable::Yes, |
| 484 | ActionId::ZoomToSelection if ctx.picks == 0 => Enable::No("Select a clip first"), |
| 485 | ActionId::NestClips if ctx.picks == 0 && ctx.clip.is_none() => Enable::No("select the clips to nest"), |
| 486 | ActionId::NestClips => Enable::Yes, |
| 487 | ActionId::CreateMulticam if ctx.media_picks < 2 => Enable::No("Needs two or more picked clips"), |
| 488 | ActionId::CreateMulticam => Enable::Yes, |
| 489 | ActionId::FlattenMulticam if ctx.multicam => Enable::Yes, |
| 490 | ActionId::FlattenMulticam => match ctx.clip { |
| 491 | None => Enable::No("select a multicam clip"), |
| 492 | Some(_) => Enable::Hidden("not a multicam clip"), |
| 493 | }, |
| 494 | ActionId::ToggleAngleMonitor | ActionId::ToggleWaveforms | ActionId::ToggleScrubAudio | ActionId::CompareOff | ActionId::CompareSplit | ActionId::CompareSide => Enable::Yes, |
| 495 | |
| 496 | ActionId::Angle1 |
| 497 | | ActionId::Angle2 |
| 498 | | ActionId::Angle3 |
| 499 | | ActionId::Angle4 |
| 500 | | ActionId::Angle5 |
| 501 | | ActionId::Angle6 |
| 502 | | ActionId::Angle7 |
| 503 | | ActionId::Angle8 |
| 504 | | ActionId::Angle9 |
| 505 | if !ctx.monitor || ctx.angles_here == 0 => |
| 506 | { |
| 507 | Enable::Hidden("the angle monitor is off or no multicam clip is under the playhead") |
| 508 | } |
| 509 | ActionId::Angle1 |
| 510 | | ActionId::Angle2 |
| 511 | | ActionId::Angle3 |
| 512 | | ActionId::Angle4 |
| 513 | | ActionId::Angle5 |
| 514 | | ActionId::Angle6 |
| 515 | | ActionId::Angle7 |
| 516 | | ActionId::Angle8 |
| 517 | | ActionId::Angle9 => { |
| 518 | let n = action.angle_number().unwrap_or(0); |
| 519 | if n > ctx.angles_here { Enable::No("this multicam clip has fewer angles") } else { Enable::Yes } |
| 520 | } |
| 521 | ActionId::BreakApart | ActionId::OpenCompound => match ctx.clip { |
| 522 | None => Enable::No("select a compound clip"), |
| 523 | Some(_) if !ctx.compound => Enable::Hidden("not a compound clip"), |
| 524 | Some(_) => Enable::Yes, |
| 525 | }, |
| 526 | |
| 527 | ActionId::TrackMask => match &ctx.clip { |
| 528 | Some((_, lane)) if lane.kind != LaneKind::Video => Enable::Hidden("this clip is sound"), |
| 529 | Some((c, _)) if !c.effects.iter().any(|e| matches!(e.kind, engine::effects::EffectKind::RectMask | engine::effects::EffectKind::EllipseMask)) => { |
| 530 | Enable::No("no rect or ellipse mask") |
| 531 | } |
| 532 | Some(_) => Enable::Yes, |
| 533 | None => Enable::No("select a video clip"), |
| 534 | }, |
| 535 | |
| 536 | ActionId::Reframe => match ctx.clip { |
| 537 | Some((_, lane)) if lane.kind != LaneKind::Video => Enable::Hidden("this clip is sound"), |
| 538 | Some(_) if ctx.image => Enable::Hidden("this clip is a still"), |
| 539 | Some(_) => Enable::Yes, |
| 540 | None => Enable::No("select a video clip"), |
| 541 | }, |
| 542 | ActionId::Visualizer if ctx.image => Enable::Hidden("this clip is a still"), |
| 543 | ActionId::Visualizer if ctx.no_sound => Enable::Hidden("this clip has no sound"), |
| 544 | ActionId::Visualizer => match ctx.clip { |
| 545 | Some(_) => Enable::Yes, |
| 546 | None => Enable::No("select a clip with sound"), |
| 547 | }, |
| 548 | ActionId::Silence | ActionId::Mix | ActionId::CleanVoice | ActionId::VoiceDynamics |
| 549 | if ctx.no_sound => { |
| 550 | Enable::Hidden("this clip has no sound") |
| 551 | } |
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | ActionId::Cut => match ctx.clip { |
| 558 | Some((clip, _)) if !(clip.start < ctx.playhead && ctx.playhead < clip.end()) => { |
| 559 | Enable::No("only from inside a clip") |
| 560 | } |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 | Some((clip, _)) if !clip.splits_at(ctx.playhead) => Enable::No(match clip.speed_keys.is_empty() { |
| 568 | true => "this speed holds one frame here", |
| 569 | false => "this speed ramp cannot be cut at this frame", |
| 570 | }), |
| 571 | _ => Enable::Yes, |
| 572 | }, |
| 573 | |
| 574 | |
| 575 | |
| 576 | ActionId::Regroup => match ctx.clip { |
| 577 | Some((clip, _)) if ctx.playhead != clip.start && ctx.playhead != clip.end() => { |
| 578 | Enable::No("only where two clips meet") |
| 579 | } |
| 580 | Some(_) if ctx.no_join => Enable::No("no cut under the playhead to close"), |
| 581 | _ => Enable::Yes, |
| 582 | }, |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | ActionId::Detach => match (ctx.clip, ctx.caption) { |
| 588 | (Some((clip, _)), _) if clip.link.is_none() || ctx.alone => { |
| 589 | Enable::No("this clip is not grouped") |
| 590 | } |
| 591 | (None, true) if ctx.caption_link.is_none() => Enable::No("this caption is not grouped"), |
| 592 | _ => Enable::Yes, |
| 593 | }, |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | |
| 599 | ActionId::Group => match ctx.picks { |
| 600 | 2.. if ctx.pick_lanes == ctx.picks => Enable::Yes, |
| 601 | 2.. => Enable::No("a lane is picked twice"), |
| 602 | _ if ctx.clip.is_some() && ctx.no_partner => { |
| 603 | Enable::No("needs a clip on another track at the same time") |
| 604 | } |
| 605 | _ => Enable::Yes, |
| 606 | }, |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | |
| 612 | ActionId::Delete if ctx.gap => Enable::Yes, |
| 613 | ActionId::Copy | ActionId::Delete | ActionId::Lift if ctx.clip.is_none() => { |
| 614 | Enable::No("nothing selected") |
| 615 | } |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | ActionId::WalkCutNext |
| 621 | | ActionId::WalkCutPrev |
| 622 | | ActionId::WalkCutNext10 |
| 623 | | ActionId::WalkCutPrev10 |
| 624 | | ActionId::TrimIn |
| 625 | | ActionId::TrimOut |
| 626 | | ActionId::LoopTrim |
| 627 | if ctx.clip.is_none() => |
| 628 | { |
| 629 | Enable::No("no clip is selected") |
| 630 | } |
| 631 | |
| 632 | |
| 633 | ActionId::SlipBack | ActionId::SlipForward if ctx.image => { |
| 634 | Enable::Hidden("this clip is a still") |
| 635 | } |
| 636 | |
| 637 | |
| 638 | |
| 639 | ActionId::RollBack |
| 640 | | ActionId::RollForward |
| 641 | | ActionId::SlipBack |
| 642 | | ActionId::SlipForward |
| 643 | | ActionId::SlideBack |
| 644 | | ActionId::SlideForward |
| 645 | if ctx.clip.is_none() => |
| 646 | { |
| 647 | Enable::No("no clip is selected") |
| 648 | } |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | ActionId::TrimInToPlayhead |
| 655 | | ActionId::TrimOutToPlayhead |
| 656 | | ActionId::RippleTrimInToPlayhead |
| 657 | | ActionId::RippleTrimOutToPlayhead => match ctx.clip { |
| 658 | None => Enable::No("no clip is selected"), |
| 659 | Some((clip, _)) if ctx.playhead < clip.start || ctx.playhead > clip.end() => { |
| 660 | Enable::No("the playhead is off this clip") |
| 661 | } |
| 662 | _ => Enable::Yes, |
| 663 | }, |
| 664 | ActionId::Paste if !ctx.clipboard => Enable::No("nothing copied yet"), |
| 665 | ActionId::CloseGap if !ctx.gap_here => Enable::No("no gap under the playhead"), |
| 666 | ActionId::Freeze | ActionId::MatchFrame if !ctx.clip_here => Enable::No("nothing under the playhead"), |
| 667 | ActionId::ReplaceEdit if !ctx.clip_here => Enable::No("nothing under the playhead"), |
| 668 | ActionId::ReplaceEdit if !ctx.asset => Enable::No("no library item selected"), |
| 669 | ActionId::PasteAttributes |
| 670 | | ActionId::PasteColor |
| 671 | | ActionId::PasteEffects |
| 672 | | ActionId::PasteTransform |
| 673 | | ActionId::PasteSpeed |
| 674 | | ActionId::PasteAudio |
| 675 | if !ctx.clipboard => |
| 676 | { |
| 677 | Enable::No("nothing copied yet") |
| 678 | } |
| 679 | ActionId::PasteAttributes |
| 680 | | ActionId::PasteColor |
| 681 | | ActionId::PasteEffects |
| 682 | | ActionId::PasteTransform |
| 683 | | ActionId::PasteSpeed |
| 684 | | ActionId::PasteAudio |
| 685 | | ActionId::NudgeBack |
| 686 | | ActionId::NudgeForward |
| 687 | | ActionId::NudgeBack10 |
| 688 | | ActionId::NudgeForward10 |
| 689 | if ctx.picks == 0 && ctx.clip.is_none() => |
| 690 | { |
| 691 | Enable::No("no clips selected") |
| 692 | } |
| 693 | ActionId::ExtendAudio | ActionId::ExtendVideo => { |
| 694 | let want = if action == ActionId::ExtendAudio { LaneKind::Audio } else { LaneKind::Video }; |
| 695 | match ctx.clip { |
| 696 | None => Enable::No("no clip selected"), |
| 697 | Some((_, lane)) if lane.kind == want => Enable::Yes, |
| 698 | Some((clip, _)) if clip.link.is_none() || ctx.alone => Enable::No(match want { |
| 699 | LaneKind::Audio => "select the sound clip, or group it with the picture", |
| 700 | _ => "select the picture clip, or group it with the sound", |
| 701 | }), |
| 702 | Some(_) => Enable::Yes, |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | |
| 707 | |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | ActionId::ToggleSubtitles if !ctx.subtitles => Enable::No("no subtitles yet"), |
| 713 | |
| 714 | |
| 715 | |
| 716 | ActionId::CancelExport => Enable::Hidden("nothing is exporting"), |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | ActionId::ShuttleStop | ActionId::ShuttleBack | ActionId::ShuttleForward if ctx.exporting => { |
| 723 | Enable::No("an export is running") |
| 724 | } |
| 725 | ActionId::Play | ActionId::Loop | ActionId::PlayAround | ActionId::ShuttleBack | ActionId::ShuttleForward |
| 726 | if !ctx.playable => { |
| 727 | Enable::No("the timeline is empty") |
| 728 | } |
| 729 | |
| 730 | |
| 731 | |
| 732 | |
| 733 | _ => Enable::Yes, |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | pub(crate) fn enable_lane(action: ActionId, lane: Lane, ctx: Ctx) -> Enable { |
| 742 | match (action, lane.kind) { |
| 743 | (ActionId::Mix, LaneKind::Audio) |
| 744 | | (ActionId::RemoveVideoLane, LaneKind::Video) |
| 745 | | (ActionId::RemoveAudioLane, LaneKind::Audio) => enable(action, ctx), |
| 746 | (ActionId::RenameLane, _) => Enable::Yes, |
| 747 | (ActionId::TrackSmall | ActionId::TrackMedium | ActionId::TrackLarge, _) => Enable::Yes, |
| 748 | _ => Enable::Hidden("this verb does not apply to this lane"), |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | |
| 753 | |
| 754 | |
| 755 | |
| 756 | |
| 757 | |
| 758 | |
| 759 | |
| 760 | |
| 761 | pub(crate) fn lane_items(lane: Lane) -> Vec<ActionId> { |
| 762 | let mut items = HEAD_ADDS.to_vec(); |
| 763 | |
| 764 | |
| 765 | |
| 766 | if lane.kind == LaneKind::Audio { |
| 767 | items.push(ActionId::Mix); |
| 768 | } |
| 769 | items.push(ActionId::RenameLane); |
| 770 | |
| 771 | |
| 772 | items.extend([ActionId::TrackSmall, ActionId::TrackMedium, ActionId::TrackLarge]); |
| 773 | items.push(match lane.kind { |
| 774 | LaneKind::Video => ActionId::RemoveVideoLane, |
| 775 | LaneKind::Audio => ActionId::RemoveAudioLane, |
| 776 | LaneKind::Subtitle => ActionId::RemoveSubtitleLane, |
| 777 | }); |
| 778 | items |
| 779 | } |
| 780 | |
| 781 | |
| 782 | |
| 783 | |
| 784 | |
| 785 | |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | |
| 796 | |
| 797 | |
| 798 | |
| 799 | pub(crate) fn menu_items(ctx: Ctx) -> Vec<ActionId> { |
| 800 | MENU_ITEMS |
| 801 | .into_iter() |
| 802 | .filter(|&action| enable(action, ctx.clone()).listed()) |
| 803 | .filter(|&action| { |
| 804 | !ctx.caption |
| 805 | || matches!( |
| 806 | action, |
| 807 | ActionId::Delete |
| 808 | | ActionId::Paste |
| 809 | | ActionId::ToggleMute |
| 810 | | ActionId::Group |
| 811 | | ActionId::Detach |
| 812 | ) |
| 813 | }) |
| 814 | .collect() |
| 815 | } |
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 | #[derive(Clone, Copy, Default)] |
| 821 | pub(crate) struct RowCtx { |
| 822 | |
| 823 | pub(crate) timeline: bool, |
| 824 | pub(crate) exporting: bool, |
| 825 | |
| 826 | |
| 827 | pub(crate) usable: bool, |
| 828 | |
| 829 | |
| 830 | pub(crate) placed: usize, |
| 831 | |
| 832 | |
| 833 | pub(crate) proxy_stops: bool, |
| 834 | |
| 835 | pub(crate) starred: bool, |
| 836 | |
| 837 | pub(crate) offline: bool, |
| 838 | |
| 839 | pub(crate) media_picks: usize, |
| 840 | } |
| 841 | |
| 842 | |
| 843 | |
| 844 | pub(crate) fn row_enable(item: RowItem, ctx: RowCtx) -> Enable { |
| 845 | match item { |
| 846 | RowItem::Relink if !ctx.offline => Enable::Hidden("the file is not missing"), |
| 847 | RowItem::Relink if ctx.exporting => Enable::No("an export is running"), |
| 848 | RowItem::Relink => Enable::Yes, |
| 849 | RowItem::CreateMulticam if ctx.media_picks < 2 => Enable::No("Needs two or more picked clips"), |
| 850 | RowItem::CreateMulticam => Enable::Yes, |
| 851 | |
| 852 | RowItem::Add | RowItem::Insert | RowItem::Preview | RowItem::Proxy if ctx.offline => { |
| 853 | Enable::No("the file is missing") |
| 854 | } |
| 855 | |
| 856 | |
| 857 | RowItem::Favourite | RowItem::MoveToBin | RowItem::NewBin if ctx.exporting => { |
| 858 | Enable::No("an export is running") |
| 859 | } |
| 860 | RowItem::Favourite | RowItem::MoveToBin | RowItem::NewBin if !ctx.timeline => { |
| 861 | Enable::No("no timeline open") |
| 862 | } |
| 863 | RowItem::Add | RowItem::Insert | RowItem::Remove | RowItem::RemoveWithClips if ctx.exporting => { |
| 864 | Enable::No("an export is running") |
| 865 | } |
| 866 | RowItem::Add | RowItem::Insert | RowItem::Remove | RowItem::RemoveWithClips if !ctx.timeline => { |
| 867 | Enable::No("no timeline open") |
| 868 | } |
| 869 | |
| 870 | |
| 871 | RowItem::Add | RowItem::Insert if !ctx.usable => Enable::No("it cannot join this one"), |
| 872 | |
| 873 | |
| 874 | |
| 875 | RowItem::Preview | RowItem::Proxy if !ctx.usable => Enable::Hidden("it cannot be read"), |
| 876 | |
| 877 | |
| 878 | |
| 879 | |
| 880 | |
| 881 | RowItem::Remove if ctx.placed > 0 => Enable::No("It's used on the timeline"), |
| 882 | RowItem::RemoveWithClips if ctx.placed == 0 => Enable::No("no clip uses it"), |
| 883 | |
| 884 | |
| 885 | _ => Enable::Yes, |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | |
| 890 | |
| 891 | |
| 892 | pub(crate) fn row_items(ctx: RowCtx) -> Vec<RowItem> { |
| 893 | ROW_ITEMS |
| 894 | .into_iter() |
| 895 | .filter(|&item| row_enable(item, ctx).listed()) |
| 896 | .collect() |
| 897 | } |
| 898 | |
| 899 | |
| 900 | |
| 901 | |
| 902 | |
| 903 | |
| 904 | |
| 905 | pub(crate) fn menu_rows_h(rows: usize, viewport: Size<Pixels>) -> f32 { |
| 906 | let room = f32::from(viewport.height) - MENU_PAD * 2. - MENU_EDGE * 2.; |
| 907 | (rows as f32 * MENU_ROW_H).min(room.max(MENU_ROW_H)) |
| 908 | } |
| 909 | |
| 910 | |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | |
| 916 | #[cfg(test)] |
| 917 | pub(crate) fn menu_at(at: Point<Pixels>, viewport: Size<Pixels>, height: f32) -> (f32, f32) { |
| 918 | menu_at_w(at, viewport, MENU_W, height) |
| 919 | } |
| 920 | |
| 921 | |
| 922 | pub(crate) fn menu_at_w( |
| 923 | at: Point<Pixels>, |
| 924 | viewport: Size<Pixels>, |
| 925 | width: f32, |
| 926 | height: f32, |
| 927 | ) -> (f32, f32) { |
| 928 | let fit = |v: f32, size: f32, room: f32| v.min(room - MENU_EDGE - size).max(MENU_EDGE); |
| 929 | ( |
| 930 | fit(f32::from(at.x), width, f32::from(viewport.width)), |
| 931 | fit(f32::from(at.y), height, f32::from(viewport.height)), |
| 932 | ) |
| 933 | } |