use crate::ReaperStringArg;
use derive_more::*;
use std::borrow::Cow;
use std::ffi::CStr;
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default, Display)]
pub struct CommandId(pub(crate) u32);
impl CommandId {
pub fn new(value: u32) -> CommandId {
assert_ne!(value, 0, "0 is not a valid command ID");
CommandId(value)
}
pub const unsafe fn new_unchecked(value: u32) -> CommandId {
CommandId(value)
}
pub const fn get(&self) -> u32 {
self.0
}
pub fn to_raw(&self) -> i32 {
self.0 as i32
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default, Display)]
pub struct SectionId(pub(crate) u32);
impl SectionId {
pub fn new(number: u32) -> SectionId {
SectionId(number)
}
pub const fn get(&self) -> u32 {
self.0
}
pub fn to_raw(&self) -> i32 {
self.0 as i32
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default, Display)]
pub struct MidiInputDeviceId(pub(crate) u8);
impl MidiInputDeviceId {
pub fn new(value: u8) -> MidiInputDeviceId {
assert!(value < 63, "MIDI input device IDs must be <= 62");
MidiInputDeviceId(value)
}
pub const fn get(&self) -> u8 {
self.0
}
pub fn to_raw(&self) -> i32 {
self.0 as i32
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default, Display)]
pub struct MidiOutputDeviceId(pub(crate) u8);
impl MidiOutputDeviceId {
pub fn new(number: u8) -> MidiOutputDeviceId {
MidiOutputDeviceId(number)
}
pub const fn get(&self) -> u8 {
self.0
}
pub fn to_raw(&self) -> i32 {
self.0 as i32
}
}
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug, Default, Display)]
pub struct ReaperNormalizedFxParamValue(pub(crate) f64);
impl ReaperNormalizedFxParamValue {
pub const MIN: ReaperNormalizedFxParamValue = ReaperNormalizedFxParamValue(0.0);
pub fn new(value: f64) -> ReaperNormalizedFxParamValue {
assert!(ReaperNormalizedFxParamValue::MIN.get() <= value);
ReaperNormalizedFxParamValue(value)
}
pub const fn get(&self) -> f64 {
self.0
}
}
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug, Default, Display)]
pub struct Bpm(pub(crate) f64);
impl Bpm {
pub const MIN: Bpm = Bpm(1.0);
pub const MAX: Bpm = Bpm(960.0);
pub fn new(value: f64) -> Bpm {
assert!(Bpm::MIN.get() <= value && value <= Bpm::MAX.get());
Bpm(value)
}
pub const fn get(&self) -> f64 {
self.0
}
}
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug, Default, Display)]
pub struct PlaybackSpeedFactor(pub(crate) f64);
impl PlaybackSpeedFactor {
pub const MIN: PlaybackSpeedFactor = PlaybackSpeedFactor(0.25);
pub const MAX: PlaybackSpeedFactor = PlaybackSpeedFactor(4.0);
pub fn new(value: f64) -> PlaybackSpeedFactor {
assert!(PlaybackSpeedFactor::MIN.get() <= value && value <= PlaybackSpeedFactor::MAX.get());
PlaybackSpeedFactor(value)
}
pub const fn get(&self) -> f64 {
self.0
}
}
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug, Default, Display)]
pub struct Hz(pub(crate) f64);
impl Hz {
pub fn new(value: f64) -> Hz {
assert!(0.0 < value);
Hz(value)
}
pub unsafe fn new_unchecked(value: f64) -> Hz {
Hz(value)
}
pub const fn get(&self) -> f64 {
self.0
}
}
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug, Default, Display)]
pub struct Db(pub(crate) f64);
impl Db {
pub const MIN: Db = Db::MINUS_INF;
pub const NAN: ReaperVolumeValue = ReaperVolumeValue(f64::NAN);
pub const MINUS_INF: Db = Db(-1000.0);
pub const MINUS_150_DB: Db = Db(-150.0);
pub const ZERO_DB: Db = Db(0.0);
pub const TWELVE_DB: Db = Db(12.0);
pub fn new(value: f64) -> Db {
assert!(Db::MIN.get() <= value || value.is_nan());
Db(value)
}
pub const fn get(&self) -> f64 {
self.0
}
}
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug, Default, Display)]
pub struct VolumeSliderValue(pub(crate) f64);
impl VolumeSliderValue {
pub const MIN: VolumeSliderValue = VolumeSliderValue::MINUS_INF_DB;
pub const NAN: ReaperVolumeValue = ReaperVolumeValue(f64::NAN);
pub const MINUS_INF_DB: VolumeSliderValue = VolumeSliderValue(0.0);
pub const MINUS_150_DB: VolumeSliderValue = VolumeSliderValue(2.5138729793972);
pub const ZERO_DB: VolumeSliderValue = VolumeSliderValue(716.0);
pub const TWELVE_DB: VolumeSliderValue = VolumeSliderValue(1000.0);
pub fn new(value: f64) -> VolumeSliderValue {
assert!(VolumeSliderValue::MIN.get() <= value || value.is_nan());
VolumeSliderValue(value)
}
pub const fn get(&self) -> f64 {
self.0
}
}
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug, Default, Display)]
pub struct ReaperVolumeValue(pub(crate) f64);
impl ReaperVolumeValue {
pub const MIN: ReaperVolumeValue = ReaperVolumeValue(0.0);
pub const NAN: ReaperVolumeValue = ReaperVolumeValue(f64::NAN);
pub const MINUS_150_DB: ReaperVolumeValue = ReaperVolumeValue(3.1622776601684e-008);
pub const ZERO_DB: ReaperVolumeValue = ReaperVolumeValue(1.0);
pub const TWELVE_DB: ReaperVolumeValue = ReaperVolumeValue(3.981071705535);
pub fn new(value: f64) -> ReaperVolumeValue {
assert!(ReaperVolumeValue::MIN.get() <= value || value.is_nan());
ReaperVolumeValue(value)
}
pub const fn get(&self) -> f64 {
self.0
}
}
#[doc(hidden)]
impl From<ReaperVolumeValue> for f64 {
fn from(v: ReaperVolumeValue) -> Self {
v.0
}
}
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug, Default, Display)]
pub struct ReaperPanValue(pub(crate) f64);
impl ReaperPanValue {
pub const MIN: ReaperPanValue = ReaperPanValue::LEFT;
pub const LEFT: ReaperPanValue = ReaperPanValue(-1.0);
pub const CENTER: ReaperPanValue = ReaperPanValue(0.0);
pub const RIGHT: ReaperPanValue = ReaperPanValue(1.0);
pub const MAX: ReaperPanValue = ReaperPanValue::RIGHT;
pub fn new(value: f64) -> ReaperPanValue {
assert!(ReaperPanValue::MIN.get() <= value && value <= ReaperPanValue::MAX.get());
ReaperPanValue(value)
}
pub const fn get(&self) -> f64 {
self.0
}
}
#[doc(hidden)]
impl From<ReaperPanValue> for f64 {
fn from(v: ReaperPanValue) -> Self {
v.0
}
}
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
pub struct ReaperVersion<'a>(Cow<'a, CStr>);
impl<'a> ReaperVersion<'a> {
pub fn new(expression: impl Into<ReaperStringArg<'a>>) -> ReaperVersion<'a> {
ReaperVersion(expression.into().into_inner())
}
pub fn into_inner(self) -> Cow<'a, CStr> {
self.0
}
}