Skip to content

Commit

Permalink
Add a better way to create chords
Browse files Browse the repository at this point in the history
  • Loading branch information
veminovici committed Mar 17, 2024
1 parent 22a5da3 commit 0a4ccd9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ println!("Dom7 C: {chord:X}");
You can find more examples in the [examples][examples_folder] folder.

## Piano Exercises
You can find all piano exercises implemented in the [practices][practices_file] file.
You can find all piano exercises implemented in the [practices][practices_file] file. You can see the practices by running:
```bsh
cargo run --example practices
```

### Exercise 1 (C - Am - F - G)
```rust
use musika_rs::*;

println!("Exercise 1: (C - Am - F - G");
println!("{:X}", chords::Major::from(C)); // C
println!("{:X}", chords::Minor::from(A)); // Amin
println!("{:X}", chords::Major::from(F)); // F
println!("{:X}", chords::Major::from(G)); // G
println!("Exercise 1: (C - Am - F - G)");
println!("{:X}", C.major()); // C [C, E, G]
println!("{:X}", A.minor()); // Am [A, C, E]
println!("{:X}", F.major()); // F [F, A, C]
println!("{:X}", G.major()); // G [G, B, D]
```

## Resources
Expand Down
10 changes: 5 additions & 5 deletions examples/practices.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use musika_rs::*;

fn exercise() {
println!("Exercise 1: (C - Am - F - G");
println!("{:X}", chords::Major::from(C)); // C
println!("{:X}", chords::Minor::from(A)); // Amin
println!("{:X}", chords::Major::from(F)); // F
println!("{:X}", chords::Major::from(G)); // G
println!("Exercise 1: (C - Am - F - G)");
println!("{:X}", C.major()); // C [C, E, G]
println!("{:X}", A.minor()); // Am [A, C, E]
println!("{:X}", F.major()); // F [F, A, C]
println!("{:X}", G.major()); // G [G, B, D]
}

fn main() {
Expand Down
34 changes: 34 additions & 0 deletions src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::{
ops::{Add, Sub},
};

use crate::chords;

use super::{Tone, OCTAVE};

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -42,6 +44,38 @@ impl Note {
octave + 3
}
}

//
// Functions which build chords
//

pub fn diminished7(self) -> chords::Diminished7 {
chords::Diminished7::from(self)
}

pub fn dominant7(self) -> chords::Dominant7 {
chords::Dominant7::from(self)
}

pub fn major(self) -> chords::Major {
chords::Major::from(self)
}

pub fn major7(self) -> chords::Major7 {
chords::Major7::from(self)
}

pub fn minor(self) -> chords::Minor {
chords::Minor::from(self)
}

pub fn minor7(self) -> chords::Minor7 {
chords::Minor7::from(self)
}

pub fn minor7b5(self) -> chords::Minor7b5 {
chords::Minor7b5::from(self)
}
}

impl Display for Note {
Expand Down

0 comments on commit 0a4ccd9

Please sign in to comment.