Skip to content

Commit

Permalink
Fix everything
Browse files Browse the repository at this point in the history
  • Loading branch information
prokopyl committed Sep 11, 2021
1 parent 859ed73 commit 89dc9b7
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 87 deletions.
6 changes: 6 additions & 0 deletions atom/src/atoms/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ impl<A: ScalarAtom> Atom for A {
}
}

impl<A: ScalarAtom> BackAsSpace for A {
fn back_as_space<'a>(handle: <Self::ReadHandle as AtomHandle<'a>>::Handle) -> &'a [u8] {
AlignedSpace::from_slice(::core::slice::from_ref(handle)).as_bytes()
}
}

/// Macro to atomate the definition of scalar atoms.
macro_rules! make_scalar_atom {
($atom:ty, $internal:ty, $uri:expr, $urid:expr) => {
Expand Down
4 changes: 4 additions & 0 deletions atom/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ pub trait Atom: UriBound {
fn init(writer: AtomSpaceWriter) -> Option<<Self::WriteHandle as AtomHandle>::Handle>;
}

pub trait BackAsSpace: Atom {
fn back_as_space<'a>(handle: <Self::ReadHandle as AtomHandle<'a>>::Handle) -> &'a [u8];
}

/// An atom of yet unknown type.
///
/// This is used by reading handles that have to return a reference to an atom, but can not check it's type. This struct contains a `Space` containing the header and the body of the atom and can identify/read the atom from it.
Expand Down
4 changes: 3 additions & 1 deletion buf-size/src/buffer_sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ impl BufferSizes {
options: &OptionsList,
urids: &BufferSizesURIDCollection,
) -> Self {
todo!()
/*
BufferSizes {
min_block_length: options
.read(urids.min_block_length, urids.atom_int, ())
Expand All @@ -46,6 +48,6 @@ impl BufferSizes {
sequence_size: options
.read(urids.sequence_size, urids.atom_int, ())
.map(|x| x.get()),
}
}*/
}
}
12 changes: 7 additions & 5 deletions buf-size/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use lv2_atom::Atom;
use lv2_atom::{Atom, AtomHandle};
use urid::UriBound;

/// A simple macro to automate the definition of the u32 options available in this module
Expand All @@ -18,17 +18,19 @@ macro_rules! make_option {
}

impl lv2_options::OptionType for $name {
type AtomType = lv2_atom::scalar::Int;
type AtomType = lv2_atom::atoms::scalar::Int;

#[inline]
fn from_option_value<'a>(
value: <lv2_atom::scalar::Int as Atom<'a, 'a>>::ReadHandle,
fn from_option_value(
value: <<lv2_atom::atoms::scalar::Int as Atom>::ReadHandle as AtomHandle>::Handle,
) -> Option<Self> {
Some(Self((*value)))
}

#[inline]
fn as_option_value<'a>(&'a self) -> <lv2_atom::scalar::Int as Atom<'a, 'a>>::ReadHandle {
fn as_option_value<'a>(
&'a self,
) -> <<lv2_atom::atoms::scalar::Int as Atom>::ReadHandle as AtomHandle>::Handle {
&self.0
}
}
Expand Down
67 changes: 45 additions & 22 deletions options/src/collection.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
use urid::{URIDCollection, Map};
use crate::request::OptionRequestList;
use crate::{OptionsError, OptionValue};
use crate::list::OptionsList;
use crate::option::request::OptionRequest;
use crate::request::OptionRequestList;
use crate::{OptionValue, OptionsError};
use urid::{Map, URIDCollection};

pub trait OptionsCollection: Sized {
type Serializer;

#[inline]
fn new_serializer<'a, M: Map + ?Sized>(map: &M) -> Option<OptionsSerializer<Self>>
where Self::Serializer: OptionsSerializationContext<'a, Self> { // FIXME
Some(OptionsSerializer { inner: Self::Serializer::from_map(map)? })
where
Self::Serializer: OptionsSerializationContext<'a, Self>,
{
// FIXME
Some(OptionsSerializer {
inner: Self::Serializer::from_map(map)?,
})
}
}

