diff --git a/CHANGELOG.md b/CHANGELOG.md index e87660b1..e6428855 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,3 +24,8 @@ Nothing has been released yet. The first release, 0.1.0, will cover what is on ` - Automation for every device control and the channel strip. - Export to WAV or MP3 (mix or stems, whole song or loop) and to an Ableton Live set with return tracks and sends. - Undo and redo for every edit, and an optional assistant panel that uses your own Anthropic API key. +- The app icon on macOS, Windows and Linux. +- Browser drag and drop: while you drag a sample or MIDI clip over the arrangement, a clip preview shows where it + will land, and it lands there (it used to land to the right of the pointer). Drop a sample on a track, below the tracks for a new audio track, or on a Sampler or + Pad Sampler to load it. Drop an instrument on an instrument track to swap its instrument, or below the tracks + for a new instrument track; double-clicking an instrument with no instrument track selected adds one. diff --git a/Cargo.lock b/Cargo.lock index 07d0e149..ebddfff6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1140,6 +1140,7 @@ dependencies = [ "chrono", "dstudio-core", "dstudio-engine", + "embed-resource", "flate2", "mp3lame-encoder", "objc2 0.6.5", @@ -1190,6 +1191,20 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be" +[[package]] +name = "embed-resource" +version = "3.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6168487b5e7eb2673e6efe1200b1848016e436a6ca0b8031bf04bd9d493a249f" +dependencies = [ + "cc", + "memchr", + "rustc_version", + "toml", + "vswhom", + "winreg", +] + [[package]] name = "endi" version = "1.1.1" @@ -5093,6 +5108,26 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "vswhom" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be979b7f07507105799e854203b470ff7c78a1639e330a58f183b5fea574608b" +dependencies = [ + "libc", + "vswhom-sys", +] + +[[package]] +name = "vswhom-sys" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb067e4cbd1ff067d1df46c9194b5de0e98efd2810bbc95c5d5e5f25a3231150" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "vtable" version = "0.5.0" @@ -5877,6 +5912,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d6f32a0ff4a9f6f01231eb2059cc85479330739333e0e58cadf03b6af2cca10" +dependencies = [ + "cfg-if", + "windows-sys 0.61.2", +] + [[package]] name = "wit-bindgen" version = "0.57.1" diff --git a/crates/dstudio-app/Cargo.toml b/crates/dstudio-app/Cargo.toml index 09d7ae8c..d42e20b5 100644 --- a/crates/dstudio-app/Cargo.toml +++ b/crates/dstudio-app/Cargo.toml @@ -49,3 +49,7 @@ objc2-foundation = { version = "0.3", default-features = false, features = ["std [build-dependencies] slint-build = "=1.18.1" + +# The app icon in device-studio.exe (build.rs). +[target.'cfg(windows)'.build-dependencies] +embed-resource = "3" diff --git a/crates/dstudio-app/build.rs b/crates/dstudio-app/build.rs index 32bbbc63..86b24646 100644 --- a/crates/dstudio-app/build.rs +++ b/crates/dstudio-app/build.rs @@ -1,3 +1,24 @@ fn main() { slint_build::compile("ui/app.slint").expect("slint build failed"); + windows_icon(); } + +/// device-studio.exe carries the app icon (icons/device.ico, made by tools/art/make-icons.mjs), +/// so Explorer, the taskbar and shortcuts show it. +#[cfg(windows)] +fn windows_icon() { + if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") { + return; + } + let dir = std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"); + let ico = std::path::Path::new(&dir).join("icons").join("device.ico"); + println!("cargo:rerun-if-changed={}", ico.display()); + let out = std::path::PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR")); + let rc = out.join("device.rc"); + // rc.exe takes forward slashes, which need no escaping in its string literals. + std::fs::write(&rc, format!("1 ICON \"{}\"\n", ico.display().to_string().replace('\\', "/"))).expect("write device.rc"); + embed_resource::compile(&rc, embed_resource::NONE).manifest_optional().expect("compile the icon resource"); +} + +#[cfg(not(windows))] +fn windows_icon() {} diff --git a/crates/dstudio-app/icons/device-256.png b/crates/dstudio-app/icons/device-256.png new file mode 100644 index 00000000..2a284678 Binary files /dev/null and b/crates/dstudio-app/icons/device-256.png differ diff --git a/crates/dstudio-app/icons/device-macos-512.png b/crates/dstudio-app/icons/device-macos-512.png new file mode 100644 index 00000000..263c565b Binary files /dev/null and b/crates/dstudio-app/icons/device-macos-512.png differ diff --git a/crates/dstudio-app/icons/device.icns b/crates/dstudio-app/icons/device.icns new file mode 100644 index 00000000..4e56785c Binary files /dev/null and b/crates/dstudio-app/icons/device.icns differ diff --git a/crates/dstudio-app/icons/device.ico b/crates/dstudio-app/icons/device.ico new file mode 100644 index 00000000..bdc4095e Binary files /dev/null and b/crates/dstudio-app/icons/device.ico differ diff --git a/crates/dstudio-app/src/appmenu.rs b/crates/dstudio-app/src/appmenu.rs index e65cf49e..6c02d6ab 100644 --- a/crates/dstudio-app/src/appmenu.rs +++ b/crates/dstudio-app/src/appmenu.rs @@ -64,3 +64,33 @@ pub fn adopt_items() { #[cfg(not(target_os = "macos"))] pub fn adopt_items() {} + +/// Outside its bundle (cargo run) the app has no Info.plist icon, so the Dock would show a +/// generic one: give it the app icon. Inside Device.app the bundle's icon is used as is. +#[cfg(target_os = "macos")] +pub fn set_dock_icon() { + use objc2::runtime::AnyObject; + use objc2::{class, msg_send}; + const PNG: &[u8] = include_bytes!("../icons/device-macos-512.png"); + // SAFETY: called on the main thread once the NSApplication exists; plain AppKit calls. + unsafe { + let bundle: *mut AnyObject = msg_send![class!(NSBundle), mainBundle]; + let icon_key: *mut AnyObject = msg_send![class!(NSString), stringWithUTF8String: c"CFBundleIconFile".as_ptr()]; + let bundled: *mut AnyObject = msg_send![bundle, objectForInfoDictionaryKey: icon_key]; + if !bundled.is_null() { + return; + } + let data: *mut AnyObject = msg_send![class!(NSData), dataWithBytes: PNG.as_ptr().cast::(), length: PNG.len()]; + let image: *mut AnyObject = msg_send![class!(NSImage), alloc]; + let image: *mut AnyObject = msg_send![image, initWithData: data]; + if image.is_null() { + return; + } + let app: *mut AnyObject = msg_send![class!(NSApplication), sharedApplication]; + // The app keeps the image for its lifetime; this runs once, so it is never released. + let _: () = msg_send![app, setApplicationIconImage: image]; + } +} + +#[cfg(not(target_os = "macos"))] +pub fn set_dock_icon() {} diff --git a/crates/dstudio-app/src/controller.rs b/crates/dstudio-app/src/controller.rs index 273f8e7b..73f43ea0 100644 --- a/crates/dstudio-app/src/controller.rs +++ b/crates/dstudio-app/src/controller.rs @@ -239,6 +239,8 @@ pub enum JobResult { Onsets { engine_asset: u64, result: Result, String>, tempo: Option }, /// A file clicked in Browser › Files, decoded for the preview voice (src/files.rs). Auditioned { path: PathBuf, result: Result }, + /// A file dragged from Browser › Files, decoded to measure its length (src/files.rs). + Measured { path: PathBuf, result: Result }, /// A Consolidate, Bounce or Export render written and loaded (src/clip_render.rs). ClipRendered(Box), /// File › Import Ableton Live Set… read and its samples decoded (src/live_import.rs). @@ -1468,6 +1470,7 @@ impl Controller { JobResult::PluginScan(r) => self.finish_plugin_scan(r), JobResult::Onsets { engine_asset, result, tempo } => self.finish_onsets(engine_asset, result, tempo), JobResult::Auditioned { path, result } => self.finish_audition(path, result), + JobResult::Measured { path, result } => self.finish_measure(path, result), JobResult::ClipRendered(r) => self.finish_clip_render(*r), JobResult::LiveSet(job) => self.finish_live_set(*job), JobResult::Reloaded { asset, doc_epoch, result } => { @@ -1690,7 +1693,7 @@ impl Controller { self.project().ticks_per_bar() as f64 / PPQ as f64 } - fn ruler_steps(&self) -> timeline::RulerSteps { + pub(crate) fn ruler_steps(&self) -> timeline::RulerSteps { let beat_len = 4.0 / self.project().transport.time_signature.denominator as f64; timeline::RulerSteps::new(self.view.px_per_beat, self.beats_per_bar(), beat_len, self.snap.grid) } diff --git a/crates/dstudio-app/src/devices.rs b/crates/dstudio-app/src/devices.rs index c5c8551e..f41225c6 100644 --- a/crates/dstudio-app/src/devices.rs +++ b/crates/dstudio-app/src/devices.rs @@ -41,7 +41,7 @@ pub const SYNTH_W: f32 = 776.5; pub const ADD_X_ALONE: f32 = 265.0; pub const ADD_W: f32 = 182.5; /// Bottom panel x (window) and its device area start (after the inspector). -const PANEL_X: f32 = 5.0; +pub(crate) const PANEL_X: f32 = 5.0; pub(crate) const CHAIN_AREA_X: f32 = 255.0; /// Browser tree: area top (window) and row pitch. pub const TREE_Y: f32 = 78.0 + 81.0; @@ -383,6 +383,8 @@ pub struct CardDrag { #[derive(Debug, Clone, Copy, PartialEq)] pub enum DropTarget { Track(TrackId), + /// Below the last track: an instrument dropped there gets a new instrument track. + NewTrack, /// Insert position in the selected track's chain (None: instrument slot / end). Chain { track: TrackId, @@ -841,6 +843,29 @@ impl Controller { /// Add `item` to `track`: an effect becomes an insert (`AddDevice`, at /// `index` or the end); an instrument replaces the track's instrument /// (`SetInstrumentPlugin`; the built-in Synth sets None). One undo step. + /// A new instrument track playing `item`, added below the others in one undo step and + /// named after the instrument. + pub fn add_item_as_new_track(&mut self, item: &Item) -> bool { + let device = match item { + Item::BuiltinSynth => dstudio_core::builtin::synth_v2::SYNTH_V2.instantiate(), + Item::Plugin(p) if p.kind == PluginKind::Instrument => Device::new(p.clone()), + Item::Builtin(d) if d.kind == PluginKind::Instrument => d.instantiate(), + _ => return false, + }; + let p = self.project(); + let id = TrackId(p.next_id); + let track = dstudio_core::Track::new(id, TrackKind::Instrument, item.name(), crate::controller::next_track_color(p)); + let commands = vec![Command::AddTrack { index: None, track }, Command::SetInstrumentPlugin { track: id, device: Some(device) }]; + if !self.execute(Command::Batch { label: "Add Instrument Track".into(), commands }) { + return false; + } + self.select_track(id); + self.select_clip(None); + self.set_bottom_tab(BottomTab::Devices); + self.reveal_last_change(id, item); + true + } + pub fn add_item_to_track(&mut self, item: &Item, track: TrackId, index: Option) -> bool { let Some(t) = self.project().track(track) else { return false }; let (kind, has_synth) = (t.kind, t.instrument_plugin.as_ref().is_some_and(is_builtin_synth)); @@ -960,10 +985,18 @@ impl Controller { self.ui_dirty = true; } - /// Double-click: add the device to the selected track. + /// Double-click: add the device to the selected track. An instrument replaces the selected + /// instrument track's instrument; with no instrument track selected it gets a new track. pub fn tree_activate(&mut self, i: usize) { let Some(item) = self.devices.entries.get(i).and_then(|e| e.item.clone()) else { return }; - let Some(t) = self.selected_track else { + let selected = self.selected_track.filter(|t| self.project().track(*t).is_some()); + if item.kind() == PluginKind::Instrument + && !selected.and_then(|t| self.project().track(t)).is_some_and(|t| t.kind == TrackKind::Instrument) + { + self.add_item_as_new_track(&item); + return; + } + let Some(t) = selected else { self.set_status("Select a track first", 3); return; }; @@ -1025,6 +1058,9 @@ impl Controller { Some(DropTarget::Track(t)) => { self.add_item_to_track(&d.item, t, None); } + Some(DropTarget::NewTrack) => { + self.add_item_as_new_track(&d.item); + } Some(DropTarget::Chain { track, index }) => { let index = index.map(|i| self.chain_device_index(i, None)); self.add_item_to_track(&d.item, track, index); @@ -1041,8 +1077,11 @@ impl Controller { let (tx, tw) = (l.timeline_x(), l.timeline_w()); let (top, bottom) = (78.0 + 66.5, 78.0 + l.top_h() - crate::timeline::MASTER_H); if x >= tx && x < tx + tw && y >= top && y < bottom { - let i = self.view.track_at(y - top + crate::timeline::RULER_H)?; - return self.project().tracks.get(i).map(|t| DropTarget::Track(t.id)); + return match self.view.track_at(y - top + crate::timeline::RULER_H).and_then(|i| self.project().tracks.get(i)) { + Some(t) => Some(DropTarget::Track(t.id)), + None if item.kind() == PluginKind::Instrument && y >= self.lanes_end_y() => Some(DropTarget::NewTrack), + None => None, + }; } if !l.mixer && !l.clip_tab { let by = l.bottom_y(); @@ -1055,6 +1094,22 @@ impl Controller { None } + /// Window y where the tracks end (the top of the empty area below them). + pub(crate) fn lanes_end_y(&self) -> f32 { + let l = self.layout(); + let n = self.project().tracks.len(); + let end = if n == 0 { 0.0 } else { self.view.track_offset(n - 1) + self.view.pitch(n - 1) }; + 78.0 + 66.5 + end - l.scroll_y + } + + /// The empty area below the tracks, where a drop adds a new track. + pub(crate) fn new_track_rect(&self) -> Option<(f32, f32, f32, f32)> { + let l = self.layout(); + let (top, bottom) = (78.0 + 66.5, 78.0 + l.top_h() - crate::timeline::MASTER_H); + let y0 = self.lanes_end_y().max(top); + (bottom - y0 > 2.0).then_some((l.timeline_x(), y0, l.timeline_w(), bottom - y0)) + } + pub(crate) fn track_rect(&self, t: TrackId) -> Option<(f32, f32, f32, f32)> { let l = self.layout(); let i = self.project().track_index(t)?; @@ -1521,6 +1576,7 @@ impl Controller { match self.devices.dnd.clone().filter(|d| d.active) { Some(d) => { s.set_dnd_active(true); + s.set_dnd_clip_visible(false); s.set_dnd_x(d.pos.0); s.set_dnd_y(d.pos.1); let target = self.drop_target(d.pos.0, d.pos.1, &d.item); @@ -1529,6 +1585,7 @@ impl Controller { }; let (ok, rect, marker) = match target { Some(DropTarget::Track(t)) => (ok_kind(t), self.track_rect(t), None), + Some(DropTarget::NewTrack) => (true, self.new_track_rect(), None), Some(DropTarget::Chain { track, index }) => { let l = self.layout(); let r = (PANEL_X + CHAIN_AREA_X, l.bottom_y() + 27.0, l.w - 2.0 * PANEL_X - CHAIN_AREA_X, l.bottom_h() - 27.0); @@ -1553,6 +1610,7 @@ impl Controller { None => { s.set_dnd_active(false); s.set_dnd_target_visible(false); + s.set_dnd_clip_visible(false); s.set_chain_marker_visible(false); } } diff --git a/crates/dstudio-app/src/files.rs b/crates/dstudio-app/src/files.rs index d9aefec0..7f2f767f 100644 --- a/crates/dstudio-app/src/files.rs +++ b/crates/dstudio-app/src/files.rs @@ -9,7 +9,7 @@ use crate::controller::{Controller, ImportTarget, JobResult, gain_from_slider, header_meter, slider_from_gain, sync_model}; use crate::{FileGuide, FileRow, Studio}; -use dstudio_core::{ClipId, Command, MidiClip, Project, Ticks, Track, TrackId, TrackKind, db_to_gain, persist}; +use dstudio_core::{ClipId, ColorIndex, Command, MidiClip, Project, Ticks, Track, TrackId, TrackKind, db_to_gain, persist}; use dstudio_engine::AssetInfo; use slint::Model; use std::collections::{HashMap, HashSet}; @@ -133,6 +133,15 @@ pub struct Audition { pub animating: bool, } +/// Where a dragged browser file lands (Controller::files_drop_at). +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum FileDrop { + /// On the arrangement: a track (None: below the last one) and the beat under the pointer. + Lane(Option, Ticks), + /// On the selected track's sampler in the Devices panel. + Sampler(dstudio_core::DeviceId), +} + #[derive(Debug, Clone)] pub struct FileDrag { pub item: FileItem, @@ -161,6 +170,8 @@ pub struct FilesUi { pub items: Vec>, pub content_h: f32, pub drag: Option, + /// Lengths of dragged audio files (engine frames), measured for the drop preview. + pub lengths: HashMap, pub audition: Audition, listings: HashMap, String>>, project_cache: HashMap>, @@ -186,6 +197,7 @@ impl Default for FilesUi { items: Vec::new(), content_h: 0.0, drag: None, + lengths: HashMap::new(), audition: Audition::default(), listings: HashMap::new(), project_cache: HashMap::new(), @@ -656,15 +668,22 @@ impl Controller { }); } 1 => { + let mut started = None; if let Some(d) = self.files.drag.as_mut() { d.pos = (x, y); if !d.active && ((x - d.start.0).abs() > 4.0 || (y - d.start.1).abs() > 4.0) { d.active = true; + if let FileItem::Audio(path) = &d.item { + started = Some(path.clone()); + } } if d.active { self.ui_dirty = true; } } + if let Some(path) = started { + self.measure(path); + } } _ => { let Some(d) = self.files.drag.take() else { return }; @@ -672,7 +691,16 @@ impl Controller { if !d.active { return; } - let Some((track, at)) = self.files_drop_at(x, y) else { return }; + let (track, at) = match self.files_drop_at(x, y, &d.item) { + Some(FileDrop::Lane(track, at)) => (track, at), + Some(FileDrop::Sampler(device)) => { + if let FileItem::Audio(path) = d.item { + self.load_into_sampler(device, vec![path]); + } + return; + } + None => return, + }; let p = self.project(); let index = track.and_then(|t| p.track_index(t)).map(|i| i + 1); match d.item { @@ -690,17 +718,108 @@ impl Controller { } } - /// Over the lanes: the track under (x, y) (None below the last track) and the beat there. - pub fn files_drop_at(&self, x: f32, y: f32) -> Option<(Option, Ticks)> { + /// Learn the length of a dragged audio file for the drop preview: from the preview voice when + /// it holds this file, else decoded on a worker thread (the preview shows a bar until then). + fn measure(&mut self, path: PathBuf) { + if self.files.lengths.contains_key(&path) { + return; + } + let a = &self.files.audition; + if a.path.as_ref() == Some(&path) + && let Some((_, frames)) = a.asset + { + self.files.lengths.insert(path, frames); + return; + } + self.files.lengths.insert(path.clone(), -1); + let engine = self.engine.clone(); + let tx = self.jobs_tx.clone(); + self.pending_jobs += 1; + std::thread::spawn(move || { + let result = engine.load_file(&path).map_err(|e| e.to_string()); + let _ = tx.send(JobResult::Measured { path, result }); + }); + } + + pub(crate) fn finish_measure(&mut self, path: PathBuf, result: Result) { + match result { + Ok(info) => { + let _ = self.engine.release_asset(info.asset_id); + self.files.lengths.insert(path, info.frames as i64); + } + Err(_) => { + self.files.lengths.remove(&path); + } + } + self.ui_dirty = true; + } + + /// The drop preview of a file dragged over the lanes: a clip outline (window x, y, w, h) where + /// the clip will land, in the colour of the track that gets it. + pub(crate) fn file_ghost(&self, item: &FileItem, drop: FileDrop) -> Option<(f32, f32, f32, f32, ColorIndex)> { + let FileDrop::Lane(track, at) = drop else { return None }; + let p = self.project(); + let len = match item { + FileItem::Audio(path) => match self.files.lengths.get(path) { + Some(&f) if f > 0 => p.frames_to_ticks(f, self.rate), + _ => p.ticks_per_bar(), + }, + FileItem::Midi { project, clip } => match self.files.project_cache.get(project) { + Some(Ok(src)) => { + src.tracks.iter().flat_map(|t| t.midi_clips.iter()).find(|c| c.id == *clip).map_or(p.ticks_per_bar(), |c| c.length) + } + _ => p.ticks_per_bar(), + }, + _ => return None, + }; + // The track that gets the clip: an audio file on a non-audio track goes to a new one. + let fits = |t: &dstudio_core::Track| match item { + FileItem::Audio(_) => t.kind == TrackKind::Audio, + _ => t.kind == TrackKind::Instrument, + }; + let on = track.and_then(|t| p.track(t)).filter(|t| fits(t)); + let (y, h, color) = match on { + Some(t) => { + let (_, y, _, h) = self.track_rect(t.id)?; + (y, h, t.color) + } + None => { + let (_, y, _, h) = self.new_track_rect()?; + (y, h.min(crate::timeline::TRACK_PITCH - 0.5), crate::controller::next_track_color(p)) + } + }; + let l = self.layout(); + let ppb = self.view.px_per_beat as f32; + let x0 = l.lanes_x() + self.view.x_of(at as f64 / dstudio_core::PPQ as f64); + let x1 = x0 + (len as f32 / dstudio_core::PPQ as f32) * ppb; + let (lo, hi) = (l.lanes_x(), l.timeline_x() + l.timeline_w()); + let (x0c, x1c) = (x0.max(lo), x1.min(hi)); + (x1c - x0c > 1.0).then_some((x0c, y + 1.0, x1c - x0c, (h - 2.0).max(4.0), color)) + } + + /// Where a browser file dropped at window (x, y) goes: over the lanes, the track under the + /// pointer (None below the last track) and the beat there; over the Devices panel of a + /// track whose instrument is a sampler, that sampler (audio files only). + pub fn files_drop_at(&self, x: f32, y: f32, item: &FileItem) -> Option { let l = self.layout(); let (tx, tw) = (l.timeline_x(), l.timeline_w()); let (top, bottom) = (78.0 + 66.5, 78.0 + l.top_h() - crate::timeline::MASTER_H); + if matches!(item, FileItem::Audio(_)) && !l.mixer && !l.clip_tab { + let by = l.bottom_y(); + if x >= crate::devices::PANEL_X + crate::devices::CHAIN_AREA_X && x < l.w - 5.0 && y >= by + 27.0 && y < by + l.bottom_h() { + return self.selected_sampler().map(FileDrop::Sampler); + } + } if x < tx || x >= tx + tw || y < top || y >= bottom { return None; } + // Over the track headers the clip starts at the left edge of the lanes. + let x = x.max(l.lanes_x()); let track = self.view.track_at(y - top + crate::timeline::RULER_H).and_then(|i| self.project().tracks.get(i)).map(|t| t.id); - let beat = self.view.beat_at(x - tx).max(0.0).round(); - Some((track, (beat * dstudio_core::PPQ as f64) as Ticks)) + // The clip starts under the pointer, on the arrangement's grid when snap is on. + let beat = self.view.beat_at(x - l.lanes_x()).max(0.0); + let beat = if self.snap_active() { self.ruler_steps().snap(beat) } else { beat }; + Some(FileDrop::Lane(track, (beat * dstudio_core::PPQ as f64).round() as Ticks)) } fn preview_gain(&self) -> f32 { @@ -914,13 +1033,27 @@ impl Controller { s.set_browser_search(self.files.search.clone().into()); } if let Some(d) = self.files.drag.as_ref().filter(|d| d.active) { - let drop = self.files_drop_at(d.pos.0, d.pos.1); + let drop = self.files_drop_at(d.pos.0, d.pos.1, &d.item); s.set_dnd_active(true); s.set_dnd_x(d.pos.0); s.set_dnd_y(d.pos.1); s.set_dnd_label(d.label.clone().into()); s.set_dnd_ok(drop.is_some()); - let rect = drop.and_then(|(t, _)| t).and_then(|t| self.track_rect(t)); + let ghost = drop.and_then(|drop| self.file_ghost(&d.item, drop)); + s.set_dnd_clip_visible(ghost.is_some()); + if let Some((x, y, w, h, color)) = ghost { + s.set_dnd_clip_x(x); + s.set_dnd_clip_y(y); + s.set_dnd_clip_w(w); + s.set_dnd_clip_h(h); + s.set_dnd_clip_color(crate::controller::slint_color(crate::controller::track_color(color))); + } + // Over the lanes the clip preview shows where it lands; the sampler gets an outline. + let rect = match drop { + Some(FileDrop::Lane(Some(t), _)) if ghost.is_none() => self.track_rect(t), + Some(FileDrop::Sampler(_)) => self.sampler_drop_rect(), + _ => None, + }; s.set_dnd_target_visible(rect.is_some()); if let Some((x, y, w, h)) = rect { s.set_dnd_tx(x); diff --git a/crates/dstudio-app/src/highlight.rs b/crates/dstudio-app/src/highlight.rs index 45649354..5c531d59 100644 --- a/crates/dstudio-app/src/highlight.rs +++ b/crates/dstudio-app/src/highlight.rs @@ -7,6 +7,9 @@ use crate::timeline::{MASTER_H, TRACK_H}; +/// Lanes start this far into the Timeline panel, right of the track headers (`Tokens.lane-x`). +pub const LANE_X: f32 = 191.0; + /// Inputs that move things around. #[derive(Debug, Clone, Copy)] pub struct Layout { @@ -45,6 +48,10 @@ impl Layout { pub fn timeline_x(&self) -> f32 { if self.sounds { 262.65 } else { 5.0 } } + /// Window x where the lanes start (right of the track headers, `Tokens.lane-x`). + pub fn lanes_x(&self) -> f32 { + self.timeline_x() + LANE_X + } pub fn timeline_w(&self) -> f32 { let right = if self.assistant { self.chat_w + ASSISTANT_GAP } else { 0.0 }; self.w - self.timeline_x() - 5.0 - right diff --git a/crates/dstudio-app/src/main.rs b/crates/dstudio-app/src/main.rs index a42cc284..cc2973fc 100644 --- a/crates/dstudio-app/src/main.rs +++ b/crates/dstudio-app/src/main.rs @@ -3292,6 +3292,7 @@ fn run() -> Result<(), Box> { // at bar 3 of the Audio track (the export covers bars 1–6), then the dialog. let app_menu_timer = slint::Timer::default(); app_menu_timer.start(slint::TimerMode::Repeated, Duration::from_millis(16), appmenu::adopt_items); + slint::Timer::single_shot(Duration::ZERO, appmenu::set_dock_icon); let dialog_timer = slint::Timer::default(); if args.dialog_state > 0 { let dir = std::env::temp_dir().join(format!("dstudio-ref-{}", std::process::id())); diff --git a/crates/dstudio-app/src/sampler_panel.rs b/crates/dstudio-app/src/sampler_panel.rs index 47326c01..954c035d 100644 --- a/crates/dstudio-app/src/sampler_panel.rs +++ b/crates/dstudio-app/src/sampler_panel.rs @@ -1413,6 +1413,12 @@ impl Controller { let Some(device) = self.selected_sampler().filter(|_| self.bottom_tab == crate::controller::BottomTab::Devices) else { return self.import_files(audio, ImportTarget::Selected, None); }; + self.load_into_sampler(device, audio); + } + + /// Load audio files into sampler `device`: the Sampler takes the first, a drum pad takes + /// them all as new layers of the pad it shows. + pub fn load_into_sampler(&mut self, device: DeviceId, audio: Vec) { let Some((d, def)) = self.sampler_def(device) else { return }; let target = if def.id == "sampler-steam" { ImportTarget::DeviceSample { device, slot: 0, next_free: false } @@ -1424,6 +1430,13 @@ impl Controller { self.import_files(audio.into_iter().take(n).collect(), target, None); } + /// The Devices panel's chain area, outlined while a file is dragged over a sampler. + pub(crate) fn sampler_drop_rect(&self) -> Option<(f32, f32, f32, f32)> { + let l = self.layout(); + let (x, chain) = (crate::devices::PANEL_X, crate::devices::CHAIN_AREA_X); + Some((x + chain, l.bottom_y() + 27.0, l.w - 2.0 * x - chain, l.bottom_h() - 27.0)) + } + /// Finish loading a file into a device: the asset and the sample in one /// undo step ("Load Sample"). Returns false when nothing was loaded. pub(crate) fn finish_device_sample( diff --git a/crates/dstudio-app/src/selftest.rs b/crates/dstudio-app/src/selftest.rs index 53c1d691..33e22fd4 100644 --- a/crates/dstudio-app/src/selftest.rs +++ b/crates/dstudio-app/src/selftest.rs @@ -15569,6 +15569,252 @@ fn velocity_lane_steps() -> Vec { ] } +/// Browser drag and drop and double-click, driven with real pointer events: a sample dragged +/// onto a track, below the tracks and onto a sampler; an instrument double-clicked with no +/// instrument track selected, dragged onto an instrument track and below the tracks. +fn browser_drop_steps() -> Vec { + use crate::files::{SECTION_DEVICES, TAB_FOLDERS}; + use Step::*; + let root = run_dir().join("drop"); + let (r1, r2) = (root.clone(), root.clone()); + let count = Rc::new(Cell::new(0usize)); + let (n0, n1, n2, n3, n4, n5, n6) = + (count.clone(), count.clone(), count.clone(), count.clone(), count.clone(), count.clone(), count.clone()); + let ghost_x = Rc::new(Cell::new(0f32)); + let (g0, g1, g2) = (ghost_x.clone(), ghost_x.clone(), ghost_x); + // Drag browser row (x, y) to the centre of a window rectangle the controller computes. + fn drag_to(a: &AppWindow, from: Option<(f32, f32)>, to: Option<(f32, f32, f32, f32)>) { + let (Some((x0, y0)), Some((x, y, w, h))) = (from, to) else { return }; + drag(a, x0, y0, x + w.min(160.0) / 2.0, y + h.min(40.0) / 2.0); + } + fn kick_row(a: &AppWindow) -> Option<(f32, f32)> { + files_row_xy(a, files_row_of(a, "kick.wav")?) + } + fn undo_to(ctl: &Ctl, n: usize) { + let mut c = ctl.borrow_mut(); + while c.project().tracks.len() > n && c.doc.undo_label().is_some() { + c.undo(); + } + } + vec![ + Do("drop: Escape (close menus)", Box::new(|a| key(a, Key::Escape, false, false))), + DoC( + "drop: a sample folder in Files › Folders, opened; select the audio track", + Box::new(move |a, ctl| { + let _ = std::fs::remove_dir_all(&r1); + let _ = std::fs::create_dir_all(&r1); + let _ = crate::wavgen::write_wav(&r1.join("kick.wav"), 48_000, 1, &crate::wavgen::sine_bursts(48_000)); + let mut c = ctl.borrow_mut(); + c.settings.prefs.browser_folders.clear(); + c.files_add_folder(&r1); + c.browser_section(crate::files::SECTION_FILES); + c.files_tab(TAB_FOLDERS); + c.set_bottom_tab(BottomTab::Devices); + if let Some(i) = track_of(&c, TrackKind::Audio) { + let t = c.project().tracks[i].id; + c.select_track(t); + } + n0.set(c.project().tracks.len()); + c.update_ui(a); + }), + ), + Do( + "drop: click the folder row to open it", + Box::new(|a| { + if let Some((x, y)) = files_row_xy(a, 0) { + click(a, x, y); + } + }), + ), + DoC( + "drop: press kick.wav and move it over the audio track's lane at beat 8 (held)", + Box::new(move |a, ctl| { + let to = { + let c = ctl.borrow(); + let y = track_of(&c, TrackKind::Audio).and_then(|i| c.track_rect(c.project().tracks[i].id)).map(|r| r.1 + r.3 / 2.0); + y.map(|y| (c.layout().lanes_x() + c.view.x_of(8.0) + 1.0, y)) + }; + let (Some((x0, y0)), Some((x, y))) = (kick_row(a), to) else { return }; + g0.set(x - 1.0); + press(a, x0, y0); + for i in 1..=12 { + let t = i as f32 / 12.0; + dispatch( + a.window(), + WindowEvent::PointerMoved { position: LogicalPosition::new(x0 + (x - x0) * t, y0 + (y - y0) * t) }, + ); + } + ctl.borrow_mut().update_ui(a); + }), + ), + Check( + "drop: a clip preview in the track's colour starts at beat 8, under the pointer", + Box::new(move |c, a| { + let s = a.global::(); + let t = track_of(c, TrackKind::Audio).map(|i| c.project().tracks[i].color); + let want = t.map(|t| crate::controller::slint_color(crate::controller::track_color(t))); + let ok = s.get_dnd_active() + && s.get_dnd_clip_visible() + && approx(s.get_dnd_clip_x(), g1.get(), 0.5) + && want == Some(s.get_dnd_clip_color()); + ok.then_some(()).ok_or(format!("visible {} x {} (want {})", s.get_dnd_clip_visible(), s.get_dnd_clip_x(), g1.get())) + }), + ), + DoC( + "drop: let go", + Box::new(move |a, ctl| { + let y = { + let c = ctl.borrow(); + track_of(&c, TrackKind::Audio).and_then(|i| c.track_rect(c.project().tracks[i].id)).map(|r| r.1 + r.3 / 2.0) + }; + if let Some(y) = y { + release(a, g2.get() + 1.0, y); + } + }), + ), + Check( + "drop: the sample lands on that track at beat 8, where the preview was (no new track)", + Box::new(move |c, a| { + let p = c.project(); + let t = track_of(c, TrackKind::Audio).map(|i| &p.tracks[i]); + let start = t.and_then(|t| t.clips.iter().find(|k| k.name == "kick")).map(|k| k.start); + let ok = p.tracks.len() == n1.get() && start == Some(8 * PPQ) && !a.global::().get_dnd_active(); + ok.then_some(()).ok_or(format!("{} tracks (was {}), start {start:?} (want {})", p.tracks.len(), n1.get(), 8 * PPQ)) + }), + ), + DoC( + "drop: undo; drag kick.wav below the last track", + Box::new(|a, ctl| { + ctl.borrow_mut().undo(); + ctl.borrow_mut().update_ui(a); + let to = ctl.borrow().new_track_rect(); + drag_to(a, kick_row(a), to); + }), + ), + Check( + "drop: below the tracks, the sample gets a new audio track", + Box::new(move |c, _| { + let p = c.project(); + let ok = p.tracks.len() == n2.get() + 1 + && p.tracks.iter().rev().find(|t| t.kind == TrackKind::Audio).is_some_and(|t| t.clips.iter().any(|k| k.name == "kick")); + ok.then_some(()).ok_or(format!("{} tracks (was {})", p.tracks.len(), n2.get())) + }), + ), + DoC( + "drop: undo; a new Sampler track; drag kick.wav onto the Devices panel", + Box::new(move |a, ctl| { + undo_to(ctl, n3.get()); + ctl.borrow_mut().add_item_as_new_track(&crate::devices::Item::Builtin(&dstudio_core::builtin::sampler::SAMPLER)); + ctl.borrow_mut().update_ui(a); + let to = ctl.borrow().sampler_drop_rect(); + drag_to(a, kick_row(a), to); + }), + ), + Check( + "drop: the sample loads into the sampler", + Box::new(|c, _| { + let d = c + .selected_sampler() + .and_then(|id| c.project().tracks.iter().find_map(|t| t.instrument_plugin.as_ref().filter(|d| d.id == id))); + let ok = d.is_some_and(|d| d.sample(0).is_some()); + ok.then_some(()).ok_or(format!("sampler {:?}, undo {:?}", d.map(|d| d.id), c.doc.undo_label())) + }), + ), + DoC( + "drop: undo both; select the audio track; Devices › Instruments, search Sampler", + Box::new(move |a, ctl| { + undo_to(ctl, n4.get()); + let mut c = ctl.borrow_mut(); + if let Some(i) = track_of(&c, TrackKind::Audio) { + let t = c.project().tracks[i].id; + c.select_track(t); + } + c.browser_section(SECTION_DEVICES); + c.browser_tab(0); + c.browser_search("Sampler"); + c.update_ui(a); + }), + ), + Do( + "drop: double-click Sampler with the audio track selected", + Box::new(|a| { + if let Some(i) = tree_row_of(a, "Sampler") { + let (x, y) = tree_row_xy(a, i); + double_click(a, x, y); + } + }), + ), + Check( + "drop: a new instrument track named Sampler plays it (one undo step)", + Box::new(move |c, _| { + let p = c.project(); + let last = p.tracks.iter().rev().find(|t| t.kind == TrackKind::Instrument); + let ok = p.tracks.len() == n5.get() + 1 + && last.is_some_and(|t| t.name == "Sampler" && c.selected_track == Some(t.id)) + && c.selected_sampler().is_some() + && c.doc.undo_label() == Some("Add Instrument Track"); + ok.then_some(()).ok_or(format!("{} tracks (was {}), undo {:?}", p.tracks.len(), n5.get(), c.doc.undo_label())) + }), + ), + DoC( + "drop: undo; drag Sampler onto the instrument track's lane", + Box::new(|a, ctl| { + ctl.borrow_mut().undo(); + ctl.borrow_mut().update_ui(a); + let to = { + let c = ctl.borrow(); + track_of(&c, TrackKind::Instrument).and_then(|i| c.track_rect(c.project().tracks[i].id)) + }; + drag_to(a, tree_row_of(a, "Sampler").map(|i| tree_row_xy(a, i)), to); + }), + ), + Check( + "drop: the instrument track's instrument is replaced by the Sampler", + Box::new(move |c, _| { + let p = c.project(); + let t = track_of(c, TrackKind::Instrument).map(|i| &p.tracks[i]); + let ok = + p.tracks.len() == n6.get() && t.and_then(|t| t.instrument_plugin.as_ref()).is_some_and(|d| d.plugin.name == "Sampler"); + ok.then_some(()).ok_or(format!("{} tracks, undo {:?}", p.tracks.len(), c.doc.undo_label())) + }), + ), + DoC( + "drop: undo; drag Sampler below the last track", + Box::new(|a, ctl| { + ctl.borrow_mut().undo(); + ctl.borrow_mut().update_ui(a); + let to = ctl.borrow().new_track_rect(); + drag_to(a, tree_row_of(a, "Sampler").map(|i| tree_row_xy(a, i)), to); + }), + ), + Check( + "drop: below the tracks, the instrument gets a new instrument track", + Box::new(move |c, _| { + let p = c.project(); + let last = p.tracks.last(); + let ok = p.tracks.len() == count.get() + 1 + && last.is_some_and(|t| t.kind == TrackKind::Instrument && t.name == "Sampler") + && c.selected_sampler().is_some(); + ok.then_some(()).ok_or(format!("{} tracks (was {})", p.tracks.len(), count.get())) + }), + ), + DoC( + "drop: undo; clear the search; forget the folder", + Box::new(move |a, ctl| { + let mut c = ctl.borrow_mut(); + c.undo(); + c.browser_search(""); + let _ = c.engine.preview_stop(); + c.files.audition.playing = false; + c.settings.prefs.browser_folders.clear(); + c.browser_section(SECTION_DEVICES); + c.update_ui(a); + let _ = std::fs::remove_dir_all(&r2); + }), + ), + ] +} + /// Run the scripted steps, one per timer tick. Prints a summary and quits. pub fn start(app: &AppWindow, ctl: Ctl) { APP.with(|a| *a.borrow_mut() = Some(app.as_weak())); @@ -15604,6 +15850,7 @@ pub fn start(app: &AppWindow, ctl: Ctl) { all.extend(splitter_steps()); all.extend(chat_dock_steps()); all.extend(files_steps()); + all.extend(browser_drop_steps()); all.extend(section_steps()); all.extend(minimap_steps()); all.extend(devminimap_steps()); diff --git a/crates/dstudio-app/ui/app.slint b/crates/dstudio-app/ui/app.slint index 2dd9954c..d671bb02 100644 --- a/crates/dstudio-app/ui/app.slint +++ b/crates/dstudio-app/ui/app.slint @@ -1128,6 +1128,8 @@ export component AppWindow inherits Window { preferred-height: 820px; min-width: 960px; min-height: 600px; + // Title bar and taskbar icon on Windows and Linux (macOS uses the bundle's, src/appmenu.rs). + icon: @image-url("../icons/device-256.png"); background: Tokens.bg-window; default-font-size: 9.5px; default-font-family: Tokens.font-ui; @@ -1482,12 +1484,24 @@ export component AppWindow inherits Window { picked(i) => { Studio.devmenu-pick(i); } } } + // Browser file drag over the lanes: the clip it will make, where it will land. + if Studio.dnd-active && Studio.dnd-clip-visible: Rectangle { + x: Studio.dnd-clip-x; y: Studio.dnd-clip-y; width: Studio.dnd-clip-w; height: Studio.dnd-clip-h; + border-radius: 3px; clip: true; + background: Studio.dnd-clip-color.with-alpha(0.32); + border-width: 1px; border-color: Studio.dnd-clip-color; + Rectangle { x: 0; y: 0; width: parent.width; height: min(13.6px, parent.height); background: Studio.dnd-clip-color.with-alpha(0.75); } + Text { + x: 5px; y: 0; width: parent.width - 10px; height: min(13.6px, parent.height); + text: Studio.dnd-label; color: #ffffff; font-size: 8.5px; font-weight: 600; vertical-alignment: center; overflow: elide; + } + } // Browser device drag: drop target outline + ghost label at the pointer. if Studio.dnd-active && Studio.dnd-target-visible: Rectangle { x: Studio.dnd-tx; y: Studio.dnd-ty; width: Studio.dnd-tw; height: Studio.dnd-th; border-radius: 4px; background: #2752f522; border-width: 1.5px; border-color: Tokens.accent; } - if Studio.dnd-active: Rectangle { + if Studio.dnd-active && !Studio.dnd-clip-visible: Rectangle { x: Studio.dnd-x + 10px; y: Studio.dnd-y + 6px; height: 20px; width: ghost.preferred-width + 18px; border-radius: 10px; background: Studio.dnd-ok ? Tokens.accent : #3a3b40; ghost := Text { text: Studio.dnd-label; color: #ffffff; font-size: 9px; font-weight: 600; horizontal-alignment: center; vertical-alignment: center; } diff --git a/crates/dstudio-app/ui/studio.slint b/crates/dstudio-app/ui/studio.slint index 90e7ed01..d119b29c 100644 --- a/crates/dstudio-app/ui/studio.slint +++ b/crates/dstudio-app/ui/studio.slint @@ -525,6 +525,13 @@ export global Studio { in property dnd-ty; in property dnd-tw; in property dnd-th; + // Browser file drag over the lanes: the clip it will make, where it will land (src/files.rs). + in property dnd-clip-visible; + in property dnd-clip-x; + in property dnd-clip-y; + in property dnd-clip-w; + in property dnd-clip-h; + in property dnd-clip-color; // ---- callbacks into Rust ---- callback play-toggle(); diff --git a/docs/art/README.md b/docs/art/README.md index 6aca46d0..6abfc0f9 100644 --- a/docs/art/README.md +++ b/docs/art/README.md @@ -19,6 +19,20 @@ node tools/art/render.mjs hero # one page `art.css` holds the shared look: colours from the app's `crates/dstudio-app/ui/tokens.slint` and the app's bundled Inter font. `mark.svg` is the mark: one cycle of a sine wave on the app's blue. +## The app icon + +`icon/app-icon-macos.svg` (the macOS icon grid: an 824 pt tile with a soft shadow on a 1024 pt canvas) and +`icon/app-icon.svg` (Windows and Linux: the mark with a small margin) are the app icon. Render them into the files +the app and its packages carry, in `crates/dstudio-app/icons/`: + +```sh +node tools/art/make-icons.mjs # device.icns, device.ico, device-256.png, device-macos-512.png +``` + +`tools/macos-bundle.sh` puts `device.icns` in Device.app, `crates/dstudio-app/build.rs` builds `device.ico` into +device-studio.exe (the installer uses it too), `tools/release/package-linux.sh` installs `device-256.png` for the +desktop entry, and the window uses it as its title bar and taskbar icon. + ## The app views `shots/` holds the app views the pages frame. They show a whole song, "Night Drive", rather than a diff --git a/docs/art/icon/app-icon-macos.svg b/docs/art/icon/app-icon-macos.svg new file mode 100644 index 00000000..4681a048 --- /dev/null +++ b/docs/art/icon/app-icon-macos.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + diff --git a/docs/art/icon/app-icon.svg b/docs/art/icon/app-icon.svg new file mode 100644 index 00000000..b80c07b5 --- /dev/null +++ b/docs/art/icon/app-icon.svg @@ -0,0 +1,8 @@ + + + + + + + diff --git a/tools/art/make-icons.mjs b/tools/art/make-icons.mjs new file mode 100644 index 00000000..b512d3ae --- /dev/null +++ b/tools/art/make-icons.mjs @@ -0,0 +1,80 @@ +// Renders the app icon (docs/art/icon/*.svg) into the files the app and its packages carry, +// in crates/dstudio-app/icons/: +// +// device.icns macOS bundle icon (16 to 1024 px, from app-icon-macos.svg) +// device.ico Windows executable and installer icon (16 to 256 px, from app-icon.svg) +// device-256.png window icon (Windows, Linux) and the Linux desktop entry's icon +// device-macos-512.png Dock icon when the app runs outside its bundle (cargo run) +// +// npm install --no-save playwright && npx playwright install chromium (once) +// node tools/art/make-icons.mjs +// +// The .icns and .ico containers hold PNG images, which macOS 10.7+ and Windows Vista+ read. +import { chromium } from "playwright"; +import { readFileSync, writeFileSync, mkdirSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +const root = join(dirname(fileURLToPath(import.meta.url)), "..", ".."); +const src = join(root, "docs", "art", "icon"); +const out = join(root, "crates", "dstudio-app", "icons"); +mkdirSync(out, { recursive: true }); + +const browser = await chromium.launch(); +async function render(svgFile, size) { + const svg = readFileSync(join(src, svgFile), "utf8"); + const page = await browser.newPage({ viewport: { width: size, height: size }, deviceScaleFactor: 1 }); + await page.setContent( + `` + + `
${svg.replace("` + + ``, + ); + const png = await page.locator("#i").screenshot({ omitBackground: true }); + await page.close(); + return png; +} + +// ICNS: "icns" + total length, then (type, length, PNG) entries. +const icnsTypes = [ + ["icp4", 16], ["icp5", 32], ["icp6", 64], ["ic07", 128], ["ic08", 256], ["ic09", 512], ["ic10", 1024], + ["ic11", 32], ["ic12", 64], ["ic13", 256], ["ic14", 512], +]; +const mac = new Map(); +for (const [, size] of icnsTypes) if (!mac.has(size)) mac.set(size, await render("app-icon-macos.svg", size)); +const entries = icnsTypes.map(([type, size]) => { + const png = mac.get(size); + const head = Buffer.alloc(8); + head.write(type, 0, "ascii"); + head.writeUInt32BE(png.length + 8, 4); + return Buffer.concat([head, png]); +}); +const body = Buffer.concat(entries); +const icnsHead = Buffer.alloc(8); +icnsHead.write("icns", 0, "ascii"); +icnsHead.writeUInt32BE(body.length + 8, 4); +writeFileSync(join(out, "device.icns"), Buffer.concat([icnsHead, body])); +writeFileSync(join(out, "device-macos-512.png"), mac.get(512)); + +// ICO: ICONDIR, one ICONDIRENTRY per size, then the PNGs. +const icoSizes = [16, 24, 32, 48, 64, 128, 256]; +const pngs = []; +for (const s of icoSizes) pngs.push(await render("app-icon.svg", s)); +const dir = Buffer.alloc(6 + 16 * icoSizes.length); +dir.writeUInt16LE(0, 0); +dir.writeUInt16LE(1, 2); +dir.writeUInt16LE(icoSizes.length, 4); +let offset = dir.length; +icoSizes.forEach((s, i) => { + const e = 6 + 16 * i; + dir.writeUInt8(s >= 256 ? 0 : s, e); + dir.writeUInt8(s >= 256 ? 0 : s, e + 1); + dir.writeUInt16LE(1, e + 4); // planes + dir.writeUInt16LE(32, e + 6); // bits per pixel + dir.writeUInt32LE(pngs[i].length, e + 8); + dir.writeUInt32LE(offset, e + 12); + offset += pngs[i].length; +}); +writeFileSync(join(out, "device.ico"), Buffer.concat([dir, ...pngs])); +writeFileSync(join(out, "device-256.png"), pngs[icoSizes.indexOf(256)]); +await browser.close(); +for (const f of ["device.icns", "device.ico", "device-256.png", "device-macos-512.png"]) console.log(`crates/dstudio-app/icons/${f}`); diff --git a/tools/macos-bundle.sh b/tools/macos-bundle.sh index b4ffa549..810e2644 100755 --- a/tools/macos-bundle.sh +++ b/tools/macos-bundle.sh @@ -20,7 +20,9 @@ fi version="$(sed -n 's/^version = "\(.*\)"/\1/p' "$root/Cargo.toml" | head -1)" app="$out/Device.app" rm -rf "$app" -mkdir -p "$app/Contents/MacOS" +mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources" +# The app icon (crates/dstudio-app/icons, made by tools/art/make-icons.mjs). +cp "$root/crates/dstudio-app/icons/device.icns" "$app/Contents/Resources/device.icns" cp "$exe" "$app/Contents/MacOS/device-studio" if [ -n "$scanner" ] && [ -x "$scanner" ]; then cp "$scanner" "$app/Contents/MacOS/dstudio_plugin_scanner" @@ -36,6 +38,7 @@ cat > "$app/Contents/Info.plist" <CFBundleDisplayNameDevice CFBundleIdentifiercom.dstudio.studio CFBundleExecutabledevice-studio + CFBundleIconFiledevice.icns CFBundlePackageTypeAPPL CFBundleShortVersionString$version CFBundleVersion$version diff --git a/tools/release/device-studio.iss b/tools/release/device-studio.iss index 12e6b5f4..349af1ab 100644 --- a/tools/release/device-studio.iss +++ b/tools/release/device-studio.iss @@ -16,6 +16,8 @@ DefaultDirName={autopf}\Device DefaultGroupName=Device UsePreviousGroup=no UninstallDisplayIcon={app}\device-studio.exe +; The installer's own icon; the app's icon is built into device-studio.exe (crates/dstudio-app/build.rs). +SetupIconFile=..\..\crates\dstudio-app\icons\device.ico OutputDir={#OutputDir} OutputBaseFilename=Device-{#AppVersion}-windows-x64-setup Compression=lzma2 diff --git a/tools/release/package-linux.sh b/tools/release/package-linux.sh index 9ca65bad..587ede5a 100755 --- a/tools/release/package-linux.sh +++ b/tools/release/package-linux.sh @@ -15,12 +15,13 @@ name="Device-$version-linux-$arch" work="$(mktemp -d)" trap 'rm -rf "$work"' EXIT stage="$work/$name" -mkdir -p "$stage/bin" "$stage/share/applications" "$out" +mkdir -p "$stage/bin" "$stage/share/applications" "$stage/share/icons/hicolor/256x256/apps" "$out" install -m 755 "$release/device-studio" "$stage/bin/device-studio" scanner="$(bash "$root/tools/release/find-scanner.sh" "$release")" install -m 755 "$scanner" "$stage/bin/dstudio_plugin_scanner" strip --strip-debug "$stage/bin/device-studio" "$stage/bin/dstudio_plugin_scanner" +install -m 644 "$root/crates/dstudio-app/icons/device-256.png" "$stage/share/icons/hicolor/256x256/apps/device-studio.png" for doc in LICENSE README.md; do [ -f "$root/$doc" ] && install -m 644 "$root/$doc" "$stage/$doc" done @@ -31,7 +32,7 @@ Type=Application Name=Device Comment=Make music: arrange, record and mix Exec=device-studio -Icon=audio-x-generic +Icon=device-studio Terminal=false Categories=AudioVideo;Audio;Midi;Music; DESKTOP @@ -44,9 +45,10 @@ set -eu here="$(cd "$(dirname "$0")" && pwd)" if [ "$(id -u)" = 0 ]; then default=/usr/local; else default="$HOME/.local"; fi prefix="${1:-${PREFIX:-$default}}" -mkdir -p "$prefix/lib/device-studio" "$prefix/bin" "$prefix/share/applications" +mkdir -p "$prefix/lib/device-studio" "$prefix/bin" "$prefix/share/applications" "$prefix/share/icons/hicolor/256x256/apps" cp "$here/bin/device-studio" "$here/bin/dstudio_plugin_scanner" "$prefix/lib/device-studio/" ln -sf "$prefix/lib/device-studio/device-studio" "$prefix/bin/device-studio" +cp "$here/share/icons/hicolor/256x256/apps/device-studio.png" "$prefix/share/icons/hicolor/256x256/apps/" sed "s#^Exec=.*#Exec=$prefix/lib/device-studio/device-studio#" \ "$here/share/applications/device-studio.desktop" > "$prefix/share/applications/device-studio.desktop" echo "Installed to $prefix (run: device-studio)"