Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
45 changes: 45 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/dstudio-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
21 changes: 21 additions & 0 deletions crates/dstudio-app/build.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Binary file added crates/dstudio-app/icons/device-256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added crates/dstudio-app/icons/device-macos-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added crates/dstudio-app/icons/device.icns
Binary file not shown.
Binary file added crates/dstudio-app/icons/device.ico
Binary file not shown.
30 changes: 30 additions & 0 deletions crates/dstudio-app/src/appmenu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<std::ffi::c_void>(), 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() {}
5 changes: 4 additions & 1 deletion crates/dstudio-app/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ pub enum JobResult {
Onsets { engine_asset: u64, result: Result<Vec<dstudio_engine::Onset>, String>, tempo: Option<f64> },
/// A file clicked in Browser › Files, decoded for the preview voice (src/files.rs).
Auditioned { path: PathBuf, result: Result<AssetInfo, String> },
/// A file dragged from Browser › Files, decoded to measure its length (src/files.rs).
Measured { path: PathBuf, result: Result<AssetInfo, String> },
/// A Consolidate, Bounce or Export render written and loaded (src/clip_render.rs).
ClipRendered(Box<crate::clip_render::ClipRendered>),
/// File › Import Ableton Live Set… read and its samples decoded (src/live_import.rs).
Expand Down Expand Up @@ -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 } => {
Expand Down Expand Up @@ -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)
}
Expand Down
68 changes: 63 additions & 5 deletions crates/dstudio-app/src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<usize>) -> 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));
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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)?;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
}
Expand Down
Loading
Loading