@k-l-lambda/lilypond-node 2.24.4 → 2.24.6

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.
Files changed (2) hide show
  1. package/README.md +254 -0
  2. package/package.json +3 -2
package/README.md ADDED
@@ -0,0 +1,254 @@
1
+ # @k-l-lambda/lilypond-node
2
+
3
+ LilyPond music engraving as a Node.js native addon. Convert LilyPond notation to SVG and MIDI directly in Node.js without spawning external processes.
4
+
5
+ ## Features
6
+
7
+ - **Fast**: Native addon with no process spawning overhead
8
+ - **In-memory output**: SVG and MIDI delivered via callbacks, no temporary files needed
9
+ - **LilyPond 2.24.4**: Based on the latest stable LilyPond release
10
+ - **Guile 3.0**: Modern Scheme runtime
11
+ - **TypeScript support**: Full type definitions included
12
+
13
+ ## Requirements
14
+
15
+ - **Node.js**: 22.0.0 or later
16
+ - **Platform**: Linux x64 (more platforms coming soon)
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @k-l-lambda/lilypond-node
22
+ ```
23
+
24
+ The install script automatically downloads prebuilt binaries from GitLab CI (~4MB).
25
+
26
+ ## Usage
27
+
28
+ ### Basic Example
29
+
30
+ ```javascript
31
+ const lilypond = require('@k-l-lambda/lilypond-node');
32
+
33
+ const lyCode = `\\version "2.24.4"
34
+ \\header { title = "Hello World" }
35
+ { c' d' e' f' g'2 g' | a' b' c''1 }
36
+ `;
37
+
38
+ lilypond.engrave(lyCode, {
39
+ onSVG: (filename, content) => {
40
+ console.log(`Generated ${filename} (${content.length} bytes)`);
41
+ // content is SVG string, save or process as needed
42
+ },
43
+ onMIDI: (filename, data) => {
44
+ console.log(`Generated ${filename} (${data.byteLength} bytes)`);
45
+ // data is ArrayBuffer containing MIDI bytes
46
+ },
47
+ log: (message) => {
48
+ console.log(message);
49
+ }
50
+ }).then((exitCode) => {
51
+ if (exitCode === 0) {
52
+ console.log('Success!');
53
+ } else {
54
+ console.log('Completed with warnings or errors:', exitCode);
55
+ }
56
+ });
57
+ ```
58
+
59
+ ### TypeScript Example
60
+
61
+ ```typescript
62
+ import { engrave, EngraveOptions } from '@k-l-lambda/lilypond-node';
63
+ import * as fs from 'fs';
64
+
65
+ const lyCode = `\\version "2.24.4"
66
+ { c' e' g' c'' }
67
+ `;
68
+
69
+ const options: EngraveOptions = {
70
+ onSVG: (filename, content) => {
71
+ fs.writeFileSync(filename, content);
72
+ },
73
+ onMIDI: (filename, data) => {
74
+ fs.writeFileSync(filename, Buffer.from(data));
75
+ }
76
+ };
77
+
78
+ const exitCode = await engrave(lyCode, options);
79
+ console.log('Exit code:', exitCode);
80
+ ```
81
+
82
+ ### Using Include Paths
83
+
84
+ ```javascript
85
+ const lilypond = require('@k-l-lambda/lilypond-node');
86
+
87
+ const lyCode = `\\version "2.24.4"
88
+ \\include "my-library.ly"
89
+ { \\myCustomFunction }
90
+ `;
91
+
92
+ lilypond.engrave(lyCode, {
93
+ includeFolders: ['/path/to/my/library', './local-includes'],
94
+ onSVG: (filename, content) => {
95
+ // handle SVG
96
+ }
97
+ });
98
+ ```
99
+
100
+ ## API Reference
101
+
102
+ ### `engrave(lyCode, options?)`
103
+
104
+ Engrave LilyPond source code to SVG and/or MIDI.
105
+
106
+ **Parameters:**
107
+
108
+ | Parameter | Type | Description |
109
+ |-----------|------|-------------|
110
+ | `lyCode` | `string` | LilyPond source code |
111
+ | `options` | `EngraveOptions` | Optional configuration object |
112
+
113
+ **Options:**
114
+
115
+ | Option | Type | Description |
116
+ |--------|------|-------------|
117
+ | `onSVG` | `(filename: string, content: string) => void` | Callback for each SVG page generated |
118
+ | `onMIDI` | `(filename: string, data: ArrayBuffer) => void` | Callback for MIDI output |
119
+ | `log` | `(message: string) => void` | Callback for LilyPond log messages |
120
+ | `includeFolders` | `string[]` | Additional paths for `\include` commands |
121
+
122
+ **Returns:** `Promise<number>` - Exit code (0 = success, 1 = warnings, other = error)
123
+
124
+ ### `getDataDir()`
125
+
126
+ Returns the path to the LilyPond data directory (LILYPOND_DATADIR).
127
+
128
+ **Returns:** `string`
129
+
130
+ ### `version`
131
+
132
+ The LilyPond version bundled with this package.
133
+
134
+ **Type:** `string` (currently `"2.24.4"`)
135
+
136
+ ## Exit Codes
137
+
138
+ | Code | Meaning |
139
+ |------|---------|
140
+ | 0 | Success |
141
+ | 1 | Completed with warnings |
142
+ | Other | Error occurred |
143
+
144
+ ## How It Works
145
+
146
+ This package wraps LilyPond as a Node.js native addon (N-API). When you install the package:
147
+
148
+ 1. The install script downloads prebuilt binaries from GitLab CI
149
+ 2. The package includes LilyPond's Scheme files and fonts
150
+ 3. SVG output uses LilyPond's in-memory rendering (no temp files)
151
+ 4. MIDI data is returned directly as an ArrayBuffer
152
+
153
+ ### Architecture
154
+
155
+ ```
156
+ ┌─────────────────────────────────────────────┐
157
+ │ Your Node.js Application │
158
+ ├─────────────────────────────────────────────┤
159
+ │ @k-l-lambda/lilypond-node │
160
+ │ (JavaScript wrapper) │
161
+ ├─────────────────────────────────────────────┤
162
+ │ lilypond.node │
163
+ │ (Native addon - NAN bindings) │
164
+ ├─────────────────────────────────────────────┤
165
+ │ liblilypond.so │
166
+ │ (LilyPond core + Guile 3.0 runtime) │
167
+ └─────────────────────────────────────────────┘
168
+ ```
169
+
170
+ ## Building from Source
171
+
172
+ If prebuilt binaries aren't available for your platform, you can build from source:
173
+
174
+ ### Prerequisites
175
+
176
+ ```bash
177
+ # Debian/Ubuntu
178
+ sudo apt install \
179
+ cmake g++ pkg-config python3 \
180
+ guile-3.0-dev libpango1.0-dev libfreetype-dev \
181
+ libfontconfig-dev libglib2.0-dev
182
+ ```
183
+
184
+ ### Build Steps
185
+
186
+ ```bash
187
+ # Clone the full repository
188
+ git clone https://gitlab.com/k.l.lambda/lilypond.git
189
+ cd lilypond
190
+
191
+ # Configure LilyPond
192
+ ./autogen.sh --noconfigure
193
+ ./configure --disable-documentation
194
+
195
+ # Build the addon
196
+ cd node-addon
197
+ npm install
198
+ npm run build
199
+ ```
200
+
201
+ ## Platform Support
202
+
203
+ | Platform | Architecture | Status |
204
+ |----------|--------------|--------|
205
+ | Linux | x64 | ✅ Supported |
206
+ | Linux | arm64 | ⏳ Planned |
207
+ | macOS | x64/arm64 | ⏳ Planned |
208
+ | Windows | x64 | ⏳ Planned |
209
+
210
+ ## Performance
211
+
212
+ Compared to spawning the `lilypond` CLI for each file:
213
+
214
+ | Scenario | CLI | This Package |
215
+ |----------|-----|--------------|
216
+ | Simple score | ~500ms | ~130ms |
217
+ | Multiple scores | N × 500ms | N × 130ms (no startup overhead) |
218
+ | Batch processing | Slow | Fast (persistent runtime) |
219
+
220
+ The native addon eliminates process startup time (~400ms) and keeps the Guile runtime warm between calls.
221
+
222
+ ## Troubleshooting
223
+
224
+ ### "LilyPond native addon not found"
225
+
226
+ The prebuilt binary wasn't downloaded. Try:
227
+
228
+ ```bash
229
+ npm rebuild @k-l-lambda/lilypond-node
230
+ ```
231
+
232
+ ### "LilyPond data directory not found"
233
+
234
+ The Scheme files weren't set up. Try:
235
+
236
+ ```bash
237
+ cd node_modules/@k-l-lambda/lilypond-node
238
+ node scripts/postinstall.js
239
+ ```
240
+
241
+ ### "Unsupported platform"
242
+
243
+ Currently only Linux x64 with Node.js 22+ is supported. For other platforms, you'll need to build from source.
244
+
245
+ ## License
246
+
247
+ GPL-3.0 - Same as LilyPond itself.
248
+
249
+ ## Links
250
+
251
+ - [LilyPond Official](https://lilypond.org/)
252
+ - [Source Repository](https://gitlab.com/k.l.lambda/lilypond)
253
+ - [Issue Tracker](https://gitlab.com/k.l.lambda/lilypond/-/issues)
254
+ - [npm Package](https://www.npmjs.com/package/@k-l-lambda/lilypond-node)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k-l-lambda/lilypond-node",
3
- "version": "2.24.4",
3
+ "version": "2.24.6",
4
4
  "description": "LilyPond music engraving as a Node.js native addon",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -51,6 +51,7 @@
51
51
  },
52
52
  "files": [
53
53
  "lib/",
54
- "scripts/"
54
+ "scripts/",
55
+ "README.md"
55
56
  ]
56
57
  }