Skip to content

Commit

Permalink
Small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
twitchax committed Apr 6, 2023
1 parent 47c39a6 commit 6ae1825
Show file tree
Hide file tree
Showing 8 changed files with 310 additions and 41 deletions.
15 changes: 14 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kord"
version = "0.5.11"
version = "0.5.16"
edition = "2021"
authors = ["Aaron Roney <[email protected]>"]
license = "MIT"
Expand Down Expand Up @@ -33,7 +33,7 @@ debug = true
wasm-opt = false

[features]
default = ["cli", "analyze", "audio"]
default = ["cli", "analyze", "audio", "wasm"]

cli = ["clap", "futures"]

Expand All @@ -54,7 +54,7 @@ ml_train = ["ml_base", "rand", "rayon", "burn-autodiff", "burn/train", "burn/std
ml_infer = ["ml_base", "burn", "burn-ndarray"]
ml_gpu = ["ml_train", "burn-tch"]

wasm = ["rodio/wasm-bindgen", "wasm-bindgen", "wasm-bindgen-futures", "js-sys", "console_error_panic_hook", "wee_alloc"]
wasm = ["rodio/wasm-bindgen", "wasm-bindgen", "wasm-bindgen-futures", "js-sys", "console_error_panic_hook", "wee_alloc", "gloo-timers"]

plot = ["plotters"]

Expand Down Expand Up @@ -103,6 +103,7 @@ wasm-bindgen-futures = { version = "0.4.34", optional = true }
js-sys = { version = "0.3.61", optional = true }
console_error_panic_hook = { version = "0.1.7", optional = true }
wee_alloc = { version = "0.4.5", optional = true }
gloo-timers = { version = "0.2.6", optional = true, features = ["futures"] }

[dev-dependencies]
pretty_assertions = "1.3.0"
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
[![Version](https://img.shields.io/crates/v/kord.svg)](https://crates.io/crates/kord)
[![Downloads](https://img.shields.io/crates/d/kord.svg)](https://crates.io/crates/kord)
[![GitHub all releases](https://img.shields.io/github/downloads/twitchax/kord/total?label=binary)](https://github.com/twitchax/kord/releases)
[![Downloads](https://img.shields.io/crates/d/kord.svg)](https://crates.io/crates/kord)
[![npm](https://img.shields.io/npm/dw/kordweb?label=npm)](https://www.npmjs.com/package/kordweb)
[![Documentation](https://docs.rs/kord/badge.svg)](https://docs.rs/kord)
[![Rust](https://img.shields.io/badge/rust-nightly-blue.svg?maxAge=3600)](https://github.com/twitchax/kord)
[![License:MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
Expand Down Expand Up @@ -231,7 +233,7 @@ chord.chordString(); // C4 E4 G4 Bb5 D#5
KordChord.parse('C7b9').withOctave(2).chord().map(n => n.name()); // [ 'C2', 'D♭2', 'E2', 'G2', 'B♭2' ]

// Build chords.
KordChord.parse('C').min().seven().chord().map(n => n.name()); // [ 'C4', 'Eb4', 'G4', 'Bb4' ]
KordChord.parse('C').minor().seven().chord().map(n => n.name()); // [ 'C4', 'Eb4', 'G4', 'Bb4' ]
```
## Feature Flags
Expand Down
125 changes: 125 additions & 0 deletions src/core/interval.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! A module for working with intervals.

use std::fmt::{Display, Formatter, Error};

#[cfg(feature = "wasm")]
use wasm_bindgen::prelude::*;

Expand Down Expand Up @@ -290,8 +292,131 @@ impl HasOctave for Interval {
}
}

impl Display for Interval {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
match self {
Interval::PerfectUnison => write!(f, "PerfectUnison"),
Interval::DiminishedSecond => write!(f, "DiminishedSecond"),

Interval::AugmentedUnison => write!(f, "AugmentedUnison"),
Interval::MinorSecond => write!(f, "MinorSecond"),

Interval::MajorSecond => write!(f, "MajorSecond"),
Interval::DiminishedThird => write!(f, "DiminishedThird"),

Interval::AugmentedSecond => write!(f, "AugmentedSecond"),
Interval::MinorThird => write!(f, "MinorThird"),

Interval::MajorThird => write!(f, "MajorThird"),
Interval::DiminishedFourth => write!(f, "DiminishedFourth"),

Interval::AugmentedThird => write!(f, "AugmentedThird"),
Interval::PerfectFourth => write!(f, "PerfectFourth"),

Interval::AugmentedFourth => write!(f, "AugmentedFourth"),
Interval::DiminishedFifth => write!(f, "DiminishedFifth"),

Interval::PerfectFifth => write!(f, "PerfectFifth"),
Interval::DiminishedSixth => write!(f, "DiminishedSixth"),

Interval::AugmentedFifth => write!(f, "AugmentedFifth"),
Interval::MinorSixth => write!(f, "MinorSixth"),

Interval::MajorSixth => write!(f, "MajorSixth"),
Interval::DiminishedSeventh => write!(f, "DiminishedSeventh"),

Interval::AugmentedSixth => write!(f, "AugmentedSixth"),
Interval::MinorSeventh => write!(f, "MinorSeventh"),

Interval::MajorSeventh => write!(f, "MajorSeventh"),
Interval::DiminishedOctave => write!(f, "DiminishedOctave"),

Interval::AugmentedSeventh => write!(f, "AugmentedSeventh"),
Interval::PerfectOctave => write!(f, "PerfectOctave"),

Interval::MinorNinth => write!(f, "MinorNinth"),
Interval::MajorNinth => write!(f, "MajorNinth"),
Interval::AugmentedNinth => write!(f, "AugmentedNinth"),

Interval::DiminishedEleventh => write!(f, "DiminishedEleventh"),
Interval::PerfectEleventh => write!(f, "PerfectEleventh"),
Interval::AugmentedEleventh => write!(f, "AugmentedEleventh"),

Interval::MinorThirteenth => write!(f, "MinorThirteenth"),
Interval::MajorThirteenth => write!(f, "MajorThirteenth"),
Interval::AugmentedThirteenth => write!(f, "AugmentedThirteenth"),

Interval::PerfectOctaveAndPerfectFifth => write!(f, "PerfectOctaveAndPerfectFifth"),
Interval::TwoPerfectOctaves => write!(f, "TwoPerfectOctaves"),
Interval::TwoPerfectOctavesAndMajorThird => write!(f, "TwoPerfectOctavesAndMajorThird"),
Interval::TwoPerfectOctavesAndPerfectFifth => write!(f, "TwoPerfectOctavesAndPerfectFifth"),
Interval::TwoPerfectOctavesAndMinorSeventh => write!(f, "TwoPerfectOctavesAndMinorSeventh"),
Interval::ThreePerfectOctaves => write!(f, "ThreePerfectOctaves"),
Interval::ThreePerfectOctavesAndMajorSecond => write!(f, "ThreePerfectOctavesAndMajorSecond"),
Interval::ThreePerfectOctavesAndMajorThird => write!(f, "ThreePerfectOctavesAndMajorThird"),
Interval::ThreePerfectOctavesAndAugmentedFourth => write!(f, "ThreePerfectOctavesAndAugmentedFourth"),
Interval::ThreePerfectOctavesAndPerfectFifth => write!(f, "ThreePerfectOctavesAndPerfectFifth"),
Interval::ThreePerfectOctavesAndMinorSixth => write!(f, "ThreePerfectOctavesAndMinorSixth"),
Interval::ThreePerfectOctavesAndMinorSeventh => write!(f, "ThreePerfectOctavesAndMinorSeventh"),
Interval::ThreePerfectOctavesAndMajorSeventh => write!(f, "ThreePerfectOctavesAndMajorSeventh"),
}
}
}

// Statics.

/// All known [`Interval`]s.
pub static ALL_INTERVALS: [Interval; 48] = [
Interval::PerfectUnison,
Interval::DiminishedSecond,
Interval::AugmentedUnison,
Interval::MinorSecond,
Interval::MajorSecond,
Interval::DiminishedThird,
Interval::AugmentedSecond,
Interval::MinorThird,
Interval::MajorThird,
Interval::DiminishedFourth,
Interval::AugmentedThird,
Interval::PerfectFourth,
Interval::AugmentedFourth,
Interval::DiminishedFifth,
Interval::PerfectFifth,
Interval::DiminishedSixth,
Interval::AugmentedFifth,
Interval::MinorSixth,
Interval::MajorSixth,
Interval::DiminishedSeventh,
Interval::AugmentedSixth,
Interval::MinorSeventh,
Interval::MajorSeventh,
Interval::DiminishedOctave,
Interval::AugmentedSeventh,
Interval::PerfectOctave,
Interval::MinorNinth,
Interval::MajorNinth,
Interval::AugmentedNinth,
Interval::DiminishedEleventh,
Interval::PerfectEleventh,
Interval::AugmentedEleventh,
Interval::MinorThirteenth,
Interval::MajorThirteenth,
Interval::AugmentedThirteenth,
Interval::PerfectOctaveAndPerfectFifth,
Interval::TwoPerfectOctaves,
Interval::TwoPerfectOctavesAndMajorThird,
Interval::TwoPerfectOctavesAndPerfectFifth,
Interval::TwoPerfectOctavesAndMinorSeventh,
Interval::ThreePerfectOctaves,
Interval::ThreePerfectOctavesAndMajorSecond,
Interval::ThreePerfectOctavesAndMajorThird,
Interval::ThreePerfectOctavesAndAugmentedFourth,
Interval::ThreePerfectOctavesAndPerfectFifth,
Interval::ThreePerfectOctavesAndMinorSixth,
Interval::ThreePerfectOctavesAndMinorSeventh,
Interval::ThreePerfectOctavesAndMajorSeventh,
];

/// The primary (first 13) harmonic series expressed as [`Interval`]s.
pub static PRIMARY_HARMONIC_SERIES: [Interval; 13] = [
Interval::PerfectOctave,
Expand Down
10 changes: 9 additions & 1 deletion src/core/named_pitch.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A module for working with named pitches.

use std::ops::Add;
use std::ops::{Add, Sub};

use crate::core::{
base::HasStaticName,
Expand Down Expand Up @@ -350,6 +350,14 @@ impl Add<i8> for NamedPitch {
}
}

impl Sub<i8> for NamedPitch {
type Output = Self;

fn sub(self, rhs: i8) -> Self {
self + (-rhs)
}
}

impl From<Pitch> for NamedPitch {
fn from(pitch: Pitch) -> Self {
NamedPitch::from(&pitch)
Expand Down
Loading

0 comments on commit 6ae1825

Please sign in to comment.