diff --git a/Cargo.lock b/Cargo.lock index de8f62b..a573654 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1325,7 +1325,7 @@ checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" [[package]] name = "edits" -version = "0.31.0" +version = "0.31.1" dependencies = [ "gpui-kit", "kael_share", diff --git a/Cargo.toml b/Cargo.toml index 125d280..0e92e2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "edits" -version = "0.31.0" +version = "0.31.1" edition = "2021" description = "One small download (under 15 MB, with its desktop app) that turns any YouTube link, channel or topic into viral TikTok, Reels and Shorts edits: Alight Motion and Premiere presets, trending songs, beat-synced cuts, captions, colour looks, MCP server for AI agents." repository = "https://github.com/OnurByte/EditsMaker" diff --git a/packs/stardust/manifest.json b/packs/stardust/manifest.json index 13878c2..6140d9d 100644 --- a/packs/stardust/manifest.json +++ b/packs/stardust/manifest.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "id": "edits.stardust", "name": "Stardust", - "version": "1.0.0", + "version": "1.0.1", "author": "EditsMaker", "description": "Soft points of light drifting towards you in 3D, drawn with three.js. Lay it over a sad or dreamy edit; it loops.", "kinds": [ diff --git a/packs/stardust/scene.js b/packs/stardust/scene.js index 8eccbf0..e78e683 100644 --- a/packs/stardust/scene.js +++ b/packs/stardust/scene.js @@ -1,6 +1,6 @@ // Stardust: soft points of light drifting towards you, turning slowly; the last frame meets the first, so it loops. (THREE, scene, camera, opts) => { - const count = 900, seconds = 6; + const count = 220, seconds = 6; const pos = new Float32Array(count * 3), seed = new Float32Array(count); let s = 7; const rand = () => ((s = (s * 16807) % 2147483647) / 2147483647); @@ -12,17 +12,24 @@ } const geo = new THREE.BufferGeometry(); geo.setAttribute("position", new THREE.BufferAttribute(pos.slice(), 3)); + // each point its own warmth and brightness, a few large and soft like lights out of focus + const col = new Float32Array(count * 3); + for (let i = 0; i < count; i++) { + const b = 0.55 + 0.45 * seed[i]; + col[i * 3] = b; col[i * 3 + 1] = b * 0.92; col[i * 3 + 2] = b * 0.8; + } + geo.setAttribute("color", new THREE.BufferAttribute(col, 3)); // a round soft dot, drawn once const c = document.createElement("canvas"); c.width = c.height = 64; const g = c.getContext("2d"); const grad = g.createRadialGradient(32, 32, 0, 32, 32, 32); grad.addColorStop(0, "rgba(255,255,255,1)"); - grad.addColorStop(0.3, "rgba(255,236,214,0.8)"); + grad.addColorStop(0.25, "rgba(255,236,214,0.75)"); grad.addColorStop(1, "rgba(255,236,214,0)"); g.fillStyle = grad; g.fillRect(0, 0, 64, 64); - const mat = new THREE.PointsMaterial({ size: 0.3, map: new THREE.CanvasTexture(c), transparent: true, depthWrite: false, blending: THREE.AdditiveBlending }); + const mat = new THREE.PointsMaterial({ size: 0.5, vertexColors: true, map: new THREE.CanvasTexture(c), transparent: true, depthWrite: false, blending: THREE.AdditiveBlending }); const points = new THREE.Points(geo, mat); scene.add(points); return (t) => { diff --git a/src/app/workspace.rs b/src/app/workspace.rs index 28dac64..362f637 100644 --- a/src/app/workspace.rs +++ b/src/app/workspace.rs @@ -391,10 +391,17 @@ impl Workspace { .detach(); } - /// Hands a file to the system's share sheet (AirDrop, Mail, Messages... on macOS; Share on Windows; mail on - /// Linux). Where there is none, the file is shown in its folder and its path copied, to drop anywhere. + /// Hands a file to the system's share sheet (AirDrop, Mail, Messages... on macOS; Share on Windows). Linux has + /// none: there the file itself goes on the clipboard, to paste into a chat or a folder, and is shown in its folder. pub fn share_file(&mut self, path: PathBuf, window: &mut Window, cx: &mut Context) { let name = path.file_name().unwrap_or_default().to_string_lossy().into_owned(); + if cfg!(target_os = "linux") { + let copied = copy_file(&path); + cx.reveal_path(&path); + let note = if copied { format!("{name} is copied: paste it into a chat, a mail or a folder") } else { format!("{name} is in the folder that opened") }; + window.push_notification(Notification::success(note).title("Share"), cx); + return; + } let sheet = kael_share::ShareSheet::builder().subject(name.clone()).file(path.clone()).build_checked(); cx.spawn_in(window, async move |_, cx| { let shown = match sheet { @@ -571,10 +578,32 @@ impl Render for Workspace { } } +/// A file's file:// address, as a clipboard's file list writes it. +pub fn file_uri(p: &Path) -> String { + let s = p.to_string_lossy(); + let enc: String = s.bytes().map(|b| if b.is_ascii_alphanumeric() || b"-_.~/".contains(&b) { (b as char).to_string() } else { format!("%{b:02X}") }).collect(); + format!("file://{enc}") +} + +/// The file itself on the clipboard (text/uri-list): Wayland's wl-copy, else X11's xclip. Whether it went. +fn copy_file(p: &Path) -> bool { + use std::io::Write; + let uri = file_uri(&std::fs::canonicalize(p).unwrap_or_else(|_| p.to_path_buf())); + let tools: &[(&str, &[&str])] = if std::env::var_os("WAYLAND_DISPLAY").is_some() { + &[("wl-copy", &["--type", "text/uri-list"]), ("xclip", &["-selection", "clipboard", "-t", "text/uri-list"])] + } else { + &[("xclip", &["-selection", "clipboard", "-t", "text/uri-list"]), ("wl-copy", &["--type", "text/uri-list"])] + }; + tools.iter().any(|(t, args)| { + std::process::Command::new(t).args(*args).stdin(std::process::Stdio::piped()).stdout(std::process::Stdio::null()).stderr(std::process::Stdio::null()).spawn() + .ok().and_then(|mut c| { c.stdin.take()?.write_all(uri.as_bytes()).ok()?; c.wait().ok() }).is_some_and(|s| s.success()) + }) +} + #[cfg(test)] mod tests { // not super::*: gpui_kit's own `test` attribute would come with it - use super::commands; + use super::{commands, file_uri}; use std::path::PathBuf; fn s(v: &[&str]) -> Vec { @@ -589,6 +618,7 @@ mod tests { assert_eq!(commands("https://youtu.be/x --preset mine", &[], Some("akis-whip"), None), [s(&["https://youtu.be/x", "--preset", "mine"])], "a typed preset wins"); assert_eq!(commands("x", &[], None, Some("stardust")), [s(&["x", "--overlay", "stardust"])], "a 3D scene goes over it"); assert!(commands(" ", &[], None, None).is_empty()); + assert_eq!(file_uri(std::path::Path::new("/home/a/Videos/Halime Sultan'ın.mp4")), "file:///home/a/Videos/Halime%20Sultan%27%C4%B1n.mp4"); } } diff --git a/src/library.rs b/src/library.rs index 3082f9c..737e57c 100644 --- a/src/library.rs +++ b/src/library.rs @@ -145,6 +145,8 @@ pub struct Overlay { pub opacity: f64, /// picture in picture: centre x, y and width as fractions of the frame, laid on top with a white frame pub place: Option<(f64, f64, f64)>, + /// a 3D scene's render: it loops under the whole edit and fills the frame + pub scene: bool, } pub fn parse(spec: &str) -> Result { @@ -172,11 +174,11 @@ pub fn parse(spec: &str) -> Result { }; // a 3D scene pack, drawn for it (shortcut: always 1080x1920, the overlay is scaled to the frame; upgrade to the edit's size if a square edit looks soft) if let Some(p) = crate::scene::find(name) { - return Ok(Overlay { file: crate::scene::render(&p, 1080, 1920)?, from, to, opacity, place }); + return Ok(Overlay { file: crate::scene::render(&p, 1080, 1920)?, from, to, opacity, place, scene: true }); } let file = find(&["overlay", "transition", "greenscreen", "background", "meme", "video", "image"], name) .ok_or(format!("--overlay {name}: no such file or library clip (edits library overlay)"))?; - Ok(Overlay { file, from, to, opacity, place }) + Ok(Overlay { file, from, to, opacity, place, scene: false }) } /// How a clip goes over the picture: (input options, filter chain for it, joining filter). @@ -187,7 +189,7 @@ fn layer(o: &Overlay, i: usize, base: &str, out: &str, w: u32, h: u32, alpha: bo let rel = o.file.to_string_lossy().to_lowercase(); let k = kind(&rel).unwrap_or("video"); // textures and backgrounds run under the whole edit; a transition, a meme or a green screen plays once - let looped = len.is_some() && matches!(k, "overlay" | "background") && o.to.is_none() && o.from == 0.0; + let looped = len.is_some() && (o.scene || matches!(k, "overlay" | "background")) && o.to.is_none() && o.from == 0.0; let end = o.to.or(if looped { None } else { len.map(|l| o.from + l) }); let when = match end { Some(b) => format!(":enable='between(t,{:.3},{b:.3})'", o.from), @@ -213,6 +215,9 @@ fn layer(o: &Overlay, i: usize, base: &str, out: &str, w: u32, h: u32, alpha: bo let pw = ((w as f64 * size) as u32 / 2 * 2).max(32); let b = (w / 270).max(2); format!("[{n}:v]{grey}scale={pw}:-2,setsar=1,fps=30,pad=iw+{b2}:ih+{b2}:{b}:{b}:white,format=rgba,colorchannelmixer=aa={:.2},{shift}[l{i}];[{base}][l{i}]overlay=x='clip(W*{x:.3}-w/2,0,W-w)':y='clip(H*{y:.3}-h/2,0,H-h)':eof_action=pass{when}[{out}];", o.opacity, b2 = b * 2) + } else if o.scene { + // drawn for any frame: cover it, the edges cropped, never bars + format!("[{n}:v]{grey}scale={w}:{h}:force_original_aspect_ratio=increase,crop={w}:{h},format=rgba,colorchannelmixer=aa={:.2},{shift}[l{i}];[{base}][l{i}]overlay=0:0:eof_action=pass{when}[{out}];", o.opacity) } else if k == "greenscreen" || alpha { let key = if k == "greenscreen" && !alpha { "chromakey=0x00FF00:0.18:0.08," } else { "" }; format!("[{n}:v]{key}{grey}scale={w}:{h}:force_original_aspect_ratio=decrease,format=rgba,colorchannelmixer=aa={:.2},{shift}[l{i}];[{base}][l{i}]overlay=(W-w)/2:(H-h)/2:eof_action=pass{when}[{out}];", o.opacity) @@ -290,7 +295,7 @@ mod tests { #[test] fn overlay_graphs() { - let o = |f: &str, from: f64, to: Option| Overlay { file: PathBuf::from(f), from, to, opacity: 0.5, place: None }; + let o = |f: &str, from: f64, to: Option| Overlay { file: PathBuf::from(f), from, to, opacity: 0.5, place: None, scene: false }; // a texture loops under the whole edit, screened let (i, g) = layer(&o("Overlays/VHS Texture.mp4", 0.0, None), 0, "0:v", "x0", 1080, 1920, false, Some(20.0), false); assert_eq!(i, ["-stream_loop", "-1", "-i", "Overlays/VHS Texture.mp4"]); @@ -309,6 +314,11 @@ mod tests { // over a black-and-white edit the burn goes grey instead of tinting it let (_, g) = layer(&o("Transitions/Burn 3.mp4", 4.0, None), 0, "0:v", "x0", 1080, 1920, false, Some(0.5), true); assert!(g.starts_with("[1:v]hue=s=0,scale="), "{g}"); + // a 3D scene loops under the whole edit and covers a square frame, cropped, never with bars + let star = Overlay { scene: true, ..o("/home/x/.cache/edits/scenes/edits.stardust-1.0.0-1080x1920.mov", 0.0, None) }; + let (i, g) = layer(&star, 0, "0:v", "x0", 1080, 1080, true, Some(6.0), false); + assert_eq!(&i[..2], ["-stream_loop", "-1"]); + assert!(g.contains("force_original_aspect_ratio=increase,crop=1080:1080") && g.contains("overlay=0:0:eof_action=pass[x0]") && !g.contains("enable"), "{g}"); // picture in picture: small, framed, placed, plays once let pip = Overlay { place: Some((0.75, 0.2, 0.35)), ..o("cam.mp4", 1.0, Some(4.0)) }; let (_, g) = layer(&pip, 0, "0:v", "x0", 1080, 1920, false, Some(10.0), false); @@ -320,11 +330,11 @@ mod tests { let f = std::env::temp_dir().join("edits-overlay-spec.mp4"); std::fs::write(&f, "").unwrap(); let s = f.to_string_lossy(); - assert_eq!(parse(&format!("{s}@1.5-3:0.4")).unwrap(), Overlay { file: f.clone(), from: 1.5, to: Some(3.0), opacity: 0.4, place: None }); - assert_eq!(parse(&format!("{s}@0-5:0.75,0.2,0.35")).unwrap(), Overlay { file: f.clone(), from: 0.0, to: Some(5.0), opacity: 1.0, place: Some((0.75, 0.2, 0.35)) }); + assert_eq!(parse(&format!("{s}@1.5-3:0.4")).unwrap(), Overlay { file: f.clone(), from: 1.5, to: Some(3.0), opacity: 0.4, place: None, scene: false }); + assert_eq!(parse(&format!("{s}@0-5:0.75,0.2,0.35")).unwrap(), Overlay { file: f.clone(), from: 0.0, to: Some(5.0), opacity: 1.0, place: Some((0.75, 0.2, 0.35)), scene: false }); assert_eq!(parse(&format!("{s}:0.8:0.5,0.5,0.4")).unwrap().opacity, 0.8); assert!(parse(&format!("{s}:2,0.5,0.4")).is_err()); - assert_eq!(parse(&s).unwrap(), Overlay { file: f.clone(), from: 0.0, to: None, opacity: 1.0, place: None }); + assert_eq!(parse(&s).unwrap(), Overlay { file: f.clone(), from: 0.0, to: None, opacity: 1.0, place: None, scene: false }); assert!(parse(&format!("{s}@x")).is_err()); let _ = std::fs::remove_file(f); }