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
use std::sync::{Arc, Mutex};
use crate::{
metronome::Beat,
pitch::{Pitch, PitchClass, PitchName},
};
/// A running state that is used to manage a resolve operation.
#[derive(Debug, Clone)]
pub struct ResolveState {
/// Previous resolved pitch.
pub pitch: Pitch,
/// Previous resolved length.
pub length: Beat,
/// The scale for scale-inversion notation.
pub scale: Vec<Pitch>,
/// The current scale inversion.
pub inversion: usize,
/// Previous used scale step, post-inversion.
pub scale_step: usize,
/// Previous used scale octave.
pub scale_octave: i8,
}
impl Default for ResolveState {
fn default() -> Self {
Self {
pitch: Pitch {
pitch_class: Arc::new(Mutex::new(PitchClass {
name: PitchName::C,
adjustment: 0.0,
})),
octave: 4,
},
length: Beat::ONE,
scale: [
PitchName::C,
PitchName::D,
PitchName::E,
PitchName::F,
PitchName::G,
PitchName::A,
PitchName::B,
]
.into_iter()
.map(|name| Pitch {
pitch_class: Arc::new(Mutex::new(PitchClass {
name,
adjustment: 0.0,
})),
octave: 4,
})
.collect(),
inversion: 0,
scale_step: 0,
scale_octave: 0,
}
}
}