Skip to content

Commit

Permalink
Add penta example
Browse files Browse the repository at this point in the history
  • Loading branch information
veminovici committed Mar 24, 2024
1 parent 477e7fc commit b242f7c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
21 changes: 21 additions & 0 deletions examples/autumn_leaves.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use musika_rs::{Bar, A, B, C, D, E, F, G};

fn main() {
let chord = E.dom7();
println!("E7: {chord:X}");

let bar0 = Bar::new().with_silence(1);
let bar1 = Bar::new().with_chord(D.min7(), 1);
let bar2 = Bar::new().with_chord(G.dom7(), 1);
let bar3 = Bar::new().with_chord(C.maj7(), 1);
let bar4 = Bar::new().with_chord(F.maj7(), 1);
let bar5 = Bar::new().with_chord(B.min7b5(), 1);
let bar6 = Bar::new().with_chord(E.dom7(), 1);
let bar7 = Bar::new().with_chord(A.min7(), 1);
let s = [bar0, bar1, bar2, bar3, bar4, bar5, bar6, bar7]
.into_iter()
.map(|bar| format!("{bar}"))
.collect::<Vec<_>>()
.join(" | ");
println!("LH: | {s} |");
}
35 changes: 35 additions & 0 deletions src/scales/penta_minor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use super::Scales;
use crate::Note;

pub fn minor(tonic: Note) -> Scales {
let steps = [3, 2, 2, 3];
Scales::minor_with_steps(" penta_minor", tonic, steps.into_iter())
}

pub fn pentatonic_minor(tonic: Note) -> Scales {
let steps = [3, 2, 2, 3, 2];
Scales::minor_with_steps(" penta minor", tonic, steps.into_iter())
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{A, C};

#[test]
fn test_minor() {
let scale = minor(C);
assert_eq!(format!("{scale:X}"), "C minor [C, D, D#, F, G, G#, A#, C]");
assert_eq!(format!("{scale:x}"), "C minor [C, D, Eb, F, G, Ab, Bb, C]");
}

#[test]
fn test_penta_minor() {
let scale = pentatonic_minor(A);
assert_eq!(format!("{scale:X}"), "A penta minor [A, C, D, E, G, A]");
assert_eq!(format!("{scale:x}"), "A penta minor [A, C, D, E, G, A]");

let scale = pentatonic_minor(D);
assert_eq!(format!("{scale:X}"), "D penta minor [D, E, F, G, B, D]");
assert_eq!(format!("{scale:x}"), "D penta minor [D, E, F, G, B, D]");
}
}

0 comments on commit b242f7c

Please sign in to comment.