Skip to content

Commit

Permalink
Option collections now work!
Browse files Browse the repository at this point in the history
  • Loading branch information
prokopyl committed Sep 12, 2021
1 parent 89dc9b7 commit 73d3684
Show file tree
Hide file tree
Showing 9 changed files with 317 additions and 163 deletions.
112 changes: 68 additions & 44 deletions buf-size/src/buffer_sizes.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,77 @@
use crate::options::*;
use lv2_atom::prelude::Int;
use lv2_options::features::OptionsList;
use urid::{Map, URIDCollection, URID};

#[derive(URIDCollection)]
pub struct BufferSizesURIDCollection {
pub atom_int: URID<Int>,
pub min_block_length: URID<MinBlockLength>,
pub max_block_length: URID<MaxBlockLength>,
pub nominal_block_length: URID<NominalBlockLength>,
pub sequence_size: URID<SequenceSize>,
}

#[derive(Copy, Clone, Debug, Default)]
pub struct BufferSizes {
min_block_length: Option<u32>,
max_block_length: Option<u32>,
nominal_block_length: Option<u32>,
sequence_size: Option<u32>,
min_block_length: Option<MinBlockLength>,
max_block_length: Option<MaxBlockLength>,
nominal_block_length: Option<NominalBlockLength>,
sequence_size: Option<SequenceSize>,
}

impl BufferSizes {
pub fn from_options(options: &OptionsList, mapper: &impl Map) -> Self {
let collection = match mapper.populate_collection() {
Some(c) => c,
None => return Default::default(),
};
BufferSizes::from_options_with_urids(options, &collection)
const _: () = {
extern crate lv2_options as _lv2_options;
extern crate urid as _urid;
use _lv2_options::collection::{OptionsCollection, OptionsSerializationContext};
use _lv2_options::features::OptionsList;
use _lv2_options::request::OptionRequestList;
use _lv2_options::OptionsError;

use _urid::*;

#[derive(_urid::URIDCollection)]
pub struct BufferSizesSerializationContext {
pub min_block_length: <Option<MinBlockLength> as OptionsCollection>::Serializer,
pub max_block_length: <Option<MaxBlockLength> as OptionsCollection>::Serializer,
pub nominal_block_length: <Option<NominalBlockLength> as OptionsCollection>::Serializer,
pub sequence_size: <Option<SequenceSize> as OptionsCollection>::Serializer,
}

pub fn from_options_with_urids(
options: &OptionsList,
urids: &BufferSizesURIDCollection,
) -> Self {
todo!()
/*
BufferSizes {
min_block_length: options
.read(urids.min_block_length, urids.atom_int, ())
.map(|x| x.get()),
max_block_length: options
.read(urids.max_block_length, urids.atom_int, ())
.map(|x| x.get()),
nominal_block_length: options
.read(urids.nominal_block_length, urids.atom_int, ())
.map(|x| x.get()),
sequence_size: options
.read(urids.sequence_size, urids.atom_int, ())
.map(|x| x.get()),
}*/
impl OptionsCollection for BufferSizes {
type Serializer = BufferSizesSerializationContext;
}
}

impl OptionsSerializationContext<BufferSizes> for BufferSizesSerializationContext {
fn deserialize_new(&self, options: &OptionsList) -> Result<BufferSizes, OptionsError> {
Ok(BufferSizes {
min_block_length: self.min_block_length.deserialize_new(options)?,
max_block_length: self.max_block_length.deserialize_new(options)?,
nominal_block_length: self.nominal_block_length.deserialize_new(options)?,
sequence_size: self.sequence_size.deserialize_new(options)?,
})
}

fn deserialize_to(
&self,
destination: &mut BufferSizes,
options: &OptionsList,
) -> Result<(), OptionsError> {
self.min_block_length
.deserialize_to(&mut destination.min_block_length, options)?;
self.max_block_length
.deserialize_to(&mut destination.max_block_length, options)?;
self.nominal_block_length
.deserialize_to(&mut destination.nominal_block_length, options)?;
self.sequence_size
.deserialize_to(&mut destination.sequence_size, options)?;

Ok(())
}

fn respond_to_requests<'a>(
&self,
options: &'a BufferSizes,
requests: &mut OptionRequestList<'a>,
) -> Result<(), OptionsError> {
self.min_block_length
.respond_to_requests(&options.min_block_length, requests)?;
self.max_block_length
.respond_to_requests(&options.max_block_length, requests)?;
self.nominal_block_length
.respond_to_requests(&options.nominal_block_length, requests)?;
self.sequence_size
.respond_to_requests(&options.sequence_size, requests)?;

Ok(())
}
}
};
2 changes: 1 addition & 1 deletion buf-size/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod buffer_sizes;
pub mod options;

pub use buffer_sizes::{BufferSizes, BufferSizesURIDCollection};
pub use buffer_sizes::BufferSizes;
1 change: 1 addition & 0 deletions buf-size/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use urid::UriBound;
/// A simple macro to automate the definition of the u32 options available in this module
macro_rules! make_option {
($name:ident, $uri:expr) => {
#[derive(Copy, Clone, Debug, Default)]
pub struct $name(i32);

impl $name {
Expand Down
Loading

0 comments on commit 73d3684

Please sign in to comment.