Skip to content
Open
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
3 changes: 2 additions & 1 deletion crates/os-app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2344,6 +2344,7 @@ impl App {
self.midi_export_chosen(p, piano);
}
}
Then::MidiFont => self.midi_font_chosen(file),
}
self.invalidate();
}
Expand Down Expand Up @@ -4711,7 +4712,7 @@ impl App {
Some((r, channel)) => crate::control_ui::command(s, crate::history::LOAD_SAMPLE, None, vec![Command::LoadSample { channel, path }]).map(|_| r),
// A new channel named after the file; undone, it goes.
None => {
let c = Command::AddChannel { name: stem.clone(), plugin: None, sample: Some(path), track: None, kind: None, color: None, target: None, points: Vec::new(), children: Vec::new() };
let c = Command::AddChannel { name: stem.clone(), plugin: None, sample: Some(path), track: None, kind: None, color: None, target: None, points: Vec::new(), children: Vec::new(), state: None };
crate::control_ui::command(s, crate::history::LOAD_SAMPLE, None, vec![c]).map(|r| {
let id = r.first().and_then(|v| v["channel"].as_u64()).unwrap_or(0) as u32;
s.session.project.channels.iter().position(|c| c.id.0 == id).unwrap_or(0)
Expand Down
2 changes: 1 addition & 1 deletion crates/os-app/src/container_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ impl App {
}
let s = &mut self.state;
crate::mixer::track_ids(s);
let c = crate::control::command::Command::AddChannel { name: None, plugin: Some(CONTAINER.into()), sample: None, track: None, kind: None, color: None, target: None, points: Vec::new(), children: Vec::new() };
let c = crate::control::command::Command::AddChannel { name: None, plugin: Some(CONTAINER.into()), sample: None, track: None, kind: None, color: None, target: None, points: Vec::new(), children: Vec::new(), state: None };
let id = match crate::control_ui::command(s, crate::history::ADD_CHANNEL, None, vec![c]) {
Ok(r) => r.first().and_then(|v| v["channel"].as_u64())? as u32,
Err(e) => return Some(e),
Expand Down
16 changes: 16 additions & 0 deletions crates/os-app/src/control/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,22 @@ fn new_things_name_their_ids() {
assert_eq!(a.state.session.project.channels.last().unwrap().volume, 0.1);
}

/// `add_channel` with a saved state: a built-in plugin's channel keeps it and is hosted from it (no new instance asked
/// for); a sampler's or an empty one is refused.
#[test]
fn a_new_channel_can_start_from_a_saved_state() {
let mut a = app();
let state = vec![2u8, 0, 0, 0, 1, 0, 0, 0];
let r = apply(&mut a.state, &test_client(), None, vec![cmd(json!({"op": "add_channel", "plugin": crate::soundfont::LEMON_SOUNDFONT, "state": state}))]).unwrap();
let ch = r[0]["channel"].as_u64().unwrap() as u32;
let c = a.state.session.project.channels.iter().find(|c| c.id.0 == ch).unwrap();
assert_eq!((c.plugin.as_deref(), c.plugin_state.as_deref()), (Some(crate::soundfont::FILE_NAME), Some(&state[..])));
assert!(a.state.session.control.host.is_empty());
for bad in [json!({"op": "add_channel", "state": state}), json!({"op": "add_channel", "plugin": crate::soundfont::LEMON_SOUNDFONT, "state": []}), json!({"op": "add_channel", "kind": "layer", "state": state})] {
assert!(apply(&mut a.state, &test_client(), None, vec![cmd(bad.clone())]).is_err(), "{bad}");
}
}

#[test]
fn a_transaction_is_one_named_step_and_all_or_nothing() {
let mut a = app();
Expand Down
2 changes: 2 additions & 0 deletions crates/os-app/src/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ pub enum Then {
MidiImport(bool),
/// Where to export a MIDI file; true: the piano roll's channel.
MidiExport(bool),
/// The SoundFont a MIDI file's import plays with Lemon SoundFont Player (`App::midi_font_chosen`).
MidiFont,
/// File ▸ FL Studio factory content folder: the folder picked (`App::set_factory_folder`).
FactoryFolder,
/// FILE ▸ Save as template...: the template's name, from the save dialog (`crate::project_files`).
Expand Down
2 changes: 1 addition & 1 deletion crates/os-app/src/lemon_midi_out_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl crate::app::App {
use crate::control::command::Command;
let s = &mut self.state;
crate::mixer::track_ids(s);
let c = Command::AddChannel { name: None, plugin: Some(LEMON_MIDI_OUT.into()), sample: None, track: None, kind: None, color: None, target: None, points: Vec::new(), children: Vec::new() };
let c = Command::AddChannel { name: None, plugin: Some(LEMON_MIDI_OUT.into()), sample: None, track: None, kind: None, color: None, target: None, points: Vec::new(), children: Vec::new(), state: None };
let id = match crate::control_ui::command(s, crate::history::ADD_CHANNEL, None, vec![c]) {
Ok(r) => r.first().and_then(|v| v["channel"].as_u64())? as u32,
Err(e) => return Some(e),
Expand Down
Loading
Loading