From 53791162b10bfeac9d9394ce86baa2faaa21e19c Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sun, 16 Mar 2025 22:49:42 -0500 Subject: [PATCH] changing how each slide in the song_editor gets its video background --- Cargo.lock | 2 +- Cargo.toml | 11 ++++++++++- src/core/slide.rs | 14 ++++++++++++++ src/ui/song_editor.rs | 35 ++++++++++++++++++++++++----------- 4 files changed, 49 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 862bd62..0e13697 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3431,7 +3431,7 @@ dependencies = [ [[package]] name = "iced_video_player" version = "0.6.0" -source = "git+https://github.com/jackpot51/iced_video_player?branch=cosmic#ff37a34f99814597db0e265e172dd5a85a03394a" +source = "git+https://github.com/jackpot51/iced_video_player.git?branch=cosmic#ff37a34f99814597db0e265e172dd5a85a03394a" dependencies = [ "glib", "gstreamer", diff --git a/Cargo.toml b/Cargo.toml index 8b7cdea..5d12c01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ serde = { version = "1.0.213", features = ["derive"] } serde-lexpr = "0.1.3" tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["fmt", "std", "chrono", "time", "local-time", "env-filter"] } -iced_video_player = { git = "https://github.com/jackpot51/iced_video_player", branch = "cosmic", features = ["wgpu"] } strum = "0.26.3" strum_macros = "0.26.4" ron = "0.8.1" @@ -31,3 +30,13 @@ cosmic-time = "0.2.0" url = "2" # rfd = { version = "0.12.1", features = ["xdg-portal"], default-features = false } +[dependencies.iced_video_player] +git = "https://github.com/jackpot51/iced_video_player.git" +branch = "cosmic" +features = ["wgpu"] + +[profile.dev] +opt-level = 0 + +[profile.release] +opt-level = 3 diff --git a/src/core/slide.rs b/src/core/slide.rs index 05c3b34..f71225b 100644 --- a/src/core/slide.rs +++ b/src/core/slide.rs @@ -52,6 +52,20 @@ pub struct Background { pub kind: BackgroundKind, } +impl TryFrom<&Background> for Video { + type Error = ParseError; + + fn try_from( + value: &Background, + ) -> std::result::Result { + Video::new( + &url::Url::from_file_path(value.path.clone()) + .map_err(|_| ParseError::BackgroundNotVideo)?, + ) + .map_err(|_| ParseError::BackgroundNotVideo) + } +} + impl TryFrom for Video { type Error = ParseError; diff --git a/src/ui/song_editor.rs b/src/ui/song_editor.rs index 296d4fb..86727c7 100644 --- a/src/ui/song_editor.rs +++ b/src/ui/song_editor.rs @@ -185,6 +185,7 @@ impl SongEditor { self.lyrics = text_editor::Content::with_text(&lyrics) }; + self.background_video(&song.background); self.background = song.background; } Message::ChangeFont(font) => { @@ -260,15 +261,8 @@ impl SongEditor { if let Some(mut song) = self.song.clone() { let background = Background::try_from(path.clone()).ok(); - if let Some(background) = background { - if background.kind == BackgroundKind::Video { - let video = - Video::try_from(background).ok(); - debug!(?video); - self.video = video; - } - } - song.background = path.try_into().ok(); + self.background_video(&background); + song.background = background; return self.update_song(song); } } @@ -309,11 +303,16 @@ impl SongEditor { if let Ok(slides) = song.to_slides() { let slides = slides .into_iter() - .map(|slide| { + .enumerate() + .map(|(index, slide)| { container( slide_view( slide, - &self.video, + if index == 0 { + &self.video + } else { + &None + }, self.current_font, false, false, @@ -424,6 +423,20 @@ order", self.song = Some(song.clone()); Action::UpdateSong(song) } + + fn background_video(&mut self, background: &Option) { + if let Some(background) = background { + if background.kind == BackgroundKind::Video { + let video = + Video::try_from(background).ok().map(|mut v| { + v.set_looping(true); + v + }); + debug!(?video); + self.video = video; + } + } + } } impl Default for SongEditor {