A clip's menu lists what that clip can do
Browse files at this commit79da4462f19389300030c298cf406331d489418fParent: 75d536b- feat
- a clip's menu lists what that clip can do
1 changed file +140 -23
- crates/app/src/main.rs +140 -23
crates/app/src/main.rsmodified+140 -23
| @@ -1156,6 +1156,12 @@ impl Player { | |||
| 1156 | action, | 1156 | action, |
| 1157 | Ctx { | 1157 | Ctx { |
| 1158 | clip, | 1158 | clip, |
| 1159 | + image: clip.is_some_and(|(clip, _)| { | ||
| 1160 | + session | ||
| 1161 | + .sources() | ||
| 1162 | + .get(clip.source) | ||
| 1163 | + .is_some_and(|s| engine::is_image(&s.path)) | ||
| 1164 | + }), | ||
| 1159 | playhead: frame_at(session.now(), self.fps), | 1165 | playhead: frame_at(session.now(), self.fps), |
| 1160 | timeline: true, | 1166 | timeline: true, |
| 1161 | clipboard: self.clipboard.is_some(), | 1167 | clipboard: self.clipboard.is_some(), |
| @@ -6652,6 +6658,15 @@ impl Player { | |||
| 6652 | // dims a row with -- and a row that takes no click says *why* | 6658 | // dims a row with -- and a row that takes no click says *why* |
| 6653 | // rather than printing a stroke that would do nothing. | 6659 | // rather than printing a stroke that would do nothing. |
| 6654 | let refusal = self.enable(action, Some((menu.lane, menu.idx))); | 6660 | let refusal = self.enable(action, Some((menu.lane, menu.idx))); |
| 6661 | + // A grade on a waveform, an equalizer on a picture, a silence | ||
| 6662 | + // scan on a still: things that do not exist for what was | ||
| 6663 | + // right-clicked, so the menu is the list of what this clip can | ||
| 6664 | + // do rather than the registry with most of it struck through. | ||
| 6665 | + // The state refusals below stay, dimmed and saying why -- the | ||
| 6666 | + // next click of the playhead lights them. | ||
| 6667 | + if !refusal.listed() { | ||
| 6668 | + continue; | ||
| 6669 | + } | ||
| 6655 | let enabled = refusal.yes(); | 6670 | let enabled = refusal.yes(); |
| 6656 | // The one item that is not about this clip says so, and says it | 6671 | // The one item that is not about this clip says so, and says it |
| 6657 | // here rather than in the registry: the stroke is global too, | 6672 | // here rather than in the registry: the stroke is global too, |
| @@ -7450,9 +7465,11 @@ fn band_label(band: &Band) -> String { | |||
| 7450 | /// kinds of no: `Hidden` is about the *kind* of thing the action was aimed at | 7465 | /// kinds of no: `Hidden` is about the *kind* of thing the action was aimed at |
| 7451 | /// -- an audio clip has no picture, so a grade is not a thing that exists for | 7466 | /// -- an audio clip has no picture, so a grade is not a thing that exists for |
| 7452 | /// it, whatever the editor does next -- and `No` is about the state of this | 7467 | /// it, whatever the editor does next -- and `No` is about the state of this |
| 7453 | -/// moment, which the next click of the playhead can change. Both dim their row | 7468 | +/// moment, which the next click of the playhead can change. The clip menu |
| 7454 | -/// today; a menu that wants to leave the class refusals out and keep the state | 7469 | +/// leaves the class refusals *out* and dims the state ones ([`Enable::listed`]); |
| 7455 | -/// ones has only to match on which of the two it got. | 7470 | +/// the actions card, which is the whole registry laid out, dims both with their |
| 7471 | +/// reason -- an action missing from the one surface that lists everything would | ||
| 7472 | +/// read as an action that does not exist. | ||
| 7456 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] | 7473 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 7457 | enum Enable { | 7474 | enum Enable { |
| 7458 | Yes, | 7475 | Yes, |
| @@ -7466,6 +7483,13 @@ impl Enable { | |||
| 7466 | self == Enable::Yes | 7483 | self == Enable::Yes |
| 7467 | } | 7484 | } |
| 7468 | 7485 | ||
| 7486 | + /// Whether a menu *about this clip* draws the row at all: a class refusal | ||
| 7487 | + /// is a thing that does not exist for what was clicked, and a row nothing | ||
| 7488 | + /// the user does could ever light is noise between the ones they came for. | ||
| 7489 | + fn listed(self) -> bool { | ||
| 7490 | + !matches!(self, Enable::Hidden(_)) | ||
| 7491 | + } | ||
| 7492 | + | ||
| 7469 | /// What the row says instead of its stroke, if it says anything. | 7493 | /// What the row says instead of its stroke, if it says anything. |
| 7470 | fn why(self) -> Option<&'static str> { | 7494 | fn why(self) -> Option<&'static str> { |
| 7471 | match self { | 7495 | match self { |
| @@ -7486,6 +7510,10 @@ struct Ctx { | |||
| 7486 | /// and the clip-relative answers stand aside: those actions find their own | 7510 | /// and the clip-relative answers stand aside: those actions find their own |
| 7487 | /// clip under the playhead and word their own refusal. | 7511 | /// clip under the playhead and word their own refusal. |
| 7488 | clip: Option<(Clip, Lane)>, | 7512 | clip: Option<(Clip, Lane)>, |
| 7513 | + /// The clip plays a still ([`engine::is_image`]), which has no sound to | ||
| 7514 | + /// reach at all -- not the lane's business, because a still sits on a video | ||
| 7515 | + /// lane exactly like a take whose sound is one lane down. | ||
| 7516 | + image: bool, | ||
| 7489 | playhead: u32, | 7517 | playhead: u32, |
| 7490 | /// A timeline is open. | 7518 | /// A timeline is open. |
| 7491 | timeline: bool, | 7519 | timeline: bool, |
| @@ -7525,6 +7553,11 @@ fn enable(action: ActionId, ctx: Ctx) -> Enable { | |||
| 7525 | Some((_, lane)) if lane.kind != LaneKind::Video => Enable::Hidden("this clip is sound"), | 7553 | Some((_, lane)) if lane.kind != LaneKind::Video => Enable::Hidden("this clip is sound"), |
| 7526 | _ => Enable::Yes, | 7554 | _ => Enable::Yes, |
| 7527 | }, | 7555 | }, |
| 7556 | + // The scan reads samples, and a still has none -- ever, unlike a video | ||
| 7557 | + // clip whose sound may be one lane down or simply silent. Exactly what | ||
| 7558 | + // `unscannable` says after the fact, said before the row is drawn so | ||
| 7559 | + // there is no row left to click. | ||
| 7560 | + ActionId::Silence if ctx.image => Enable::Hidden("this clip is a still"), | ||
| 7528 | // -- state: true of this clip now, and the next playhead click or the | 7561 | // -- state: true of this clip now, and the next playhead click or the |
| 7529 | // next selection changes the answer. Splits this clip only from inside | 7562 | // next selection changes the answer. Splits this clip only from inside |
| 7530 | // it: at either edge there is nothing to split off -- and, on a speeded | 7563 | // it: at either edge there is nothing to split off -- and, on a speeded |
| @@ -9647,37 +9680,121 @@ mod tests { | |||
| 9647 | // clip wherever the playhead is, dimmed on a waveform. | 9680 | // clip wherever the playhead is, dimmed on a waveform. |
| 9648 | assert!(offered(&clip, v1, ActionId::Color, 0)); | 9681 | assert!(offered(&clip, v1, ActionId::Color, 0)); |
| 9649 | assert!(!offered(&clip, a1, ActionId::Color, 60)); | 9682 | assert!(!offered(&clip, a1, ActionId::Color, 60)); |
| 9650 | - // The two kinds of no, which is what the row can be told apart by: a | 9683 | + // The two kinds of no, which is what the row is told apart by: a grade |
| 9651 | - // grade on a waveform is a *class* answer -- an audio clip has no | 9684 | + // on a waveform is a *class* answer -- an audio clip has no picture and |
| 9652 | - // picture and never will, so a menu may leave the item out -- where a | 9685 | + // never will, so the menu leaves the item out entirely -- where a cut at |
| 9653 | - // cut at the clip's edge is this moment's answer and the next click of | 9686 | + // the clip's edge is this moment's answer and the next click of the |
| 9654 | - // the playhead changes it, so that one is dimmed and stays. | 9687 | + // playhead changes it, so that one is drawn, dimmed, and says why. |
| 9655 | - assert!(matches!( | 9688 | + // |
| 9656 | - on(&clip, a1, ActionId::Color, 60), | 9689 | + // What the menu draws for a clip of each kind, in order: the render |
| 9657 | - Enable::Hidden(_) | 9690 | + // loop's `continue`, as a list. |
| 9658 | - )); | 9691 | + let menu = |lane, image, playhead| { |
| 9659 | - assert!(matches!( | 9692 | + MENU_ITEMS |
| 9660 | - on(&clip, a1, ActionId::Fit, 60), | 9693 | + .into_iter() |
| 9661 | - Enable::Hidden(_) | 9694 | + .filter(|&action| { |
| 9662 | - )); | 9695 | + enable( |
| 9663 | - assert!(matches!( | 9696 | + action, |
| 9664 | - on(&clip, v1, ActionId::Equalizer, 60), | 9697 | + Ctx { |
| 9665 | - Enable::Hidden(_) | 9698 | + clip: Some((clip, lane)), |
| 9666 | - )); | 9699 | + image, |
| 9700 | + playhead, | ||
| 9701 | + timeline: true, | ||
| 9702 | + ..Ctx::default() | ||
| 9703 | + }, | ||
| 9704 | + ) | ||
| 9705 | + .listed() | ||
| 9706 | + }) | ||
| 9707 | + .collect::<Vec<_>>() | ||
| 9708 | + }; | ||
| 9709 | + // Sound: no grade and no fit policy, and the equalizer that is the | ||
| 9710 | + // whole reason an audio clip has a menu of its own. | ||
| 9711 | + let sound = menu(a1, false, 60); | ||
| 9712 | + assert!(!sound.contains(&ActionId::Color), "{sound:?}"); | ||
| 9713 | + assert!(!sound.contains(&ActionId::Fit), "{sound:?}"); | ||
| 9714 | + assert!(sound.contains(&ActionId::Equalizer)); | ||
| 9715 | + assert!(sound.contains(&ActionId::Silence)); | ||
| 9716 | + // Picture: the mirror of it. The sound of a take is the audio lane's, | ||
| 9717 | + // clip for clip, so the equalizer is not this clip's business -- but the | ||
| 9718 | + // silence scan is, because it opens on the half it is grouped with. | ||
| 9719 | + let picture = menu(v1, false, 60); | ||
| 9720 | + assert!(!picture.contains(&ActionId::Equalizer), "{picture:?}"); | ||
| 9721 | + assert!(picture.contains(&ActionId::Color)); | ||
| 9722 | + assert!(picture.contains(&ActionId::Fit)); | ||
| 9723 | + assert!(picture.contains(&ActionId::Silence)); | ||
| 9724 | + // A still: picture with no sound anywhere, ever. Graded, fitted and | ||
| 9725 | + // re-timed like any other clip (a speed reaches a still through the same | ||
| 9726 | + // rewrite), scanned like none. | ||
| 9727 | + let still = menu(v1, true, 60); | ||
| 9728 | + assert!(!still.contains(&ActionId::Silence), "{still:?}"); | ||
| 9729 | + assert!(!still.contains(&ActionId::Equalizer), "{still:?}"); | ||
| 9730 | + assert!(still.contains(&ActionId::Color)); | ||
| 9731 | + assert!(still.contains(&ActionId::Fit)); | ||
| 9732 | + assert!(still.contains(&ActionId::Speed)); | ||
| 9733 | + // ...and the state refusals are on all three, dimmed rather than gone: | ||
| 9734 | + // at 30 the playhead is on this clip's head, where a cut has nothing to | ||
| 9735 | + // split off -- a row the next click of the playhead lights. | ||
| 9736 | + for rows in [menu(a1, false, 30), menu(v1, false, 30), menu(v1, true, 30)] { | ||
| 9737 | + assert!(rows.contains(&ActionId::Cut), "{rows:?}"); | ||
| 9738 | + assert!(rows.contains(&ActionId::Detach), "{rows:?}"); | ||
| 9739 | + } | ||
| 9740 | + // The actions card is the other half of the rule: it lists the whole | ||
| 9741 | + // registry, so a class refusal is dimmed there with its reason and never | ||
| 9742 | + // dropped -- an action missing from the one surface that lists | ||
| 9743 | + // everything would read as an action that does not exist. | ||
| 9744 | + let listed: Vec<ActionId> = keys_rows() | ||
| 9745 | + .into_iter() | ||
| 9746 | + .filter_map(|r| match r { | ||
| 9747 | + KeyRow::Act(action) => Some(action), | ||
| 9748 | + _ => None, | ||
| 9749 | + }) | ||
| 9750 | + .collect(); | ||
| 9751 | + for (lane, action) in [ | ||
| 9752 | + (a1, ActionId::Color), | ||
| 9753 | + (a1, ActionId::Fit), | ||
| 9754 | + (v1, ActionId::Equalizer), | ||
| 9755 | + ] { | ||
| 9756 | + assert!(matches!(on(&clip, lane, action, 60), Enable::Hidden(_))); | ||
| 9757 | + assert!(listed.contains(&action), "{action:?} left the actions card"); | ||
| 9758 | + assert!(on(&clip, lane, action, 60).why().is_some()); | ||
| 9759 | + } | ||
| 9667 | assert!(matches!(on(&clip, v1, ActionId::Cut, 30), Enable::No(_))); | 9760 | assert!(matches!(on(&clip, v1, ActionId::Cut, 30), Enable::No(_))); |
| 9668 | assert!(matches!(on(&clip, v1, ActionId::Regroup, 60), Enable::No(_))); | 9761 | assert!(matches!(on(&clip, v1, ActionId::Regroup, 60), Enable::No(_))); |
| 9669 | assert!(matches!(on(&clip, v1, ActionId::Detach, 0), Enable::No(_))); | 9762 | assert!(matches!(on(&clip, v1, ActionId::Detach, 0), Enable::No(_))); |
| 9670 | // Every refusal says something, and says it short enough to sit in the | 9763 | // Every refusal says something, and says it short enough to sit in the |
| 9671 | - // menu's right-hand column beside a label. | 9764 | + // menu's right-hand column beside a label -- the still's included, which |
| 9765 | + // the card dims with while the menu leaves the row out. | ||
| 9672 | for action in MENU_ITEMS { | 9766 | for action in MENU_ITEMS { |
| 9673 | - for lane in [v1, a1] { | 9767 | + for (lane, image) in [(v1, false), (a1, false), (v1, true)] { |
| 9674 | for playhead in [0, 30, 60, 90] { | 9768 | for playhead in [0, 30, 60, 90] { |
| 9675 | - if let Some(why) = on(&clip, lane, action, playhead).why() { | 9769 | + let refusal = enable( |
| 9770 | + action, | ||
| 9771 | + Ctx { | ||
| 9772 | + clip: Some((clip, lane)), | ||
| 9773 | + image, | ||
| 9774 | + playhead, | ||
| 9775 | + timeline: true, | ||
| 9776 | + ..Ctx::default() | ||
| 9777 | + }, | ||
| 9778 | + ); | ||
| 9779 | + if let Some(why) = refusal.why() { | ||
| 9676 | assert!(!why.is_empty() && why.len() <= 30, "{action:?}: {why:?}"); | 9780 | assert!(!why.is_empty() && why.len() <= 30, "{action:?}: {why:?}"); |
| 9677 | } | 9781 | } |
| 9678 | } | 9782 | } |
| 9679 | } | 9783 | } |
| 9680 | } | 9784 | } |
| 9785 | + assert!(matches!( | ||
| 9786 | + enable( | ||
| 9787 | + ActionId::Silence, | ||
| 9788 | + Ctx { | ||
| 9789 | + clip: Some((clip, v1)), | ||
| 9790 | + image: true, | ||
| 9791 | + playhead: 60, | ||
| 9792 | + timeline: true, | ||
| 9793 | + ..Ctx::default() | ||
| 9794 | + } | ||
| 9795 | + ), | ||
| 9796 | + Enable::Hidden(_) | ||
| 9797 | + )); | ||
| 9681 | // The editor as a whole, which is how the actions card asks: with no | 9798 | // The editor as a whole, which is how the actions card asks: with no |
| 9682 | // timeline nothing is offered, an export leaves only its own cancel, | 9799 | // timeline nothing is offered, an export leaves only its own cancel, |
| 9683 | // and the three that act on the marked clip say so when none is. | 9800 | // and the three that act on the marked clip say so when none is. |