1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
//! Iced Audio is an extension to the [`Iced`] GUI library with useful widgets
//! for audio applications such as VST / LV2 plugins.
//!
//! # Installation
//!
//! Add `iced` and `iced_audio` as dependencies in your `Cargo.toml`:
//!
//! ```
//! iced = { version = "0.1", features = ["image"] }
//! iced_audio = "0.1"
//! ```
//!
//! This crate is currently experimental and incomplete. Master branch moves
//! fast and may contain breaking changes!
//!
//! # Simple Usage Example
//!
//! This crate assumes you know the basics of how to use [`Iced`]. If you
//! haven't alreay, please check it out [`here`].
//!
//! ```
//! // Import iced modules.
//! use iced::{
//!     Column, Container, Element, Length, Sandbox, Settings, Align
//! };
//! // Import iced_audio modules.
//! use iced_audio::{
//!     Normal, FloatParam, LogDBParam, OctaveParam, h_slider, HSlider,
//!     v_slider, VSlider, knob, Knob, xy_pad, XYPad, TickMarkGroup, TickMark,
//!     TickMarkTier
//! };
//! 
//! // Create a unique identifier for each parameter. Note you may also use any
//! // type you want such as u32, i32, Strings, etc.
//! #[derive(Debug, Copy, Clone)]
//! pub enum ParamID {
//!     HSliderFloat,
//!     VSliderDB,
//!     KnobOctave,
//!     XYPadFloatX,
//!     XYPadFloatY,
//! }
//! 
//! // The message when a parameter widget is changed by the user
//! #[derive(Debug, Clone)]
//! pub enum Message {
//!     ParamChanged((ParamID, Normal)),
//! }
//! 
//! pub fn main() {
//!     App::run(Settings::default())
//! }
//! 
//! pub struct App {
//!     
//!     // The parameters (`Param`) hold the current and default values.
//!     // They also handle converting the output of the widget to a usable value.
//!     //
//!     // There are 4 options available for a parameter:
//!     //
//!     // * FloatParam - a linear range of f32 values
//!     // * IntParam - a discrete range of i32 values. This will cause the widget
//!     // to "step" when moved.
//!     // * LogDBParam - a logarithmic range of decibel values. Values around 0 dB
//!     // will increment slower than values farther away from 0 dB.
//!     // * OctaveParam - a logarithmic range of frequency values. Each octave in
//!     // the 10 octave spectrum (from 20 Hz to 20480 Hz) is spaced evenly.
//!     //
//!     h_slider_float_param: FloatParam<ParamID>,
//!     v_slider_db_param: LogDBParam<ParamID>,
//!     knob_octave_param: OctaveParam<ParamID>,
//!     xy_pad_float_x_param: FloatParam<ParamID>,
//!     xy_pad_float_y_param: FloatParam<ParamID>,
//! 
//!     // The states of the parameter widgets that will control the parameters.
//!     h_slider_state: h_slider::State,
//!     v_slider_state: v_slider::State,
//!     knob_state: knob::State,
//!     xy_pad_state: xy_pad::State,
//! 
//!     // A group of tick marks with their size and position.
//!     center_tick_mark: TickMarkGroup,
//! }
//! 
//! impl Sandbox for App {
//!     type Message = Message;
//! 
//!     fn new() -> App {
//! 
//!         // Initialize each parameter:
//!         // * `ID` - A unique identifier for each parameter
//!         // * `min` - The minimum of the range (inclusive)
//!         // * `max` - The maximum of the range (inclusive)
//!         // * `value` - The initial value of the parameter
//!         // * `default_value` - The default value of the parameter
//!         let h_slider_float_param = FloatParam::<ParamID>::new(
//!             ParamID::HSliderFloat , -1.0, 1.0, 0.0, 0.0);
//! 
//!         let v_slider_db_param = LogDBParam::<ParamID>::new(
//!             ParamID::VSliderDB , -12.0, 12.0, 0.0, 0.0, 0.5.into());
//! 
//!         let knob_octave_param = OctaveParam::<ParamID>::new(
//!             ParamID::KnobOctave , 20.0, 20480.0, 1000.0, 1000.0);
//! 
//!         let xy_pad_float_x_param = FloatParam::<ParamID>::new(
//!             ParamID::XYPadFloatX , -1.0, 1.0, 0.0, 0.0);
//!         let xy_pad_float_y_param = FloatParam::<ParamID>::new(
//!             ParamID::XYPadFloatY , -1.0, 1.0, 0.0, 0.0);
//! 
//!         App {
//!             // Add the parameters.
//!             h_slider_float_param,
//!             v_slider_db_param,
//!             knob_octave_param,
//!             xy_pad_float_x_param,
//!             xy_pad_float_y_param,
//! 
//!             // Initialize the state of the widgets with the initial value
//!             // of the corresponding parameter.
//!             h_slider_state: h_slider::State::new(&h_slider_float_param),
//!             v_slider_state: v_slider::State::new(&v_slider_db_param),
//!             knob_state: knob::State::new(&knob_octave_param),
//!             xy_pad_state: xy_pad::State::new(
//!                 &xy_pad_float_x_param, &xy_pad_float_y_param),
//!             
//!             // Add a tick mark at the center position with the tier 2 size
//!             center_tick_mark: vec![
//!                 TickMark::center(TickMarkTier::Two)
//!             ].into(),
//!         }
//!     }
//! 
//!     fn title(&self) -> String {
//!         format!("Simple Example - Iced Audio")
//!     }
//! 
//!     fn update(&mut self, event: Message) {
//!         match event {
//!             Message::ParamChanged((id, normal)) => {
//! 
//!                 // Update each parameter with the `Normal` output value from
//!                 // the corresponding parameter widget.
//!                 //
//!                 // Now do something useful with that value!
//!                 //
//!                 match id {
//!                     ParamID::HSliderFloat => {
//!                         self.h_slider_float_param.set_from_normal(normal);
//!                         // println!("{}", self.h_slider_float_param.value());
//!                     },
//!                     ParamID::VSliderDB => {
//!                         self.v_slider_db_param.set_from_normal(normal);
//!                         // println!("{}", self.v_slider_db_param.value());
//!                     },
//!                     ParamID::KnobOctave => {
//!                         self.knob_octave_param.set_from_normal(normal);
//!                         // println!("{}", self.knob_octave_param.value());
//!                     },
//!                     ParamID::XYPadFloatX => {
//!                         self.xy_pad_float_x_param.set_from_normal(normal);
//!                         // println!("{}", self.xy_pad_float_x_param.value());
//!                     },
//!                     ParamID::XYPadFloatY => {
//!                         self.xy_pad_float_y_param.set_from_normal(normal);
//!                         // println!("{}", self.xy_pad_float_y_param.value());
//!                     },
//!                 }
//!             }
//!         }
//!     }
//! 
//!     fn view(&mut self) -> Element<Message> {
//!         
//!         // Create each parameter widget, passing in the current value of the
//!         // corresponding parameter.
//!         let h_slider_widget = HSlider::new(
//!             &mut self.h_slider_state,
//!             &self.h_slider_float_param,
//!             Message::ParamChanged,
//!         )
//!         // Add the tick mark group to this widget.
//!         .tick_marks(&self.center_tick_mark);
//! 
//!         let v_slider_widget = VSlider::new(
//!             &mut self.v_slider_state,
//!             &self.v_slider_db_param,
//!             Message::ParamChanged,
//!         )
//!         .tick_marks(&self.center_tick_mark);
//! 
//!         let knob_widget = Knob::new(
//!             &mut self.knob_state,
//!             &self.knob_octave_param,
//!             Message::ParamChanged,
//!         );
//! 
//!         let xy_pad_widget = XYPad::new(
//!             &mut self.xy_pad_state,
//!             &self.xy_pad_float_x_param,
//!             &self.xy_pad_float_y_param,
//!             Message::ParamChanged,
//!         );
//! 
//!         // Push the widgets into the iced DOM
//!         let content: Element<_> = Column::new()
//!             .max_width(250)
//!             .max_height(400)
//!             .spacing(20)
//!             .padding(20)
//!             .align_items(Align::Center)
//!             .push(h_slider_widget)
//!             .push(v_slider_widget)
//!             .push(knob_widget)
//!             .push(xy_pad_widget)
//!             .into();
//! 
//!         Container::new(content)
//!             .width(Length::Fill)
//!             .height(Length::Fill)
//!             .center_x()
//!             .center_y()
//!             .into()
//!     }
//! }
//! ```
//! [`Iced`]: https://github.com/hecrj/iced
//! [`here`]: https://github.com/hecrj/iced

#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
#![deny(unused_results)]
#![forbid(unsafe_code)]
#![forbid(rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg))]

pub mod core;
pub mod native;
pub mod style;
pub mod wgpu;

#[doc(no_inline)]
pub use crate::core::*;

#[cfg(not(target_arch = "wasm32"))]
mod platform {
    #[doc(no_inline)]
    pub use crate::wgpu::{
        h_slider,
        v_slider,
        knob,
        xy_pad,
    };

    #[doc(no_inline)]
    pub use {
        h_slider::HSlider,
        v_slider::VSlider,
        knob::Knob,
        xy_pad::XYPad,
    };
}

#[doc(no_inline)]
pub use platform::*;