🔀 merge(C4): the right-click menu knows what it's pointing at — sound clips lose Color, stills lose Silence, reasons stay visible
Browse files at this commit1 changed file +140 -23
- crates/app/src/main.rs +140 -23
crates/app/src/main.rsmodified+140 -23
| @@ -1229,6 +1229,12 @@ impl Player { | |||
| 1229 | action, | 1229 | action, |
| 1230 | Ctx { | 1230 | Ctx { |
| 1231 | clip, | 1231 | clip, |
| 1232 | + image: clip.is_some_and(|(clip, _)| { | ||
| 1233 | + session | ||
| 1234 | + .sources() | ||
| 1235 | + .get(clip.source) | ||
| 1236 | + .is_some_and(|s| engine::is_image(&s.path)) | ||
| 1237 | + }), | ||
| 1232 | playhead: frame_at(session.now(), self.fps), | 1238 | playhead: frame_at(session.now(), self.fps), |
| 1233 | timeline: true, | 1239 | timeline: true, |
| 1234 | clipboard: self.clipboard.is_some(), | 1240 | clipboard: self.clipboard.is_some(), |
| @@ -7010,6 +7016,15 @@ impl Player { | |||
| 7010 | // dims a row with -- and a row that takes no click says *why* | 7016 | // dims a row with -- and a row that takes no click says *why* |
| 7011 | // rather than printing a stroke that would do nothing. | 7017 | // rather than printing a stroke that would do nothing. |
| 7012 | let refusal = self.enable(action, Some((menu.lane, menu.idx))); | 7018 | let refusal = self.enable(action, Some((menu.lane, menu.idx))); |
| 7019 | + // A grade on a waveform, an equalizer on a picture, a silence | ||
| 7020 | + // scan on a still: things that do not exist for what was | ||
| 7021 | + // right-clicked, so the menu is the list of what this clip can | ||
| 7022 | + // do rather than the registry with most of it struck through. | ||
| 7023 | + // The state refusals below stay, dimmed and saying why -- the | ||
| 7024 | + // next click of the playhead lights them. | ||
| 7025 | + if !refusal.listed() { | ||
| 7026 | + continue; | ||
| 7027 | + } | ||
| 7013 | let enabled = refusal.yes(); | 7028 | let enabled = refusal.yes(); |
| 7014 | // The one item that is not about this clip says so, and says it | 7029 | // The one item that is not about this clip says so, and says it |
| 7015 | // here rather than in the registry: the stroke is global too, | 7030 | // here rather than in the registry: the stroke is global too, |
| @@ -7931,9 +7946,11 @@ fn band_label(band: &Band) -> String { | |||
| 7931 | /// kinds of no: `Hidden` is about the *kind* of thing the action was aimed at | 7946 | /// kinds of no: `Hidden` is about the *kind* of thing the action was aimed at |
| 7932 | /// -- an audio clip has no picture, so a grade is not a thing that exists for | 7947 | /// -- an audio clip has no picture, so a grade is not a thing that exists for |
| 7933 | /// it, whatever the editor does next -- and `No` is about the state of this | 7948 | /// it, whatever the editor does next -- and `No` is about the state of this |
| 7934 | -/// moment, which the next click of the playhead can change. Both dim their row | 7949 | +/// moment, which the next click of the playhead can change. The clip menu |
| 7935 | -/// today; a menu that wants to leave the class refusals out and keep the state | 7950 | +/// leaves the class refusals *out* and dims the state ones ([`Enable::listed`]); |
| 7936 | -/// ones has only to match on which of the two it got. | 7951 | +/// the actions card, which is the whole registry laid out, dims both with their |
| 7952 | +/// reason -- an action missing from the one surface that lists everything would | ||
| 7953 | +/// read as an action that does not exist. | ||
| 7937 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] | 7954 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 7938 | enum Enable { | 7955 | enum Enable { |
| 7939 | Yes, | 7956 | Yes, |
| @@ -7947,6 +7964,13 @@ impl Enable { | |||
| 7947 | self == Enable::Yes | 7964 | self == Enable::Yes |
| 7948 | } | 7965 | } |
| 7949 | 7966 | ||
| 7967 | + /// Whether a menu *about this clip* draws the row at all: a class refusal | ||
| 7968 | + /// is a thing that does not exist for what was clicked, and a row nothing | ||
| 7969 | + /// the user does could ever light is noise between the ones they came for. | ||
| 7970 | + fn listed(self) -> bool { | ||
| 7971 | + !matches!(self, Enable::Hidden(_)) | ||
| 7972 | + } | ||
| 7973 | + | ||
| 7950 | /// What the row says instead of its stroke, if it says anything. | 7974 | /// What the row says instead of its stroke, if it says anything. |
| 7951 | fn why(self) -> Option<&'static str> { | 7975 | fn why(self) -> Option<&'static str> { |
| 7952 | match self { | 7976 | match self { |
| @@ -7967,6 +7991,10 @@ struct Ctx { | |||
| 7967 | /// and the clip-relative answers stand aside: those actions find their own | 7991 | /// and the clip-relative answers stand aside: those actions find their own |
| 7968 | /// clip under the playhead and word their own refusal. | 7992 | /// clip under the playhead and word their own refusal. |
| 7969 | clip: Option<(Clip, Lane)>, | 7993 | clip: Option<(Clip, Lane)>, |
| 7994 | + /// The clip plays a still ([`engine::is_image`]), which has no sound to | ||
| 7995 | + /// reach at all -- not the lane's business, because a still sits on a video | ||
| 7996 | + /// lane exactly like a take whose sound is one lane down. | ||
| 7997 | + image: bool, | ||
| 7970 | playhead: u32, | 7998 | playhead: u32, |
| 7971 | /// A timeline is open. | 7999 | /// A timeline is open. |
| 7972 | timeline: bool, | 8000 | timeline: bool, |
| @@ -8006,6 +8034,11 @@ fn enable(action: ActionId, ctx: Ctx) -> Enable { | |||
| 8006 | Some((_, lane)) if lane.kind != LaneKind::Video => Enable::Hidden("this clip is sound"), | 8034 | Some((_, lane)) if lane.kind != LaneKind::Video => Enable::Hidden("this clip is sound"), |
| 8007 | _ => Enable::Yes, | 8035 | _ => Enable::Yes, |
| 8008 | }, | 8036 | }, |
| 8037 | + // The scan reads samples, and a still has none -- ever, unlike a video | ||
| 8038 | + // clip whose sound may be one lane down or simply silent. Exactly what | ||
| 8039 | + // `unscannable` says after the fact, said before the row is drawn so | ||
| 8040 | + // there is no row left to click. | ||
| 8041 | + ActionId::Silence if ctx.image => Enable::Hidden("this clip is a still"), | ||
| 8009 | // -- state: true of this clip now, and the next playhead click or the | 8042 | // -- state: true of this clip now, and the next playhead click or the |
| 8010 | // next selection changes the answer. Splits this clip only from inside | 8043 | // next selection changes the answer. Splits this clip only from inside |
| 8011 | // it: at either edge there is nothing to split off -- and, on a speeded | 8044 | // it: at either edge there is nothing to split off -- and, on a speeded |
| @@ -10308,37 +10341,121 @@ mod tests { | |||
| 10308 | // clip wherever the playhead is, dimmed on a waveform. | 10341 | // clip wherever the playhead is, dimmed on a waveform. |
| 10309 | assert!(offered(&clip, v1, ActionId::Color, 0)); | 10342 | assert!(offered(&clip, v1, ActionId::Color, 0)); |
| 10310 | assert!(!offered(&clip, a1, ActionId::Color, 60)); | 10343 | assert!(!offered(&clip, a1, ActionId::Color, 60)); |
| 10311 | - // The two kinds of no, which is what the row can be told apart by: a | 10344 | + // The two kinds of no, which is what the row is told apart by: a grade |
| 10312 | - // grade on a waveform is a *class* answer -- an audio clip has no | 10345 | + // on a waveform is a *class* answer -- an audio clip has no picture and |
| 10313 | - // picture and never will, so a menu may leave the item out -- where a | 10346 | + // never will, so the menu leaves the item out entirely -- where a cut at |
| 10314 | - // cut at the clip's edge is this moment's answer and the next click of | 10347 | + // the clip's edge is this moment's answer and the next click of the |
| 10315 | - // the playhead changes it, so that one is dimmed and stays. | 10348 | + // playhead changes it, so that one is drawn, dimmed, and says why. |
| 10316 | - assert!(matches!( | 10349 | + // |
| 10317 | - on(&clip, a1, ActionId::Color, 60), | 10350 | + // What the menu draws for a clip of each kind, in order: the render |
| 10318 | - Enable::Hidden(_) | 10351 | + // loop's `continue`, as a list. |
| 10319 | - )); | 10352 | + let menu = |lane, image, playhead| { |
| 10320 | - assert!(matches!( | 10353 | + MENU_ITEMS |
| 10321 | - on(&clip, a1, ActionId::Fit, 60), | 10354 | + .into_iter() |
| 10322 | - Enable::Hidden(_) | 10355 | + .filter(|&action| { |
| 10323 | - )); | 10356 | + enable( |
| 10324 | - assert!(matches!( | 10357 | + action, |
| 10325 | - on(&clip, v1, ActionId::Equalizer, 60), | 10358 | + Ctx { |
| 10326 | - Enable::Hidden(_) | 10359 | + clip: Some((clip, lane)), |
| 10327 | - )); | 10360 | + image, |
| 10361 | + playhead, | ||
| 10362 | + timeline: true, | ||
| 10363 | + ..Ctx::default() | ||
| 10364 | + }, | ||
| 10365 | + ) | ||
| 10366 | + .listed() | ||
| 10367 | + }) | ||
| 10368 | + .collect::<Vec<_>>() | ||
| 10369 | + }; | ||
| 10370 | + // Sound: no grade and no fit policy, and the equalizer that is the | ||
| 10371 | + // whole reason an audio clip has a menu of its own. | ||
| 10372 | + let sound = menu(a1, false, 60); | ||
| 10373 | + assert!(!sound.contains(&ActionId::Color), "{sound:?}"); | ||
| 10374 | + assert!(!sound.contains(&ActionId::Fit), "{sound:?}"); | ||
| 10375 | + assert!(sound.contains(&ActionId::Equalizer)); | ||
| 10376 | + assert!(sound.contains(&ActionId::Silence)); | ||
| 10377 | + // Picture: the mirror of it. The sound of a take is the audio lane's, | ||
| 10378 | + // clip for clip, so the equalizer is not this clip's business -- but the | ||
| 10379 | + // silence scan is, because it opens on the half it is grouped with. | ||
| 10380 | + let picture = menu(v1, false, 60); | ||
| 10381 | + assert!(!picture.contains(&ActionId::Equalizer), "{picture:?}"); | ||
| 10382 | + assert!(picture.contains(&ActionId::Color)); | ||
| 10383 | + assert!(picture.contains(&ActionId::Fit)); | ||
| 10384 | + assert!(picture.contains(&ActionId::Silence)); | ||
| 10385 | + // A still: picture with no sound anywhere, ever. Graded, fitted and | ||
| 10386 | + // re-timed like any other clip (a speed reaches a still through the same | ||
| 10387 | + // rewrite), scanned like none. | ||
| 10388 | + let still = menu(v1, true, 60); | ||
| 10389 | + assert!(!still.contains(&ActionId::Silence), "{still:?}"); | ||
| 10390 | + assert!(!still.contains(&ActionId::Equalizer), "{still:?}"); | ||
| 10391 | + assert!(still.contains(&ActionId::Color)); | ||
| 10392 | + assert!(still.contains(&ActionId::Fit)); | ||
| 10393 | + assert!(still.contains(&ActionId::Speed)); | ||
| 10394 | + // ...and the state refusals are on all three, dimmed rather than gone: | ||
| 10395 | + // at 30 the playhead is on this clip's head, where a cut has nothing to | ||
| 10396 | + // split off -- a row the next click of the playhead lights. | ||
| 10397 | + for rows in [menu(a1, false, 30), menu(v1, false, 30), menu(v1, true, 30)] { | ||
| 10398 | + assert!(rows.contains(&ActionId::Cut), "{rows:?}"); | ||
| 10399 | + assert!(rows.contains(&ActionId::Detach), "{rows:?}"); | ||
| 10400 | + } | ||
| 10401 | + // The actions card is the other half of the rule: it lists the whole | ||
| 10402 | + // registry, so a class refusal is dimmed there with its reason and never | ||
| 10403 | + // dropped -- an action missing from the one surface that lists | ||
| 10404 | + // everything would read as an action that does not exist. | ||
| 10405 | + let listed: Vec<ActionId> = keys_rows() | ||
| 10406 | + .into_iter() | ||
| 10407 | + .filter_map(|r| match r { | ||
| 10408 | + KeyRow::Act(action) => Some(action), | ||
| 10409 | + _ => None, | ||
| 10410 | + }) | ||
| 10411 | + .collect(); | ||
| 10412 | + for (lane, action) in [ | ||
| 10413 | + (a1, ActionId::Color), | ||
| 10414 | + (a1, ActionId::Fit), | ||
| 10415 | + (v1, ActionId::Equalizer), | ||
| 10416 | + ] { | ||
| 10417 | + assert!(matches!(on(&clip, lane, action, 60), Enable::Hidden(_))); | ||
| 10418 | + assert!(listed.contains(&action), "{action:?} left the actions card"); | ||
| 10419 | + assert!(on(&clip, lane, action, 60).why().is_some()); | ||
| 10420 | + } | ||
| 10328 | assert!(matches!(on(&clip, v1, ActionId::Cut, 30), Enable::No(_))); | 10421 | assert!(matches!(on(&clip, v1, ActionId::Cut, 30), Enable::No(_))); |
| 10329 | assert!(matches!(on(&clip, v1, ActionId::Regroup, 60), Enable::No(_))); | 10422 | assert!(matches!(on(&clip, v1, ActionId::Regroup, 60), Enable::No(_))); |
| 10330 | assert!(matches!(on(&clip, v1, ActionId::Detach, 0), Enable::No(_))); | 10423 | assert!(matches!(on(&clip, v1, ActionId::Detach, 0), Enable::No(_))); |
| 10331 | // Every refusal says something, and says it short enough to sit in the | 10424 | // Every refusal says something, and says it short enough to sit in the |
| 10332 | - // menu's right-hand column beside a label. | 10425 | + // menu's right-hand column beside a label -- the still's included, which |
| 10426 | + // the card dims with while the menu leaves the row out. | ||
| 10333 | for action in MENU_ITEMS { | 10427 | for action in MENU_ITEMS { |
| 10334 | - for lane in [v1, a1] { | 10428 | + for (lane, image) in [(v1, false), (a1, false), (v1, true)] { |
| 10335 | for playhead in [0, 30, 60, 90] { | 10429 | for playhead in [0, 30, 60, 90] { |
| 10336 | - if let Some(why) = on(&clip, lane, action, playhead).why() { | 10430 | + let refusal = enable( |
| 10431 | + action, | ||
| 10432 | + Ctx { | ||
| 10433 | + clip: Some((clip, lane)), | ||
| 10434 | + image, | ||
| 10435 | + playhead, | ||
| 10436 | + timeline: true, | ||
| 10437 | + ..Ctx::default() | ||
| 10438 | + }, | ||
| 10439 | + ); | ||
| 10440 | + if let Some(why) = refusal.why() { | ||
| 10337 | assert!(!why.is_empty() && why.len() <= 30, "{action:?}: {why:?}"); | 10441 | assert!(!why.is_empty() && why.len() <= 30, "{action:?}: {why:?}"); |
| 10338 | } | 10442 | } |
| 10339 | } | 10443 | } |
| 10340 | } | 10444 | } |
| 10341 | } | 10445 | } |
| 10446 | + assert!(matches!( | ||
| 10447 | + enable( | ||
| 10448 | + ActionId::Silence, | ||
| 10449 | + Ctx { | ||
| 10450 | + clip: Some((clip, v1)), | ||
| 10451 | + image: true, | ||
| 10452 | + playhead: 60, | ||
| 10453 | + timeline: true, | ||
| 10454 | + ..Ctx::default() | ||
| 10455 | + } | ||
| 10456 | + ), | ||
| 10457 | + Enable::Hidden(_) | ||
| 10458 | + )); | ||
| 10342 | // The editor as a whole, which is how the actions card asks: with no | 10459 | // The editor as a whole, which is how the actions card asks: with no |
| 10343 | // timeline nothing is offered, an export leaves only its own cancel, | 10460 | // timeline nothing is offered, an export leaves only its own cancel, |
| 10344 | // and the three that act on the marked clip say so when none is. | 10461 | // and the three that act on the marked clip say so when none is. |