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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pitch-detection = "0.3.0"
symphonia = { version = "0.6.1", features = ["aac", "alac", "flac", "isomp4", "mp3", "ogg", "vorbis", "wav"] }
maolan-baseview = { version = "0.1.1", features = ["canvas"] }
maolan-editor = { version = "0.1.3", default-features = false }
maolan-widgets = "0.1.2"
maolan-widgets = "0.1.3"
parking_lot = "0.13.0"
portable-atomic = { version = "1.15.0", features = ["float"] }
quick-xml = { version = "0.42.0", features = ["serialize"] }
Expand Down
24 changes: 11 additions & 13 deletions src/common/wavetable_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ pub const FACTORY_SIZE: usize = 2048;
/// Number of bundled factory wavetables. Param values `0..FACTORY_COUNT`
/// select factory tables, `FACTORY_COUNT` selects the custom file loaded
/// through the GUI.
pub const FACTORY_COUNT: usize = 12;
pub const FACTORY_COUNT: usize = 11;

/// Entry label selecting the per-patch custom file instead of a factory table.
pub const CUSTOM_WAVETABLE_LABEL: &str = "Custom file...";

pub const FACTORY_NAMES: [&str; FACTORY_COUNT] = [
"Sine",
"Triangle",
"Square",
"Sawtooth",
Expand Down Expand Up @@ -60,19 +59,18 @@ fn additive(size: usize, max_harmonic: usize, mut amp: impl FnMut(usize) -> f32)
fn build_factory_table(index: usize) -> Wavetable {
let size = FACTORY_SIZE;
let frames = match index {
0 => additive(size, 1, |_| 1.0),
1 => additive(size, 64, |h| {
0 => additive(size, 64, |h| {
if h % 2 == 1 {
1.0 / (h * h) as f32
} else {
0.0
}
}),
2 => additive(size, 64, |h| if h % 2 == 1 { 1.0 / h as f32 } else { 0.0 }),
3 => additive(size, 96, |h| 1.0 / h as f32),
4 => additive(size, 32, |h| 1.0 / (h * h) as f32),
5 => additive(size, 192, |h| 1.0 / h as f32),
6 => additive(size, 64, |h| {
1 => additive(size, 64, |h| if h % 2 == 1 { 1.0 / h as f32 } else { 0.0 }),
2 => additive(size, 96, |h| 1.0 / h as f32),
3 => additive(size, 32, |h| 1.0 / (h * h) as f32),
4 => additive(size, 192, |h| 1.0 / h as f32),
5 => additive(size, 64, |h| {
// 25% pulse via odd-harmonic Lanczos-ish sigma approximation.
let sigma = 0.25f32;
if h % 2 == 1 {
Expand All @@ -82,8 +80,8 @@ fn build_factory_table(index: usize) -> Wavetable {
0.0
}
}),
7 => additive(size, 8, |h| 1.0 / h as f32),
8 => additive(size, 12, |h| match h {
6 => additive(size, 8, |h| 1.0 / h as f32),
7 => additive(size, 12, |h| match h {
1 => 1.0,
2 => 0.6,
3 => 0.35,
Expand All @@ -92,8 +90,8 @@ fn build_factory_table(index: usize) -> Wavetable {
6 => 0.08,
_ => 0.05,
}),
9 => additive(size, 48, |h| 1.0 / (h as f32).powi(3).sqrt()),
10 => {
8 => additive(size, 48, |h| 1.0 / (h as f32).powi(3).sqrt()),
9 => {
// Two slightly detuned saws plus a touch of noise for a "dirty" table.
let mut table = additive(size, 48, |h| 1.0 / h as f32);
for (i, slot) in table.iter_mut().enumerate() {
Expand Down
64 changes: 10 additions & 54 deletions src/synth/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::{
lfo_assignment::{LfoAssignmentConfig, LfoAssignmentState, ModRouteParamIds},
preset::{self, PresetProvider, PresetUi},
wavetable::Wavetable,
wavetable_factory::{CUSTOM_WAVETABLE_LABEL, FACTORY_COUNT, FACTORY_NAMES},
wavetable_factory::FACTORY_COUNT,
},
synth::{
dsp::{FilterRouting, LfoShape, ModTarget, OscType},
Expand Down Expand Up @@ -655,49 +655,6 @@ fn waveform_options(osc_type: OscType) -> Vec<&'static str> {
}
}

/// Wavetable selector for the Wavetable and Window oscillator types. Renders
/// as a zero-width empty container for other oscillator types so the osc
/// panel layout stays stable.
fn wavetable_dropdown<'a>(state: &'a State, osc_index: usize) -> Element<'a, Message> {
let (type_id, wt_id) = match osc_index {
0 => (ParamId::Osc1Type, ParamId::Osc1Wavetable),
1 => (ParamId::Osc2Type, ParamId::Osc2Wavetable),
_ => (ParamId::Osc3Type, ParamId::Osc3Wavetable),
};
let osc_type = OscType::from_u8(state.shared.params.get(type_id) as u8);
if osc_type != OscType::Wavetable && osc_type != OscType::Window {
return container(text("")).width(Length::Fixed(0.0)).into();
}

let value = state.shared.params.get(wt_id) as usize;
let selected: &'static str = if value >= FACTORY_COUNT {
CUSTOM_WAVETABLE_LABEL
} else {
FACTORY_NAMES[value]
};
let options: Vec<&'static str> = FACTORY_NAMES
.iter()
.copied()
.chain(std::iter::once(CUSTOM_WAVETABLE_LABEL))
.collect();
let dropdown = maolan_baseview::iced::widget::pick_list(options, Some(selected), move |name| {
match FACTORY_NAMES.iter().position(|&n| n == name) {
Some(index) => Message::SetParam(wt_id, index as f32),
None => Message::PickWavetableFile(osc_index),
}
})
.placeholder("Wavetable")
.width(Length::Fixed(104.0));

container(
column![text("Wavetable").size(11), dropdown]
.spacing(2)
.align_x(Alignment::Center),
)
.width(Length::Fixed(110.0))
.into()
}

const FILTER_TYPES: &[FilterType] = &[
FilterType::Off,
FilterType::Lowpass,
Expand Down Expand Up @@ -792,7 +749,6 @@ fn lfo_shape_dropdown<'a>(id: ParamId, state: &'a State) -> Element<'a, Message>
fn named_enum_dropdown<'a>(
id: ParamId,
options: &'static [&'static str],
width: f32,
state: &'a State,
) -> Element<'a, Message> {
let index = (state.shared.params.get(id) as usize).min(options.len() - 1);
Expand All @@ -808,8 +764,8 @@ fn named_enum_dropdown<'a>(
Message::SetParam(id, value as f32)
},
)
.width(Length::Fixed(width));
container(dropdown).width(Length::Fixed(width + 6.0)).into()
.width(Length::Shrink);
container(dropdown).width(Length::Shrink).into()
}

const OSC_FM_MODE_NAMES: &[&str] = &[
Expand Down Expand Up @@ -1032,10 +988,13 @@ fn lfo_tab_button(label: &'static str, index: usize, state: &State) -> Element<'
}

fn view(state: &State) -> Element<'_, Message> {
let fm_panel = panel_no_title(knob_row(vec![
named_enum_dropdown(ParamId::OscFmMode, OSC_FM_MODE_NAMES, 112.0, state),
param_control(ParamId::OscFmDepth, "Depth", state),
]));
let fm_panel = panel(
"FM Mode",
knob_row(vec![
named_enum_dropdown(ParamId::OscFmMode, OSC_FM_MODE_NAMES, state),
param_control(ParamId::OscFmDepth, "Depth", state),
]),
);

let filter_routing = column![
filter_routing_dropdown(state),
Expand Down Expand Up @@ -1076,7 +1035,6 @@ fn view(state: &State) -> Element<'_, Message> {

let osc1 = column![
knob_row(vec![
wavetable_dropdown(state, 0),
param_control(ParamId::Osc1Octave, "Oct", state),
param_control(ParamId::Osc1Semitone, "Semi", state),
param_control(ParamId::Osc1Fine, "Fine", state),
Expand All @@ -1095,7 +1053,6 @@ fn view(state: &State) -> Element<'_, Message> {

let osc2 = column![
knob_row(vec![
wavetable_dropdown(state, 1),
param_control(ParamId::Osc2Octave, "Oct", state),
param_control(ParamId::Osc2Semitone, "Semi", state),
param_control(ParamId::Osc2Fine, "Fine", state),
Expand All @@ -1114,7 +1071,6 @@ fn view(state: &State) -> Element<'_, Message> {

let osc3 = column![
knob_row(vec![
wavetable_dropdown(state, 2),
param_control(ParamId::Osc3Octave, "Oct", state),
param_control(ParamId::Osc3Semitone, "Semi", state),
param_control(ParamId::Osc3Fine, "Fine", state),
Expand Down
Loading
Loading