lv2_units/
lib.rs

1//! LV2 specification for measuring unit definitions.
2//!
3//! The original [specification](http://lv2plug.in/ns/extensions/units/units.html) contains means to describe units for LV2 values in RDF files. This implementation is focused on the stock units defined by the specification by binding them to marker types.
4extern crate lv2_sys as sys;
5
6use urid::*;
7
8/// All unit URI bounds.
9pub mod units {
10    use urid::UriBound;
11
12    pub struct Bar;
13    unsafe impl UriBound for Bar {
14        const URI: &'static [u8] = sys::LV2_UNITS__bar;
15    }
16
17    pub struct Beat;
18    unsafe impl UriBound for Beat {
19        const URI: &'static [u8] = sys::LV2_UNITS__beat;
20    }
21
22    pub struct BeatPerMinute;
23    unsafe impl UriBound for BeatPerMinute {
24        const URI: &'static [u8] = sys::LV2_UNITS__bpm;
25    }
26
27    pub struct Cent;
28    unsafe impl UriBound for Cent {
29        const URI: &'static [u8] = sys::LV2_UNITS__cent;
30    }
31
32    pub struct Centimeter;
33    unsafe impl UriBound for Centimeter {
34        const URI: &'static [u8] = sys::LV2_UNITS__cm;
35    }
36
37    pub struct Coefficient;
38    unsafe impl UriBound for Coefficient {
39        const URI: &'static [u8] = sys::LV2_UNITS__coef;
40    }
41
42    pub struct Decibel;
43    unsafe impl UriBound for Decibel {
44        const URI: &'static [u8] = sys::LV2_UNITS__db;
45    }
46
47    pub struct Degree;
48    unsafe impl UriBound for Degree {
49        const URI: &'static [u8] = sys::LV2_UNITS__degree;
50    }
51
52    pub struct Frame;
53    unsafe impl UriBound for Frame {
54        const URI: &'static [u8] = sys::LV2_UNITS__frame;
55    }
56
57    pub struct Hertz;
58    unsafe impl UriBound for Hertz {
59        const URI: &'static [u8] = sys::LV2_UNITS__hz;
60    }
61
62    pub struct Inch;
63    unsafe impl UriBound for Inch {
64        const URI: &'static [u8] = sys::LV2_UNITS__inch;
65    }
66
67    pub struct Kilohertz;
68    unsafe impl UriBound for Kilohertz {
69        const URI: &'static [u8] = sys::LV2_UNITS__khz;
70    }
71
72    pub struct Kilometer;
73    unsafe impl UriBound for Kilometer {
74        const URI: &'static [u8] = sys::LV2_UNITS__km;
75    }
76
77    pub struct Meter;
78    unsafe impl UriBound for Meter {
79        const URI: &'static [u8] = sys::LV2_UNITS__m;
80    }
81
82    pub struct Megahertz;
83    unsafe impl UriBound for Megahertz {
84        const URI: &'static [u8] = sys::LV2_UNITS__mhz;
85    }
86
87    pub struct MIDINote;
88    unsafe impl UriBound for MIDINote {
89        const URI: &'static [u8] = sys::LV2_UNITS__midiNote;
90    }
91
92    pub struct Mile;
93    unsafe impl UriBound for Mile {
94        const URI: &'static [u8] = sys::LV2_UNITS__mile;
95    }
96
97    pub struct Minute;
98    unsafe impl UriBound for Minute {
99        const URI: &'static [u8] = sys::LV2_UNITS__min;
100    }
101
102    pub struct Millimeter;
103    unsafe impl UriBound for Millimeter {
104        const URI: &'static [u8] = sys::LV2_UNITS__mm;
105    }
106
107    pub struct Millisecond;
108    unsafe impl UriBound for Millisecond {
109        const URI: &'static [u8] = sys::LV2_UNITS__ms;
110    }
111
112    pub struct Octave;
113    unsafe impl UriBound for Octave {
114        const URI: &'static [u8] = sys::LV2_UNITS__oct;
115    }
116
117    pub struct Percent;
118    unsafe impl UriBound for Percent {
119        const URI: &'static [u8] = sys::LV2_UNITS__pc;
120    }
121
122    pub struct Second;
123    unsafe impl UriBound for Second {
124        const URI: &'static [u8] = sys::LV2_UNITS__s;
125    }
126
127    pub struct Semitone;
128    unsafe impl UriBound for Semitone {
129        const URI: &'static [u8] = sys::LV2_UNITS__semitone12TET;
130    }
131}
132
133use units::*;
134
135/// A URID cache containing all units.
136#[derive(URIDCollection)]
137pub struct UnitURIDCollection {
138    pub bar: URID<Bar>,
139    pub beat: URID<Beat>,
140    pub bpm: URID<BeatPerMinute>,
141    pub cent: URID<Cent>,
142    pub cm: URID<Centimeter>,
143    pub coef: URID<Coefficient>,
144    pub db: URID<Decibel>,
145    pub degree: URID<Degree>,
146    pub frame: URID<Frame>,
147    pub hz: URID<Hertz>,
148    pub inch: URID<Inch>,
149    pub khz: URID<Kilohertz>,
150    pub km: URID<Kilometer>,
151    pub m: URID<Meter>,
152    pub mhz: URID<Megahertz>,
153    pub note: URID<MIDINote>,
154    pub mile: URID<Mile>,
155    pub min: URID<Minute>,
156    pub mm: URID<Millimeter>,
157    pub ms: URID<Millisecond>,
158    pub octave: URID<Octave>,
159    pub percent: URID<Percent>,
160    pub s: URID<Second>,
161    pub semitone: URID<Semitone>,
162}
163
164/// Prelude of `lv2_units` for wildcard usage.
165pub mod prelude {
166    pub use crate::units::*;
167    pub use crate::UnitURIDCollection;
168}