@scorelabs/core
v1.1.0
Published
Core logic and models for ScoreLabs music notation
Readme
@scorelabs/core
Core logic and models for ScoreLabs music notation and processing. This package provides the foundational data structures and algorithms used across the ScoreLabs ecosystem, including the Note and NoteSet models, instrument definitions, and MusicXML importing capabilities.
Installation
npm install @scorelabs/coreFeatures
- Comprehensive Music Models: Strongly typed classes for
Score,Part,Staff,Measure,NoteSet,Note,Pitch, and more. - MusicXML Import: Robust
MusicXMLParserto convert MusicXML files into ScoreLabs models. - Type Safety: Written in TypeScript with complete type definitions.
- Modular Architecture: Designed to be platform-agnostic (Node.js and Browser).
Usage
Importing a MusicXML File
import { MusicXMLParser } from '@scorelabs/core';
// Assuming you have the XML content as a string
const xmlContent = `<?xml version="1.0" ... >`;
const parser = new MusicXMLParser();
const score = parser.parse(xmlContent);
console.log(`Score Title: ${score.title}`);
console.log(`Number of Parts: ${score.parts.length}`);Working with Notes and NoteSets
The core model uses NoteSet to represent a collection of notes at a specific point data (e.g., a chord or a single note).
import { Duration, Note, NoteSet, Pitch } from '@scorelabs/core';
// Create a C4 quarter note
const c4 = new Note(new Pitch('C', 4), Duration.Quarter);
const noteSet = new NoteSet([c4]);
// Transpose up a whole step
const d4Set = noteSet.transpose(2);
console.log(d4Set.pitch.toString()); // "D4"Architecture
The library is organized into two main modules:
models/: Contains the data structures representing musical elements.Score: The root object representing a musical piece.Part: Represents a single instrument or voice within a score.Staff: A collection of measures for a specific part.Measure: Contains musical events like notes, rests, and directions.NoteSet: A grouping of simultaneousNoteobjects (chords).Note: The fundamental musical unit containing pitch, duration, and stylistic attributes.
importers/: logic for importing external formats.MusicXMLParser: Converts MusicXML data into the internal object model.
Development
- Clone the repository
- Install dependencies:
npm install - Build:
npm run build
License
MIT
