npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

chord-engine-core

v0.1.0

Published

Chord detection, MIDI utilities, voicing resolution, and Tone.js playback engines for music applications.

Readme

chord-engine-core

Chord detection, MIDI utilities, voicing resolution, and Tone.js playback engines for music applications.

This package is the standalone logic layer extracted from the Interactive Chord Generator. It has zero UI dependencies — bring your own framework or use it headless.

Install

npm install chord-engine-core tone

tone is a peer dependency and must be installed alongside.

Quick start

import {
  identifyChord,
  buildChordMidi,
  analyzeChord,
  ChordEngine,
  PITCH_CLASSES,
} from "chord-engine-core";

// Identify a chord from numeric pitch classes (0 = C, 4 = E, 7 = G)
identifyChord([0, 4, 7]);   // → "C Major"
identifyChord([9, 0, 4]);   // → "A Minor"

// Build MIDI note array from root + quality
buildChordMidi(0, "Major"); // → [48, 52, 55]
buildChordMidi(2, "Minor"); // → [50, 53, 57]

// Full chord analysis with voicing
const resolved = analyzeChord(["D", "F#", "A"], {
  inversion: 0,
  spread: "close",
  registerShift: "center",
  bassPitchClass: "auto",
});
// → { name: "D", quality: "Major", midiNotes: [50, 54, 57], ... }

// Play a chord through Tone.js
const engine = new ChordEngine();
engine.playChord([60, 64, 67], "piano", 1.5);

API reference

Chord detection

| Function | Signature | Description | |----------|-----------|-------------| | identifyChord | (pitchClasses: number[]) → string | Returns the chord name for a set of numeric pitch classes. | | analyzeChord | (pcs: PitchClass[], voicing: WorkingVoicing) → ResolvedChord | Full analysis: name, quality, intervals, MIDI notes, labels, and colours. | | buildChordDefinition | (pcs: PitchClass[], voicing: WorkingVoicing) → ChordDefinition | Builds a storable chord object with unique ID and timestamp. |

MIDI utilities

| Function | Signature | Description | |----------|-----------|-------------| | buildChordMidi | (root: number, quality: string) → number[] | Generates MIDI note numbers for a root + quality combination. | | pitchClassesToMidi | (pcs: number[]) → number[] | Converts numeric pitch classes to MIDI in octave 4, wrapping as needed. | | midiToPitchClass | (midi: number) → PitchClass | Converts a MIDI note number to its pitch class name. | | midiToLabel | (midi: number) → string | Converts a MIDI number to a human-readable label (e.g. "C4"). | | pitchClassToMidi | (pc: PitchClass, octave?: number) → number | Converts a named pitch class to a MIDI number at a given octave. |

Voicing

| Function | Signature | Description | |----------|-----------|-------------| | resolveChordVoicing | (pcs: PitchClass[], voicing: WorkingVoicing) → ChordVoicing | Applies inversion, spread, register shift, and bass note override to produce final MIDI voicing. | | normalizePitchClasses | (pcs: PitchClass[]) → PitchClass[] | Deduplicates and sorts pitch classes chromatically. | | isBlackKeyPitchClass | (pc: PitchClass) → boolean | Returns true for sharps/flats. |

Progression scheduling

| Function | Signature | Description | |----------|-----------|-------------| | buildProgressionPlayback | (steps: ProgressionStep[]) → ProgressionPlaybackEvent[] | Converts progression steps with beat counts into timed playback events. | | totalProgressionDuration | (events: ProgressionPlaybackEvent[]) → number | Returns the total duration of a progression in seconds. |

Audio engines

ChordEngine

High-level engine for playing chords and progressions with typed instrument presets.

const engine = new ChordEngine();
engine.playChord(midiNotes, "synthPad", 2.0);
engine.playProgression(events, "piano", 120, true); // tempo 120, loop on
engine.stopProgression();

Instrument presets: "piano" | "synthPad" | "guitar" | "strings"

AudioEngine

Lower-level engine with volume control and seven instrument presets.

const engine = new AudioEngine();
await engine.init();
engine.setInstrument("organ");
engine.playChord([60, 64, 67], 1.5);
engine.playProgression(chordArray, 100, onChordCallback);
engine.stopAll();

Instrument presets: "piano" | "strings" | "organ" | "synth" | "guitar" | "brass" | "marimba"

Constants

| Export | Description | |--------|-------------| | PITCH_CLASSES | ["C", "C#", "D", ..., "B"] — all 12 pitch classes | | PITCH_CLASS_TO_SEMITONE | Map from pitch class name to semitone number | | NOTE_COLOR_MAP | Unique hex colour for each pitch class | | INTERVAL_LABELS | Human-readable interval names (unison, minor 2nd, etc.) | | INSTRUMENT_LABELS | Display names for the four instrument presets | | CHORD_TYPES | Array of 16 chord type definitions with intervals | | PRESET_PROGRESSIONS | 8 built-in progressions (Pop, Jazz, Classic, etc.) |

Types

All TypeScript types are exported for use in your own projects:

PitchClass · InstrumentPreset · ChordVoicing · ChordDefinition · ProgressionStep · ProgressionDefinition · WorkingVoicing · ResolvedChord · ProgressionPlaybackEvent

Peer dependencies

| Package | Version | |---------|---------| | tone | ^15.0.0 |

Author

Yehuda Levy

License

CC BY 4.0 — see LICENSE for details.