#[doc(hidden)]
pub mod implementation {
use crate::{OptionType, OptionsError, OptionValue};
use std::marker::PhantomData;
use urid::{URID, URIDCollection, Map};
use crate::collection::{OptionsSerializationContext, OptionsCollection};
use crate::collection::{OptionsCollection, OptionsSerializationContext};
use crate::option::request::OptionRequest;
use crate::{OptionType, OptionValue, OptionsError};
use lv2_atom::atoms::scalar::ScalarAtom;
use lv2_atom::{Atom, BackAsSpace};
use lv2_atom::scalar::ScalarAtom;
use std::marker::PhantomData;
use urid::{Map, URIDCollection, URID};

pub struct OptionTypeSerializationContext<O: OptionType> {
option_urid: URID<O>,
option_type_atom_urid: URID<O::AtomType>
option_type_atom_urid: URID<O::AtomType>,
}

impl<'a, O: OptionType> OptionsCollection for O
where <O as OptionType>::AtomType: BackAsSpace<'a>,
<<O as OptionType>::AtomType as Atom<'a, 'a>>::ReadParameter: Default {
where
<O as OptionType>::AtomType: BackAsSpace,
{
type Serializer = OptionTypeSerializationContext<O>;
}

Expand All @@ -46,25 +52,34 @@ pub mod implementation {
}

impl<'a, O: OptionType> OptionsSerializationContext<'a, O> for OptionTypeSerializationContext<O>
where <O as OptionType>::AtomType: BackAsSpace<'a>,
<<O as OptionType>::AtomType as Atom<'a, 'a>>::ReadParameter: Default {
where
<O as OptionType>::AtomType: BackAsSpace,
{
#[inline]
fn deserialize_new(&self, option: &'a OptionValue) -> Option<O> {
option.read(self.option_urid, self.option_type_atom_urid, Default::default())
option.read(self.option_urid, self.option_type_atom_urid)
}

fn deserialize_to(&self, options: &mut O, option: &OptionValue) -> Result<(), OptionsError> {
fn deserialize_to(
&self,
options: &mut O,
option: &OptionValue,
) -> Result<(), OptionsError> {
todo!()
}

fn respond_to_request<'r>(&self, options: &'r O, requests: &'r mut OptionRequest) -> Result<(), OptionsError> {
fn respond_to_request<'r>(
&self,
options: &'r O,
requests: &'r mut OptionRequest,
) -> Result<(), OptionsError> {
todo!()
}
}
}

pub struct OptionsSerializer<T: OptionsCollection> {
inner: T::Serializer
inner: T::Serializer,
}

impl<T: OptionsCollection> OptionsSerializer<T> {
Expand All @@ -76,7 +91,11 @@ impl<T: OptionsCollection> OptionsSerializer<T> {
todo!()
}

pub fn respond_to_requests<'a>(&self, options: &T, requests: &mut OptionRequestList) -> Result<(), OptionsError> {
pub fn respond_to_requests<'a>(
&self,
options: &T,
requests: &mut OptionRequestList,
) -> Result<(), OptionsError> {
todo!()
}
}
Expand All @@ -86,5 +105,9 @@ pub trait OptionsSerializationContext<'a, T: OptionsCollection>: URIDCollection

fn deserialize_to(&self, options: &mut T, option: &OptionValue) -> Result<(), OptionsError>;

fn respond_to_request<'r>(&self, options: &'r T, request: &'r mut OptionRequest) -> Result<(), OptionsError>;
}
fn respond_to_request<'r>(
&self,
options: &'r T,
request: &'r mut OptionRequest,
) -> Result<(), OptionsError>;
}
2 changes: 1 addition & 1 deletion options/src/extensions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Contains the [`OptionsInterface`](crate::extensions::OptionsInterface) extension interface.
use crate::features::OptionsList;
use crate::option::request::OptionRequestList;
use crate::OptionsError;
use lv2_core::feature::Feature;
use lv2_core::plugin::PluginInstance;
Expand All @@ -9,7 +10,6 @@ use std::ffi::c_void;
use std::marker::PhantomData;
use std::panic::AssertUnwindSafe;
use urid::UriBound;
use crate::option::request::OptionRequestList;

/// An interface to allow dynamically setting options from the host.
///
Expand Down
10 changes: 5 additions & 5 deletions options/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
//! See the [LV2 Options documentation](http://lv2plug.in/ns/ext/options) for more information.
pub use option::error::OptionsError;
pub use option::OptionType;
pub use option::request;
pub use option::subject::Subject;
pub use option::value::OptionValue;
pub use option::OptionType;

pub mod collection;
pub mod extensions;
mod option;
pub mod list;
pub mod collection;
mod option;

/// Contains the [`OptionsList`](features::OptionsList) feature.
pub mod features {
Expand All @@ -34,8 +34,8 @@ pub mod features {

/// Prelude of `lv2_options` for wildcard usage.
pub mod prelude {
pub use crate::extensions::{OptionsDescriptor, OptionsInterface};
pub use crate::list::OptionsList;
pub use crate::OptionsError;
pub use crate::Subject;
pub use crate::extensions::{OptionsDescriptor, OptionsInterface};
}
}
6 changes: 4 additions & 2 deletions options/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ impl<'f> OptionsList<'f> {
/// Returns an iterator over the slice.
#[inline]
pub fn iter(&self) -> OptionsListIter<'f> {
OptionsListIter { current: self.options_list }
OptionsListIter {
current: self.options_list,
}
}
}

