1
0
Fork 0

Pass sample rate to Diopser's editor

This commit is contained in:
Robbert van der Helm 2022-11-18 00:38:54 +01:00
parent ba9b1f9e94
commit 3e935dc5ad
2 changed files with 17 additions and 19 deletions

View file

@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use atomic_float::AtomicF32;
use nih_plug::nih_debug_assert_failure; use nih_plug::nih_debug_assert_failure;
use nih_plug::prelude::{Editor, Plugin}; use nih_plug::prelude::{Editor, Plugin};
use nih_plug_vizia::vizia::prelude::*; use nih_plug_vizia::vizia::prelude::*;
@ -37,15 +38,17 @@ const SPECTRUM_ANALYZER_HEIGHT: f32 = 260.0;
const DARK_GRAY: Color = Color::rgb(0xc4, 0xc4, 0xc4); const DARK_GRAY: Color = Color::rgb(0xc4, 0xc4, 0xc4);
const DARKER_GRAY: Color = Color::rgb(0x69, 0x69, 0x69); const DARKER_GRAY: Color = Color::rgb(0x69, 0x69, 0x69);
#[derive(Lens)] #[derive(Lens, Clone)]
struct Data { pub(crate) struct Data {
params: Arc<DiopserParams>, pub(crate) params: Arc<DiopserParams>,
spectrum: Arc<Mutex<SpectrumOutput>>, /// The plugin's current sample rate.
pub(crate) sample_rate: Arc<AtomicF32>,
pub(crate) spectrum: Arc<Mutex<SpectrumOutput>>,
/// Whether the safe mode button is enabled. The number of filter stages is capped at 40 while /// Whether the safe mode button is enabled. The number of filter stages is capped at 40 while
/// this is active. /// this is active.
/// TODO: Actually hook up safe mode /// TODO: Actually hook up safe mode
safe_mode: Arc<AtomicBool>, pub(crate) safe_mode: Arc<AtomicBool>,
} }
impl Model for Data {} impl Model for Data {}
@ -55,24 +58,14 @@ pub(crate) fn default_state() -> Arc<ViziaState> {
ViziaState::from_size(EDITOR_WIDTH, EDITOR_HEIGHT) ViziaState::from_size(EDITOR_WIDTH, EDITOR_HEIGHT)
} }
pub(crate) fn create( pub(crate) fn create(editor_data: Data, editor_state: Arc<ViziaState>) -> Option<Box<dyn Editor>> {
params: Arc<DiopserParams>,
spectrum: Arc<Mutex<SpectrumOutput>>,
editor_state: Arc<ViziaState>,
) -> Option<Box<dyn Editor>> {
create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| { create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
assets::register_noto_sans_light(cx); assets::register_noto_sans_light(cx);
assets::register_noto_sans_thin(cx); assets::register_noto_sans_thin(cx);
cx.add_theme(include_str!("editor/theme.css")); cx.add_theme(include_str!("editor/theme.css"));
Data { editor_data.clone().build(cx);
params: params.clone(),
spectrum: spectrum.clone(),
safe_mode: params.safe_mode.clone(),
}
.build(cx);
ResizeHandle::new(cx); ResizeHandle::new(cx);

View file

@ -299,8 +299,13 @@ impl Plugin for Diopser {
fn editor(&self, _async_executor: AsyncExecutor<Self>) -> Option<Box<dyn Editor>> { fn editor(&self, _async_executor: AsyncExecutor<Self>) -> Option<Box<dyn Editor>> {
editor::create( editor::create(
self.params.clone(), editor::Data {
self.spectrum_output.clone(), params: self.params.clone(),
sample_rate: self.sample_rate.clone(),
spectrum: self.spectrum_output.clone(),
safe_mode: self.params.safe_mode.clone(),
},
self.params.editor_state.clone(), self.params.editor_state.clone(),
) )
} }