Skip to content

Commit 9f39e4d

Browse files
committed
update
Signed-off-by: Joe McCain III <jo3mccain@icloud.com>
1 parent 8dd0200 commit 9f39e4d

File tree

5 files changed

+56
-43
lines changed

5 files changed

+56
-43
lines changed

core/src/intervals/interval.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,32 @@ use super::IntervalLevel;
66

77
pub struct Interval<Q> {
88
pub level: IntervalLevel,
9-
pub quality: Option<Q>,
9+
pub quality: Q,
1010
pub value: i8,
1111
}
1212

13+
impl<Q> Interval<Q> {
14+
pub fn new(level: IntervalLevel, quality: Q, value: i8) -> Self {
15+
Self {
16+
level,
17+
quality,
18+
value,
19+
}
20+
}
21+
}
22+
23+
pub struct IntervalQuality<T> {
24+
pub level: IntervalLevel,
25+
pub name: &'static str,
26+
pub value: Option<T>,
27+
}
28+
1329
pub trait Quality<T> {
14-
type Group;
30+
type Level;
1531

16-
fn group(&self) -> Self::Group;
32+
fn level(&self) -> Self::Level;
1733

1834
fn name(&self) -> &str;
1935

2036
fn value(&self) -> T;
2137
}
22-
23-
pub struct Variant<K, V> {
24-
pub group: K,
25-
pub name: &'static str,
26-
pub value: V,
27-
}

core/src/intervals/kinds.rs

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Intervals {
7272
9 => Sevenths(Seventh::Diminished),
7373
10 => Sevenths(Seventh::Minor),
7474
11 => Sevenths(Seventh::Major),
75-
_ => panic!("Invalid interval value: {}", pitch),
75+
_ => unreachable!("The pitch value is out of range."),
7676
}
7777
}
7878
/// A convenience method for constructing a new instance of the [Octave](Intervals::Octave) variant.
@@ -91,7 +91,6 @@ impl Intervals {
9191
pub fn third(third: Third) -> Self {
9292
Intervals::Thirds(third)
9393
}
94-
9594
/// A convenience method for constructing a new variant, [`Fourths`](Intervals::Fourths).
9695
pub fn fourth(fourth: Fourth) -> Self {
9796
Intervals::Fourths(fourth)
@@ -124,28 +123,24 @@ impl Intervals {
124123
Intervals::Octave => 12,
125124
}
126125
}
127-
}
128126

129-
macro_rules! impl_new_interval {
130-
(@impl $name:ident::$variant:ident.$call:ident($($T:ident)::*)) => {
131-
pub fn $call() -> Self {
132-
$name::$variant($($T)::*)
133-
}
134-
};
135-
136-
(@impl $name:ident::$variant:ident.$call:ident) => {
137-
pub fn $call() -> Self {
138-
$name::$variant
139-
}
140-
};
127+
variant_constructors! {
128+
Intervals {
129+
Thirds.major_third::<Third::Major>(),
130+
Thirds.minor_third::<Third::Minor>(),
131+
Fourths.perfect_fourth::<Fourth::Perfect>(),
132+
Fifths.diminished_fifth::<Fifth::Diminished>(),
133+
Fifths.perfect_fifth::<Fifth::Perfect>(),
134+
Fifths.augmented_fifth::<Fifth::Augmented>(),
135+
Sevenths.diminished_seventh::<Seventh::Diminished>(),
136+
Sevenths.minor_seventh::<Seventh::Minor>(),
137+
Sevenths.major_seventh::<Seventh::Major>(),
141138

142-
($name:ident {$($variant:ident.$call:ident$(($($T:ident)::*))?),* $(,)?}) => {
143-
impl $name {
144-
$(impl_new_interval!(@impl $name::$variant.$call$(($($T)::*))?);)*
145139
}
146-
};
140+
}
147141
}
148142

143+
149144
macro_rules! impl_from_value {
150145
(@impl $name:ident::$variant:ident($T:ty)) => {
151146
impl From<$T> for $name {
@@ -161,20 +156,7 @@ macro_rules! impl_from_value {
161156
};
162157
}
163158

164-
impl_new_interval! {
165-
Intervals {
166-
Thirds.minor_third(Third::Minor),
167-
Thirds.major_third(Third::Major),
168-
Fourths.perfect_fourth(Fourth::Perfect),
169-
Fifths.diminished_fifth(Fifth::Diminished),
170-
Fifths.perfect_fifth(Fifth::Perfect),
171-
Fifths.augmented_fifth(Fifth::Augmented),
172-
Sevenths.diminished_seventh(Seventh::Diminished),
173-
Sevenths.minor_seventh(Seventh::Minor),
174-
Sevenths.major_seventh(Seventh::Major),
175-
Sevenths.augmented_seventh(Seventh::Augmented),
176-
}
177-
}
159+
178160

179161
impl<P> From<P> for Intervals
180162
where

core/src/intervals/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#[doc(inline)]
66
pub use self::{kinds::*, types::*};
77

8+
#[macro_use]
89
pub(crate) mod kinds;
910
pub(crate) mod types;
1011

core/src/macros/enums.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33
Contrib: FL03 <jo3mccain@icloud.com>
44
*/
55

6+
macro_rules! variant_constructors {
7+
(@impl $name:ident::$variant:ident.$call:ident::<$($T:ident)::*>()) => {
8+
pub fn $call() -> Self {
9+
$name::$variant($($T)::*)
10+
}
11+
};
12+
13+
(@impl $name:ident::$variant:ident.$call:ident()) => {
14+
pub fn $call() -> Self {
15+
$name::$variant
16+
}
17+
};
18+
19+
($name:ident {$($variant:ident.$call:ident$(::<$($T:ident)::*>)?()),* $(,)?}) => {
20+
$(
21+
variant_constructors!(@impl $name::$variant.$call$(::<$($T)::*>)?());
22+
)*
23+
};
24+
}
25+
626
macro_rules! unit_enum {
727
($(#[derive($($der:ident),*$(,)?)])? $vis:vis enum $class:ident $($rest:tt)*) => {
828
unit_enum!(

neo/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub use self::{
2121
kinds::{Augmented, Diminished, Major, Minor},
2222
Triad,
2323
},
24-
types::*,
24+
types::prelude::*,
2525
};
2626

2727
#[macro_use]

0 commit comments

Comments
 (0)