use crate::raw::preview_register_t;
use crate::{
register_plugin_destroy_hook, PluginContext, Reaper,
ReaperFunctionPointers,
};
static mut INSTANCE: Option<Reaper> = None;
impl Reaper {
pub fn make_available_globally(functions: Reaper) {
static INIT_INSTANCE: std::sync::Once = std::sync::Once::new();
unsafe {
INIT_INSTANCE.call_once(|| {
INSTANCE = Some(functions);
register_plugin_destroy_hook(|| INSTANCE = None);
});
}
}
pub fn get() -> &'static Reaper {
unsafe {
INSTANCE.as_ref().expect(
"call `make_available_globally()` before using `get()`",
)
}
}
pub fn pointers(&self) -> &ReaperFunctionPointers {
&self.pointers
}
pub fn plugin_context(&self) -> &PluginContext {
self.plugin_context
.as_ref()
.expect("plug-in context not available on demo instances")
}
}
impl std::fmt::Debug for ReaperFunctionPointers {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ReaperFunctionPointers")
.field("loaded_count", &self.loaded_count)
.field("total_count", &Self::TOTAL_COUNT)
.finish()
}
}
impl std::fmt::Debug for preview_register_t {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("preview_register_t").finish()
}
}