Expand Down Expand Up @@ -45,7 +47,7 @@ impl<'a> IntoIterator for &'a OptionsList<'a> {
}

pub struct OptionsListIter<'a> {
current: &'a lv2_sys::LV2_Options_Option
current: &'a lv2_sys::LV2_Options_Option,
}

impl<'a> Iterator for OptionsListIter<'a> {
Expand Down
14 changes: 9 additions & 5 deletions options/src/option.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use lv2_atom::Atom;
use lv2_atom::{Atom, AtomHandle};
use urid::UriBound;

pub mod error;
pub mod request;
pub mod subject;
pub mod value;
pub mod request;

/// A trait representing an LV2 Option type.
///
Expand Down Expand Up @@ -32,17 +32,21 @@ pub mod request;
/// }
/// ```
pub trait OptionType: UriBound + Sized {
type AtomType: UriBound;
type AtomType: Atom;

/// Creates a new instance of this Option type from a given atom value.
///
/// This method may return `None` if the Atom's value is invalid for this option type.
///
/// This method is used to store option data when received by the host.
fn from_option_value<'a>(value: <Self::AtomType as Atom<'a, 'a>>::ReadHandle) -> Option<Self> where Self::AtomType: Atom<'a, 'a>;
fn from_option_value(
value: <<<Self as OptionType>::AtomType as Atom>::ReadHandle as AtomHandle>::Handle,
) -> Option<Self>;

/// Returns this Option's value as a reference to its Atom type.
///
/// This method is used to send the option's value to the host when it is requested.
fn as_option_value<'a>(&'a self) -> <Self::AtomType as Atom<'a, 'a>>::ReadHandle where Self::AtomType: Atom<'a, 'a>;
fn as_option_value(
&self,
) -> <<<Self as OptionType>::AtomType as Atom>::ReadHandle as AtomHandle>::Handle;
}
10 changes: 7 additions & 3 deletions options/src/option/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ impl OptionsError {
pub(crate) fn result_into_raw(value: Result<(), OptionsError>) -> lv2_sys::LV2_Options_Status {
match value {
Ok(()) => lv2_sys::LV2_Options_Status_LV2_OPTIONS_SUCCESS,
Err(OptionsError::BadSubject) => lv2_sys::LV2_Options_Status_LV2_OPTIONS_ERR_BAD_SUBJECT,
Err(OptionsError::BadSubject) => {
lv2_sys::LV2_Options_Status_LV2_OPTIONS_ERR_BAD_SUBJECT
}
Err(OptionsError::BadKey) => lv2_sys::LV2_Options_Status_LV2_OPTIONS_ERR_BAD_KEY,
Err(OptionsError::BadValue) => lv2_sys::LV2_Options_Status_LV2_OPTIONS_ERR_BAD_VALUE,
Err(_) => lv2_sys::LV2_Options_Status_LV2_OPTIONS_ERR_UNKNOWN,
Expand All @@ -30,7 +32,9 @@ impl OptionsError {
pub(crate) fn from_raw(status: lv2_sys::LV2_Options_Status) -> Result<(), OptionsError> {
match status {
lv2_sys::LV2_Options_Status_LV2_OPTIONS_SUCCESS => Ok(()),
lv2_sys::LV2_Options_Status_LV2_OPTIONS_ERR_BAD_SUBJECT => Err(OptionsError::BadSubject),
lv2_sys::LV2_Options_Status_LV2_OPTIONS_ERR_BAD_SUBJECT => {
Err(OptionsError::BadSubject)
}
lv2_sys::LV2_Options_Status_LV2_OPTIONS_ERR_BAD_KEY => Err(OptionsError::BadKey),
lv2_sys::LV2_Options_Status_LV2_OPTIONS_ERR_BAD_VALUE => Err(OptionsError::BadValue),
_ => Err(OptionsError::Unknown),
Expand All @@ -44,7 +48,7 @@ impl Display for OptionsError {
OptionsError::Unknown => "Unknown error while reading/writing Option",
OptionsError::BadSubject => "Unknown Option subject",
OptionsError::BadKey => "Unknown Option key",
OptionsError::BadValue => "Invalid Option value"
OptionsError::BadValue => "Invalid Option value",
};

write!(f, "{}", msg)
Expand Down
Loading

0 comments on commit 89dc9b7

Please sign in to comment.