diff --git a/gb-vst/Cargo.toml b/gb-vst/Cargo.toml index 481e0e4..acf14bc 100644 --- a/gb-vst/Cargo.toml +++ b/gb-vst/Cargo.toml @@ -7,8 +7,9 @@ edition = "2021" name = "vst" crate-type = ["cdylib", "rlib"] - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = [] +savestate = [] [dependencies] gb-emu-lib = { path = "../lib", features = ["async"] } diff --git a/gb-vst/src/lib.rs b/gb-vst/src/lib.rs index f82347b..e25a38d 100644 --- a/gb-vst/src/lib.rs +++ b/gb-vst/src/lib.rs @@ -1,27 +1,31 @@ use async_ringbuf::AsyncHeapConsumer; use futures::executor; use gb_emu_lib::{ - connect::{ - AudioOutput, CpuSaveState, DownsampleType, EmulatorMessage, JoypadButtons, RomFile, - SerialTarget, - }, + connect::{AudioOutput, DownsampleType, EmulatorMessage, JoypadButtons, RomFile, SerialTarget}, EmulatorCore, }; +use nih_plug::midi::MidiResult::Basic; use nih_plug::prelude::*; -use nih_plug::{midi::MidiResult::Basic, params::persist::PersistentField}; use std::sync::{ mpsc::{self, channel, Receiver, Sender}, Arc, Mutex, }; use ui::{Emulator, EmulatorRenderer}; +#[cfg(feature = "savestate")] +use gb_emu_lib::connect::CpuSaveState; +#[cfg(feature = "savestate")] +use nih_plug::params::persist::PersistentField; + mod ui; +#[cfg(feature = "savestate")] #[derive(Default)] struct SaveStateParam { state: Arc>>>, } +#[cfg(feature = "savestate")] impl PersistentField<'_, Option>> for SaveStateParam { fn set(&self, new_value: Option>) { *self.state.lock().unwrap() = new_value; @@ -37,6 +41,7 @@ impl PersistentField<'_, Option>> for SaveStateParam { #[derive(Params, Default)] struct EmuParams { + #[cfg(feature = "savestate")] #[persist = "save_state"] last_save_state: SaveStateParam, } @@ -252,6 +257,7 @@ impl Plugin for GameboyEmu { tx: None, }; + #[cfg(feature = "savestate")] let mut emulator_core = if let Some(state) = self.params.last_save_state.state.lock().unwrap().take() { @@ -264,6 +270,16 @@ impl Plugin for GameboyEmu { EmulatorCore::init(receiver, options, window, output, None) }; + #[cfg(not(feature = "savestate"))] + let mut emulator_core = { + let options = gb_emu_lib::Options::new(rom) + .with_bootrom(bootrom) + .with_serial_target(serial_target) + .force_no_save(); + + EmulatorCore::init(receiver, options, window, output, None) + }; + emulator_core.run_until_buffer_full(); self.vars = Some(EmuVars { @@ -292,6 +308,7 @@ impl Plugin for GameboyEmu { impl GameboyEmu { fn update_save_state(&mut self) { + #[cfg(feature = "savestate")] if let Some(ref mut vars) = self.vars { *self.params.last_save_state.state.lock().unwrap() = Some(vars.emulator_core.get_save_state());