kordweb 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Aaron Roney
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,224 @@
1
+ [![Build and Test](https://github.com/twitchax/kord/actions/workflows/build.yml/badge.svg)](https://github.com/twitchax/kord/actions/workflows/build.yml)
2
+ [![codecov](https://codecov.io/gh/twitchax/kord/branch/main/graph/badge.svg?token=35MZN0YFZF)](https://codecov.io/gh/twitchax/kord)
3
+ [![Version](https://img.shields.io/crates/v/kord.svg)](https://crates.io/crates/kord)
4
+ [![Downloads](https://img.shields.io/crates/d/kord.svg)](https://crates.io/crates/kord)
5
+ [![GitHub all releases](https://img.shields.io/github/downloads/twitchax/kord/total?label=binary)](https://github.com/twitchax/kord/releases)
6
+ [![Documentation](https://docs.rs/kord/badge.svg)](https://docs.rs/kord)
7
+ [![Rust](https://img.shields.io/badge/rust-nightly-blue.svg?maxAge=3600)](https://github.com/twitchax/kord)
8
+ [![License:MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+
10
+ # kord
11
+
12
+ A music theory binary and library for Rust ([capability playground](https://kord.twitchax.com/)).
13
+
14
+ ## Binary Usage
15
+
16
+ ### Install
17
+
18
+ Windows:
19
+
20
+ ```powershell
21
+ iwr https://github.com/twitchax/kord/releases/latest/download/kord_x86_64-pc-windows-gnu.zip
22
+ Expand-Archive kord_x86_64-pc-windows-gnu.zip -DestinationPath C:\Users\%USERNAME%\AppData\Local\Programs\kord
23
+ ```
24
+
25
+ Mac OS (Apple Silicon):
26
+
27
+ ```bash
28
+ curl -LO https://github.com/twitchax/kord/releases/latest/download/kord_aarch64-apple-darwin.zip
29
+ unzip kord_aarch64-apple-darwin.zip -d /usr/local/bin
30
+ chmod a+x /usr/local/bin/kord
31
+ ```
32
+
33
+ Linux:
34
+
35
+ ```bash
36
+ curl -LO https://github.com/twitchax/kord/releases/latest/download/kord_x86_64-unknown-linux-gnu.zip
37
+ unzip kord_x86_64-unknown-linux-gnu.zip -d /usr/local/bin
38
+ chmod a+x /usr/local/bin/kord
39
+ ```
40
+
41
+ Cargo:
42
+
43
+ ```bash
44
+ $ cargo install kord
45
+ ```
46
+
47
+ ### Help Docs
48
+
49
+ ```bash
50
+ $ kord -h
51
+
52
+ A tool to easily explore music theory principles.
53
+
54
+ Usage: kord.exe [COMMAND]
55
+
56
+ Commands:
57
+ describe Describes a chord
58
+ play Describes and plays a chord
59
+ loop Loops on a set of chord changes, while simultaneously outputting the descriptions
60
+ guess Attempt to guess the chord from a set of notes (ordered by simplicity)
61
+ analyze Set of commands to analyze audio data
62
+ ml Set of commands to train and infer with ML
63
+ help Print this message or the help of the given subcommand(s)
64
+
65
+ Options:
66
+ -h, --help Print help information
67
+ -V, --version Print version information
68
+ ```
69
+
70
+ ### Describe A Chord
71
+
72
+ ```bash
73
+ $ kord describe Cmaj7
74
+
75
+ Cmaj7
76
+ major 7, ionian, first mode of major scale
77
+ C, D, E, F, G, A, B
78
+ C, E, G, B
79
+ ```
80
+
81
+ ### Play A Chord
82
+
83
+ ```bash
84
+ $ kord play Bb7#9#11
85
+
86
+ B♭7(♯9)(♯11)
87
+ dominant sharp 9, altered, altered dominant, super locrian, diminished whole tone, seventh mode of a melodic minor scale, melodic minor up a half step
88
+ B♭, C♭, D♭, E𝄫, F♭, G♭, A♭
89
+ B♭, D, F, A♭, C♯, E
90
+ ```
91
+
92
+ ### Loop Through Chord Changes
93
+
94
+ ```bash
95
+ $ kord loop -b 120 "Em7b5@3^2" "A7b13@3!" "D-maj7@3^2" "G7@3" "Cmaj7@3^2"
96
+ ```
97
+
98
+ ### Guess A Chord
99
+
100
+ ```bash
101
+ $ kord guess C F# D# A
102
+ Cdim
103
+ fully diminished (whole first), diminished seventh, whole/half/whole diminished
104
+ C, D, E♭, F, G♭, A♭, B𝄫, B
105
+ C, E♭, G♭, B𝄫
106
+ Cm(♭5)(add6)
107
+ minor
108
+ C, D, E♭, F, G, A♭, B♭
109
+ C, E♭, G♭, A
110
+ ```
111
+
112
+ ```bash
113
+ $ kord guess C G Bb F#5 F
114
+ C7(♯11)(sus4)
115
+ dominant sharp 11, lydian dominant, lyxian, major with sharp four and flat seven
116
+ C, D, E, F♯, G, A, B♭
117
+ C, F, G, B♭, F♯
118
+ Cm7(♯11)(sus4)
119
+ minor 7, dorian, second mode of major scale, major with flat third and flat seven
120
+ C, D, E♭, F, G, A, B♭
121
+ C, F, G, B♭, F♯
122
+ ```
123
+
124
+ ```bash
125
+ $ kord guess E3 C4 Eb4 F#4 A#4 D5 D4
126
+ Cm9(♭5)(add2)/E
127
+ half diminished, locrian, minor seven flat five, seventh mode of major scale, major scale starting one half step up
128
+ C, D, E♭, F, G♭, A♭, B♭
129
+ E, C, D, E♭, G♭, B♭, D
130
+ ```
131
+
132
+ ### Guess Notes / Chord From Audio
133
+
134
+ Using the deterministic algorithm only:
135
+
136
+ ```bash
137
+ $ kord analyze mic
138
+
139
+ Notes: C3 E3 G3
140
+ C@3
141
+ major
142
+ C, D, E, F, G, A, B
143
+ C, E, G
144
+ ```
145
+
146
+ Using the ML algorithm:
147
+
148
+ ```bash
149
+ $ kord ml infer mic
150
+
151
+ Notes: C3 E3 G3
152
+ C@3
153
+ major
154
+ C, D, E, F, G, A, B
155
+ C, E, G
156
+ ```
157
+
158
+ ## Library Usage
159
+
160
+ Add this to your `Cargo.toml`:
161
+
162
+ ```toml
163
+ [dependencies]
164
+ kord = "*" #choose a version
165
+ ```
166
+
167
+ ### Examples
168
+
169
+ ```rust
170
+ use klib::known_chord::KnownChord;
171
+ use klib::modifier::Degree;
172
+ use klib::note::*;
173
+ use klib::chord::*;
174
+
175
+ // Check to see what _kind_ of chord this is.
176
+ assert_eq!(Chord::new(C).augmented().seven().known_chord(), KnownChord::AugmentedDominant(Degree::Seven));
177
+ ```
178
+
179
+ ```rust
180
+ use crate::klib::base::Parsable;
181
+ use klib::note::*;
182
+ use klib::chord::*;
183
+
184
+ // Parse a chord from a string, and inspect the scale.
185
+ assert_eq!(Chord::parse("Cm7b5").unwrap().scale(), vec![C, D, EFlat, F, GFlat, AFlat, BFlat]);
186
+ ```
187
+
188
+ ```rust
189
+ use klib::note::*;
190
+ use klib::chord::*;
191
+
192
+ // From a note, create a chord, and look at the chord tones.
193
+ assert_eq!(C.into_chord().augmented().major7().chord(), vec![C, E, GSharp, B]);
194
+ ```
195
+
196
+ ## Feature Flags
197
+
198
+ The library and binary both support various feature flags. Of most important note are:
199
+ * `default = ["cli", "analyze", "audio"]`
200
+ * `cli`: enables the CLI features, and can be removed if only compiling the library.
201
+ * `analyze = ["analyze_mic", "analyze_file"]`: enables the `analyze` subcommand, which allows for analyzing audio data (and the underlying library features).
202
+ * `analyze_mic`: enables the `analyze mic` subcommand, which allows for analyzing audio from a microphone (and the underlying library features).
203
+ * `analyze_file`: enables the `analyze file` subcommand, which allows for analyzing audio from a file (and the underlying library features).
204
+ * `analyze_file_mp3`: enables the features to analyze mp3 files.
205
+ * `analyze_file_aac`: enables the features to analyze aac files.
206
+ * `analyze_file_alac`: enables the features to analyze alac files.
207
+ * `ml = ["ml_train", "ml_infer"]`: enables the `ml` subcommand, which allows for training and inferring with ML (and the underlying library features).
208
+ * `ml_train`: enables the `ml train` subcommand, which allows for training ML models (and the underlying library features).
209
+ * `ml_infer`: enables the `ml infer` subcommand, which allows for inferring with ML models (and the underlying library features).
210
+ * > NOTE: Adding the `analyze_mic` feature flag will enable the `ml infer mic` subcommand, which allows for inferring with ML models from a microphone.
211
+ * > NOTE: Adding the `analyze_file` feature flag will enable the `ml infer file` subcommand, which allows for inferring with ML models from a file.
212
+ * `ml_gpu`: enables the features to use a GPU for ML _training_.
213
+ * `wasm`: enables the features to compile to wasm.
214
+ * `plot`: enables the features to plot data.
215
+
216
+ ## Test
217
+
218
+ ```bash
219
+ cargo test
220
+ ```
221
+
222
+ ## License
223
+
224
+ MIT
package/klib.d.ts ADDED
@@ -0,0 +1,254 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * The [`Chord`] wrapper.
5
+ */
6
+ export class KordChord {
7
+ free(): void;
8
+ /**
9
+ * Creates a new [`Chord`] from a frequency.
10
+ * @param {string} name
11
+ * @returns {KordChord}
12
+ */
13
+ static parse(name: string): KordChord;
14
+ /**
15
+ * Creates a new [`Chord`] from a set of [`Note`]s.
16
+ *
17
+ * The [`Note`]s should be represented as a space-separated string.
18
+ * E.g., `C E G`.
19
+ * @param {string} notes
20
+ * @returns {KordChords}
21
+ */
22
+ static from_notes_string(notes: string): KordChords;
23
+ /**
24
+ * Creates a new [`Chord`] from a set of [`Note`]s.
25
+ * @param {KordNotes} notes
26
+ * @returns {KordChords}
27
+ */
28
+ static from_notes(notes: KordNotes): KordChords;
29
+ /**
30
+ * Returns the [`Chord`]'s friendly name.
31
+ * @returns {string}
32
+ */
33
+ name(): string;
34
+ /**
35
+ * Returns the [`Chord`]'s precise name.
36
+ * @returns {string}
37
+ */
38
+ precise_name(): string;
39
+ /**
40
+ * Returns the [`Chord`]'s description.
41
+ * @returns {string}
42
+ */
43
+ description(): string;
44
+ /**
45
+ * Returns the [`Chord`]'s display text.
46
+ * @returns {string}
47
+ */
48
+ display(): string;
49
+ /**
50
+ * Returns the [`Chord`]'s root note.
51
+ * @returns {string}
52
+ */
53
+ root(): string;
54
+ /**
55
+ * Returns the [`Chord`]'s slash note.
56
+ * @returns {string}
57
+ */
58
+ slash(): string;
59
+ /**
60
+ * Returns the [`Chord`]'s inversion.
61
+ * @returns {number}
62
+ */
63
+ inversion(): number;
64
+ /**
65
+ * Returns whether or not the [`Chord`] is "crunchy".
66
+ * @returns {boolean}
67
+ */
68
+ is_crunchy(): boolean;
69
+ /**
70
+ * Returns the [`Chord`]'s chord tones.
71
+ * @returns {KordNotes}
72
+ */
73
+ chord(): KordNotes;
74
+ /**
75
+ * Returns the [`Chord`]'s chord tones as a string.
76
+ * @returns {string}
77
+ */
78
+ chord_string(): string;
79
+ /**
80
+ * Returns the [`Chord`]'s scale tones.
81
+ * @returns {KordNotes}
82
+ */
83
+ scale(): KordNotes;
84
+ /**
85
+ * Returns the [`Chord`]'s scale tones as a string.
86
+ * @returns {string}
87
+ */
88
+ scale_string(): string;
89
+ /**
90
+ * Plays the [`Chord`].
91
+ * @param {number} delay
92
+ * @param {number} length
93
+ * @param {number} fade_in
94
+ * @returns {Promise<void>}
95
+ */
96
+ play(delay: number, length: number, fade_in: number): Promise<void>;
97
+ }
98
+ /**
99
+ * The [`Chord`]s wrapper.
100
+ */
101
+ export class KordChords {
102
+ free(): void;
103
+ /**
104
+ * Gets an item from the collection.
105
+ * @param {number} index
106
+ * @returns {KordChord | undefined}
107
+ */
108
+ get(index: number): KordChord | undefined;
109
+ /**
110
+ * Returns the [`Chord`]s as a space-separated string.
111
+ * @returns {string}
112
+ */
113
+ to_string(): string;
114
+ /**
115
+ * Returns the number of items in the collection.
116
+ */
117
+ readonly length: number;
118
+ }
119
+ /**
120
+ * The [`Note`] wrapper.
121
+ */
122
+ export class KordNote {
123
+ free(): void;
124
+ /**
125
+ * Creates a new [`Note`] from a frequency.
126
+ * @param {string} name
127
+ * @returns {KordNote}
128
+ */
129
+ static parse(name: string): KordNote;
130
+ /**
131
+ * Returns [`Note`]s from audio data.
132
+ * @param {Float32Array} data
133
+ * @param {number} length_in_seconds
134
+ * @returns {KordNotes}
135
+ */
136
+ static from_audio(data: Float32Array, length_in_seconds: number): KordNotes;
137
+ /**
138
+ * Returns [`Note`]s from audio data using the ML inference algorithm.
139
+ * @param {Float32Array} data
140
+ * @param {number} length_in_seconds
141
+ * @returns {KordNotes}
142
+ */
143
+ static from_audio_ml(data: Float32Array, length_in_seconds: number): KordNotes;
144
+ /**
145
+ * Returns the [`Note`]'s friendly name.
146
+ * @returns {string}
147
+ */
148
+ name(): string;
149
+ /**
150
+ * Returns the [`Note`]'s [`NamedPitch`].
151
+ * @returns {string}
152
+ */
153
+ pitch(): string;
154
+ /**
155
+ * Returns the [`Note`]'s [`Octave`].
156
+ * @returns {number}
157
+ */
158
+ octave(): number;
159
+ /**
160
+ * Returns the [`Note`]'s frequency.
161
+ * @returns {number}
162
+ */
163
+ frequency(): number;
164
+ }
165
+ /**
166
+ * The [`Note`]s wrapper.
167
+ */
168
+ export class KordNotes {
169
+ free(): void;
170
+ /**
171
+ * Gets an item from the collection.
172
+ * @param {number} index
173
+ * @returns {KordNote | undefined}
174
+ */
175
+ get(index: number): KordNote | undefined;
176
+ /**
177
+ * Returns the [`Note`]s as a space-separated string.
178
+ * @returns {string}
179
+ */
180
+ to_string(): string;
181
+ /**
182
+ * Returns the number of items in the collection.
183
+ */
184
+ readonly length: number;
185
+ }
186
+
187
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
188
+
189
+ export interface InitOutput {
190
+ readonly memory: WebAssembly.Memory;
191
+ readonly __wbg_kordnote_free: (a: number) => void;
192
+ readonly kordnote_parse: (a: number, b: number, c: number) => void;
193
+ readonly kordnote_from_audio: (a: number, b: number, c: number, d: number) => void;
194
+ readonly kordnote_from_audio_ml: (a: number, b: number, c: number, d: number) => void;
195
+ readonly kordnote_name: (a: number, b: number) => void;
196
+ readonly kordnote_pitch: (a: number, b: number) => void;
197
+ readonly kordnote_octave: (a: number) => number;
198
+ readonly kordnote_frequency: (a: number) => number;
199
+ readonly __wbg_kordnotes_free: (a: number) => void;
200
+ readonly kordnotes_get: (a: number, b: number) => number;
201
+ readonly kordnotes_to_string: (a: number, b: number) => void;
202
+ readonly __wbg_kordchord_free: (a: number) => void;
203
+ readonly kordchord_parse: (a: number, b: number, c: number) => void;
204
+ readonly kordchord_from_notes_string: (a: number, b: number, c: number) => void;
205
+ readonly kordchord_from_notes: (a: number, b: number) => void;
206
+ readonly kordchord_name: (a: number, b: number) => void;
207
+ readonly kordchord_precise_name: (a: number, b: number) => void;
208
+ readonly kordchord_description: (a: number, b: number) => void;
209
+ readonly kordchord_display: (a: number, b: number) => void;
210
+ readonly kordchord_root: (a: number, b: number) => void;
211
+ readonly kordchord_slash: (a: number, b: number) => void;
212
+ readonly kordchord_inversion: (a: number) => number;
213
+ readonly kordchord_is_crunchy: (a: number) => number;
214
+ readonly kordchord_chord: (a: number) => number;
215
+ readonly kordchord_chord_string: (a: number, b: number) => void;
216
+ readonly kordchord_scale: (a: number) => number;
217
+ readonly kordchord_scale_string: (a: number, b: number) => void;
218
+ readonly kordchord_play: (a: number, b: number, c: number, d: number) => number;
219
+ readonly __wbg_kordchords_free: (a: number) => void;
220
+ readonly kordchords_get: (a: number, b: number) => number;
221
+ readonly kordchords_length: (a: number) => number;
222
+ readonly kordchords_to_string: (a: number, b: number) => void;
223
+ readonly kordnotes_length: (a: number) => number;
224
+ readonly __wbindgen_malloc: (a: number) => number;
225
+ readonly __wbindgen_realloc: (a: number, b: number, c: number) => number;
226
+ readonly __wbindgen_export_2: WebAssembly.Table;
227
+ readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h747aa41a80ad2697: (a: number, b: number, c: number) => void;
228
+ readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__heeae151cfd26f044: (a: number, b: number) => void;
229
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
230
+ readonly __wbindgen_free: (a: number, b: number) => void;
231
+ readonly __wbindgen_exn_store: (a: number) => void;
232
+ readonly wasm_bindgen__convert__closures__invoke2_mut__h768f6593dd414d73: (a: number, b: number, c: number, d: number) => void;
233
+ }
234
+
235
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
236
+ /**
237
+ * Instantiates the given `module`, which can either be bytes or
238
+ * a precompiled `WebAssembly.Module`.
239
+ *
240
+ * @param {SyncInitInput} module
241
+ *
242
+ * @returns {InitOutput}
243
+ */
244
+ export function initSync(module: SyncInitInput): InitOutput;
245
+
246
+ /**
247
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
248
+ * for everything else, calls `WebAssembly.instantiate` directly.
249
+ *
250
+ * @param {InitInput | Promise<InitInput>} module_or_path
251
+ *
252
+ * @returns {Promise<InitOutput>}
253
+ */
254
+ export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;