initial commit
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import type { Project } from './types';
|
||||
import { app, setActiveSwitch, setMarkers, setSelectedIds } from './store.svelte';
|
||||
|
||||
export function buildProject(): Project {
|
||||
return {
|
||||
version: 1,
|
||||
switch: app.activeSwitch,
|
||||
markers: app.markers.map((m) => ({ ...m })),
|
||||
};
|
||||
}
|
||||
|
||||
export function downloadProject(filename = 'project.json') {
|
||||
const project = buildProject();
|
||||
const blob = new Blob([JSON.stringify(project, null, 2)], { type: 'application/json' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = url;
|
||||
anchor.download = filename;
|
||||
anchor.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
export function loadProject(data: Project) {
|
||||
if (data.version !== 1) {
|
||||
throw new Error(`Unsupported project version: ${data.version}`);
|
||||
}
|
||||
setMarkers(data.markers.map((m) => ({ ...m })));
|
||||
setActiveSwitch(data.switch);
|
||||
setSelectedIds(new Set());
|
||||
}
|
||||
|
||||
export async function exportAudio(duration: number) {
|
||||
const project = buildProject();
|
||||
const response = await fetch('/api/export/audio', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
duration,
|
||||
switch: project.switch,
|
||||
markers: project.markers,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const detail = await response.text();
|
||||
throw new Error(detail || 'Audio export failed');
|
||||
}
|
||||
|
||||
const blob = await response.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = url;
|
||||
anchor.download = 'keyboard_track.wav';
|
||||
anchor.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
Reference in New Issue
Block a user