1
0
Fork 0

Temporarily show this slider for a skewed int

This commit is contained in:
Robbert van der Helm 2022-02-09 11:51:53 +01:00
parent 9dfac991c8
commit 5dd3cab305

View file

@ -19,11 +19,11 @@ extern crate nih_plug;
use atomic_float::AtomicF32; use atomic_float::AtomicF32;
use nih_plug::{ use nih_plug::{
formatters, util, Buffer, BufferConfig, BusConfig, Editor, Plugin, ProcessContext, formatters, util, Buffer, BufferConfig, BusConfig, Editor, IntParam, Plugin, ProcessContext,
ProcessStatus, Vst3Plugin, ProcessStatus, Vst3Plugin,
}; };
use nih_plug::{FloatParam, Param, Params, Range, Smoother, SmoothingStyle}; use nih_plug::{FloatParam, Param, Params, Range, Smoother, SmoothingStyle};
use nih_plug_egui::{create_egui_editor, egui, EguiState}; use nih_plug_egui::{create_egui_editor, egui, widgets, EguiState};
use std::pin::Pin; use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
@ -46,6 +46,10 @@ struct Gain {
struct GainParams { struct GainParams {
#[id = "gain"] #[id = "gain"]
pub gain: FloatParam, pub gain: FloatParam,
// TODO: Remove this parameter when we're done implementing the widgets
#[id = "foobar"]
pub some_int: IntParam,
} }
impl Default for Gain { impl Default for Gain {
@ -76,6 +80,17 @@ impl Default for GainParams {
value_to_string: formatters::f32_rounded(2), value_to_string: formatters::f32_rounded(2),
string_to_value: None, string_to_value: None,
}, },
some_int: IntParam {
value: 3,
smoothed: Smoother::none(),
name: "Something",
range: Range::Skewed {
min: 0,
max: 3,
factor: Range::skew_factor(1.0),
},
..Default::default()
},
} }
} }
} }
@ -105,16 +120,18 @@ impl Plugin for Gain {
(), (),
move |egui_ctx, setter, _state| { move |egui_ctx, setter, _state| {
egui::CentralPanel::default().show(egui_ctx, |ui| { egui::CentralPanel::default().show(egui_ctx, |ui| {
ui.allocate_space(egui::Vec2::splat(3.0)); // This is a fancy widget that can get all the information it needs to properly
ui.label("Gain"); // display and modify the parameter from the parametr itself
// It's not yet fully implemented, as the text is missing.
ui.label("Gain (now linked to some random skewed int)");
ui.add(widgets::ParamSlider::for_param(&params.some_int, setter));
// TODO: Create a custom widget that can do all of the parameter handling and // This is a simple naieve version of a parameter slider that's not aware of how
// works with nonlinear ranges // the parmaeters work
ui.add( ui.add(
egui::widgets::Slider::from_get_set(-30.0..=30.0, |new_value| { egui::widgets::Slider::from_get_set(-30.0..=30.0, |new_value| {
match new_value { match new_value {
Some(new_value) => { Some(new_value) => {
// TODO: Gestures?
setter.begin_set_parameter(&params.gain); setter.begin_set_parameter(&params.gain);
setter.set_parameter(&params.gain, new_value as f32); setter.set_parameter(&params.gain, new_value as f32);
setter.end_set_parameter(&params.gain); setter.end_set_parameter(&params.gain);