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
6 changes: 6 additions & 0 deletions crates/rustjay-core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,10 @@ pub struct EngineState {
pub midi_learn_mode: bool,
/// UI map mode: clicking a mappable param opens an LFO-assign popup.
pub lfo_assign_mode: bool,
/// UI map mode: clicking a mappable param copies its OSC address.
pub osc_copy_mode: bool,
/// Id of the param whose address was copied last, so its outline can confirm it.
pub osc_copied_param: Option<String>,
/// Active mappings, synced each frame from MidiState (includes min/max for preset round-trip).
pub midi_mappings: Vec<MidiMappingSnapshot>,
/// Last MIDI message received, for the MIDI monitor display:
Expand Down Expand Up @@ -1254,6 +1258,8 @@ impl EngineState {
midi_learning_param_name: None,
midi_learn_mode: false,
lfo_assign_mode: false,
osc_copy_mode: false,
osc_copied_param: None,
midi_last_input: None,
midi_mappings: Vec::new(),
osc_command: OscCommand::None,
Expand Down
70 changes: 64 additions & 6 deletions crates/rustjay-gui/src/egui_control_gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ impl EguiControlGui {
output_sinks,
lfo_assign_mode,
midi_learn_mode,
osc_copy_mode,
) = {
let state = self.shared_state.lock().unwrap_or_else(|e| e.into_inner());
let perf = state.performance.lock().unwrap_or_else(|e| e.into_inner());
Expand All @@ -399,6 +400,7 @@ impl EguiControlGui {
.unwrap_or_default(),
state.lfo_assign_mode,
state.midi_learn_mode,
state.osc_copy_mode,
)
};

Expand Down Expand Up @@ -561,6 +563,7 @@ impl EguiControlGui {
state.lfo_assign_mode = !state.lfo_assign_mode;
if state.lfo_assign_mode {
state.midi_learn_mode = false;
state.osc_copy_mode = false;
}
}
ui.add_space(6.0);
Expand All @@ -579,12 +582,36 @@ impl EguiControlGui {
state.midi_learn_mode = !state.midi_learn_mode;
if state.midi_learn_mode {
state.lfo_assign_mode = false;
state.osc_copy_mode = false;
} else {
// Leaving map mode cancels any pending arm.
state.midi_command = rustjay_core::MidiCommand::CancelLearn;
}
}
ui.add_space(6.0);
// OSC-copy mode: click a param to put its address on the clipboard.
if ui
.button(
egui::RichText::new("📋 OSC COPY")
.size(11.0)
.color(if osc_copy_mode { amber() } else { ink_2() }),
)
.on_hover_text("Click a parameter to copy its OSC address")
.clicked()
{
let mut state =
self.shared_state.lock().unwrap_or_else(|e| e.into_inner());
state.osc_copy_mode = !state.osc_copy_mode;
state.osc_copied_param = None;
if state.osc_copy_mode {
state.lfo_assign_mode = false;
if state.midi_learn_mode {
state.midi_learn_mode = false;
state.midi_command = rustjay_core::MidiCommand::CancelLearn;
}
}
}
ui.add_space(6.0);
if ui
.button(
egui::RichText::new(if show_preview {
Expand Down Expand Up @@ -1590,7 +1617,7 @@ impl EguiControlGui {
ParamType::Float => {
let mut v = value;
let id_tag = format!("{}/{}", desc.category.name().to_lowercase(), desc.id);
if state.midi_learn_mode || state.lfo_assign_mode {
if map_mode_active(state) {
let scope = ui.scope(|ui| {
ui.disable();
crate::egui_widgets::parameter_card_f32(
Expand Down Expand Up @@ -1633,7 +1660,7 @@ impl EguiControlGui {
let min = desc.min as i32;
let max = desc.max as i32;
log::trace!("Int slider {}: {} (range {}..{})", desc.id, v, min, max);
if state.midi_learn_mode || state.lfo_assign_mode {
if map_mode_active(state) {
let scope = ui.scope(|ui| {
ui.disable();
ui.add(
Expand Down Expand Up @@ -1709,22 +1736,22 @@ impl EguiControlGui {
}
}

/// True when either top-bar map mode (MIDI learn / LFO assign) is active.
/// True when a top-bar map mode (MIDI learn / LFO assign / OSC copy) is active.
///
/// Custom egui tabs that render their own param sliders should check this and,
/// when true, render the slider disabled and call [`apply_param_map_overlay`]
/// so their params participate in the map modes like the built-in tabs do.
pub fn map_mode_active(engine: &EngineState) -> bool {
engine.midi_learn_mode || engine.lfo_assign_mode
engine.midi_learn_mode || engine.lfo_assign_mode || engine.osc_copy_mode
}

/// Draw the active map-mode outline over `rect` and handle clicks on a param.
///
/// In MIDI-learn mode a click arms `StartLearn` for the param; in LFO-assign
/// mode a click opens a popup listing modulation sources to bind. `midi_path`
/// is the learn target path (conventionally `"<category>/<id>"`), `id` is the
/// engine param id (also the modulation-assignment key). No-op when neither
/// mode is active.
/// engine param id (also the modulation-assignment key). In OSC-copy mode a
/// click copies the param's OSC address. No-op when no mode is active.
#[allow(deprecated)] // egui::Popup builder migration is project-wide; tracked separately
#[allow(clippy::too_many_arguments)] // overlay needs full param context; bundling adds no clarity
pub fn apply_param_map_overlay(
Expand All @@ -1739,6 +1766,37 @@ pub fn apply_param_map_overlay(
) {
use crate::egui_theme::colors::*;

if engine.osc_copy_mode {
// The "<category>/<id>" path MIDI learn uses is also the param's OSC
// address under the server's base (see `param_osc_addresses`).
let address = format!("/rustjay/{midi_path}");
let copied = engine.osc_copied_param.as_deref() == Some(id);
let color = if copied {
accent_green() // just copied
} else {
egui::Color32::from_rgb(90, 160, 255) // copyable: blue
};
ui.painter().rect_stroke(
rect.expand(2.0),
0.0,
egui::Stroke::new(2.0_f32, color),
egui::StrokeKind::Outside,
);
let click_id = ui.make_persistent_id(("osc_copy_click", id));
let resp = ui
.interact(rect, click_id, egui::Sense::click())
.on_hover_text(if copied {
format!("Copied {address}")
} else {
format!("{address}\nClick to copy")
});
if resp.clicked() {
ui.ctx().copy_text(address);
engine.osc_copied_param = Some(id.to_string());
}
return;
}

if engine.midi_learn_mode {
let armed = engine.midi_learn_active
&& engine.midi_learning_param_name.as_deref() == Some(name);
Expand Down
Binary file modified crates/rustjay-gui/tests/snapshots/output_tab.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 modified crates/rustjay-gui/tests/snapshots/settings_tab.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 modified crates/rustjay-gui/tests/snapshots/sidebar_expanded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion guide/src/external-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,18 @@ ParameterDescriptor::float("flow_scale", ...)
.category(ParamCategory::Flux)
```

The address is `/rustjay/flux/flow_scale`. Send a float value in the parameter's `[min, max]` range.
The address is `/rustjay/flux/flow_scale`. Send a float from `0.0` to `1.0`; the engine scales it onto the parameter's `[min, max]` range. An integer argument is read MIDI-style, as `0`–`127`.

Parameters that appear while the app is running, such as those of an effect added to a layer, are addressable as soon as they exist.

The OSC tab in the desktop GUI (or a plain `cat /proc/<pid>/net/udp6` on the Pi) shows the active port.

### Copying an address

There is no need to work an address out by hand. Click **📋 OSC COPY** in the top bar and every mappable control gets a blue outline. Hover over a control to see its address, and click it to copy the address to the clipboard; the outline turns green to confirm. Click **OSC COPY** again to leave the mode.

OSC COPY is a map mode like **MIDI MAP** and **LFO MAP**, and only one of the three is on at a time. An app that draws its own controls takes part the same way it does for the other two: check `map_mode_active` and call `apply_param_map_overlay`.

### Changing the port

From the **Control** web panel, update the *Listen Port* field. The server restarts on the new port immediately. The new port is saved to config.
Expand Down
Loading