feat(braze): add Braze tempo-locked beating
Check and Windows preview / check (anvil) (push) Successful in 2m15s
Check and Windows preview / check (braze) (push) Successful in 2m26s
Check and Windows preview / check (crucible) (push) Successful in 1m52s
Check and Windows preview / check (knurl) (push) Successful in 1m42s
Check and Windows preview / check (lathe) (push) Successful in 1m44s
Check and Windows preview / check (patina) (push) Successful in 2m38s
Check and Windows preview / check (planish) (push) Successful in 1m29s
Check and Windows preview / check (rivet) (push) Successful in 1m39s
Check and Windows preview / check (temper) (push) Successful in 1m37s
Check and Windows preview / check (weld) (push) Canceled after 2s
Check and Windows preview / previews (push) Canceled after 0s
Check and Windows preview / windows (push) Canceled after 0s
Check and Windows preview / check (anvil) (push) Successful in 2m15s
Check and Windows preview / check (braze) (push) Successful in 2m26s
Check and Windows preview / check (crucible) (push) Successful in 1m52s
Check and Windows preview / check (knurl) (push) Successful in 1m42s
Check and Windows preview / check (lathe) (push) Successful in 1m44s
Check and Windows preview / check (patina) (push) Successful in 2m38s
Check and Windows preview / check (planish) (push) Successful in 1m29s
Check and Windows preview / check (rivet) (push) Successful in 1m39s
Check and Windows preview / check (temper) (push) Successful in 1m37s
Check and Windows preview / check (weld) (push) Canceled after 2s
Check and Windows preview / previews (push) Canceled after 0s
Check and Windows preview / windows (push) Canceled after 0s
Adds a detuned copy of the bass whose beating stays on the tempo grid on every note. The chosen harmonic k beats once per Rate note value, and harmonic n beats n/k times as fast, so every harmonic is on the grid. - The copy is read from a delay line whose delay falls one period of the tracked note per beat cycle (r = 1 + B/(k f0)) and jumps back exactly one period, crossfaded over 6 ms. On a periodic note the jump has no seam: the output matches the ideal sum within 0.003 on harmonics 1-4. - The delay follows the host's beat position, shifted by the lookahead, so beat peaks land on the grid; free-running when stopped. - Low cut: LR4 high-pass on the copy, the bass split by the same crossover, so the sub does not beat and keeps its level. - Depth, Width, Phase, Gate, Output, Snap, Bypass. Pitch from audio (about 67 ms lookahead) or MIDI. - Editor: one bar of the beat per harmonic with the grid and a playhead. - Catalog, workflows, editor-check, docs, signal chain and site copy.
This commit is contained in:
1 parent
e7f3346077
commit
330ec54150
28 files changed
+4565
-18
No files matched your search
@@ -0,0 +1,410 @@
|
||||
//! Braze editor, shared by the CLAP wrapper and the headless renderer.
|
||||
use braze_core::{
|
||||
cycles, envelope, AnalyzerFrame, Rate, Settings, Source, HARMONIC_MAX, LOW_CUT_MAX, LOW_CUT_OFF,
|
||||
};
|
||||
use common_ui::*;
|
||||
use egui::{self, Color32, FontId, Pos2, Rect, RichText, Sense, Stroke, Vec2};
|
||||
|
||||
pub use common_ui::style;
|
||||
pub const WIDTH: u32 = 980;
|
||||
pub const HEIGHT: u32 = 716;
|
||||
|
||||
pub struct State {
|
||||
pub analyzer: AnalyzerFrame,
|
||||
/// True while a pointer button is held, so knob drags become one host gesture.
|
||||
pub gesture_active: bool,
|
||||
pub help: String,
|
||||
}
|
||||
impl Default for State {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
analyzer: AnalyzerFrame::default(),
|
||||
gesture_active: false,
|
||||
help: DEFAULT_HELP.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
const DEFAULT_HELP: &str =
|
||||
"Put Braze on a reese or a layered bass. Pick the note value the beating should follow.";
|
||||
impl State {
|
||||
pub fn accept_frame(&mut self, frame: AnalyzerFrame) {
|
||||
self.analyzer = frame;
|
||||
}
|
||||
}
|
||||
fn hint(r: &egui::Response, state: &mut State, text: &str) {
|
||||
if r.hovered() || r.has_focus() {
|
||||
state.help = text.into();
|
||||
}
|
||||
}
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn knob(
|
||||
ui: &mut egui::Ui,
|
||||
state: &mut State,
|
||||
name: &str,
|
||||
value: &mut f32,
|
||||
range: std::ops::RangeInclusive<f32>,
|
||||
default: f32,
|
||||
unit: &str,
|
||||
size: f32,
|
||||
help: &str,
|
||||
) {
|
||||
ui.vertical_centered(|ui| {
|
||||
let r = rotary(ui, name, value, range, default, unit, size, ACCENT);
|
||||
hint(&r, state, help);
|
||||
});
|
||||
}
|
||||
|
||||
/// Note value of one beat of harmonic `n`, as a label: "1/8", "1/16T", "1/8D", or "1/40".
|
||||
pub fn beat_label(s: &Settings, n: u32) -> String {
|
||||
let quarters = s.rate.quarters() * s.harmonic as f64 / n as f64;
|
||||
let per_whole = 4. / quarters;
|
||||
for den in [1u32, 2, 4, 8, 16, 32, 64, 128] {
|
||||
let d = den as f64;
|
||||
if (per_whole - d).abs() < 1e-6 {
|
||||
return format!("1/{den}");
|
||||
}
|
||||
if (per_whole - d * 1.5).abs() < 1e-6 {
|
||||
return format!("1/{den}T");
|
||||
}
|
||||
if (per_whole - d / 1.5).abs() < 1e-6 {
|
||||
return format!("1/{den}D");
|
||||
}
|
||||
}
|
||||
if (per_whole - per_whole.round()).abs() < 1e-6 {
|
||||
format!("1/{}", per_whole.round())
|
||||
} else {
|
||||
format!("{:.2} beats", quarters)
|
||||
}
|
||||
}
|
||||
|
||||
/// One bar of the beat of harmonics 1–8, with the beat grid and a playhead.
|
||||
fn beats(ui: &mut egui::Ui, settings: &Settings, frame: &AnalyzerFrame, height: f32) {
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::new(ui.available_width(), height), Sense::hover());
|
||||
let p = ui.painter_at(rect);
|
||||
p.rect_filled(rect, 2., SCREEN);
|
||||
let label_w = 86.;
|
||||
let area = Rect::from_min_max(
|
||||
rect.left_top() + Vec2::new(label_w, 26.),
|
||||
rect.right_bottom() - Vec2::new(12., 10.),
|
||||
);
|
||||
p.text(
|
||||
rect.left_top() + Vec2::new(10., 8.),
|
||||
egui::Align2::LEFT_TOP,
|
||||
"BEAT PER HARMONIC · ONE BAR",
|
||||
FontId::proportional(11.),
|
||||
MUTED,
|
||||
);
|
||||
p.text(
|
||||
rect.right_top() + Vec2::new(-12., 8.),
|
||||
egui::Align2::RIGHT_TOP,
|
||||
if frame.synced {
|
||||
format!("{:.1} BPM · host transport", frame.tempo)
|
||||
} else {
|
||||
format!("{:.1} BPM · free running", frame.tempo)
|
||||
},
|
||||
FontId::proportional(11.),
|
||||
MUTED,
|
||||
);
|
||||
// Grid: every beat of the chosen rate, quarters brighter.
|
||||
let step = settings.rate.quarters();
|
||||
let mut q = 0f64;
|
||||
while q < 4. - 1e-9 {
|
||||
let x = area.left() + area.width() * (q / 4.) as f32;
|
||||
let on_quarter = (q - q.round()).abs() < 1e-6;
|
||||
let color = if on_quarter {
|
||||
Color32::from_rgb(58, 62, 70)
|
||||
} else {
|
||||
Color32::from_rgb(32, 35, 40)
|
||||
};
|
||||
p.line_segment(
|
||||
[Pos2::new(x, area.top()), Pos2::new(x, area.bottom())],
|
||||
Stroke::new(1.0_f32, color),
|
||||
);
|
||||
q += step;
|
||||
}
|
||||
let rows = HARMONIC_MAX as usize;
|
||||
let row_h = area.height() / rows as f32;
|
||||
let depth = settings.depth * 0.01;
|
||||
let points = 240;
|
||||
let bar_start = (frame.beats / 4.).floor() * 4.;
|
||||
for row in 0..rows {
|
||||
let n = row as u32 + 1;
|
||||
let top = area.top() + row_h * row as f32;
|
||||
let chosen = n == settings.harmonic;
|
||||
// Under the low cut the copy is removed: that harmonic keeps the bass's level.
|
||||
let cut = settings.low_cut >= LOW_CUT_OFF
|
||||
&& frame.hz > 0.
|
||||
&& n as f32 * frame.hz < settings.low_cut;
|
||||
let color = match (cut, chosen) {
|
||||
(true, _) => DIM,
|
||||
(false, true) => ACCENT,
|
||||
(false, false) => STEEL,
|
||||
};
|
||||
p.text(
|
||||
Pos2::new(rect.left() + 10., top + row_h * 0.5),
|
||||
egui::Align2::LEFT_CENTER,
|
||||
format!("H{n}"),
|
||||
FontId::proportional(11.),
|
||||
if chosen { ACCENT } else { MUTED },
|
||||
);
|
||||
p.text(
|
||||
Pos2::new(rect.left() + 36., top + row_h * 0.5),
|
||||
egui::Align2::LEFT_CENTER,
|
||||
if cut {
|
||||
"cut".to_string()
|
||||
} else {
|
||||
beat_label(settings, n)
|
||||
},
|
||||
FontId::monospace(11.),
|
||||
if chosen { TEXT } else { DIM },
|
||||
);
|
||||
let line: Vec<Pos2> = (0..=points)
|
||||
.map(|i| {
|
||||
let t = i as f64 / points as f64;
|
||||
let level = if cut {
|
||||
1.
|
||||
} else {
|
||||
envelope(settings, n, cycles(settings, bar_start + 4. * t, 0), depth)
|
||||
};
|
||||
// 0 at the bottom of the row, twice the bass (√2 after correction) at the top.
|
||||
let y = top + row_h * (0.92 - 0.8 * level / 2f32.sqrt());
|
||||
Pos2::new(area.left() + area.width() * t as f32, y)
|
||||
})
|
||||
.collect();
|
||||
p.add(egui::Shape::line(
|
||||
line,
|
||||
Stroke::new(if chosen { 2.0_f32 } else { 1.2_f32 }, color),
|
||||
));
|
||||
}
|
||||
let head = area.left() + area.width() * ((frame.beats - bar_start) / 4.) as f32;
|
||||
p.line_segment(
|
||||
[Pos2::new(head, area.top()), Pos2::new(head, area.bottom())],
|
||||
Stroke::new(1.0_f32, Color32::from_rgba_unmultiplied(255, 255, 255, 90)),
|
||||
);
|
||||
p.rect_stroke(
|
||||
rect,
|
||||
2.,
|
||||
Stroke::new(1.0_f32, EDGE),
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn show(ui: &mut egui::Ui, settings: &mut Settings, state: &mut State) {
|
||||
backdrop(ui);
|
||||
state.help = DEFAULT_HELP.into();
|
||||
state.gesture_active = ui.input(|i| i.pointer.any_down());
|
||||
ui.add_space(2.);
|
||||
header(ui, "BRAZE", "TEMPO-LOCKED BEATING", |ui| {
|
||||
let r = ui
|
||||
.selectable_label(settings.bypass, RichText::new("BYPASS").size(13.))
|
||||
.on_hover_text("Crossfade to the delayed dry signal.");
|
||||
if r.clicked() {
|
||||
settings.bypass = !settings.bypass;
|
||||
}
|
||||
ui.separator();
|
||||
for (source, label) in [(Source::Midi, "MIDI"), (Source::Audio, "AUDIO")] {
|
||||
let r = ui.selectable_label(settings.source == source, RichText::new(label).size(13.));
|
||||
if r.clicked() {
|
||||
settings.source = source;
|
||||
}
|
||||
}
|
||||
caption(ui, "PITCH FROM");
|
||||
});
|
||||
ui.add_space(6.);
|
||||
let frame = state.analyzer;
|
||||
ui.horizontal_top(|ui| {
|
||||
panel(ui, |ui| {
|
||||
ui.set_width(240.);
|
||||
ui.set_min_height(TOP);
|
||||
ui.vertical(|ui| note_panel(ui, settings, &frame));
|
||||
});
|
||||
ui.add_space(4.);
|
||||
panel(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
beats(ui, settings, &frame, TOP);
|
||||
});
|
||||
});
|
||||
ui.add_space(6.);
|
||||
panel(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.vertical(|ui| controls(ui, settings, state));
|
||||
});
|
||||
ui.separator();
|
||||
ui.label(RichText::new(&state.help).color(MUTED));
|
||||
}
|
||||
const TOP: f32 = 300.;
|
||||
fn note_panel(ui: &mut egui::Ui, settings: &Settings, frame: &AnalyzerFrame) {
|
||||
caption(ui, "NOTE");
|
||||
let (name, hz) = match frame.note {
|
||||
Some(n) if frame.hz > 0. => (common_dsp::note_name(n), format!("{:.1} Hz", frame.hz)),
|
||||
_ => ("—".into(), "no note".into()),
|
||||
};
|
||||
ui.label(
|
||||
RichText::new(name)
|
||||
.font(FontId::new(54., egui::FontFamily::Name("medium".into())))
|
||||
.color(if frame.note.is_some() { TEXT } else { DIM }),
|
||||
);
|
||||
ui.label(RichText::new(hz).monospace().size(14.).color(MUTED));
|
||||
ui.add_space(14.);
|
||||
let beat_hz = frame.tempo / 60. / settings.rate.quarters();
|
||||
readout(
|
||||
ui,
|
||||
&format!("HARMONIC {} BEATS", settings.harmonic),
|
||||
format!("{:.2} Hz, every {}", beat_hz, settings.rate.label()),
|
||||
ACCENT,
|
||||
);
|
||||
if settings.low_cut >= LOW_CUT_OFF
|
||||
&& frame.hz > 0.
|
||||
&& settings.harmonic as f32 * frame.hz < settings.low_cut
|
||||
{
|
||||
ui.label(
|
||||
RichText::new("Under Low cut on this note: it does not beat. Pick a higher harmonic.")
|
||||
.size(12.)
|
||||
.color(ACCENT),
|
||||
);
|
||||
ui.add_space(6.);
|
||||
}
|
||||
let cents = 1200. * frame.ratio.max(1e-6).log2();
|
||||
readout(
|
||||
ui,
|
||||
"COPY DETUNE ON THIS NOTE",
|
||||
if frame.hz > 0. {
|
||||
format!("+{cents:.1} cents")
|
||||
} else {
|
||||
"waiting for a note".into()
|
||||
},
|
||||
TEXT,
|
||||
);
|
||||
ui.label(
|
||||
RichText::new(format!(
|
||||
"{:.0} ms lookahead · {}",
|
||||
frame.latency as f32 / frame.sample_rate * 1000.,
|
||||
match settings.source {
|
||||
Source::Audio => "detecting pitch",
|
||||
Source::Midi => "following MIDI notes",
|
||||
}
|
||||
))
|
||||
.size(12.)
|
||||
.color(MUTED),
|
||||
);
|
||||
}
|
||||
fn controls(ui: &mut egui::Ui, settings: &mut Settings, state: &mut State) {
|
||||
let d = Settings::default();
|
||||
ui.horizontal(|ui| {
|
||||
caption(ui, "RATE");
|
||||
ui.add_space(6.);
|
||||
for rate in Rate::ALL {
|
||||
let r =
|
||||
ui.selectable_label(settings.rate == rate, RichText::new(rate.label()).size(13.));
|
||||
if r.clicked() {
|
||||
settings.rate = rate;
|
||||
}
|
||||
hint(
|
||||
&r,
|
||||
state,
|
||||
"One beat cycle of the chosen harmonic lasts this note value, on every note.",
|
||||
);
|
||||
}
|
||||
ui.add_space(18.);
|
||||
caption(ui, "ON HARMONIC");
|
||||
ui.add_space(6.);
|
||||
for n in 1..=HARMONIC_MAX {
|
||||
let r = ui.selectable_label(
|
||||
settings.harmonic == n,
|
||||
RichText::new(format!("{n}")).size(13.),
|
||||
);
|
||||
if r.clicked() {
|
||||
settings.harmonic = n;
|
||||
}
|
||||
hint(
|
||||
&r,
|
||||
state,
|
||||
"This harmonic beats at Rate. Harmonic n beats n/this times as fast. \
|
||||
Pick the harmonic you hear the movement on.",
|
||||
);
|
||||
}
|
||||
});
|
||||
ui.add_space(8.);
|
||||
ui.separator();
|
||||
ui.columns(6, |c| {
|
||||
knob(
|
||||
&mut c[0],
|
||||
state,
|
||||
"Depth",
|
||||
&mut settings.depth,
|
||||
0. ..=100.,
|
||||
d.depth,
|
||||
" %",
|
||||
72.,
|
||||
"Level of the detuned copy. 100 % beats down to full nulls; 0 % is the dry bass.",
|
||||
);
|
||||
knob(
|
||||
&mut c[1],
|
||||
state,
|
||||
"Low cut",
|
||||
&mut settings.low_cut,
|
||||
0. ..=LOW_CUT_MAX,
|
||||
d.low_cut,
|
||||
" Hz",
|
||||
72.,
|
||||
"No copy below this frequency: the sub does not beat and keeps its level. \
|
||||
Under 20 Hz the cut is off.",
|
||||
);
|
||||
knob(
|
||||
&mut c[2],
|
||||
state,
|
||||
"Width",
|
||||
&mut settings.width,
|
||||
0. ..=100.,
|
||||
d.width,
|
||||
" %",
|
||||
72.,
|
||||
"Moves the right channel's beat against the left. 100 %: one side peaks while \
|
||||
the other nulls. Check the mono sum.",
|
||||
);
|
||||
knob(
|
||||
&mut c[3],
|
||||
state,
|
||||
"Phase",
|
||||
&mut settings.phase,
|
||||
0. ..=360.,
|
||||
d.phase,
|
||||
"°",
|
||||
72.,
|
||||
"Where the beat peaks. 0° puts the peak of the chosen harmonic on the beat.",
|
||||
);
|
||||
knob(
|
||||
&mut c[4],
|
||||
state,
|
||||
"Gate",
|
||||
&mut settings.gate,
|
||||
-60. ..=-20.,
|
||||
d.gate,
|
||||
" dB",
|
||||
72.,
|
||||
"Input level that counts as a note. Raise it if tails retrigger.",
|
||||
);
|
||||
knob(
|
||||
&mut c[5],
|
||||
state,
|
||||
"Output",
|
||||
&mut settings.output,
|
||||
-12. ..=12.,
|
||||
d.output,
|
||||
" dB",
|
||||
72.,
|
||||
"Output trim.",
|
||||
);
|
||||
});
|
||||
ui.add_space(4.);
|
||||
let r = ui.selectable_label(settings.snap, RichText::new("SNAP TO SEMITONE").size(13.));
|
||||
if r.clicked() {
|
||||
settings.snap = !settings.snap;
|
||||
}
|
||||
hint(
|
||||
&r,
|
||||
state,
|
||||
"Round the detected pitch. Off keeps the copy's jumps on the real period, which is \
|
||||
seamless on detuned patches.",
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user