|
1 | 1 | use crate::options::*;
|
2 |
| -use lv2_atom::prelude::Int; |
3 |
| -use lv2_options::features::OptionsList; |
4 |
| -use urid::{Map, URIDCollection, URID}; |
5 |
| - |
6 |
| -#[derive(URIDCollection)] |
7 |
| -pub struct BufferSizesURIDCollection { |
8 |
| - pub atom_int: URID<Int>, |
9 |
| - pub min_block_length: URID<MinBlockLength>, |
10 |
| - pub max_block_length: URID<MaxBlockLength>, |
11 |
| - pub nominal_block_length: URID<NominalBlockLength>, |
12 |
| - pub sequence_size: URID<SequenceSize>, |
13 |
| -} |
14 | 2 |
|
15 | 3 | #[derive(Copy, Clone, Debug, Default)]
|
16 | 4 | pub struct BufferSizes {
|
17 |
| - min_block_length: Option<u32>, |
18 |
| - max_block_length: Option<u32>, |
19 |
| - nominal_block_length: Option<u32>, |
20 |
| - sequence_size: Option<u32>, |
| 5 | + min_block_length: Option<MinBlockLength>, |
| 6 | + max_block_length: Option<MaxBlockLength>, |
| 7 | + nominal_block_length: Option<NominalBlockLength>, |
| 8 | + sequence_size: Option<SequenceSize>, |
21 | 9 | }
|
22 | 10 |
|
23 |
| -impl BufferSizes { |
24 |
| - pub fn from_options(options: &OptionsList, mapper: &impl Map) -> Self { |
25 |
| - let collection = match mapper.populate_collection() { |
26 |
| - Some(c) => c, |
27 |
| - None => return Default::default(), |
28 |
| - }; |
29 |
| - BufferSizes::from_options_with_urids(options, &collection) |
| 11 | +const _: () = { |
| 12 | + extern crate lv2_options as _lv2_options; |
| 13 | + extern crate urid as _urid; |
| 14 | + use _lv2_options::collection::{OptionsCollection, OptionsSerializationContext}; |
| 15 | + use _lv2_options::features::OptionsList; |
| 16 | + use _lv2_options::request::OptionRequestList; |
| 17 | + use _lv2_options::OptionsError; |
| 18 | + |
| 19 | + use _urid::*; |
| 20 | + |
| 21 | + #[derive(_urid::URIDCollection)] |
| 22 | + pub struct BufferSizesSerializationContext { |
| 23 | + pub min_block_length: <Option<MinBlockLength> as OptionsCollection>::Serializer, |
| 24 | + pub max_block_length: <Option<MaxBlockLength> as OptionsCollection>::Serializer, |
| 25 | + pub nominal_block_length: <Option<NominalBlockLength> as OptionsCollection>::Serializer, |
| 26 | + pub sequence_size: <Option<SequenceSize> as OptionsCollection>::Serializer, |
30 | 27 | }
|
31 | 28 |
|
32 |
| - pub fn from_options_with_urids( |
33 |
| - options: &OptionsList, |
34 |
| - urids: &BufferSizesURIDCollection, |
35 |
| - ) -> Self { |
36 |
| - todo!() |
37 |
| - /* |
38 |
| - BufferSizes { |
39 |
| - min_block_length: options |
40 |
| - .read(urids.min_block_length, urids.atom_int, ()) |
41 |
| - .map(|x| x.get()), |
42 |
| - max_block_length: options |
43 |
| - .read(urids.max_block_length, urids.atom_int, ()) |
44 |
| - .map(|x| x.get()), |
45 |
| - nominal_block_length: options |
46 |
| - .read(urids.nominal_block_length, urids.atom_int, ()) |
47 |
| - .map(|x| x.get()), |
48 |
| - sequence_size: options |
49 |
| - .read(urids.sequence_size, urids.atom_int, ()) |
50 |
| - .map(|x| x.get()), |
51 |
| - }*/ |
| 29 | + impl OptionsCollection for BufferSizes { |
| 30 | + type Serializer = BufferSizesSerializationContext; |
52 | 31 | }
|
53 |
| -} |
| 32 | + |
| 33 | + impl OptionsSerializationContext<BufferSizes> for BufferSizesSerializationContext { |
| 34 | + fn deserialize_new(&self, options: &OptionsList) -> Result<BufferSizes, OptionsError> { |
| 35 | + Ok(BufferSizes { |
| 36 | + min_block_length: self.min_block_length.deserialize_new(options)?, |
| 37 | + max_block_length: self.max_block_length.deserialize_new(options)?, |
| 38 | + nominal_block_length: self.nominal_block_length.deserialize_new(options)?, |
| 39 | + sequence_size: self.sequence_size.deserialize_new(options)?, |
| 40 | + }) |
| 41 | + } |
| 42 | + |
| 43 | + fn deserialize_to( |
| 44 | + &self, |
| 45 | + destination: &mut BufferSizes, |
| 46 | + options: &OptionsList, |
| 47 | + ) -> Result<(), OptionsError> { |
| 48 | + self.min_block_length |
| 49 | + .deserialize_to(&mut destination.min_block_length, options)?; |
| 50 | + self.max_block_length |
| 51 | + .deserialize_to(&mut destination.max_block_length, options)?; |
| 52 | + self.nominal_block_length |
| 53 | + .deserialize_to(&mut destination.nominal_block_length, options)?; |
| 54 | + self.sequence_size |
| 55 | + .deserialize_to(&mut destination.sequence_size, options)?; |
| 56 | + |
| 57 | + Ok(()) |
| 58 | + } |
| 59 | + |
| 60 | + fn respond_to_requests<'a>( |
| 61 | + &self, |
| 62 | + options: &'a BufferSizes, |
| 63 | + requests: &mut OptionRequestList<'a>, |
| 64 | + ) -> Result<(), OptionsError> { |
| 65 | + self.min_block_length |
| 66 | + .respond_to_requests(&options.min_block_length, requests)?; |
| 67 | + self.max_block_length |
| 68 | + .respond_to_requests(&options.max_block_length, requests)?; |
| 69 | + self.nominal_block_length |
| 70 | + .respond_to_requests(&options.nominal_block_length, requests)?; |
| 71 | + self.sequence_size |
| 72 | + .respond_to_requests(&options.sequence_size, requests)?; |
| 73 | + |
| 74 | + Ok(()) |
| 75 | + } |
| 76 | + } |
| 77 | +}; |
0 commit comments