Skip to content

Commit

Permalink
Merge 430ff0d into 09456c4
Browse files Browse the repository at this point in the history
  • Loading branch information
XBagon committed Aug 26, 2020
2 parents 09456c4 + 430ff0d commit f8be37a
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 136 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license = "MIT"
version = "0.2.0"
readme = "README.md"
repository = "https://github.com/ozankasikci/rust-music-theory"
authors = ["Ozan Kasikci <ozan@kasikci.io>"]
authors = ["Ozan Kaşıkçı <ozan@kasikci.io>"]
edition = "2018"
exclude = ["/.travis.yml", ".gitignore"]
keywords = ["music", "music-theory"]
Expand All @@ -14,5 +14,5 @@ keywords = ["music", "music-theory"]
strum = "0.17.1"
strum_macros = "0.17.1"
regex = "1"
clap = "2.31"
structopt = "0.3.16"
lazy_static = "1.4.0"
133 changes: 0 additions & 133 deletions src/bin/rustmt.rs

This file was deleted.

79 changes: 79 additions & 0 deletions src/bin/rustmt/chord.rs
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
}
}
}
29 changes: 29 additions & 0 deletions src/bin/rustmt/main.rs
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();
}
}
}
}
66 changes: 66 additions & 0 deletions src/bin/rustmt/scale.rs
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
}
}
}
2 changes: 1 addition & 1 deletion src/scale/scale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ impl Default for Scale {
direction: Direction::Ascending,
}
}
}
}

0 comments on commit f8be37a

Please sign in to comment.