Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

feat(colour): the range is the media's, set from the bin, and Auto reads the codec

Jareer1c5d7e8edf5e
diff --git a/src/crates/concat-media/src/decode.rs b/src/crates/concat-media/src/decode.rs
index b55b3342..75fa6019 100644
--- a/src/crates/concat-media/src/decode.rs
+++ b/src/crates/concat-media/src/decode.rs
@@ -233,6 +233,77 @@ impl ColorRange {
/// Every range, in the order a menu lists them.
pub const ALL: [ColorRange; 2] = [ColorRange::Limited, ColorRange::Full];
+ /// The range a stream is taken to span when its file says nothing,
+ /// read off what the codec and its pixels are by convention - the
+ /// call Resolve's "Auto" makes. JPEG and the picture formats are full
+ /// range by definition, as is anything RGB rather than YCbCr: there
+ /// is no matrix for RGB to be limited under. Every YCbCr video codec
+ /// is limited unless tagged otherwise, which is what a player assumes
+ /// and what a camera writes. A screen recording holding full-range
+ /// pixels and saying nothing is the one case this cannot know, and is
+ /// what the override is for.
+ /// https://github.com/jub0t/Concat/issues/103
+ pub fn implied(codec: ffmpeg::codec::Id, pixel: Pixel) -> ColorRange {
+ use ffmpeg::codec::Id;
+ let picture = matches!(
+ codec,
+ Id::MJPEG | Id::PNG | Id::APNG | Id::BMP | Id::GIF | Id::TIFF | Id::WEBP
+ );
+ // The `j` formats are libavcodec's own way of saying full range;
+ // a hardware decoder hands the same stream back as plain NV12,
+ // which is why the codec is asked as well as the pixels.
+ let full_pixels = matches!(
+ pixel,
+ Pixel::YUVJ420P
+ | Pixel::YUVJ422P
+ | Pixel::YUVJ444P
+ | Pixel::YUVJ440P
+ | Pixel::YUVJ411P
+ | Pixel::RGB24
+ | Pixel::BGR24
+ | Pixel::RGBA
+ | Pixel::BGRA
+ | Pixel::ARGB
+ | Pixel::ABGR
+ | Pixel::ZRGB
+ | Pixel::ZBGR
+ | Pixel::RGB8
+ | Pixel::BGR8
+ | Pixel::PAL8
+ | Pixel::RGB48BE
+ | Pixel::RGB48LE
+ | Pixel::RGBA64BE
+ | Pixel::RGBA64LE
+ | Pixel::RGB565BE
+ | Pixel::RGB565LE
+ | Pixel::RGB555BE
+ | Pixel::RGB555LE
+ | Pixel::GBRP
+ | Pixel::GBRAP
+ | Pixel::GBRP10BE
+ | Pixel::GBRP10LE
+ | Pixel::GBRP12BE
+ | Pixel::GBRP12LE
+ | Pixel::GBRP16BE
+ | Pixel::GBRP16LE
+ | Pixel::GBRAP10BE
+ | Pixel::GBRAP10LE
+ | Pixel::GBRAP12BE
+ | Pixel::GBRAP12LE
+ | Pixel::GBRAP16BE
+ | Pixel::GBRAP16LE
+ | Pixel::X2RGB10LE
+ | Pixel::X2RGB10BE
+ | Pixel::X2BGR10LE
+ | Pixel::X2BGR10BE
+ );
+ if picture || full_pixels {
+ ColorRange::Full
+ } else {
+ ColorRange::Limited
+ }
+ }
+
/// The name a document or a request stores.
pub fn name(self) -> &'static str {
match self {
@@ -298,6 +369,11 @@ pub struct ColorSignal {
pub matrix: ffmpeg::color::Space,
/// Video (16-235) or full range.
pub range: ffmpeg::color::Range,
+ /// `range` is a reading of the codec rather than the file's tag or
+ /// the caller's word: the file said nothing, and
+ /// [`ColorRange::implied`] answered for it. The frames then carry no
+ /// tag either, so a full reading has to be told to the fit by name.
+ pub implied: bool,
}
impl ColorSignal {
@@ -383,13 +459,16 @@ fn video_filter(
// A BT.709 one is left to swscale's reading of the frames' own tag,
// unless the caller has said what the levels really are: then the
// range is named and the tag ignored, which is the whole of the fix
- // for a file that lies about it.
- let convert = match color {
- Some(signal) if signal.is_wide() => signal.bt709_args(),
- _ => options
- .color_range
- .map(|range| format!(":in_range={}", range.scale_name()))
- .unwrap_or_default(),
+ // for a file that lies about it. A range read off the codec in place
+ // of a tag is named only when it is full: the frames carry no tag for
+ // swscale to read, and untagged already means limited to it.
+ let convert = match (color, options.color_range) {
+ (Some(signal), _) if signal.is_wide() => signal.bt709_args(),
+ (_, Some(range)) => format!(":in_range={}", range.scale_name()),
+ (Some(signal), None) if signal.implied && signal.range == ffmpeg::color::Range::JPEG => {
+ ":in_range=pc".to_owned()
+ }
+ _ => String::new(),
};
parts.push(format!("scale={width}:{height}:flags=bilinear{convert}"));
if let Some(chain) = &options.filter_chain {
@@ -486,15 +565,21 @@ impl Decoder {
},
None => Self::open_codec(path, &stream, options, None)?,
};
+ // The caller's word over the file's, where the caller has one: the
+ // file's tag is what the override exists to correct. Where neither
+ // says, the codec's convention does; see `ColorRange::implied`.
+ let tagged = decoder.color_range();
+ let implied = options.color_range.is_none() && tagged == ffmpeg::color::Range::Unspecified;
let color = ColorSignal {
primaries: decoder.color_primaries(),
transfer: decoder.color_transfer_characteristic(),
matrix: decoder.color_space(),
- // The caller's word over the file's, where the caller has one:
- // the file's tag is what the override exists to correct.
- range: options
- .color_range
- .map_or_else(|| decoder.color_range(), ColorRange::as_ffmpeg),
+ range: match options.color_range {
+ Some(range) => range.as_ffmpeg(),
+ None if implied => ColorRange::implied(decoder.id(), decoder.format()).as_ffmpeg(),
+ None => tagged,
+ },
+ implied,
};
let (width, height) = match options.size {
@@ -999,6 +1084,7 @@ mod tests {
transfer: Transfer::BT709,
matrix: Space::BT709,
range: Range::MPEG,
+ implied: false,
};
assert!(!sdr.is_wide());
assert_eq!(
@@ -1010,6 +1096,7 @@ mod tests {
transfer: Transfer::SMPTE2084,
matrix: Space::BT2020NCL,
range: Range::MPEG,
+ implied: false,
};
assert!(hdr.is_wide() && hdr.is_hdr());
let spec = video_filter(0, &options, 640, 360, Some(&hdr));
@@ -1022,6 +1109,7 @@ mod tests {
transfer: Transfer::Unspecified,
matrix: Space::Unspecified,
range: Range::Unspecified,
+ implied: false,
};
assert!(wide.is_wide() && !wide.is_hdr());
assert!(
@@ -1030,6 +1118,82 @@ mod tests {
);
}
+ /// With no tag and no override, the codec's convention names the
+ /// range: JPEG, the picture formats and anything RGB are full, and a
+ /// YCbCr video codec is limited - even one a hardware decoder has
+ /// handed back as plain NV12.
+ #[test]
+ fn an_untagged_stream_takes_its_codecs_range() {
+ use ffmpeg::codec::Id;
+ assert_eq!(
+ ColorRange::implied(Id::MJPEG, Pixel::YUVJ420P),
+ ColorRange::Full
+ );
+ assert_eq!(
+ ColorRange::implied(Id::MJPEG, Pixel::NV12),
+ ColorRange::Full
+ );
+ assert_eq!(
+ ColorRange::implied(Id::H264, Pixel::YUVJ420P),
+ ColorRange::Full
+ );
+ assert_eq!(ColorRange::implied(Id::PNG, Pixel::RGBA), ColorRange::Full);
+ assert_eq!(
+ ColorRange::implied(Id::RAWVIDEO, Pixel::BGRA),
+ ColorRange::Full
+ );
+ assert_eq!(
+ ColorRange::implied(Id::H264, Pixel::YUV420P),
+ ColorRange::Limited
+ );
+ assert_eq!(
+ ColorRange::implied(Id::HEVC, Pixel::YUV420P10LE),
+ ColorRange::Limited
+ );
+ assert_eq!(
+ ColorRange::implied(Id::RAWVIDEO, Pixel::NV12),
+ ColorRange::Limited
+ );
+ assert_eq!(
+ ColorRange::implied(Id::None, Pixel::None),
+ ColorRange::Limited
+ );
+ }
+
+ /// An implied full range is named to the fit, because the frames
+ /// carry no tag to read; an implied limited one is left unsaid, since
+ /// unsaid already means limited; a tagged one is the frames' to say;
+ /// and an override still beats the reading.
+ #[test]
+ fn an_implied_full_range_reaches_the_filter() {
+ use ffmpeg::color::{Primaries, Range, Space, TransferCharacteristic as Transfer};
+ let options = DecodeOptions::default().scaled_to(640, 360);
+ let signal = |range, implied| ColorSignal {
+ primaries: Primaries::BT709,
+ transfer: Transfer::BT709,
+ matrix: Space::BT709,
+ range,
+ implied,
+ };
+ assert_eq!(
+ video_filter(0, &options, 640, 360, Some(&signal(Range::JPEG, true))),
+ "scale=640:360:flags=bilinear:in_range=pc,format=rgba"
+ );
+ assert_eq!(
+ video_filter(0, &options, 640, 360, Some(&signal(Range::MPEG, true))),
+ "scale=640:360:flags=bilinear,format=rgba"
+ );
+ assert_eq!(
+ video_filter(0, &options, 640, 360, Some(&signal(Range::JPEG, false))),
+ "scale=640:360:flags=bilinear,format=rgba"
+ );
+ let limited = options.clone().in_range(Some(ColorRange::Limited));
+ assert_eq!(
+ video_filter(0, &limited, 640, 360, Some(&signal(Range::JPEG, true))),
+ "scale=640:360:flags=bilinear:in_range=tv,format=rgba"
+ );
+ }
+
/// A range the caller names is the range the picture is read as: on
/// an SDR file it is the one term added to the fit, on a wide one it
/// replaces the file's tag among the conversion's terms, and with no
@@ -1043,6 +1207,7 @@ mod tests {
transfer: Transfer::BT709,
matrix: Space::BT709,
range: Range::MPEG,
+ implied: false,
};
let full = DecodeOptions::default()
.scaled_to(640, 360)
@@ -1072,6 +1237,7 @@ mod tests {
transfer: Transfer::SMPTE2084,
matrix: Space::BT2020NCL,
range: ColorRange::Full.as_ffmpeg(),
+ implied: false,
};
assert!(
video_filter(0, &full, 640, 360, Some(&hdr_full)).contains(":in_range=pc:"),
diff --git a/src/crates/concat/locales/en.json b/src/crates/concat/locales/en.json
index f6a78126..8ca456fb 100644
--- a/src/crates/concat/locales/en.json
+++ b/src/crates/concat/locales/en.json
@@ -56,6 +56,7 @@
"Accent": "Accent",
"Add": "Add",
"Add a panel": "Add a panel",
+ "Add at playhead": "Add at playhead",
"Add captions": "Add captions",
"Add selected to timeline": "Add selected to timeline",
"Add track": "Add track",
@@ -79,7 +80,6 @@
"Appearance": "Appearance",
"Application": "Application",
"Apply": "Apply",
- "As tagged": "As tagged",
"at the playhead": "at the playhead",
"Atmosphere": "Atmosphere",
"Audio": "Audio",
diff --git a/src/crates/concat/locales/zh-TW.json b/src/crates/concat/locales/zh-TW.json
index 28a3a930..7eb9bdbc 100644
--- a/src/crates/concat/locales/zh-TW.json
+++ b/src/crates/concat/locales/zh-TW.json
@@ -77,7 +77,6 @@
"Appearance": "外觀",
"Application": "應用程式",
"Apply": "套用",
- "As tagged": "依照標記",
"at the playhead": "在播放頭位置",
"Atmosphere": "氛圍",
"Audio": "音訊",
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rs
index 584ad0a9..d4f6e097 100644
--- a/src/crates/concat/src/lib.rs
+++ b/src/crates/concat/src/lib.rs
@@ -973,6 +973,7 @@ pub fn run() -> Result<(), slint::PlatformError> {
// ── the context menu ──
editor.on_clip_context(on_window!(|state, id: SharedString| {
state.menu_token += 1;
+ state.menu_media = None;
if state.clip(id.as_str()).is_none() {
state.menu_target = None;
return;
@@ -982,7 +983,21 @@ pub fn run() -> Result<(), slint::PlatformError> {
}
state.menu_target = Some(id.to_string());
}));
+ // The bin's cards share the menu's rows and token with the clips; which
+ // one was asked for is what the two targets below remember.
+ editor.on_media_context(on_window!(|state, row: i32| {
+ state.menu_token += 1;
+ state.menu_target = None;
+ state.menu_media = state
+ .media
+ .by_row(state.project(), row)
+ .map(|item| item.id.clone());
+ }));
editor.on_menu_selected(on_window!(|state, action: SharedString| {
+ if let Some(id) = state.menu_media.clone() {
+ state.media_action(&id, action.as_str());
+ return;
+ }
// The clip the menu was opened on; failing that, the one clip that
// is selected, which is what the menu was showing anyway.
let target = state.menu_target.clone().or_else(|| state.sole_selection());
diff --git a/src/crates/concat/src/panes/media_bin.rs b/src/crates/concat/src/panes/media_bin.rs
index 19069762..3a5b463f 100644
--- a/src/crates/concat/src/panes/media_bin.rs
+++ b/src/crates/concat/src/panes/media_bin.rs
@@ -211,6 +211,11 @@ impl MediaBin {
project.media_by_id(id)
}
+ /// The row an id is shown at, for a message that names rows.
+ pub fn row_of(&self, id: &str) -> Option<i32> {
+ self.rows.get(id).copied()
+ }
+
/// Whether the filter lets an item through. The Media shelves, "All
/// media" included, are the imports: a file the editor made is on its
/// origin's shelf under Generated and nowhere else, so a read-aloud
diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rs
index 49a4d0ca..3ea4c307 100644
--- a/src/crates/concat/src/studio.rs
+++ b/src/crates/concat/src/studio.rs
@@ -630,6 +630,9 @@ pub struct Studio {
pub open_menu: i32,
pub menu_bar_token: i32,
pub menu_target: Option<String>,
+ /// The media the bin's menu was opened on, when it was the bin's menu
+ /// and not a clip's: the two share one set of rows and one token.
+ pub menu_media: Option<String>,
pub menu_token: i32,
pub toast: ToastState,
@@ -1343,6 +1346,7 @@ impl Studio {
open_menu: -1,
menu_bar_token: 0,
menu_target: None,
+ menu_media: None,
menu_token: 0,
toast: ToastState::default(),
on_start: true,
@@ -3312,30 +3316,11 @@ impl Studio {
};
self.begin_echo();
let value = f64::from(value);
- // The one field that is the media's rather than the clip's: set on
- // the echo's bin item, and committed as its own command below.
- if field == ClipField::ColorRange {
- let media_id = self.clip(&id).map(|clip| clip.media_id.clone());
- if let Some(media_id) = media_id
- && let Some(item) = self
- .echo
- .as_mut()
- .and_then(|echo| echo.media.iter_mut().find(|item| item.id == media_id))
- {
- item.color_range = match value as i32 {
- 1 => Some(model::ColorRange::Limited),
- 2 => Some(model::ColorRange::Full),
- _ => None,
- };
- }
- return;
- }
let Some(clip) = self.echo_clip_mut(&id) else {
return;
};
let text = clip.text.get_or_insert_with(TextStyle::default);
match field {
- ClipField::ColorRange => {}
ClipField::Scale => clip.scale = value.clamp(0.05, 8.0),
ClipField::AudioTrack => {
// The first row is the file's default and is stored as such,
@@ -3712,26 +3697,6 @@ impl Studio {
if patch != ClipPatch::default() {
commands.push(Command::UpdateClip { clip_id: id, patch });
}
- // The media's own field, edited through the clip: the echo's bin
- // item against the session's.
- let range_after = self
- .echo
- .as_ref()
- .and_then(|echo| echo.media_by_id(&after.media_id))
- .map(|item| item.color_range);
- let range_before = self
- .session
- .as_ref()
- .and_then(|session| session.project().media_by_id(&after.media_id))
- .map(|item| item.color_range);
- if let (Some(now), Some(was)) = (range_after, range_before)
- && now != was
- {
- commands.push(Command::SetMediaColorRange {
- media_id: after.media_id.clone(),
- range: now,
- });
- }
self.echo = None;
if commands.is_empty() {
return;
@@ -6065,19 +6030,6 @@ impl Studio {
});
SelectedClipData {
present: true,
- // -1 hides the control: a title, a layer or a sound has no
- // picture file whose levels could be named.
- color_range: if clip.kind.is_visual() {
- self.project()
- .media_by_id(&clip.media_id)
- .map_or(-1, |item| match item.color_range {
- None => 0,
- Some(model::ColorRange::Limited) => 1,
- Some(model::ColorRange::Full) => 2,
- })
- } else {
- -1
- },
frame_width: self.output_size().0 as i32,
frame_height: self.output_size().1 as i32,
id: clip.id.as_str().into(),
@@ -6575,8 +6527,12 @@ impl Studio {
}
}
- /// The right-click menu for the clip it was opened on.
+ /// The right-click menu: the bin card's when it was opened on one,
+ /// else the clip's.
fn menu(&self) -> Vec<MenuItemData> {
+ if let Some(id) = self.menu_media.as_deref() {
+ return self.media_menu(id);
+ }
let Some(clip) = self.menu_target.as_ref().and_then(|id| self.clip(id)) else {
return Vec::new();
};
@@ -6711,6 +6667,109 @@ impl Studio {
rows
}
+ /// The right-click menu for a card in the bin: the file's verbs, and
+ /// the one attribute a file has that every clip cut from it inherits.
+ ///
+ /// A picture's colour range is the media's rather than any clip's -
+ /// the fix for a file that lies about its levels is a fact about the
+ /// file - so it is set here, off the card, the way Resolve keeps Clip
+ /// Attributes off the media pool, and not in a clip's inspector where
+ /// it read as a property of the cut. Auto is the file's tag, and the
+ /// codec's convention where there is none; see
+ /// `concat_media::ColorRange::implied`.
+ /// https://github.com/jub0t/Concat/issues/103
+ fn media_menu(&self, id: &str) -> Vec<MenuItemData> {
+ let Some(item) = self.project().media_by_id(id) else {
+ return Vec::new();
+ };
+ let action = |id: &str, label: String, glyph: Glyph, danger: bool| MenuItemData {
+ id: id.into(),
+ label: label.into(),
+ kind: MenuRow::Action,
+ glyph,
+ shortcut: "".into(),
+ enabled: true,
+ danger,
+ checkable: false,
+ checked: false,
+ };
+ // The levels go where a shortcut would: the number is what the
+ // word means, and a person who knows one knows the other.
+ let check = |id: &str, label: String, levels: &str, on: bool| MenuItemData {
+ id: id.into(),
+ label: label.into(),
+ kind: MenuRow::Action,
+ glyph: Glyph::None,
+ shortcut: levels.into(),
+ enabled: true,
+ danger: false,
+ checkable: true,
+ checked: on,
+ };
+ let rule = || MenuItemData {
+ kind: MenuRow::Separator,
+ ..Default::default()
+ };
+ let mut rows = vec![
+ action("add", t("Add at playhead"), Glyph::Plus, false),
+ rule(),
+ ];
+ if item.kind != model::MediaKind::Audio {
+ let range = item.color_range;
+ rows.push(MenuItemData {
+ label: t("Colour range").to_uppercase().into(),
+ kind: MenuRow::Label,
+ ..Default::default()
+ });
+ rows.push(check("range-auto", t("Auto"), "", range.is_none()));
+ rows.push(check(
+ "range-limited",
+ t("Limited"),
+ "16-235",
+ range == Some(model::ColorRange::Limited),
+ ));
+ rows.push(check(
+ "range-full",
+ t("Full"),
+ "0-255",
+ range == Some(model::ColorRange::Full),
+ ));
+ rows.push(rule());
+ }
+ rows.push(action("remove", t("Remove"), Glyph::Trash, true));
+ rows
+ }
+
+ /// A row of a bin card's menu, for the media it was opened on.
+ pub fn media_action(&mut self, id: &str, action: &str) {
+ let Some(row) = self.media.row_of(id) else {
+ return;
+ };
+ if self.project().media_by_id(id).is_none() {
+ return;
+ }
+ let range = |range| Command::SetMediaColorRange {
+ media_id: id.to_owned(),
+ range,
+ };
+ match action {
+ "add" => self.place_at_playhead(&format!("media:{row}")),
+ "remove" => self.handle(crate::panes::Msg::Media(
+ crate::panes::media_bin::MediaMsg::Remove(row),
+ )),
+ "range-auto" => {
+ self.apply(range(None));
+ }
+ "range-limited" => {
+ self.apply(range(Some(model::ColorRange::Limited)));
+ }
+ "range-full" => {
+ self.apply(range(Some(model::ColorRange::Full)));
+ }
+ _ => {}
+ }
+ }
+
pub fn menu_height(rows: &[MenuItemData]) -> f32 {
let metrics = |kind: MenuRow| match kind {
MenuRow::Action => 26.0,
diff --git a/src/crates/concat/ui/editor.slint b/src/crates/concat/ui/editor.slint
index 3889028a..38baf8ee 100644
--- a/src/crates/concat/ui/editor.slint
+++ b/src/crates/concat/ui/editor.slint
@@ -86,6 +86,9 @@ export global Editor {
callback media-remove(id: int);
callback media-remove-selected();
callback media-activate(id: int);
+ /// Right-click on a card in the bin: Rust fills `menu-items` for the
+ /// file and bumps `menu-token`, the same round trip as `clip-context`.
+ callback media-context(id: int);
// library catalogue pages
/// The looks the Text page offers, published once.
diff --git a/src/crates/concat/ui/inspector/clip-inspector.slint b/src/crates/concat/ui/inspector/clip-inspector.slint
index d7eb61ee..25d55041 100644
--- a/src/crates/concat/ui/inspector/clip-inspector.slint
+++ b/src/crates/concat/ui/inspector/clip-inspector.slint
@@ -1410,9 +1410,10 @@ export component AudioPanel inherits VerticalLayout {
/// which one this clip plays; a file with one has nothing to choose and
/// shows no row.
in property <[string]> audio-tracks;
- /// The Source section has something to offer: a choice of audio
- /// track, or a picture file whose levels can be named.
- property <bool> choosing: root.audio-tracks.length > 1 || root.selected.color-range >= 0;
+ /// The Source section has something to offer: a choice of audio track.
+ /// A file's colour range used to sit here too and is the media's now,
+ /// in the bin card's menu: it is a fact about the file, not the cut.
+ property <bool> choosing: root.audio-tracks.length > 1;
callback set(field: ClipField, value: float);
callback commit();
@@ -1458,23 +1459,6 @@ export component AudioPanel inherits VerticalLayout {
}
}
}
- // The levels the file really spans, for one that lies about it: a
- // screen recording that plays grey where it should be black is a
- // full-range file tagged nothing, and "Full" is the fix. Set on
- // the media, so every clip of the file follows.
- // https://github.com/jub0t/Concat/issues/103
- if root.selected.color-range >= 0: Row {
- label: I18n.t("Colour range");
- Select {
- options: [I18n.t("As tagged"), I18n.t("Limited"), I18n.t("Full")];
- details: ["", "16-235", "0-255"];
- current: root.selected.color-range;
- changed(index) => {
- root.set(ClipField.color-range, index);
- root.commit();
- }
- }
- }
}
}
diff --git a/src/crates/concat/ui/timeline/model.slint b/src/crates/concat/ui/timeline/model.slint
index 8838dc93..b011c950 100644
--- a/src/crates/concat/ui/timeline/model.slint
+++ b/src/crates/concat/ui/timeline/model.slint
@@ -166,9 +166,6 @@ export enum ClipField {
/// which of the media's audio tracks the clip plays, as a row of
/// Editor.audio-tracks
audio-track,
- /// the levels the clip's file is read as: 0 as tagged, 1 limited,
- /// 2 full. A property of the media, set from the clip.
- color-range,
}
/// One keyable property's state at the playhead, as the inspector needs it.
@@ -334,11 +331,6 @@ export struct SelectedClipData {
enhance-progress: float,
enhance-fetching: bool,
- // the levels the clip's media is read as: 0 as the file is tagged,
- // 1 limited, 2 full; -1 for a clip with no picture file behind it,
- // which hides the control
- color-range: int,
-
// the overlay, when this is a text clip
content: string,
font-family: string,
diff --git a/src/crates/concat/ui/workspace/media-pane.slint b/src/crates/concat/ui/workspace/media-pane.slint
index 13d56c24..2c2d066e 100644
--- a/src/crates/concat/ui/workspace/media-pane.slint
+++ b/src/crates/concat/ui/workspace/media-pane.slint
@@ -11,6 +11,7 @@ import { CatalogueEntryData, Library } from "../inspector/clip-inspector.slint";
import { SearchField } from "../inspector/controls.slint";
import { Select } from "../primitives/select.slint";
import { Wave } from "../primitives/wave.slint";
+import { ContextMenu, MenuItemData } from "../primitives/context-menu.slint";
// The library pane: a strip of pages across the top, then a narrow category
// sidebar and the browsing area beside it. Media is the bin; Text adds a
@@ -393,6 +394,8 @@ component MediaCard inherits Rectangle {
/// double click: put it on the timeline at the playhead
callback activated();
callback removed();
+ /// right click, with where on the card it landed: the menu opens there
+ callback context(x: length, y: length);
property <color> mark: root.item.kind == MediaKind.audio ? Theme.kind-audio
: root.item.kind == MediaKind.image ? Theme.kind-image
@@ -437,6 +440,15 @@ component MediaCard inherits Rectangle {
card := TouchArea {
mouse-cursor: pointer;
pointer-event(event) => {
+ // The right button asks for the menu and does nothing
+ // else, on the release rather than the press, for the
+ // reasons the lanes give beside their own.
+ if (event.button == PointerEventButton.right) {
+ if (event.kind == PointerEventKind.up) {
+ root.context(self.mouse-x, self.mouse-y);
+ }
+ return;
+ }
if (event.kind == PointerEventKind.down) {
root.additive = event.modifiers.shift || event.modifiers.control
|| event.modifiers.meta;
@@ -600,6 +612,24 @@ component MediaGrid inherits Rectangle {
callback clicked(id: int, additive: bool);
callback activated(id: int);
callback removed(id: int);
+ /// Right-click on a card. Rust fills the menu and bumps `menu-token`;
+ /// where it opens is decided here, because only this side knows where
+ /// the pointer was. The token is gated the way the lanes gate theirs:
+ /// it is one number for the whole window, and only the grid that
+ /// asked opens on it.
+ callback context(id: int);
+ callback menu-selected(id: string);
+ in property <[MenuItemData]> menu-items;
+ in property <length> menu-height;
+ in property <int> menu-token;
+ property <bool> asked;
+ property <int> own-token;
+ changed menu-token => {
+ if (root.asked) {
+ root.asked = false;
+ root.own-token = root.menu-token;
+ }
+ }
/// A press on the gutter between the cards, before any band.
callback pressed();
/// A marquee closed over the grid, given as the block of cells it caught:
@@ -723,6 +753,15 @@ component MediaGrid inherits Rectangle {
removed => {
root.removed(entry.id);
}
+ context(x, y) => {
+ // Captured before the round trip, and `asked` goes up first:
+ // the call below publishes before it returns, so the token
+ // can arrive inside it.
+ menu.request-x = self.x + x;
+ menu.request-y = self.y + y;
+ root.asked = true;
+ root.context(entry.id);
+ }
}
// The band being drawn, declared last so it lies over the cards it is
@@ -737,6 +776,19 @@ component MediaGrid inherits Rectangle {
border-width: 1px;
border-color: Theme.accent;
}
+
+ // Over everything, like the lanes' one: a PopupWindow is its own layer,
+ // but the element that places it has to be able to measure the grid.
+ menu := ContextMenu {
+ x: 0;
+ y: 0;
+ width: parent.width;
+ height: parent.height;
+ items: root.menu-items;
+ menu-height: root.menu-height;
+ token: root.own-token;
+ selected(id) => { root.menu-selected(id); }
+ }
}
// ── the catalogue pages ──────────────────────────────────────────────────────
@@ -1379,6 +1431,12 @@ export component MediaPane inherits Rectangle {
callback remove-selected();
/// double-clicked: place it on the timeline at the playhead
callback activate(id: int);
+ /// right-clicked: the card's menu, filled by Rust; see MediaGrid.context
+ callback context(id: int);
+ callback menu-selected(id: string);
+ in property <[MenuItemData]> menu-items;
+ in property <length> menu-height;
+ in property <int> menu-token;
/// The looks the Text page's Presets shelf offers.
in property <[TextPresetData]> presets;
@@ -2073,10 +2131,16 @@ export component MediaPane inherits Rectangle {
page-floor: Math.max(0px, pages.height - 52px
- (root.selected-count > 1 ? 36px : 0px) - 8px);
+ menu-items: root.menu-items;
+ menu-height: root.menu-height;
+ menu-token: root.menu-token;
+
pressed => { root.floor-pressed(); }
clicked(id, additive) => { root.select(id, additive); }
activated(id) => { root.activate(id); }
removed(id) => { root.remove(id); }
+ context(id) => { root.context(id); }
+ menu-selected(id) => { root.menu-selected(id); }
band-selected(columns, from-col, to-col, from-row, to-row, additive) => {
root.band-selected(columns, from-col, to-col,
from-row, to-row, additive);
diff --git a/src/crates/concat/ui/workspace/seat.slint b/src/crates/concat/ui/workspace/seat.slint
index 88d17ac8..702871d1 100644
--- a/src/crates/concat/ui/workspace/seat.slint
+++ b/src/crates/concat/ui/workspace/seat.slint
@@ -116,6 +116,11 @@ export component Seat inherits Rectangle {
remove(id) => { Editor.media-remove(id); }
remove-selected => { Editor.media-remove-selected(); }
activate(id) => { Editor.media-activate(id); }
+ context(id) => { Editor.media-context(id); }
+ menu-items: Editor.menu-items;
+ menu-height: Editor.menu-height;
+ menu-token: Editor.menu-token;
+ menu-selected(id) => { Editor.menu-selected(id); }
presets: Editor.text-presets;
catalogue-effects: Editor.catalogue-effects;