lilylet-live-editor 0.0.4 → 0.0.7
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lilylet-live-editor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite dev",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@codemirror/state": "^6.4.0",
|
|
34
34
|
"@codemirror/theme-one-dark": "^6.1.0",
|
|
35
35
|
"@codemirror/view": "^6.25.0",
|
|
36
|
-
"@k-l-lambda/lilylet": "^0.1.
|
|
36
|
+
"@k-l-lambda/lilylet": "^0.1.39",
|
|
37
37
|
"@k-l-lambda/lilylet-markdown": "^0.1.20",
|
|
38
38
|
"@k-l-lambda/music-widgets": "^1.0.1",
|
|
39
39
|
"codemirror": "^6.0.0",
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { editorStore } from '$lib/stores/editor';
|
|
4
4
|
import Player from './Player.svelte';
|
|
5
5
|
import { tick } from 'svelte';
|
|
6
|
+
import { lilyletToLilyPond, lilyletToMusicXml } from '$lib/lilylet';
|
|
6
7
|
|
|
7
8
|
let svgContainer: HTMLDivElement;
|
|
8
9
|
let previewContainer: HTMLDivElement;
|
|
@@ -113,9 +114,25 @@
|
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
function exportLilyPond() {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
if ($editorStore.code) {
|
|
118
|
+
const result = lilyletToLilyPond($editorStore.code);
|
|
119
|
+
if (result.success) {
|
|
120
|
+
downloadFile(result.data, 'lilylet-score.ly', 'text/x-lilypond');
|
|
121
|
+
} else {
|
|
122
|
+
console.error('LilyPond export failed:', result.error);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function exportMusicXml() {
|
|
128
|
+
if ($editorStore.code) {
|
|
129
|
+
const result = lilyletToMusicXml($editorStore.code);
|
|
130
|
+
if (result.success) {
|
|
131
|
+
downloadFile(result.data, 'lilylet-score.musicxml', 'application/vnd.recordare.musicxml+xml');
|
|
132
|
+
} else {
|
|
133
|
+
console.error('MusicXML export failed:', result.error);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
119
136
|
}
|
|
120
137
|
|
|
121
138
|
function toggleExportMenu() {
|
|
@@ -134,6 +151,9 @@
|
|
|
134
151
|
case 'lilypond':
|
|
135
152
|
exportLilyPond();
|
|
136
153
|
break;
|
|
154
|
+
case 'musicxml':
|
|
155
|
+
exportMusicXml();
|
|
156
|
+
break;
|
|
137
157
|
case 'mei':
|
|
138
158
|
exportMEI();
|
|
139
159
|
break;
|
|
@@ -195,15 +215,14 @@
|
|
|
195
215
|
<button
|
|
196
216
|
class="export-item"
|
|
197
217
|
on:click={() => handleExport('lilypond')}
|
|
198
|
-
disabled
|
|
199
|
-
title="Not implemented yet"
|
|
218
|
+
disabled={!$editorStore.code}
|
|
200
219
|
>
|
|
201
220
|
LilyPond (.ly)
|
|
202
221
|
</button>
|
|
203
222
|
<button
|
|
204
223
|
class="export-item"
|
|
205
|
-
|
|
206
|
-
|
|
224
|
+
on:click={() => handleExport('musicxml')}
|
|
225
|
+
disabled={!$editorStore.code}
|
|
207
226
|
>
|
|
208
227
|
MusicXML
|
|
209
228
|
</button>
|
package/src/lib/lilylet/index.ts
CHANGED
|
@@ -90,4 +90,47 @@ export function lilypondToLilylet(source: string): ConversionResult {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Convert Lilylet code to LilyPond
|
|
95
|
+
*/
|
|
96
|
+
export function lilyletToLilyPond(code: string): ConversionResult {
|
|
97
|
+
try {
|
|
98
|
+
// Parse Lilylet code to LilyletDoc
|
|
99
|
+
const doc = lilylet.parseCode(code);
|
|
100
|
+
|
|
101
|
+
// Encode to LilyPond
|
|
102
|
+
const ly = lilylet.lilypondEncoder.encode(doc, {
|
|
103
|
+
paper: { width: 210, height: 297 },
|
|
104
|
+
fontSize: 20,
|
|
105
|
+
withMIDI: true,
|
|
106
|
+
autoBeaming: false
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return { success: true, data: ly };
|
|
110
|
+
} catch (error) {
|
|
111
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
112
|
+
console.error('LilyPond encoding error:', error);
|
|
113
|
+
return { success: false, error: `LilyPond encoding failed: ${errorMessage}` };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Convert Lilylet code to MusicXML
|
|
119
|
+
*/
|
|
120
|
+
export function lilyletToMusicXml(code: string): ConversionResult {
|
|
121
|
+
try {
|
|
122
|
+
// Parse Lilylet code to LilyletDoc
|
|
123
|
+
const doc = lilylet.parseCode(code);
|
|
124
|
+
|
|
125
|
+
// Encode to MusicXML
|
|
126
|
+
const xml = lilylet.musicXmlEncoder.encode(doc);
|
|
127
|
+
|
|
128
|
+
return { success: true, data: xml };
|
|
129
|
+
} catch (error) {
|
|
130
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
131
|
+
console.error('MusicXML encoding error:', error);
|
|
132
|
+
return { success: false, error: `MusicXML encoding failed: ${errorMessage}` };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
93
136
|
export { lilylet } from './highlight';
|