@scorelabs/core 1.0.1 → 1.0.2
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/README.md +73 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @scorelabs/core
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @scorelabs/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Comprehensive Music Models**: Strongly typed classes for `Score`, `Part`, `Staff`, `Measure`, `NoteSet`, `Note`, `Pitch`, and more.
|
|
14
|
+
- **MusicXML Import**: Robust `MusicXMLParser` to convert MusicXML files into ScoreLabs models.
|
|
15
|
+
- **Type Safety**: Written in TypeScript with complete type definitions.
|
|
16
|
+
- **Modular Architecture**: Designed to be platform-agnostic (Node.js and Browser).
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Importing a MusicXML File
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { MusicXMLParser } from '@scorelabs/core';
|
|
24
|
+
|
|
25
|
+
// Assuming you have the XML content as a string
|
|
26
|
+
const xmlContent = `<?xml version="1.0" ... >`;
|
|
27
|
+
const parser = new MusicXMLParser();
|
|
28
|
+
const score = parser.parse(xmlContent);
|
|
29
|
+
|
|
30
|
+
console.log(`Score Title: ${score.title}`);
|
|
31
|
+
console.log(`Number of Parts: ${score.parts.length}`);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Working with Notes and NoteSets
|
|
35
|
+
|
|
36
|
+
The core model uses `NoteSet` to represent a collection of notes at a specific point data (e.g., a chord or a single note).
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { Note, NoteSet, Pitch, Duration } from '@scorelabs/core';
|
|
40
|
+
|
|
41
|
+
// Create a C4 quarter note
|
|
42
|
+
const c4 = new Note(new Pitch('C', 4), Duration.Quarter);
|
|
43
|
+
const noteSet = new NoteSet([c4]);
|
|
44
|
+
|
|
45
|
+
// Transpose up a whole step
|
|
46
|
+
const d4Set = noteSet.transpose(2);
|
|
47
|
+
|
|
48
|
+
console.log(d4Set.pitch.toString()); // "D4"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Architecture
|
|
52
|
+
|
|
53
|
+
The library is organized into two main modules:
|
|
54
|
+
|
|
55
|
+
* **`models/`**: Contains the data structures representing musical elements.
|
|
56
|
+
* `Score`: The root object representing a musical piece.
|
|
57
|
+
* `Part`: Represents a single instrument or voice within a score.
|
|
58
|
+
* `Staff`: A collection of measures for a specific part.
|
|
59
|
+
* `Measure`: Contains musical events like notes, rests, and directions.
|
|
60
|
+
* `NoteSet`: A grouping of simultaneous `Note` objects (chords).
|
|
61
|
+
* `Note`: The fundamental musical unit containing pitch, duration, and stylistic attributes.
|
|
62
|
+
* **`importers/`**: logic for importing external formats.
|
|
63
|
+
* `MusicXMLParser`: Converts MusicXML data into the internal object model.
|
|
64
|
+
|
|
65
|
+
## Development
|
|
66
|
+
|
|
67
|
+
1. **Clone the repository**
|
|
68
|
+
2. **Install dependencies**: `npm install`
|
|
69
|
+
3. **Build**: `npm run build`
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
MIT
|