kord
A music theory binary and library for Rust / JS (via WASM) (capability playground).
Note: The
kord-webdirectory contains a web application that serves as a demonstration and example of how to integrate the Kord library with modern web frameworks. It is not part of the core library but showcases the library's WASM capabilities in a real-world web application (and it is the example website linked above).
Binary Usage
Install
Windows:
$ iwr https://github.com/twitchax/kord/releases/latest/download/kord_x86_64-pc-windows-gnu.zip
$ Expand-Archive kord_x86_64-pc-windows-gnu.zip -DestinationPath C:\Users\%USERNAME%\AppData\Local\Programs\kord
Mac OS (Apple Silicon):
Linux:
Cargo:
NPM:
WebAssembly (via OCI Registry)
Run directly from GitHub Container Registry using any WASI-compatible runtime. This has a reduced capability set (no audio input / output), but works well for core use cases.
With Wasmtime:
With wkg (WebAssembly Package Manager):
Help Docs
)
)
Describe A Chord
Describe A Scale
The describe command automatically detects scales:
Describe A Mode
Modes are also auto-detected:
You can also force interpretation with --type:
Play A Chord
)()
Loop Through Chord Changes
Guess A Chord
)
)()
)()
)()
)()
Guess Notes / Chord From Audio
Using the deterministic algorithm only:
Using the ML algorithm:
Library Usage
Add this to your Cargo.toml:
[]
= "*" #choose a version
Examples
use KnownChord;
use Degree;
use *;
use *;
// Check to see what _kind_ of chord this is.
assert_eq!;
use Parsable;
use *;
use *;
// Parse a chord from a string, and inspect the scale.
assert_eq!;
use *;
use *;
// From a note, create a chord, and look at the chord tones.
assert_eq!;
use Parsable;
use Notation;
// Parse any notation type (chord, scale, or mode) automatically.
let scale = parse.unwrap;
assert!;
let mode = parse.unwrap;
assert!;
let chord = parse.unwrap;
assert!;
JS Usage
The npm package is available here.
First, load the module as you would any other ES module.
import init from 'kordweb/klib.js';
// Run `init` once.
await ;
Then, you can use the library similarly as you would in Rust.
// Create a note.
const note = ;
note.; // C4
note.; // 4
// Create a chord.
const chord = ;
chord.; // C7(♯9)
chord.; // C4 E4 G4 Bb5 D#5
// Easy chaining.
...; // [ 'C2', 'D♭2', 'E2', 'G2', 'B♭2' ]
// Build chords.
....; // [ 'C4', 'Eb4', 'G4', 'Bb4' ]
Feature Flags
The library and binary both support various feature flags. Of most important note are:
default = ["cli", "analyze", "audio", "ml_infer", "ml_loader_mel", "ml_target_folded", "ml_train_precision_fp32", "ml_store_precision_half"]cli: enables the CLI features, and can be removed if only compiling the library.analyze = ["analyze_mic", "analyze_file"]: enables theanalyzesubcommand, which allows for analyzing audio data (and the underlying library features).analyze_mic: enables theanalyze micsubcommand, which allows for analyzing audio from a microphone (and the underlying library features).analyze_file: enables theanalyze filesubcommand, which allows for analyzing audio from a file (and the underlying library features).analyze_file_mp3: enables the features to analyze mp3 files.analyze_file_aac: enables the features to analyze aac files.analyze_file_alac: enables the features to analyze alac files.
ml = ["ml_train", "ml_infer"]: enables themlsubcommand, which allows for training and inferring with ML (and the underlying library features).ml_train: enables theml trainsubcommand, which allows for training ML models (and the underlying library features).ml_infer: enables theml infersubcommand, which allows for inferring with ML models (and the underlying library features).-
NOTE: Adding the
analyze_micfeature flag will enable theml infer micsubcommand, which allows for inferring with ML models from a microphone. -
NOTE: Adding the
analyze_filefeature flag will enable theml infer filesubcommand, which allows for inferring with ML models from a file.
-
ml_gpu: enables the features to use a GPU for ML training.ml_sample_gather: enables theml gathersubcommand for capturing raw samples from a microphone (requiresanalyze_mic).ml_hpt: enables theml hptsubcommand for sweeping hyperparameters (impliesml_train).
ml_sample_process: enables theml processsubcommand for generating samples from aligned MIDI and audio files (WAV or FLAC), naming each emitted sample with its originating measure index, rounded duration (in seconds), and chord tones.wasm: enables the features to compile to wasm.plot: enables the features to plot data.
For detailed ML training configuration options (loaders, targets, precision settings), see the ML Training Configuration section in DEVELOPMENT.md.
Development
For detailed development instructions, see DEVELOPMENT.md.
Test
Docker
Build:
Run:
Fly.io Deployment
This assumes there is a fly.toml file in the .hidden directory.
License
MIT