forge
Explore
Log in

Don't you dare go Hollow

🔀 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 commit

eee9e6e3c897e765e7591c669b080a3dd8c8623cAhmet Kaan GümüşParent: 1c587575007fc6
crates/app/src/main.rsmodified+140 -23
@@ -1229,6 +1229,12 @@ impl Player {
12291229 action,
12301230 Ctx {
12311231 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+ }),
12321238 playhead: frame_at(session.now(), self.fps),
12331239 timeline: true,
12341240 clipboard: self.clipboard.is_some(),
@@ -7010,6 +7016,15 @@ impl Player {
70107016 // dims a row with -- and a row that takes no click says *why*
70117017 // rather than printing a stroke that would do nothing.
70127018 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+ }
70137028 let enabled = refusal.yes();
70147029 // The one item that is not about this clip says so, and says it
70157030 // here rather than in the registry: the stroke is global too,
@@ -7931,9 +7946,11 @@ fn band_label(band: &Band) -> String {
79317946 /// kinds of no: `Hidden` is about the *kind* of thing the action was aimed at
79327947 /// -- an audio clip has no picture, so a grade is not a thing that exists for
79337948 /// 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
7935-/// today; a menu that wants to leave the class refusals out and keep the state
7936-/// ones has only to match on which of the two it got.
7949+/// moment, which the next click of the playhead can change. The clip menu
7950+/// leaves the class refusals *out* and dims the state ones ([`Enable::listed`]);
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.
79377954 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
79387955 enum Enable {
79397956 Yes,
@@ -7947,6 +7964,13 @@ impl Enable {
79477964 self == Enable::Yes
79487965 }
79497966
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+
79507974 /// What the row says instead of its stroke, if it says anything.
79517975 fn why(self) -> Option<&'static str> {
79527976 match self {
@@ -7967,6 +7991,10 @@ struct Ctx {
79677991 /// and the clip-relative answers stand aside: those actions find their own
79687992 /// clip under the playhead and word their own refusal.
79697993 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,
79707998 playhead: u32,
79717999 /// A timeline is open.
79728000 timeline: bool,
@@ -8006,6 +8034,11 @@ fn enable(action: ActionId, ctx: Ctx) -> Enable {
80068034 Some((_, lane)) if lane.kind != LaneKind::Video => Enable::Hidden("this clip is sound"),
80078035 _ => Enable::Yes,
80088036 },
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"),
80098042 // -- state: true of this clip now, and the next playhead click or the
80108043 // next selection changes the answer. Splits this clip only from inside
80118044 // it: at either edge there is nothing to split off -- and, on a speeded
@@ -10308,37 +10341,121 @@ mod tests {
1030810341 // clip wherever the playhead is, dimmed on a waveform.
1030910342 assert!(offered(&clip, v1, ActionId::Color, 0));
1031010343 assert!(!offered(&clip, a1, ActionId::Color, 60));
10311- // The two kinds of no, which is what the row can be told apart by: a
10312- // grade on a waveform is a *class* answer -- an audio clip has no
10313- // picture and never will, so a menu may leave the item out -- where a
10314- // cut at the clip's edge is this moment's answer and the next click of
10315- // the playhead changes it, so that one is dimmed and stays.
10316- assert!(matches!(
10317- on(&clip, a1, ActionId::Color, 60),
10318- Enable::Hidden(_)
10319- ));
10320- assert!(matches!(
10321- on(&clip, a1, ActionId::Fit, 60),
10322- Enable::Hidden(_)
10323- ));
10324- assert!(matches!(
10325- on(&clip, v1, ActionId::Equalizer, 60),
10326- Enable::Hidden(_)
10327- ));
10344+ // The two kinds of no, which is what the row is told apart by: a grade
10345+ // on a waveform is a *class* answer -- an audio clip has no picture and
10346+ // never will, so the menu leaves the item out entirely -- where a cut at
10347+ // the clip's edge is this moment's answer and the next click of the
10348+ // playhead changes it, so that one is drawn, dimmed, and says why.
10349+ //
10350+ // What the menu draws for a clip of each kind, in order: the render
10351+ // loop's `continue`, as a list.
10352+ let menu = |lane, image, playhead| {
10353+ MENU_ITEMS
10354+ .into_iter()
10355+ .filter(|&action| {
10356+ enable(
10357+ action,
10358+ Ctx {
10359+ clip: Some((clip, lane)),
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+ }
1032810421 assert!(matches!(on(&clip, v1, ActionId::Cut, 30), Enable::No(_)));
1032910422 assert!(matches!(on(&clip, v1, ActionId::Regroup, 60), Enable::No(_)));
1033010423 assert!(matches!(on(&clip, v1, ActionId::Detach, 0), Enable::No(_)));
1033110424 // 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.
1033310427 for action in MENU_ITEMS {
10334- for lane in [v1, a1] {
10428+ for (lane, image) in [(v1, false), (a1, false), (v1, true)] {
1033510429 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() {
1033710441 assert!(!why.is_empty() && why.len() <= 30, "{action:?}: {why:?}");
1033810442 }
1033910443 }
1034010444 }
1034110445 }
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+ ));
1034210459 // The editor as a whole, which is how the actions card asks: with no
1034310460 // timeline nothing is offered, an export leaves only its own cancel,
1034410461 // and the three that act on the marked clip say so when none is.