1
1
//! Contains the [`OptionsInterface`](crate::extensions::OptionsInterface) extension interface.
2
-
3
2
use crate :: features:: OptionsList ;
4
3
use crate :: { OptionsError , OptionsWriter } ;
5
4
use lv2_core:: feature:: Feature ;
@@ -12,6 +11,100 @@ use std::panic::AssertUnwindSafe;
12
11
use urid:: UriBound ;
13
12
14
13
/// An interface to allow dynamically setting options from the host.
14
+ ///
15
+ /// # Example
16
+ ///
17
+ ///
18
+ ///
19
+ /// ```
20
+ /// # use lv2_core::prelude::*;
21
+ /// # use lv2_options::{OptionType, OptionsWriter, OptionsError, Subject};
22
+ /// # use lv2_options::features::OptionsList;
23
+ /// # use lv2_options::extensions::{OptionsDescriptor, OptionsInterface};
24
+ /// #
25
+ /// # use urid::{URID, Uri};
26
+ /// # use std::any::Any;
27
+ /// #
28
+ /// # impl<'a> OptionType<'a> for SomeIntOption {
29
+ /// # type AtomType = lv2_atom::scalar::Int;
30
+ /// #
31
+ /// # fn from_option_value(value: &i32) -> Option<Self> {
32
+ /// # Some(Self(*value))
33
+ /// # }
34
+ /// #
35
+ /// # fn as_option_value(&'a self) -> &'a i32 {
36
+ /// # &self.0
37
+ /// # }
38
+ /// # }
39
+ /// #
40
+ /// # #[derive(URIDCollection)]
41
+ /// pub struct PluginUridCollection {
42
+ /// some_int_option: URID<SomeIntOption>,
43
+ /// int: URID<lv2_atom::scalar::Int>,
44
+ /// }
45
+ /// #
46
+ /// # #[derive(FeatureCollection)]
47
+ /// # pub struct PluginFeatures<'a> {
48
+ /// # options: OptionsList<'a>,
49
+ /// # }
50
+ ///
51
+ /// # #[uri("urn:lv2_options:test:OptionablePlugin")]
52
+ /// pub struct OptionablePlugin {
53
+ /// some_int: SomeIntOption,
54
+ /// urids: PluginUridCollection,
55
+ /// }
56
+ /// #
57
+ /// # impl Plugin for OptionablePlugin {
58
+ /// # type Ports = ();
59
+ /// # type InitFeatures = PluginFeatures<'static>;
60
+ /// # type AudioFeatures = ();
61
+ /// #
62
+ /// # fn new(_plugin_info: &PluginInfo, _features: &mut Self::InitFeatures) -> Option<Self> {
63
+ /// # unimplemented!()
64
+ /// # }
65
+ ///#
66
+ /// # fn run(
67
+ /// # &mut self,
68
+ /// # _ports: &mut Self::Ports,
69
+ /// # _features: &mut Self::AudioFeatures,
70
+ /// # _sample_count: u32,
71
+ /// # ) {
72
+ /// # unimplemented!()
73
+ /// # }
74
+ /// #
75
+ /// # fn extension_data(uri: &Uri) -> Option<&'static dyn Any> {
76
+ /// # unimplemented!()
77
+ /// # }
78
+ /// # }
79
+ /// #
80
+ ///
81
+ /// #[uri("urn:lv2_options:test:SomeIntOption")]
82
+ /// pub struct SomeIntOption(i32);
83
+ ///
84
+ /// impl OptionsInterface for OptionablePlugin {
85
+ /// fn get<'a>(&'a self, mut writer: OptionsWriter<'a>) -> Result<(), OptionsError> {
86
+ /// writer.process(|subject, options| match subject { // We will want to get/set our opions differently depending on the subject
87
+ /// Subject::Instance => { // In our case however, only our instance has an option
88
+ /// options.handle(self.urids.some_int_option, self.urids.int, || {
89
+ /// &self.some_int
90
+ /// });
91
+ /// }
92
+ /// _ => {}
93
+ /// })
94
+ /// }
95
+ ///
96
+ /// fn set(&mut self, options: OptionsList) -> Result<(), OptionsError> {
97
+ /// options.process(|subject, options| match subject {
98
+ /// Subject::Instance => {
99
+ /// options.handle(self.urids.some_int_option, self.urids.int, (), |value| {
100
+ /// self.some_int = value
101
+ /// })
102
+ /// }
103
+ /// _ => {}
104
+ /// })
105
+ /// }
106
+ /// }
107
+ /// ```
15
108
pub trait OptionsInterface : Plugin {
16
109
/// Allows the host to retrieve the value of the given options, as currently stored by the plugin.
17
110
///
0 commit comments