-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
177 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use rust_music_theory::{ | ||
chord::Chord, | ||
note::Notes, | ||
}; | ||
use structopt::StructOpt; | ||
|
||
const AVAILABLE_CHORDS: [&str; 22] = [ | ||
"Major Triad", | ||
"Minor Triad", | ||
"Suspended2 Triad", | ||
"Suspended4 Triad", | ||
"Augmented Triad", | ||
"Diminished Triad", | ||
"Major Seventh", | ||
"Minor Seventh", | ||
"Augmented Seventh", | ||
"Augmented Major Seventh", | ||
"Diminished Seventh", | ||
"Half Diminished Seventh", | ||
"Minor Major Seventh", | ||
"Dominant Seventh", | ||
"Dominant Ninth", | ||
"Major Ninth", | ||
"Dominant Eleventh", | ||
"Major Eleventh", | ||
"Minor Eleventh", | ||
"Dominant Thirteenth", | ||
"Major Thirteenth", | ||
"Minor Thirteenth", | ||
]; | ||
|
||
#[derive(StructOpt, Debug)] | ||
#[structopt(about = "Provides information for the specified chord")] | ||
pub enum Command { | ||
List(ListCommand), | ||
Notes(NotesCommand), | ||
} | ||
|
||
impl Command { | ||
pub fn execute(self) { | ||
match self { | ||
Command::List(list_command) => list_command.execute(), | ||
Command::Notes(note_command) => note_command.execute(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(StructOpt, Debug)] | ||
#[structopt(alias = "l", about = "Prints out the available chords")] | ||
pub struct ListCommand {} | ||
|
||
impl ListCommand { | ||
pub fn execute(self) { | ||
println!("Available chords:"); | ||
for chord in &AVAILABLE_CHORDS { | ||
println!(" - {}", chord); | ||
} | ||
} | ||
} | ||
|
||
#[derive(StructOpt, Debug)] | ||
#[structopt(alias = "n", about = "Prints out the notes of the <chord>", help = "Examples:\n- C minor\n- Ab augmented major seventh\n- F# dominant seventh / C#\n- C/1", help = "test")] | ||
pub struct NotesCommand { | ||
#[structopt(name = "chord", required = true)] | ||
chord_strings: Vec<String>, | ||
} | ||
|
||
impl NotesCommand { | ||
pub fn execute(self) { | ||
let chord_string = self.chord_strings.join(" "); | ||
let chord = Chord::from_regex(&chord_string); | ||
if let Ok(chord) = chord { | ||
chord.print_notes(); | ||
} else { | ||
use structopt::clap::*; | ||
Error::with_description("Couldn't parse chord", ErrorKind::ValueValidation).exit(); //TODO: Better Errors | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use structopt::StructOpt; | ||
|
||
mod chord; | ||
mod scale; | ||
|
||
fn main() { | ||
let opt = Cli::from_args(); | ||
opt.execute(); | ||
} | ||
|
||
#[derive(StructOpt, Debug)] | ||
#[structopt(name = "rust-music-theory", author, about = "A music theory guide")] | ||
enum Cli { | ||
Scale(scale::Command), | ||
Chord(chord::Command), | ||
} | ||
|
||
impl Cli { | ||
fn execute(self) { | ||
match self { | ||
Cli::Scale(scale_command) => { | ||
scale_command.execute(); | ||
} | ||
Cli::Chord(chord_command) => { | ||
chord_command.execute(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use rust_music_theory::{ | ||
note::Notes, | ||
scale::Scale, | ||
}; | ||
use structopt::StructOpt; | ||
|
||
const AVAILABLE_SCALES: [&str; 9] = [ | ||
"Major|Ionian", | ||
"Minor|Aeolian", | ||
"Dorian", | ||
"Phrygian", | ||
"Lydian", | ||
"Mixolydian", | ||
"Locrian", | ||
"HarmonicMinor", | ||
"MelodicMinor", | ||
]; | ||
|
||
#[derive(StructOpt, Debug)] | ||
#[structopt(about = "Provides information for the specified scale")] | ||
pub enum Command { | ||
List(ListCommand), | ||
Notes(NotesCommand), | ||
} | ||
|
||
impl Command { | ||
pub fn execute(self) { | ||
match self { | ||
Command::List(list_command) => list_command.execute(), | ||
Command::Notes(note_command) => note_command.execute(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(StructOpt, Debug)] | ||
#[structopt(alias = "l", about = "Prints out the available scales")] | ||
pub struct ListCommand {} | ||
|
||
impl ListCommand { | ||
pub fn execute(self) { | ||
println!("Available Scales:"); | ||
for scale in &AVAILABLE_SCALES { | ||
println!(" - {}", scale); | ||
} | ||
} | ||
} | ||
|
||
#[derive(StructOpt, Debug)] | ||
#[structopt(alias = "n", about = "Prints out the notes of the <scale>", help = "Examples:\n- C melodic minor\n- D# dorian")] | ||
pub struct NotesCommand { | ||
#[structopt(name = "scale", required = true)] | ||
scale_strings: Vec<String>, | ||
} | ||
|
||
impl NotesCommand { | ||
pub fn execute(self) { | ||
let scale_string = self.scale_strings.join(" "); | ||
let scale = Scale::from_regex(&scale_string); //TODO: reintegrate direction (directly into from_str/regex) | ||
if let Ok(scale) = scale { | ||
scale.print_notes(); | ||
} else { | ||
use structopt::clap::*; | ||
Error::with_description("Couldn't parse scale", ErrorKind::ValueValidation).exit(); //TODO: Better Errors | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,4 +115,4 @@ impl Default for Scale { | |
direction: Direction::Ascending, | ||
} | ||
} | ||
} | ||
} |