#music #music-theory

bin+lib rust-music-theory

A library that procedurally implements music theory notions like Scale, Chord, Interval, Note

9 releases

0.2.0 Aug 19, 2020
0.1.7 May 3, 2020
0.1.6 Jan 25, 2020

#131 in Audio

Download history 4/week @ 2021-05-23 2/week @ 2021-05-30 13/week @ 2021-06-06 4/week @ 2021-06-13 3/week @ 2021-06-20 2/week @ 2021-06-27 4/week @ 2021-07-04 3/week @ 2021-07-11 10/week @ 2021-07-18 13/week @ 2021-07-25 22/week @ 2021-08-01 3/week @ 2021-08-08 14/week @ 2021-08-15 3/week @ 2021-08-22 2/week @ 2021-09-05

67 downloads per month
Used in usfx

MIT license

41KB
974 lines

Rust Music Theory

Build Status Coverage Status Crates.io Documentation

A library and executable that provides programmatic implementation of the basis of the music theory.

Table of Contents

Overview

Rust Music Theory is used to procedurally utilize music theory notions like Note, Chord, Scale, Interval and more. The main purpose of this library is to let music theory be used in other programs and produce music/audio in a programmatic way.

Usage as a Library

Add rust-music-theory as a dependency in your Cargo.toml.

[dependencies]
rust-music-theory = "0.2"

After installing the dependencies, you can use the library as follows.

extern crate rust_music_theory as rustmt;
use rustmt::note::{Note, Notes, PitchClass};
use rustmt::scale::{Scale, ScaleType, Mode, Direction};
use rustmt::chord::{Chord, Number as ChordNumber, Quality as ChordQuality};

// to create a Note, specify a pitch class and an octave;
let note = Note::new(PitchClass::As, 4);

// Scale Example;
let scale = Scale::new(
    ScaleType::Diatonic,    // scale type
    PitchClass::C,          // tonic
    4,                      // octave
    Some(Mode::Ionian),     // scale mode
    Direction::Ascending,   // scale direction
).unwrap();

// returns a Vector of the Notes of the scale
let scale_notes = scale.notes();

// Chord Example;
let chord = Chord::new(PitchClass::C, ChordQuality::Major, ChordNumber::Triad);

// returns a Vector of the Notes of the chord
let chord_notes = chord.notes();

This is the simplest form of the usage. For detailed examples, please see the tests folder.

Usage as an Executable

cargo install --git https://github.com/ozankasikci/rust-music-theory

This lets cargo install the library as an executable called rustmt. Some usage examples;

rustmt scale D Locrian

Notes:
  1: D
  2: D#
  3: F
  4: G
  5: G#
  6: A#
  7: C
  8: D

rustmt chord C# Dominant Eleventh

Notes:
  1: C#
  2: F
  3: G#
  4: B
  5: D#
  6: G

rustmt scale list

Available Scales:
 - Major|Ionian
 - Minor|Aeolian
 - Dorian
 - Phrygian
 - Lydian
 - Mixolydian
 - Locrian
 - Harmonic Minor
 - Melodic Minor

rustmt chord list

Available chords:
 - 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

Building From Source

The binary is implemented as a regex parser cli that returns the notes of the given scale/chord. To quickly build and run the executable locally;

git clone http://github.com/ozankasikci/rust-music-theory && cd rust-music-theory

Then you can directly compile using cargo. An example;

cargo run scale D Locrian

Notes:
  1: D
  2: D#
  3: F
  4: G
  5: G#
  6: A#
  7: C
  8: D

Roadmap

  • Add missing modes for Melodic & Harmonic minor scales
    • Add support for arbitrary accidentals
    • Add support for the alternative names of the modes to regex parser
  • Properly display enharmonic spelling
  • Add inversion support for chords
  • Add support for cadences
  • Add a mechanism to find the chord from the given notes

Dependencies

~2.5–3.5MB
~77K SLoC