UNPKG

@tonaljs/range

Version:

Create (musical) note ranges

54 lines (53 loc) 1.86 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // index.ts var index_exports = {}; __export(index_exports, { chromatic: () => chromatic, default: () => index_default, numeric: () => numeric }); module.exports = __toCommonJS(index_exports); var import_collection = require("@tonaljs/collection"); var import_midi = require("@tonaljs/midi"); function numeric(notes) { const midi = (0, import_collection.compact)( notes.map((note) => typeof note === "number" ? note : (0, import_midi.toMidi)(note)) ); if (!notes.length || midi.length !== notes.length) { return []; } return midi.reduce( (result, note) => { const last = result[result.length - 1]; return result.concat((0, import_collection.range)(last, note).slice(1)); }, [midi[0]] ); } function chromatic(notes, options) { return numeric(notes).map((midi) => (0, import_midi.midiToNoteName)(midi, options)); } var index_default = { numeric, chromatic }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { chromatic, numeric }); //# sourceMappingURL=index.js.map