### Import Scala tuning with scalaTuning Source: https://zachacious.github.io/MusicTheoryJS Imports a Scala tuning file (sclFileText) and shows how to access the number of notes in the scale and the cents for a given degree. ```javascript const tuning = scalaTuning(sclFileText); tuning.size; // number of notes in the scale tuning.centsForDegree(4); // cents above the tonic ``` -------------------------------- ### From chords to a track Source: https://zachacious.github.io/MusicTheoryJS Shows building a track from chords: comped hits over a walking bass, swung, then converting beats exactly to MIDI ticks and writing a real MIDI file. ```javascript import { compProgression, bassline, swing, mergeStreams, sequenceToMidi, writeMidi } from "musictheoryjs"; // A played ii-V-I: comped hits over a walking bass, swung. const comp = compProgression("C major", "ii-V-I", { rhythm: [1, 0, 0, 1, 0, 0, 0, 0] }); const track = mergeStreams(swing(comp), bassline(["Dm7", "G7", "Cmaj7"])); // Beats convert exactly to ticks — straight into a real MIDI file. writeMidi(sequenceToMidi(track, { bpm: 140 })); ``` -------------------------------- ### MIDI and audio without extra packages Source: https://zachacious.github.io/MusicTheoryJS Shows reading and writing Standard MIDI Files with a small byte codec, and detecting pitch from audio samples with a dependency-free DSP layer (monophonic, YIN). ```javascript import { parseMidi, midiToNoteStream, writeMidi, noteStreamToMidi, detectNote } from "musictheoryjs"; // Read a MIDI file, spell its notes, analyze it, write one back const stream = midiToNoteStream(parseMidi(midiBytes)); const bytes = writeMidi(noteStreamToMidi(stream, { tempo: 500000 })); // Detect a pitch from audio samples you already have detectNote(float32Samples, 44100)?.toString(); // "A4" (monophonic, YIN) ``` -------------------------------- ### Scales, modes, and detection Source: https://zachacious.github.io/MusicTheoryJS Demonstrates creating a scale from a tonic and mode name, extracting a mode from a scale, and detecting scales from a set of notes. The comments show the tonic of the sixth mode of C major and the detected scale names. ```javascript Scale.from("D4", "dorian").noteNames(); mode(Scale.from("C4", "major"), 6).tonic.toString(); // "A4" detectScales(["C4","D4","E4","G4","A4"]); // major pentatonic, … ``` -------------------------------- ### Create scales, chords, and progressions with musictheoryjs Source: https://zachacious.github.io/MusicTheoryJS Shows the core v3 API for creating a major scale, a Cmaj7 chord, and a Roman-numeral progression, each returning note names or chord symbols. The output comments show the expected results for each call. ```javascript import { Note, Scale, Chord, Key } from "musictheoryjs"; Scale.from("C4", "major").noteNames(); // ["C4", "D4", "E4", "F4", "G4", "A4", "B4"] Chord.from("Cmaj7").noteNames(); // ["C4", "E4", "G4", "B4"] Key.major("C").progression("ii7 V7 Imaj7").map(String); // ["Dm7", "G7", "Cmaj7"] ``` -------------------------------- ### Tunings beyond 12-TET Source: https://zachacious.github.io/MusicTheoryJS Shows how to use tunings beyond 12-TET: equal temperament of any size, just intonation, and a maqam defined in cents. The default is 12-TET, but it is not wired into the core. ```javascript import { equalTemperament, centsTuning, justIntonation, scaleFromTuning, frequencyOfNote, Note } from "musictheoryjs"; frequencyOfNote(new Note("A4")); // 440 (12-TET default) frequencyOfNote(new Note("E4"), justIntonation()); // pure third above C // 24 equal divisions of the octave — quarter tones scaleFromTuning(equalTemperament(24)); // A maqam Rast defined in cents, anchored to a real frequency const rast = centsTuning([0, 204, 355, 498, 702, 906, 1057], { name: "Rast" }); scaleFromTuning(rast, { frequency: 264 }, true); ``` -------------------------------- ### Key detection and harmonic analysis Source: https://zachacious.github.io/MusicTheoryJS Shows key detection with the Krumhansl–Schmuckler algorithm and harmonic analysis that segments a timed note stream into a chord timeline, labels Roman numerals, and marks cadences. ```javascript import { detectKey, analyzeHarmony } from "musictheoryjs"; detectKey(["C4", "E4", "G4"])[0].key.toString(); // "C major" // From a stream of timed notes (MIDI, a sequencer, a transcriber you supply): const { key, timeline, cadences } = analyzeHarmony(noteStream); // key: C major // timeline: [{ …, roman: "ii" }, { …, roman: "V" }, { …, roman: "I" }] // cadences: [{ type: "authentic", index: 1 }] ``` -------------------------------- ### Roman numerals with Key.major Source: https://zachacious.github.io/MusicTheoryJS Shows how to work with Roman numerals in the key of C major: converting a chord to its Roman numeral, converting a Roman numeral to a chord, and generating a chord progression. The comments show the expected results. ```javascript Key.major("C").romanNumeral(Chord.from("G7")); // "V7" Key.major("C").chordFromRoman("bVII"); // Bb Key.major("C").progression("ii7 V7 Imaj7"); // [Dm7, G7, Cmaj7] ``` -------------------------------- ### Drop-2 voicing with drop2 Source: https://zachacious.github.io/MusicTheoryJS Applies a drop-2 voicing to a Cmaj7 chord and converts the resulting notes to strings. The comment shows the expected voicing. ```javascript drop2(Chord.from("Cmaj7")).map(String); // ["G3", "C4", "E4", "B4"] ``` -------------------------------- ### Detect chord from notes with detectChord Source: https://zachacious.github.io/MusicTheoryJS Uses the detectChord function to identify a chord from an array of note names. The optional chaining (?.) is used because the function may return null or undefined; the comments show the detected chord names. ```javascript detectChord(["G4", "B4", "D5", "F5"])?.toString(); // "G7" detectChord(["C4", "Eb4", "Gb4", "A4"])?.toString(); // "Cdim7" ``` -------------------------------- ### Pitch class loses spelling Source: https://zachacious.github.io/MusicTheoryJS Shows that a bare pitch class (0–11) loses the spelling, so you cannot tell whether it is F, E#, or Gbb. ```javascript // A note stored as a number 0–11 const pitchClass = 5; // is this F? or E#? or Gbb? // You can't tell. The spelling is gone. ``` -------------------------------- ### Interval spelling with intervalTo and intervalName Source: https://zachacious.github.io/MusicTheoryJS Shows how intervals preserve their spelling: the interval from C4 to Fb4 is a diminished fourth, and intervalName returns "d4" rather than the enharmonically equivalent "M3". ```javascript new Note("C4").intervalTo("Fb4"); // diminished fourth intervalName(interval(4, "d")); // "d4" (not "M3") ``` -------------------------------- ### Note keeps spelling Source: https://zachacious.github.io/MusicTheoryJS Shows that Note keeps the letter and accidental apart, so transposition and naming stay correct (e.g., E#4 transposed by a major third gives G##4, not A4). ```javascript const eSharp = new Note("E#4"); eSharp.letter; // "E" eSharp.pitchClass; // 5 eSharp.transpose(interval(3, "M")).toString(); // "G##4", not "A4" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.