The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.
Rust ffmpegfree-video-editormodel-context-protocolnon-linear-editoroffline-firstopen-source-video-editorself-hostedvideo-editingvideo-editing-automationvideo-editing-softwarevideo-editing-toolsvideo-editorvoice-cloningyoutube-automationyoutube-shorts
refactor(ui): the media bin is a pane behind a message
Jareer04327e504552
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rsindex 2f484de5..3e7445d9 100644--- a/src/crates/concat/src/lib.rs+++ b/src/crates/concat/src/lib.rs@@ -53,6 +53,7 @@ use host::{Host, Shell, on_ui};use panes::Msg;use panes::captions::CaptionsMsg;use panes::export::ExportMsg;+use panes::media_bin::MediaMsg;use panes::project::ProjectMsg;use panes::relink::RelinkMsg;use panes::settings::SettingsMsg;@@ -93,7 +94,7 @@ pub fn run() -> Result<(), slint::PlatformError> {Shell::with(|shell, app| {{let mut studio = shell.studio.borrow_mut();- studio.import(paths);+ studio.handle(Msg::Media(MediaMsg::Import(paths)));}shell.studio.borrow_mut().refresh_art();shell.studio.borrow().publish(&app, &shell.models);@@ -454,15 +455,13 @@ pub fn run() -> Result<(), slint::PlatformError> {// ── the bin ──editor.on_media_filter_changed(on_window!(|state, filter: MediaFilter| {- state.set_media_filter(filter);+ state.handle(Msg::Media(MediaMsg::FilterChanged(filter)));}));editor.on_media_sort_changed(on_window!(|state, index: i32| {- // Slint hands indices over as i32; the sort is an index into a- // three-entry table, so clamp negatives to the default order.- state.set_media_sort(index.max(0) as usize);+ state.handle(Msg::Media(MediaMsg::SortChanged(index)));}));- editor.on_media_select(on_window!(|state, id: i32, additive: bool| {- state.media_select(id, additive);+ editor.on_media_select(on_window!(|state, row: i32, additive: bool| {+ state.handle(Msg::Media(MediaMsg::Select { row, additive }));}));editor.on_media_band_selected(on_window!(|state,@@ -472,14 +471,21 @@ pub fn run() -> Result<(), slint::PlatformError> {from_row: i32,to_row: i32,additive: bool| {- state.media_band(columns, from_col, to_col, from_row, to_row, additive);+ state.handle(Msg::Media(MediaMsg::Band {+ columns,+ from_col,+ to_col,+ from_row,+ to_row,+ additive,+ }));}));- editor.on_media_remove(on_window!(|state, id: i32| {- state.media_remove(id);+ editor.on_media_remove(on_window!(|state, row: i32| {+ state.handle(Msg::Media(MediaMsg::Remove(row)));}));editor.on_media_remove_selected(on_window!(|state| {- state.media_remove_selected();+ state.handle(Msg::Media(MediaMsg::RemoveSelected));}));// Not through the handler macro: nothing here changes the state, and// the import is asynchronous - a phone's picker is another screen, and@@ -499,7 +505,9 @@ pub fn run() -> Result<(), slint::PlatformError> {"flac", "ogg", "png", "jpg", "jpeg", "webp", "gif", "bmp", "tif", "tiff",],)),- |paths| on_ui(move |studio, _, _| studio.import(paths)),+ |paths| {+ on_ui(move |studio, _, _| studio.handle(Msg::Media(MediaMsg::Import(paths))))+ },);});});@@ -1122,7 +1130,7 @@ pub fn run() -> Result<(), slint::PlatformError> {let mut state = shell.studio.borrow_mut();state.open_menu = -1;match action.as_str() {- "add-selected" => state.add_selected_media(),+ "add-selected" => state.handle(Msg::Media(MediaMsg::AddSelectedAtPlayhead)),"open" => {if let Some(path) = platform::pick_folder(&i18n::t("Open project"), ""){@@ -1138,7 +1146,9 @@ pub fn run() -> Result<(), slint::PlatformError> {}"import" => {platform::pick_files_async(&i18n::t("Import media"), None, |paths| {- on_ui(move |studio, _, _| studio.import(paths))+ on_ui(move |studio, _, _| {+ studio.handle(Msg::Media(MediaMsg::Import(paths)))+ })});}"export" => state.handle(Msg::Export(ExportMsg::Open)),@@ -1150,9 +1160,9 @@ pub fn run() -> Result<(), slint::PlatformError> {"undo" => state.undo(),"redo" => state.redo(),"snap" => state.snap = !state.snap,- "sort-added" => state.set_media_sort(0),- "sort-name" => state.set_media_sort(1),- "sort-kind" => state.set_media_sort(2),+ "sort-added" => state.handle(Msg::Media(MediaMsg::SortChanged(0))),+ "sort-name" => state.handle(Msg::Media(MediaMsg::SortChanged(1))),+ "sort-kind" => state.handle(Msg::Media(MediaMsg::SortChanged(2))),"zoom-in" => {state.seconds_per_pixel = (state.seconds_per_pixel / 1.4).max(0.000_5)}diff --git a/src/crates/concat/src/panes/media_bin.rs b/src/crates/concat/src/panes/media_bin.rsnew file mode 100644index 00000000..4f629ac2--- /dev/null+++ b/src/crates/concat/src/panes/media_bin.rs@@ -0,0 +1,437 @@+// SPDX-License-Identifier: AGPL-3.0-or-later+// SPDX-FileCopyrightText: 2026 Jareer and Concat contributors++//! The media bin: the project's files as cards, filtered, sorted and+//! selected.+//!+//! The bin owns what is the window's about the media and not the+//! document's: the integer row Slint knows each item by, the selection,+//! the filter and the sort, and the card artwork. The peaks and+//! filmstrips are not here: the lanes draw them too, so they stay on the+//! controller's art store. An import probes on a worker and comes back+//! as [`MediaMsg::Imported`], one batch of `AddMedia` commands.++use std::collections::{HashMap, HashSet};+use std::path::PathBuf;++use concat_host::media::{self, MediaSummary};+use concat_project::Command;+use concat_project::model::{self, MediaItem, Project};+use slint::SharedString;++use crate::format::wave_path;+use crate::host::{probe_error, spawn};+use crate::i18n::{t, tf};+use crate::panes::Msg;+use crate::studio::Studio;+use crate::ui::{MediaFilter, MediaItemData, MediaKind};++/// Everything that can happen to the bin.+#[derive(Clone, Debug)]+pub enum MediaMsg {+ FilterChanged(MediaFilter),+ /// 0 added, 1 name, 2 kind.+ SortChanged(i32),+ /// A card clicked, by its row; additive keeps what was selected.+ Select {+ row: i32,+ additive: bool,+ },+ /// A marquee closed over the grid: the block of cells it caught.+ Band {+ columns: i32,+ from_col: i32,+ to_col: i32,+ from_row: i32,+ to_row: i32,+ additive: bool,+ },+ Remove(i32),+ RemoveSelected,+ /// Files picked, dropped or handed over by the platform.+ Import(Vec<PathBuf>),+ /// The import's worker is done probing.+ Imported(Vec<Result<MediaSummary, String>>),+ /// Everything selected goes on the timeline at the playhead.+ AddSelectedAtPlayhead,+}++/// The bin's state.+pub struct MediaBin {+ /// Slint's rows are integers; the document's ids are strings. Assigned+ /// once per id and never reused, so a payload in flight names the row it+ /// was dragged from.+ rows: HashMap<String, i32>,+ next_row: i32,+ pub selected: HashSet<String>,+ pub filter: MediaFilter,+ /// 0 = Added, 1 = Name, 2 = Kind+ pub sort: usize,+ /// The cards' pictures by media id.+ pub thumbs: HashMap<String, slint::Image>,+}++impl Default for MediaBin {+ fn default() -> Self {+ Self {+ rows: HashMap::new(),+ next_row: 1,+ selected: HashSet::new(),+ filter: MediaFilter::All,+ sort: 0,+ thumbs: HashMap::new(),+ }+ }+}++impl MediaBin {+ /// Applies one message. The studio is the rest of the window; while+ /// this runs the studio's copy of the pane is a blank it must not read.+ pub fn update(&mut self, msg: MediaMsg, studio: &mut Studio) {+ match msg {+ MediaMsg::FilterChanged(filter) => self.filter = filter,+ MediaMsg::SortChanged(index) => self.sort = (index.max(0) as usize).min(2),+ MediaMsg::Select { row, additive } => {+ let Some(id) = self+ .by_row(studio.project(), row)+ .map(|item| item.id.clone())+ else {+ return;+ };+ self.select(id, additive);+ }+ MediaMsg::Band {+ columns,+ from_col,+ to_col,+ from_row,+ to_row,+ additive,+ } => {+ self.selected = self.band(+ studio.project(),+ columns,+ (from_col, to_col),+ (from_row, to_row),+ additive,+ );+ }+ MediaMsg::Remove(row) => {+ if let Some(id) = self+ .by_row(studio.project(), row)+ .map(|item| item.id.clone())+ {+ self.selected.remove(&id);+ studio.apply(Command::RemoveMedia { media_id: id });+ }+ }+ MediaMsg::RemoveSelected => {+ let doomed: Vec<String> = self.selected.drain().collect();+ if doomed.is_empty() {+ return;+ }+ studio.apply(Command::Batch {+ commands: doomed+ .into_iter()+ .map(|media_id| Command::RemoveMedia { media_id })+ .collect(),+ });+ }+ MediaMsg::Import(paths) => {+ if paths.is_empty() || studio.session.is_none() {+ return;+ }+ spawn(+ move || {+ paths+ .iter()+ .map(|path| media::probe(&path.to_string_lossy()))+ .collect::<Vec<_>>()+ },+ |studio, _, _, results| studio.handle(Msg::Media(MediaMsg::Imported(results))),+ );+ }+ MediaMsg::Imported(results) => {+ let mut commands = Vec::new();+ let mut failures = Vec::new();+ for result in results {+ match result {+ Ok(summary) => commands.push(Command::AddMedia {+ item: summary.to_new_media(),+ }),+ Err(error) => failures.push(error),+ }+ }+ let added = commands.len();+ if !commands.is_empty() {+ studio.apply(Command::Batch { commands });+ }+ if let Some(error) = failures.first() {+ studio.notify(&probe_error(error), true);+ } else if added > 0 {+ studio.notify(+ &if added == 1 {+ t("Imported 1 file")+ } else {+ tf("Imported {0} files", &[&added])+ },+ false,+ );+ }+ }+ MediaMsg::AddSelectedAtPlayhead => {+ let ids: Vec<String> = studio+ .project()+ .media+ .iter()+ .filter(|item| self.selected.contains(&item.id))+ .map(|item| item.id.clone())+ .collect();+ let start = f64::from(studio.playhead.max(0.0));+ for media_id in ids {+ studio.apply(Command::AddClipAtFirstFree { media_id, start });+ }+ }+ }+ }++ /// Gives every media item the integer row Slint knows it by. New items+ /// get the next number; nothing is ever renumbered.+ pub fn assign_rows(&mut self, project: &Project) {+ for item in &project.media {+ if !self.rows.contains_key(&item.id) {+ self.rows.insert(item.id.clone(), self.next_row);+ self.next_row += 1;+ }+ }+ }++ /// The item Slint's row names, if it is still in the project.+ pub fn by_row<'a>(&self, project: &'a Project, row: i32) -> Option<&'a MediaItem> {+ let id = self.rows.iter().find(|(_, held)| **held == row)?.0;+ project.media_by_id(id)+ }++ /// Whether the filter lets an item of this kind through.+ fn shows(filter: MediaFilter, kind: model::MediaKind) -> bool {+ match filter {+ MediaFilter::All => true,+ MediaFilter::Video => kind == model::MediaKind::Video,+ MediaFilter::Audio => kind == model::MediaKind::Audio,+ MediaFilter::Images => kind == model::MediaKind::Image,+ }+ }++ /// A click: the one card, or toggled into what is held.+ fn select(&mut self, id: String, additive: bool) {+ if additive {+ if !self.selected.remove(&id) {+ self.selected.insert(id);+ }+ } else {+ self.selected.clear();+ self.selected.insert(id);+ }+ }++ /// A marquee closed over the grid, as the block of cells it caught. The+ /// walk is over the filtered order, because that is what the grid was+ /// laid out from.+ fn band(+ &self,+ project: &Project,+ columns: i32,+ (from_col, to_col): (i32, i32),+ (from_row, to_row): (i32, i32),+ additive: bool,+ ) -> HashSet<String> {+ let mut cell = 0;+ let mut next = if additive {+ self.selected.clone()+ } else {+ HashSet::new()+ };+ for item in &project.media {+ if !Self::shows(self.filter, item.kind) {+ continue;+ }+ let (row, col) = (cell / columns.max(1), cell % columns.max(1));+ if row >= from_row && row <= to_row && col >= from_col && col <= to_col {+ next.insert(item.id.clone());+ }+ cell += 1;+ }+ next+ }++ /// The items the bin shows, filtered and in the chosen order.+ fn visible<'a>(&self, project: &'a Project) -> Vec<&'a MediaItem> {+ let mut visible: Vec<&MediaItem> = project+ .media+ .iter()+ .filter(|item| Self::shows(self.filter, item.kind))+ .collect();+ match self.sort {+ // Added: the import order, as the document keeps it.+ 0 => {}+ 1 => visible.sort_by(|a, b| a.name.to_lowercase().cmp(&b.name.to_lowercase())),+ // Video, then audio, then stills; each by name.+ 2 => visible.sort_by(|a, b| {+ let rank = |kind: model::MediaKind| match kind {+ model::MediaKind::Video => 0,+ model::MediaKind::Audio => 1,+ model::MediaKind::Image => 2,+ };+ rank(a.kind)+ .cmp(&rank(b.kind))+ .then_with(|| a.name.to_lowercase().cmp(&b.name.to_lowercase()))+ }),+ _ => {}+ }+ visible+ }++ /// The cards, as Slint shows them.+ pub fn rows(&self, studio: &Studio) -> Vec<MediaItemData> {+ self.visible(studio.project())+ .into_iter()+ .map(|item| MediaItemData {+ id: *self.rows.get(&item.id).unwrap_or(&0),+ name: item.name.as_str().into(),+ kind: media_kind_of(item.kind),+ duration: item.duration.unwrap_or(0.0) as f32,+ format: std::path::Path::new(&item.path)+ .extension()+ .and_then(|extension| extension.to_str())+ .map(|extension| extension.to_ascii_lowercase())+ .unwrap_or_default()+ .into(),+ thumbnail: self.thumbs.get(&item.id).cloned().unwrap_or_default(),+ wave: match studio.peaks.get(&item.id) {+ Some(peaks) if item.kind == model::MediaKind::Audio => {+ wave_path(peaks, 0.0, item.duration.unwrap_or(0.0) as f32, 1.0).into()+ }+ _ => SharedString::new(),+ },+ selected: self.selected.contains(&item.id),+ })+ .collect()+ }+}++/// The document's kind as the card's.+fn media_kind_of(kind: model::MediaKind) -> MediaKind {+ match kind {+ model::MediaKind::Video => MediaKind::Video,+ model::MediaKind::Audio => MediaKind::Audio,+ model::MediaKind::Image => MediaKind::Image,+ }+}++#[cfg(test)]+mod tests {+ use super::*;+ use concat_project::model::{MediaKind as Kind, Project};++ fn project() -> Project {+ let mut project = Project::default();+ for (id, name, kind) in [+ ("v1", "Zebra.mp4", Kind::Video),+ ("a1", "alpha.wav", Kind::Audio),+ ("i1", "Mid.png", Kind::Image),+ ("v2", "apple.mov", Kind::Video),+ ] {+ project.media.push(MediaItem {+ id: id.to_owned(),+ name: name.to_owned(),+ kind,+ ..MediaItem::default()+ });+ }+ project+ }++ #[test]+ fn rows_are_assigned_once_and_never_reused() {+ let mut bin = MediaBin::default();+ let mut project = project();+ bin.assign_rows(&project);+ let zebra = bin.by_row(&project, 1).expect("row 1").id.clone();+ assert_eq!(zebra, "v1");+ // The first item goes; its row goes with it and is never given out+ // again, so a payload in flight cannot name the wrong file.+ project.media.remove(0);+ bin.assign_rows(&project);+ assert!(bin.by_row(&project, 1).is_none());+ project.media.push(MediaItem {+ id: "v3".to_owned(),+ ..MediaItem::default()+ });+ bin.assign_rows(&project);+ assert_eq!(bin.by_row(&project, 5).expect("a new row").id, "v3");+ assert!(bin.by_row(&project, 0).is_none(), "zero names nothing");+ assert!(bin.by_row(&project, -7).is_none());+ }++ #[test]+ fn a_filter_and_a_sort_shape_the_visible_list() {+ let mut bin = MediaBin::default();+ let project = project();+ bin.filter = MediaFilter::Video;+ bin.sort = 1;+ let names: Vec<&str> = bin+ .visible(&project)+ .iter()+ .map(|item| item.name.as_str())+ .collect();+ assert_eq!(names, ["apple.mov", "Zebra.mp4"], "by name, case aside");+ bin.filter = MediaFilter::All;+ bin.sort = 2;+ let names: Vec<&str> = bin+ .visible(&project)+ .iter()+ .map(|item| item.name.as_str())+ .collect();+ assert_eq!(names, ["apple.mov", "Zebra.mp4", "alpha.wav", "Mid.png"]);+ bin.sort = 99;+ assert_eq!(+ bin.visible(&project).len(),+ 4,+ "an unknown sort keeps the order"+ );+ }++ #[test]+ fn a_click_toggles_only_when_additive() {+ let mut bin = MediaBin::default();+ bin.select("a".into(), false);+ bin.select("b".into(), false);+ assert_eq!(bin.selected.len(), 1);+ assert!(bin.selected.contains("b"));+ bin.select("a".into(), true);+ assert_eq!(bin.selected.len(), 2);+ bin.select("a".into(), true);+ assert!(!bin.selected.contains("a"));+ }++ #[test]+ fn a_band_walks_the_filtered_grid_and_survives_zero_columns() {+ let mut bin = MediaBin::default();+ let project = project();+ // Two columns over all four: rows are (v1 a1) (i1 v2).+ let caught = bin.band(&project, 2, (1, 1), (0, 1), false);+ assert_eq!(caught.len(), 2);+ assert!(caught.contains("a1") && caught.contains("v2"));+ // Zero or negative columns is one column, not a division by zero.+ let caught = bin.band(&project, 0, (0, 0), (0, 3), false);+ assert_eq!(caught.len(), 4);+ let caught = bin.band(&project, -3, (0, 0), (5, 9), false);+ assert!(caught.is_empty(), "rows past the end catch nothing");+ // Additive keeps what was there; a filter changes the walk.+ bin.selected.insert("x".into());+ bin.filter = MediaFilter::Images;+ let caught = bin.band(&project, 1, (0, 0), (0, 0), true);+ assert_eq!(caught.len(), 2);+ assert!(caught.contains("i1") && caught.contains("x"));+ }+}diff --git a/src/crates/concat/src/panes/mod.rs b/src/crates/concat/src/panes/mod.rsindex 587568dd..440bfdf4 100644--- a/src/crates/concat/src/panes/mod.rs+++ b/src/crates/concat/src/panes/mod.rs@@ -15,6 +15,7 @@pub mod captions;pub mod export;+pub mod media_bin;pub mod project;pub mod relink;pub mod settings;@@ -38,4 +39,6 @@ pub enum Msg {Project(project::ProjectMsg),/// To the launch screen's form.Start(start::StartMsg),+ /// To the media bin.+ Media(media_bin::MediaMsg),}diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rsindex abb9e158..64b5cf01 100644--- a/src/crates/concat/src/studio.rs+++ b/src/crates/concat/src/studio.rs@@ -531,18 +531,9 @@ pub struct Studio {autosave: slint::Timer,// ── the bin ──- /// Slint's rows are integers; the document's ids are strings. Assigned- /// once per id and never reused, so a payload in flight names the row it- /// was dragged from.- media_rows: HashMap<String, i32>,- next_media_row: i32,- media_selected: HashSet<String>,- media_filter: MediaFilter,- /// 0 = Added, 1 = Name, 2 = Kind- media_sort: usize,+ pub media: crate::panes::media_bin::MediaBin,/// Decoded art by media id, and the ids a worker is decoding for.pub peaks: HashMap<String, Arc<Peaks>>,- pub thumbs: HashMap<String, slint::Image>,/// Filmstrips by media id: the picture, how many frames are in it, one/// frame's width and the strip's height, in the picture's own pixels.pub strips: HashMap<String, Strip>,@@ -726,14 +717,6 @@ fn kind_of(clip: &Clip) -> ClipKind {}}-fn media_kind_of(kind: model::MediaKind) -> MediaKind {- match kind {- model::MediaKind::Video => MediaKind::Video,- model::MediaKind::Audio => MediaKind::Audio,- model::MediaKind::Image => MediaKind::Image,- }-}-fn align_of(align: TextAlign) -> TextAlignment {match align {TextAlign::Left => TextAlignment::Left,@@ -1229,13 +1212,8 @@ impl Studio {empty: Project::new(),dirty: false,autosave: slint::Timer::default(),- media_rows: HashMap::new(),- next_media_row: 1,- media_selected: HashSet::new(),- media_filter: MediaFilter::All,- media_sort: 0,+ media: crate::panes::media_bin::MediaBin::default(),peaks: HashMap::new(),- thumbs: HashMap::new(),strips: HashMap::new(),windows: HashMap::new(),art_pending: HashSet::new(),@@ -1927,152 +1905,12 @@ impl Studio {// ── the bin ──- /// Gives every media item the integer row Slint knows it by. New items- /// get the next number; nothing is ever renumbered.+ /// Gives every media item the row Slint knows it by; see+ /// `MediaBin::assign_rows`.fn assign_media_rows(&mut self) {- let ids: Vec<String> = self- .project()- .media- .iter()- .map(|item| item.id.clone())- .collect();- for id in ids {- if !self.media_rows.contains_key(&id) {- self.media_rows.insert(id, self.next_media_row);- self.next_media_row += 1;- }- }- }-- pub fn media_by_row(&self, row: i32) -> Option<&model::MediaItem> {- let id = self.media_rows.iter().find(|(_, held)| **held == row)?.0;- self.project().media_by_id(id)- }-- fn shows(filter: MediaFilter, kind: model::MediaKind) -> bool {- match filter {- MediaFilter::All => true,- MediaFilter::Video => kind == model::MediaKind::Video,- MediaFilter::Audio => kind == model::MediaKind::Audio,- MediaFilter::Images => kind == model::MediaKind::Image,- }- }-- pub fn set_media_filter(&mut self, filter: MediaFilter) {- self.media_filter = filter;- }-- pub fn set_media_sort(&mut self, sort: usize) {- self.media_sort = sort.min(2);- }-- pub fn media_select(&mut self, row: i32, additive: bool) {- let Some(id) = self.media_by_row(row).map(|item| item.id.clone()) else {- return;- };- if additive {- if !self.media_selected.remove(&id) {- self.media_selected.insert(id);- }- } else {- self.media_selected.clear();- self.media_selected.insert(id);- }- }-- /// A marquee closed over the grid, as the block of cells it caught. The- /// walk is over the filtered order, because that is what the grid was- /// laid out from.- pub fn media_band(- &mut self,- columns: i32,- from_col: i32,- to_col: i32,- from_row: i32,- to_row: i32,- additive: bool,- ) {- let filter = self.media_filter;- let mut cell = 0;- let mut next = if additive {- self.media_selected.clone()- } else {- HashSet::new()- };- for item in &self.project().media {- if !Self::shows(filter, item.kind) {- continue;- }- let (row, col) = (cell / columns.max(1), cell % columns.max(1));- if row >= from_row && row <= to_row && col >= from_col && col <= to_col {- next.insert(item.id.clone());- }- cell += 1;- }- self.media_selected = next;- }-- pub fn media_remove(&mut self, row: i32) {- if let Some(id) = self.media_by_row(row).map(|item| item.id.clone()) {- self.media_selected.remove(&id);- self.apply(Command::RemoveMedia { media_id: id });- }- }-- pub fn media_remove_selected(&mut self) {- let doomed: Vec<String> = self.media_selected.drain().collect();- if doomed.is_empty() {- return;- }- self.apply(Command::Batch {- commands: doomed- .into_iter()- .map(|media_id| Command::RemoveMedia { media_id })- .collect(),- });- }-- /// Probes the files on a worker and adds what probed as media.- pub fn import(&mut self, paths: Vec<std::path::PathBuf>) {- if paths.is_empty() || self.session.is_none() {- return;- }- spawn(- move || {- paths- .iter()- .map(|path| media::probe(&path.to_string_lossy()))- .collect::<Vec<_>>()- },- |studio, _, _, results| {- let mut commands = Vec::new();- let mut failures = Vec::new();- for result in results {- match result {- Ok(summary) => commands.push(Command::AddMedia {- item: summary.to_new_media(),- }),- Err(error) => failures.push(error),- }- }- let added = commands.len();- if !commands.is_empty() {- studio.apply(Command::Batch { commands });- }- if let Some(error) = failures.first() {- studio.notify(&crate::host::probe_error(error), true);- } else if added > 0 {- studio.notify(- &if added == 1 {- t("Imported 1 file")- } else {- tf("Imported {0} files", &[&added])- },- false,- );- }- },- );+ let mut bin = std::mem::take(&mut self.media);+ bin.assign_rows(self.project());+ self.media = bin;}/// Decodes art for every media item that has none yet: its pictures@@ -2103,7 +1941,8 @@ impl Studio {.filter(|item| !self.art_pending.contains(&item.id)).filter(|item| {let needs_thumb = item.kind != model::MediaKind::Audio- && (!self.thumbs.contains_key(&item.id) || !self.strips.contains_key(&item.id));+ && (!self.media.thumbs.contains_key(&item.id)+ || !self.strips.contains_key(&item.id));let needs_peaks = (item.kind == model::MediaKind::Audio || item.has_audio)&& !self.peaks.contains_key(&item.id);needs_thumb || needs_peaks@@ -2175,12 +2014,12 @@ impl Studio {if stream.is_none() && kind != model::MediaKind::Audio {let cached = cached_media_art(&project_path, &id, &path, kind);if let Some(image) = cached.thumbnail {- self.thumbs.insert(id.clone(), image);+ self.media.thumbs.insert(id.clone(), image);}if let Some(strip) = cached.strip {self.strips.insert(id.clone(), strip.into());}- pictures = !self.thumbs.contains_key(&id) || !self.strips.contains_key(&id);+ pictures = !self.media.thumbs.contains_key(&id) || !self.strips.contains_key(&id);}let needs_peaks =@@ -2202,7 +2041,7 @@ impl Studio {let key = art_key(&art.id, art.stream);studio.art_pending.remove(&key);if let Some(frame) = art.thumbnail {- studio.thumbs.insert(art.id.clone(), image_of(&frame));+ studio.media.thumbs.insert(art.id.clone(), image_of(&frame));}if let Some((frame, frames)) = art.strip {studio@@ -2393,7 +2232,7 @@ impl Studio {let label = fields.next().unwrap_or(id);match sort {"media" => {- let item = self.media_by_row(id.parse().ok()?)?;+ let item = self.media.by_row(self.project(), id.parse().ok()?)?;Some(DropPlan {kind: match item.kind {model::MediaKind::Audio => ClipKind::Audio,@@ -4770,7 +4609,7 @@ impl Studio {self.project_name = info.name.clone();self.export.name = projects::folder_name(&info.name);self.selection.clear();- self.media_selected.clear();+ self.media.selected.clear();self.lane_view.clear();self.playhead = 0.0;self.scroll_left = 0.0;@@ -4930,6 +4769,11 @@ impl Studio {pane.update(msg, self);self.start = pane;}+ crate::panes::Msg::Media(msg) => {+ let mut pane = std::mem::take(&mut self.media);+ pane.update(msg, self);+ self.media = pane;+ }}}@@ -5835,57 +5679,8 @@ impl Studio {);// The bin.- let filter = self.media_filter;let items = &self.project().media;-- // Grupiši po tipu (Video -> Audio -> Slike), pa abecedno po imenu- let mut visible: Vec<_> = items- .iter()- .filter(|item| Self::shows(filter, item.kind))- .collect();-- match self.media_sort {- 0 => { /* Added - no sorting, keep import order */ }- 1 => visible.sort_by(|a, b| a.name.to_lowercase().cmp(&b.name.to_lowercase())),- 2 => visible.sort_by(|a, b| {- let rank = |kind: model::MediaKind| match kind {- model::MediaKind::Video => 0,- model::MediaKind::Audio => 1,- model::MediaKind::Image => 2,- };- rank(a.kind)- .cmp(&rank(b.kind))- .then_with(|| a.name.to_lowercase().cmp(&b.name.to_lowercase()))- }),- _ => {}- }-- sync(- &models.media,- visible- .into_iter()- .map(|item| MediaItemData {- id: *self.media_rows.get(&item.id).unwrap_or(&0),- name: item.name.as_str().into(),- kind: media_kind_of(item.kind),- duration: item.duration.unwrap_or(0.0) as f32,- format: std::path::Path::new(&item.path)- .extension()- .and_then(|extension| extension.to_str())- .map(|extension| extension.to_ascii_lowercase())- .unwrap_or_default()- .into(),- thumbnail: self.thumbs.get(&item.id).cloned().unwrap_or_default(),- wave: match self.peaks.get(&item.id) {- Some(peaks) if item.kind == model::MediaKind::Audio => {- wave_path(peaks, 0.0, item.duration.unwrap_or(0.0) as f32, 1.0).into()- }- _ => SharedString::new(),- },- selected: self.media_selected.contains(&item.id),- })- .collect(),- );+ sync(&models.media, self.media.rows(self));editor.set_media_count_all(items.len() as i32);editor.set_media_count_video(items@@ -5905,7 +5700,7 @@ impl Studio {.filter(|item| item.kind == model::MediaKind::Image).count() as i32,);- editor.set_media_selected_count(self.media_selected.len() as i32);+ editor.set_media_selected_count(self.media.selected.len() as i32);editor.set_importing(false);let (width, height) = self.output_size();@@ -6150,7 +5945,7 @@ impl Studio {let (can_undo, can_redo) = self.session.as_ref().map_or((false, false), |session| {(session.can_undo(), session.can_redo())});- let has_selection_media = !self.media_selected.is_empty();+ let has_selection_media = !self.media.selected.is_empty();match self.open_menu {0 => vec![@@ -6240,9 +6035,9 @@ impl Studio {row("zoom-in", t("Zoom in"), Glyph::Plus, "+", true),row("zoom-out", t("Zoom out"), Glyph::Minus, "-", true),rule(),- check("sort-added", "Sort by: Added", self.media_sort == 0),- check("sort-name", "Sort by: Name", self.media_sort == 1),- check("sort-kind", "Sort by: Type", self.media_sort == 2),+ check("sort-added", "Sort by: Added", self.media.sort == 0),+ check("sort-name", "Sort by: Name", self.media.sort == 1),+ check("sort-kind", "Sort by: Type", self.media.sort == 2),rule(),row("start", t("Go to start"), Glyph::SkipBack, "Home", true),row("end", t("Go to end"), Glyph::SkipForward, "End", true),@@ -6251,21 +6046,6 @@ impl Studio {}}- /// Everything the media bin's selection would add at the playhead.- pub fn add_selected_media(&mut self) {- let ids: Vec<String> = self- .project()- .media- .iter()- .filter(|item| self.media_selected.contains(&item.id))- .map(|item| item.id.clone())- .collect();- let start = f64::from(self.playhead.max(0.0));- for media_id in ids {- self.apply(Command::AddClipAtFirstFree { media_id, start });- }- }-/// The clip's track flags, as one command per flag that changed, plus/// the lock, which is the window's.pub fn track_flags(&mut self, row: i32, visible: bool, muted: bool, locked: bool) {