diff --git a/README.md b/README.md index edb60752..fd084cd7 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,8 @@ wgpu. Waveforms, clips and the playhead are drawn on the GPU, so the timeline stays at 60 fps with thousands of clips. Shortcuts cover the common moves: ⇧⌘T adds an instrument track, ⌘R reverses the selected clip, ⌘L loops the selected clip or section, ⌘D duplicates the selected clip or section. Settings › Shortcuts lists them all by section; click - one's keys to record new ones, search by name or key, and reset to the defaults at any time. ↑/↓ select the track above + one's keys to record new ones, search by name or key, and reset to the defaults at any time. Its Preset menu swaps in + the keys of Ableton Live, Logic Pro, GarageBand, FL Studio, Fender Studio Pro, Bitwig, Pro Tools or BandLab. ↑/↓ select the track above or below, ⇧↑/⇧↓ (⌘⇧ for an octave) transpose the selected MIDI clips, U folds a group, A shows automation, I monitors the selected track's input and ⌘⌥M shows the mixer. In the piano roll, ⌘↑/⌘↓ (⌥ for 10) change the selected notes' velocity and ←/→ (⇧ for a bar) move them. 0 or M mutes the selected clips (or the track), ←/→ step diff --git a/crates/dstudio-app/src/main.rs b/crates/dstudio-app/src/main.rs index 91953ac3..10c51215 100644 --- a/crates/dstudio-app/src/main.rs +++ b/crates/dstudio-app/src/main.rs @@ -90,6 +90,7 @@ mod selftest; mod send_to_sampler; mod settings; mod shape_rack; +mod shortcut_presets; mod shortcuts; mod showcase; mod snap; @@ -711,7 +712,9 @@ fn parse_args() -> Result { | "review-shortcuts-strip" | "review-shortcuts-zoom" | "review-shortcuts-move" - | "review-shortcuts-mouse") => { + | "review-shortcuts-mouse" + | "review-shortcuts-preset-menu" + | "review-shortcuts-logic") => { a.reference_default = true; a.shortcuts_review = match st { "review-shortcuts-recording" => 2, @@ -723,12 +726,14 @@ fn parse_args() -> Result { "review-shortcuts-zoom" => 8, "review-shortcuts-move" => 9, "review-shortcuts-mouse" => 10, + "review-shortcuts-preset-menu" => 11, + "review-shortcuts-logic" => 12, _ => 1, }; } s => { return Err(format!( - "unknown state {s} (supported: reference-default, reference-mixer, reference-assistant, reference-midi-clip, reference-pianoroll, reference-synth, reference-input-menu, reference-settings-audio, reference-devices-effects, reference-automation, reference-live, review-automation, review-automation-picker, review-recording, review-midi-recording, review-settings-midi, review-shortcuts, review-shortcuts-recording, review-shortcuts-unmapped, review-shortcuts-tracks, review-shortcuts-notes, review-shortcuts-transpose, review-shortcuts-strip, review-shortcuts-zoom, review-shortcuts-move, review-shortcuts-mouse, review-device-chain, review-devices-minimap, review-returns, review-returns-strip, review-returns-empty, review-returns-options, review-snap-menu, review-count-in-menu, review-clip-takes, review-track-menu, review-track-drag, review-clip-selection, review-transport-sig, review-transport-key, review-track-rename, review-audio-loop-drag, review-pr-zoom, review-pr-typing, review-pr-reverse, review-pr-velocity, reference- e.g. reference-compressor, window- and review-window- (expanded window, review- with a test signal), reference-lfo, reference-chain, review-settings-plugins, review-strip-trim, review-plugin-folders, review-analyzers, review-assistant-)" + "unknown state {s} (supported: reference-default, reference-mixer, reference-assistant, reference-midi-clip, reference-pianoroll, reference-synth, reference-input-menu, reference-settings-audio, reference-devices-effects, reference-automation, reference-live, review-automation, review-automation-picker, review-recording, review-midi-recording, review-settings-midi, review-shortcuts, review-shortcuts-recording, review-shortcuts-unmapped, review-shortcuts-tracks, review-shortcuts-notes, review-shortcuts-transpose, review-shortcuts-strip, review-shortcuts-zoom, review-shortcuts-move, review-shortcuts-mouse, review-shortcuts-preset-menu, review-shortcuts-logic, review-device-chain, review-devices-minimap, review-returns, review-returns-strip, review-returns-empty, review-returns-options, review-snap-menu, review-count-in-menu, review-clip-takes, review-track-menu, review-track-drag, review-clip-selection, review-transport-sig, review-transport-key, review-track-rename, review-audio-loop-drag, review-pr-zoom, review-pr-typing, review-pr-reverse, review-pr-velocity, reference- e.g. reference-compressor, window- and review-window- (expanded window, review- with a test signal), reference-lfo, reference-chain, review-settings-plugins, review-strip-trim, review-plugin-folders, review-analyzers, review-assistant-)" )); } }, @@ -941,6 +946,11 @@ fn key_name(text: &str) -> Option { "\u{F703}" => "Right", "," => "Comma", "." => "Period", + "\u{14}" => "CapsLock", + // F1..F12 (Slint sends them as private-use characters). + t if t.chars().count() == 1 && ('\u{F704}'..='\u{F70F}').contains(&t.chars().next().unwrap_or(' ')) => { + return Some(format!("F{}", t.chars().next().unwrap_or(' ') as u32 - 0xF704 + 1)); + } t if t.chars().count() == 1 && t.chars().all(|c| c.is_ascii_graphic()) => return Some(t.to_ascii_uppercase()), _ => return None, }; @@ -2614,12 +2624,15 @@ fn run() -> Result<(), Box> { 8 => c.shortcuts_search("zoom"), 9 => c.shortcuts_search("move"), 10 => c.shortcuts_search("mouse"), + // The Preset menu open; Logic Pro's keys in use (prefs are never saved in --state runs). + 11 => c.settings_dropdown(4), + 12 => c.shortcuts_set_preset("Logic Pro"), _ => {} } if args.shortcuts_review == 3 { // SCREENSHOT-ONLY: a changed keymap (prefs are never saved in --state runs). c.settings.keys.map.set_chords("transport.tap_tempo", Vec::new()); - c.settings.prefs.shortcuts = shortcuts::changes(&c.settings.keys.map); + c.settings.prefs.shortcuts = shortcuts::changes(&c.settings.keys.map, &c.settings.prefs.shortcut_preset); } } if args.settings_midi_review { diff --git a/crates/dstudio-app/src/prefs.rs b/crates/dstudio-app/src/prefs.rs index 49b54fb7..67131685 100644 --- a/crates/dstudio-app/src/prefs.rs +++ b/crates/dstudio-app/src/prefs.rs @@ -92,6 +92,11 @@ pub struct Preferences { /// `Chord::parse` form (an empty list = unmapped). Actions not listed keep their defaults. #[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")] pub shortcuts: std::collections::BTreeMap>, + /// Settings › Shortcuts › Preset: the other DAW whose keys the keymap starts from + /// (`shortcut_presets::PRESETS`; empty = Device Studio's own). `shortcuts` holds the + /// changes on top of it. + #[serde(default, skip_serializing_if = "String::is_empty")] + pub shortcut_preset: String, } fn is_zero_u8(v: &u8) -> bool { @@ -221,6 +226,7 @@ mod tests { plugin_folders: vec!["/opt/plugins".into()], count_in_bars: 2, shortcuts: [("transport.record".to_string(), vec!["primary+shift+r".to_string()])].into_iter().collect(), + shortcut_preset: "Logic Pro".into(), }; save(&path, &p).unwrap(); assert_eq!(load(&path).unwrap(), Some(p.clone())); @@ -236,6 +242,7 @@ mod tests { assert!(loaded.midi.disabled_inputs.is_empty(), "MIDI inputs default to on"); assert!(loaded.plugin_folders.is_empty(), "files without custom plugin folders have none"); assert!(loaded.shortcuts.is_empty(), "files without shortcut changes keep the defaults"); + assert!(loaded.shortcut_preset.is_empty(), "files without a preset use Device Studio's keys"); assert_eq!(loaded.count_in_bars, 0, "files without a count-in record straight away"); let _ = std::fs::remove_dir_all(dir); } diff --git a/crates/dstudio-app/src/selftest.rs b/crates/dstudio-app/src/selftest.rs index cade1f91..83e27207 100644 --- a/crates/dstudio-app/src/selftest.rs +++ b/crates/dstudio-app/src/selftest.rs @@ -12618,6 +12618,58 @@ fn shortcut_page_steps() -> Vec { .ok_or(format!("saved {:?}", c.settings.prefs.shortcuts)) }), ), + Do("shortcuts: open the Preset menu", Box::new(|a| a.global::().invoke_settings_dropdown(4))), + Check( + "shortcuts: the menu lists the nine presets, Device Studio checked", + Box::new(|_, a| { + let s = a.global::(); + let items = s.get_settings_menu_items(); + let labels: Vec = (0..slint::Model::row_count(&items)) + .filter_map(|i| slint::Model::row_data(&items, i)) + .map(|it| format!("{}{}", it.label, if it.checked { " ✓" } else { "" })) + .collect(); + (s.get_settings_menu_open() && labels.len() == 9 && labels[0] == "Device Studio ✓" && labels[2] == "Logic Pro") + .then_some(()) + .ok_or(format!("{labels:?}")) + }), + ), + Do("shortcuts: pick Logic Pro", Box::new(|a| a.global::().invoke_settings_menu_pick(2))), + Check( + "shortcuts: Logic Pro's keys are in use (Loop on / off on C), saved, nothing to reset", + Box::new(|c, a| { + let s = a.global::(); + let r = rows(a); + let lp = r.iter().find(|r| r.label == "Loop on / off"); + let keys = lp.and_then(|p| slint::Model::row_data(&p.chords, 0)).map(|k| { + (0..slint::Model::row_count(&k.parts)).filter_map(|i| slint::Model::row_data(&k.parts, i)).collect::>() + }); + (c.settings.prefs.shortcut_preset == "Logic Pro" + && s.get_shortcut_preset() == "Logic Pro" + && !s.get_settings_menu_open() + && keys == Some(vec!["C".into()]) + && !s.get_shortcut_reset_enabled()) + .then_some(()) + .ok_or(format!("preset {:?} keys {keys:?}", c.settings.prefs.shortcut_preset)) + }), + ), + Do( + "shortcuts: back to the Device Studio preset", + Box::new(|a| { + let s = a.global::(); + s.invoke_settings_dropdown(4); + s.invoke_settings_menu_pick(0); + }), + ), + Check( + "shortcuts: the default keys are back", + Box::new(|c, a| { + (c.settings.keys.map == crate::app_keymap() + && c.settings.prefs.shortcut_preset.is_empty() + && a.global::().get_shortcut_preset() == "Device Studio") + .then_some(()) + .ok_or(format!("preset {:?}", c.settings.prefs.shortcut_preset)) + }), + ), DoC("shortcuts: close Settings", Box::new(|_, ctl| ctl.borrow_mut().close_settings())), ] } diff --git a/crates/dstudio-app/src/settings.rs b/crates/dstudio-app/src/settings.rs index e4be7b6c..4026cb39 100644 --- a/crates/dstudio-app/src/settings.rs +++ b/crates/dstudio-app/src/settings.rs @@ -32,11 +32,13 @@ pub enum Field { Input = 1, SampleRate = 2, BufferSize = 3, + /// Settings › Shortcuts › Preset. + ShortcutPreset = 4, } impl Field { fn from_i32(i: i32) -> Option { - [Field::Output, Field::Input, Field::SampleRate, Field::BufferSize].into_iter().find(|f| *f as i32 == i) + [Field::Output, Field::Input, Field::SampleRate, Field::BufferSize, Field::ShortcutPreset].into_iter().find(|f| *f as i32 == i) } } @@ -46,6 +48,7 @@ pub enum Choice { Device(Option<(String, String)>), // (id, name) Rate(f64), Buffer(u32), + Preset(&'static str), } #[derive(Debug)] @@ -308,6 +311,9 @@ impl Controller { let rate = self.current_rate(); BUFFER_SIZES.iter().map(|&n| (fmt_buffer(n, rate), Choice::Buffer(n))).collect() } + Field::ShortcutPreset => { + crate::shortcut_presets::PRESETS.iter().map(|p| (p.name.to_string(), Choice::Preset(p.name))).collect() + } } } @@ -318,6 +324,7 @@ impl Controller { (Field::Input, Choice::Device(d)) => d.as_ref().map(|d| &d.0) == a.input.as_ref(), (Field::SampleRate, Choice::Rate(r)) => (r - self.current_rate()).abs() < 0.5, (Field::BufferSize, Choice::Buffer(n)) => *n == self.current_buffer(), + (Field::ShortcutPreset, Choice::Preset(p)) => *p == crate::shortcut_presets::find(&self.settings.prefs.shortcut_preset).name, _ => false, } } @@ -345,6 +352,10 @@ impl Controller { if self.is_current(f, &c) { return; } + if let Choice::Preset(name) = c { + self.shortcuts_set_preset(name); + return; + } let mut next = self.settings.prefs.clone(); let a = &mut next.audio; match (f, c) { diff --git a/crates/dstudio-app/src/shortcut_presets.rs b/crates/dstudio-app/src/shortcut_presets.rs new file mode 100644 index 00000000..a4a7a051 --- /dev/null +++ b/crates/dstudio-app/src/shortcut_presets.rs @@ -0,0 +1,204 @@ +//! Shortcut presets (Settings › Shortcuts › Preset): the keys other DAWs use for the same +//! actions, so people can keep their habits. A preset is the default keymap with these +//! actions' keys replaced (an empty list leaves the action unmapped); the user's own +//! changes go on top of the chosen preset. + +/// One preset: its name and the actions whose keys differ from the defaults. +pub struct Preset { + pub name: &'static str, + pub keys: &'static [(&'static str, &'static [&'static str])], +} + +/// Logic Pro and GarageBand share their keys. +const LOGIC: &[(&str, &[&str])] = &[ + ("transport.record", &["r", "shift+r", "*"]), + ("transport.loop_selection", &["u", "primary+u"]), + ("transport.loop_toggle", &["c"]), + ("clip.split_at_range", &["primary+alt+t"]), + ("clip.split_at_marker", &["primary+t"]), + ("clip.reverse", &["ctrl+shift+r"]), + ("clip.bounce_to_track", &["ctrl+b"]), + ("fx.duplicate", &["primary+r"]), + ("range.duplicate", &["primary+r"]), + ("clip.duplicate", &["primary+r"]), + ("clip.quantize", &["q"]), + ("track.duplicate_with_clips", &["primary+shift+alt+d"]), + ("track.add_instrument", &["primary+alt+s"]), + ("track.add_audio", &["primary+alt+a"]), + ("track.arm", &["r", "ctrl+r"]), + ("track.mute", &["m", "ctrl+m"]), + ("track.fold", &[]), + ("view.toggle_mixer", &["x"]), +]; + +pub static PRESETS: &[Preset] = &[ + Preset { name: "Device Studio", keys: &[] }, + Preset { + name: "Ableton Live", + keys: &[ + ("transport.record", &["r", "f9"]), + ("midi.paint_pen", &["b"]), + ("track.arm", &["c"]), + ("track.mute", &["0"]), + ("view.switch_bottom_tab", &["shift+tab", "f12"]), + ("file.export_audio", &["primary+shift+r"]), + ("view.musical_typing", &["m"]), + ], + }, + Preset { name: "Logic Pro", keys: LOGIC }, + Preset { name: "GarageBand", keys: LOGIC }, + Preset { + name: "FL Studio", + keys: &[ + ("transport.tap_tempo", &[]), + ("clip.consolidate", &["primary+g", "primary+j"]), + ("clip.bounce_to_track", &["primary+alt+c"]), + ("fx.duplicate", &["primary+b"]), + ("range.duplicate", &["primary+b"]), + ("clip.duplicate", &["primary+b"]), + ("section.duplicate", &["primary+b"]), + ("midi.paint_pen", &["p", "shift+p"]), + ("clip.transpose_up", &[]), + ("clip.transpose_down", &[]), + ("clip.quantize", &["alt+q", "primary+u", "q"]), + ("clip.move_to_track_above", &["shift+up"]), + ("clip.move_to_track_below", &["shift+down"]), + ("track.group", &[]), + ("track.ungroup", &[]), + ("track.duplicate", &["primary+b"]), + ("track.add_audio", &["shift+t"]), + ("track.arm", &["r"]), + ("track.mute", &["m"]), + ("view.toggle_mixer", &["f9"]), + ("view.musical_typing", &["primary+t"]), + ("midi.transpose_up", &["shift+up", "up"]), + ("midi.transpose_down", &["shift+down", "down"]), + ("midi.octave_up", &["primary+up"]), + ("midi.octave_down", &["primary+down"]), + ("midi.velocity_up", &[]), + ("midi.velocity_down", &[]), + ("midi.nudge_left", &["shift+left", "left"]), + ("midi.nudge_right", &["shift+right", "right"]), + ("midi.nudge_bar_left", &[]), + ("midi.nudge_bar_right", &[]), + ("midi.glue", &["primary+g"]), + ], + }, + Preset { + name: "Fender Studio Pro", + keys: &[ + ("transport.record", &["r", "*"]), + ("transport.loop_toggle", &["/"]), + ("clip.split_at_range", &["primary+alt+x"]), + ("clip.split_at_marker", &["alt+x"]), + ("fx.duplicate", &["d"]), + ("range.duplicate", &["d"]), + ("clip.duplicate", &["d"]), + ("section.duplicate", &["d"]), + ("clip.insert_midi", &["primary+p"]), + ("midi.paint_pen", &["5", "shift+5"]), + ("track.duplicate", &["d"]), + ("track.arm", &["r"]), + ("track.mute", &["m"]), + ("view.toggle_mixer", &["f3"]), + ("view.musical_typing", &["capslock"]), + ], + }, + Preset { + name: "Bitwig", + keys: &[ + ("transport.loop_toggle", &["\\"]), + ("midi.paint_pen", &["3", "shift+3"]), + ("track.add_instrument", &["primary+t"]), + ("track.add_audio", &[]), + ("track.arm", &["a"]), + ("track.mute", &["m"]), + ("view.toggle_mixer", &["f4"]), + ("view.musical_typing", &["capslock"]), + ], + }, + Preset { + name: "Pro Tools", + keys: &[ + ("transport.record", &["r", "f12"]), + ("transport.loop_selection", &["primary+shift+l"]), + ("transport.loop_toggle", &["primary+shift+l"]), + ("clip.consolidate", &["shift+alt+3"]), + ("clip.bounce_to_track", &[]), + ("midi.paint_pen", &["f10", "primary+6"]), + ("clip.quantize", &["alt+0", "q"]), + ("track.duplicate_with_clips", &["shift+alt+d"]), + ("track.duplicate", &[]), + ("track.add_instrument", &[]), + ("track.add_audio", &["primary+shift+n"]), + ("track.arm", &["shift+r"]), + ("track.mute", &["shift+m"]), + ("track.solo", &["shift+s"]), + ("track.monitor", &["shift+i"]), + ("view.toggle_mixer", &["primary+="]), + // ⌘= opens the mixer here, so the interface zooms with ⌘+ or ⌃=. + ("view.ui_zoom_in", &["primary+plus", "ctrl+="]), + ("view.fit_width", &["alt+a"]), + ("view.musical_typing", &["shift+k"]), + ], + }, + Preset { + name: "BandLab", + keys: &[ + ("transport.loop_toggle", &["c"]), + ("clip.split_at_range", &["s"]), + ("clip.split_at_marker", &["s"]), + ("track.duplicate_with_clips", &["primary+shift+d", "shift+d"]), + ("track.arm", &["r"]), + ("track.mute", &["shift+m"]), + ("track.solo", &["shift+s"]), + ], + }, +]; + +/// The preset called `name` (an unknown or empty name is the default). +pub fn find(name: &str) -> &'static Preset { + PRESETS.iter().find(|p| p.name == name).unwrap_or(&PRESETS[0]) +} + +/// The default keymap with the preset's keys applied. +pub fn keymap(name: &str) -> dstudio_core::keymap::Keymap { + let mut map = crate::app_keymap(); + for (action, chords) in find(name).keys { + let chords = chords.iter().map(|c| dstudio_core::keymap::Chord::parse(c).expect("valid preset chord")).collect(); + map.set_chords(action, chords); + } + map +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn every_preset_parses_names_known_actions_and_has_no_conflicts() { + let defaults = crate::app_keymap(); + for p in PRESETS { + for (action, _) in p.keys { + assert!(defaults.condition_of(action).is_some(), "{}: {action} is not an action", p.name); + } + let map = keymap(p.name); + assert!(map.conflicts().is_empty(), "{}: {:?}", p.name, map.conflicts()); + } + } + + #[test] + fn presets_change_the_keys_they_list() { + use dstudio_core::keymap::{Chord, Context}; + let ch = |s: &str| Chord::parse(s).unwrap(); + let ctx = Context::default(); + assert_eq!(keymap("Device Studio"), crate::app_keymap()); + assert_eq!(keymap("nonsense"), crate::app_keymap()); + assert_eq!(keymap("Logic Pro").resolve(&ch("c"), &ctx), Some("transport.loop_toggle")); + assert_eq!(keymap("Logic Pro").resolve(&ch("x"), &ctx), Some("view.toggle_mixer")); + assert_eq!(keymap("Ableton Live").resolve(&ch("f9"), &ctx), Some("transport.record")); + assert_eq!(keymap("FL Studio").resolve(&ch("f9"), &ctx), Some("view.toggle_mixer")); + assert_eq!(keymap("Pro Tools").resolve(&ch("primary+="), &ctx), Some("view.toggle_mixer")); + assert!(keymap("Logic Pro").chords_for("track.fold").is_empty()); + } +} diff --git a/crates/dstudio-app/src/shortcuts.rs b/crates/dstudio-app/src/shortcuts.rs index b1bfd611..dba48c5c 100644 --- a/crates/dstudio-app/src/shortcuts.rs +++ b/crates/dstudio-app/src/shortcuts.rs @@ -170,9 +170,9 @@ impl Default for ShortcutsUi { } } -/// The defaults with `saved` applied (unknown actions and chords that no longer parse are skipped). -pub fn keymap_with(saved: &std::collections::BTreeMap>) -> Keymap { - let mut map = crate::app_keymap(); +/// The preset's keys with `saved` applied (unknown actions and chords that no longer parse are skipped). +pub fn keymap_with(preset: &str, saved: &std::collections::BTreeMap>) -> Keymap { + let mut map = crate::shortcut_presets::keymap(preset); for (action, chords) in saved { let chords: Vec = chords.iter().filter_map(|c| Chord::parse(c)).collect(); map.set_chords(action, chords); @@ -180,9 +180,9 @@ pub fn keymap_with(saved: &std::collections::BTreeMap>) -> K map } -/// The saved form of `map`: the listed actions whose chords differ from the defaults. -pub fn changes(map: &Keymap) -> std::collections::BTreeMap> { - let defaults = crate::app_keymap(); +/// The saved form of `map`: the listed actions whose chords differ from the preset's. +pub fn changes(map: &Keymap, preset: &str) -> std::collections::BTreeMap> { + let defaults = crate::shortcut_presets::keymap(preset); SECTIONS .iter() .flat_map(|(_, rows)| rows.iter()) @@ -292,11 +292,12 @@ impl Controller { /// Startup: apply the saved shortcut changes. pub fn shortcuts_load(&mut self) { - self.settings.keys.map = keymap_with(&self.settings.prefs.shortcuts); + let p = &self.settings.prefs; + self.settings.keys.map = keymap_with(&p.shortcut_preset, &p.shortcuts); } fn shortcuts_save(&mut self) { - self.settings.prefs.shortcuts = changes(&self.settings.keys.map); + self.settings.prefs.shortcuts = changes(&self.settings.keys.map, &self.settings.prefs.shortcut_preset); self.save_prefs(); self.ui_dirty = true; } @@ -316,8 +317,19 @@ impl Controller { self.shortcuts_save(); } + /// Reset to defaults: the chosen preset's keys, without the user's changes. pub fn shortcuts_reset(&mut self) { - self.settings.keys.map = crate::app_keymap(); + self.settings.keys.map = crate::shortcut_presets::keymap(&self.settings.prefs.shortcut_preset); + self.settings.keys.recording = None; + self.shortcuts_save(); + } + + /// Preset menu: start from another DAW's keys (the changes made on the old preset are dropped). + pub fn shortcuts_set_preset(&mut self, name: &str) { + let preset = crate::shortcut_presets::find(name); + let saved = if preset.name == crate::shortcut_presets::PRESETS[0].name { String::new() } else { preset.name.to_string() }; + self.settings.prefs.shortcut_preset = saved; + self.settings.keys.map = crate::shortcut_presets::keymap(preset.name); self.settings.keys.recording = None; self.shortcuts_save(); } @@ -421,6 +433,7 @@ impl Controller { s.set_shortcut_list_h(y + 12.0); s.set_shortcut_recording(keys.recording.is_some()); s.set_shortcut_reset_enabled(!self.settings.prefs.shortcuts.is_empty()); + s.set_shortcut_preset(crate::shortcut_presets::find(&self.settings.prefs.shortcut_preset).name.into()); s.set_shortcut_empty(empty); if s.get_shortcut_search().as_str() != keys.search { s.set_shortcut_search(keys.search.as_str().into()); @@ -455,14 +468,21 @@ mod tests { #[test] fn saved_changes_round_trip() { let mut map = crate::app_keymap(); - assert!(changes(&map).is_empty()); + assert!(changes(&map, "").is_empty()); map.set_chords("transport.record", vec![Chord::parse("primary+shift+r").unwrap()]); map.set_chords("clip.cut", Vec::new()); - let saved = changes(&map); + let saved = changes(&map, ""); assert_eq!(saved.get("transport.record"), Some(&vec!["primary+shift+r".to_string()])); assert_eq!(saved.get("clip.cut"), Some(&Vec::new())); assert_eq!(saved.len(), 2); - assert_eq!(keymap_with(&saved), map); + assert_eq!(keymap_with("", &saved), map); + // On a preset, the changes are relative to its keys. + let mut logic = crate::shortcut_presets::keymap("Logic Pro"); + assert!(changes(&logic, "Logic Pro").is_empty()); + logic.set_chords("transport.loop_toggle", vec![Chord::parse("primary+l").unwrap()]); + let saved = changes(&logic, "Logic Pro"); + assert_eq!(saved.len(), 1); + assert_eq!(keymap_with("Logic Pro", &saved), logic); } #[test] diff --git a/crates/dstudio-app/ui/settings.slint b/crates/dstudio-app/ui/settings.slint index 8a57b74d..967270bf 100644 --- a/crates/dstudio-app/ui/settings.slint +++ b/crates/dstudio-app/ui/settings.slint @@ -169,8 +169,8 @@ component GeneralPage inherits Rectangle { // ---------------------------------------------------------------- Shortcuts page // Settings › Shortcuts (src/shortcuts.rs). Every action by section, its keys as badges and // the context it works in. Click the keys to record new ones ("Press keys", Escape cancels), -// hover a row for × (unmapped), Reset to defaults drops every change. One preset for now -// (shown, not a menu). +// hover a row for × (unmapped), Reset to defaults drops every change. Preset starts from +// another DAW's keys (src/shortcut_presets.rs). // One chord: a pill holding a round badge per key ("⌘", "L"), or a wider one for a name ("Space"). component KeyChord inherits Rectangle { @@ -219,9 +219,12 @@ component ShortcutsPage inherits Rectangle { FieldLabel { x: 20.5px; y: 33px; height: 24px; text: "Shortcuts"; font-size: 17.25px; font-weight: 700; } Text { x: 20.5px; y: 78px; height: 14px; text: "Preset"; color: #7e7f83; font-size: 10px; font-weight: 500; vertical-alignment: center; } Rectangle { - x: 57.5px; y: 74.75px; width: 134px; height: 20.4px; border-radius: 10.2px; background: #2a2b30; - accessible-role: combobox; accessible-label: "Preset"; accessible-value: "Device Studio"; - Text { x: 10.5px; text: "Device Studio"; color: #bdbec2; font-size: 10px; font-weight: 600; vertical-alignment: center; } + x: 57.5px; y: 74.75px; width: 134px; height: 20.4px; border-radius: 10.2px; + accessible-role: combobox; accessible-label: "Preset"; accessible-value: Studio.shortcut-preset; + accessible-action-default => { Studio.settings-dropdown(4); } + background: preset-ta.has-hover ? #303136 : #2a2b30; + preset-ta := TouchArea { clicked => { Studio.settings-dropdown(4); } } + Text { x: 10.5px; width: parent.width - 30px; text: Studio.shortcut-preset; color: #bdbec2; font-size: 10px; font-weight: 600; vertical-alignment: center; overflow: elide; } Path { x: parent.width - 17.5px; y: (parent.height - 3.6px) / 2; width: 6px; height: 3.6px; viewbox-width: 6; viewbox-height: 3.6; commands: "M0 0 L6 0 L3 3.6 Z"; fill: #8e8f94; } } Rectangle { @@ -569,10 +572,12 @@ export component SettingsPanel inherits Rectangle { // Dropdown list (click outside closes). if Studio.settings-menu-open: Rectangle { TouchArea { clicked => { Studio.settings-menu-dismiss(); } } - property field-y: Studio.settings-menu-field == 0 ? 90px : Studio.settings-menu-field == 1 ? 151px : Studio.settings-menu-field == 2 ? 251px : 312px; + property field-y: Studio.settings-menu-field == 0 ? 90px : Studio.settings-menu-field == 1 ? 151px : Studio.settings-menu-field == 2 ? 251px : Studio.settings-menu-field == 3 ? 312px : 74.75px; + property preset: Studio.settings-menu-field == 4; ChoiceList { - x: 187px + 20.5px; y: min(parent.field-y + 31px, root.height - 5px - self.height); - width: Studio.settings-menu-field == 0 ? root.width - 187px - 20.5px - 76.5px : root.width - 187px - 41px; + x: parent.preset ? 187px + 57.5px : 187px + 20.5px; + y: min(parent.field-y + (parent.preset ? 23.4px : 31px), root.height - 5px - self.height); + width: parent.preset ? 134px : Studio.settings-menu-field == 0 ? root.width - 187px - 20.5px - 76.5px : root.width - 187px - 41px; height: Studio.settings-menu-h; items: Studio.settings-menu-items; font-size: 10.5px; text-x: 11px; diff --git a/crates/dstudio-app/ui/studio.slint b/crates/dstudio-app/ui/studio.slint index e08031aa..516a7032 100644 --- a/crates/dstudio-app/ui/studio.slint +++ b/crates/dstudio-app/ui/studio.slint @@ -1038,6 +1038,7 @@ export global Studio { in property shortcut-recording; // a row is waiting for keys in property shortcut-reset-enabled; // some shortcut differs from the defaults in property shortcut-empty; // the search matches nothing + in property shortcut-preset: "Device Studio"; // Preset menu: the other DAW's keys in use in-out property shortcut-search; // the search field's text callback shortcut-record(int); // click a row's keys: record new ones callback shortcut-clear(int); // ×: unmapped diff --git a/crates/dstudio-core/src/keymap.rs b/crates/dstudio-core/src/keymap.rs index 3941667d..4f901c15 100644 --- a/crates/dstudio-core/src/keymap.rs +++ b/crates/dstudio-core/src/keymap.rs @@ -57,6 +57,7 @@ fn normalize_key(k: &str) -> Option { "end", "comma", "period", + "capslock", ]; if k == "plus" { return Some("+".into()); @@ -70,6 +71,7 @@ fn normalize_key(k: &str) -> Option { return Some(match s.as_str() { "Pageup" => "PageUp".into(), "Pagedown" => "PageDown".into(), + "Capslock" => "CapsLock".into(), _ => s, }); } @@ -112,6 +114,7 @@ impl Chord { "Backspace" => "⌫", "Delete" => "⌦", "Escape" => "Esc", + "CapsLock" => "Caps Lock", k => k, } .to_string(),