Multi sample bulk import
This commit is contained in:
@@ -224,6 +224,8 @@ pub enum PendingSamplerLoad {
|
||||
MultiFromFolder { node_id: NodeId, folder_id: uuid::Uuid },
|
||||
/// Open a file/folder dialog to load into a MultiSampler
|
||||
MultiFromFilesystem { node_id: NodeId, backend_node_id: u32 },
|
||||
/// Open a folder dialog for batch import with heuristic mapping
|
||||
MultiFromFolderFilesystem { node_id: NodeId, backend_node_id: u32 },
|
||||
}
|
||||
|
||||
/// Custom graph state - can track selected nodes, etc.
|
||||
@@ -261,6 +263,8 @@ pub struct GraphState {
|
||||
pub draw_vms: HashMap<NodeId, beamdsp::DrawVM>,
|
||||
/// Pending param changes from draw block (node_id, param_index, new_value)
|
||||
pub pending_draw_param_changes: Vec<(NodeId, u32, f32)>,
|
||||
/// Active sample import dialog (folder import with heuristic mapping)
|
||||
pub sample_import_dialog: Option<crate::sample_import_dialog::SampleImportDialog>,
|
||||
}
|
||||
|
||||
impl Default for GraphState {
|
||||
@@ -283,6 +287,7 @@ impl Default for GraphState {
|
||||
pending_script_sample_load: None,
|
||||
draw_vms: HashMap::new(),
|
||||
pending_draw_param_changes: Vec::new(),
|
||||
sample_import_dialog: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -661,6 +666,14 @@ impl NodeTemplateTrait for NodeTemplate {
|
||||
}
|
||||
NodeTemplate::MultiSampler => {
|
||||
graph.add_input_param(node_id, "MIDI In".into(), DataType::Midi, ValueType::float(0.0), InputParamKind::ConnectionOnly, true);
|
||||
graph.add_input_param(node_id, "Gain".into(), DataType::CV,
|
||||
ValueType::float_param(1.0, 0.0, 2.0, "", 0, None), InputParamKind::ConstantOnly, true);
|
||||
graph.add_input_param(node_id, "Attack".into(), DataType::CV,
|
||||
ValueType::float_param(0.01, 0.001, 1.0, " s", 1, None), InputParamKind::ConstantOnly, true);
|
||||
graph.add_input_param(node_id, "Release".into(), DataType::CV,
|
||||
ValueType::float_param(0.1, 0.01, 5.0, " s", 2, None), InputParamKind::ConstantOnly, true);
|
||||
graph.add_input_param(node_id, "Transpose".into(), DataType::CV,
|
||||
ValueType::float_param(0.0, -24.0, 24.0, " st", 3, None), InputParamKind::ConstantOnly, true);
|
||||
graph.add_output_param(node_id, "Audio Out".into(), DataType::Audio);
|
||||
}
|
||||
NodeTemplate::Reverb => {
|
||||
@@ -1123,6 +1136,15 @@ impl NodeDataTrait for NodeData {
|
||||
}
|
||||
close_popup = true;
|
||||
}
|
||||
if is_multi {
|
||||
if ui.button("Import Folder...").clicked() {
|
||||
user_state.pending_sampler_load = Some(PendingSamplerLoad::MultiFromFolderFilesystem {
|
||||
node_id,
|
||||
backend_node_id,
|
||||
});
|
||||
close_popup = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if close_popup {
|
||||
|
||||
@@ -793,6 +793,23 @@ impl NodeGraphPane {
|
||||
}
|
||||
}
|
||||
}
|
||||
graph_data::PendingSamplerLoad::MultiFromFolderFilesystem { node_id, backend_node_id } => {
|
||||
if let Some(path) = rfd::FileDialog::new().pick_folder() {
|
||||
match crate::sample_import::scan_folder(&path) {
|
||||
Ok(samples) => {
|
||||
let scan_result = crate::sample_import::build_import_layers(samples, &path);
|
||||
let track_id = backend_track_id;
|
||||
let dialog = crate::sample_import_dialog::SampleImportDialog::new(
|
||||
path, scan_result, track_id, backend_node_id, node_id,
|
||||
);
|
||||
self.user_state.sample_import_dialog = Some(dialog);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to scan folder '{}': {}", path.display(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2584,6 +2601,54 @@ impl crate::panes::PaneRenderer for NodeGraphPane {
|
||||
self.handle_pending_sampler_load(load, shared);
|
||||
}
|
||||
|
||||
// Render sample import dialog if active
|
||||
if let Some(dialog) = &mut self.user_state.sample_import_dialog {
|
||||
let still_open = dialog.show(ui.ctx());
|
||||
if !still_open {
|
||||
// Dialog closed — check if confirmed
|
||||
let dialog = self.user_state.sample_import_dialog.take().unwrap();
|
||||
if dialog.confirmed {
|
||||
let backend_track_id = dialog.track_id;
|
||||
let backend_node_id = dialog.backend_node_id;
|
||||
let node_id = dialog.node_id;
|
||||
let loop_mode = dialog.loop_mode;
|
||||
let enabled_layers: Vec<_> = dialog.scan_result.layers.iter()
|
||||
.filter(|l| l.enabled)
|
||||
.collect();
|
||||
let layer_count = enabled_layers.len();
|
||||
let folder_name = dialog.folder_path.file_name()
|
||||
.map(|n| n.to_string_lossy().to_string())
|
||||
.unwrap_or_else(|| "Folder".to_string());
|
||||
|
||||
if let Some(controller_arc) = &shared.audio_controller {
|
||||
let mut controller = controller_arc.lock().unwrap();
|
||||
// Clear existing layers before importing new ones
|
||||
controller.multi_sampler_clear_layers(backend_track_id, backend_node_id);
|
||||
for layer in &enabled_layers {
|
||||
controller.multi_sampler_add_layer(
|
||||
backend_track_id,
|
||||
backend_node_id,
|
||||
layer.path.to_string_lossy().to_string(),
|
||||
layer.key_min,
|
||||
layer.key_max,
|
||||
layer.root_key,
|
||||
layer.velocity_min,
|
||||
layer.velocity_max,
|
||||
None, None, // loop points auto-detected by backend
|
||||
loop_mode,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(node) = self.state.graph.nodes.get_mut(node_id) {
|
||||
node.user_data.sample_display_name = Some(
|
||||
format!("{} ({} layers)", folder_name, layer_count)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle pending script sample load requests from bottom_ui()
|
||||
if let Some(load) = self.user_state.pending_script_sample_load.take() {
|
||||
self.handle_pending_script_sample_load(load, shared);
|
||||
|
||||
Reference in New Issue
Block a user