@xiaolaa2/ableton-copilot-mcp
Version:
Ableton Live MCP depend on Ableton JS
65 lines • 2.63 kB
JavaScript
import { ableton } from '../ableton.js';
import { SnapshotType } from '../entities/Snapshot.js';
import { createSnapshot } from './snapshot-utils.js';
import { NoteExtendedToNote } from './obj-utils.js';
import { ErrorTypes } from '../mcp/error-handler.js';
export async function removeNotesExtended(clip, fromPitch, pitchSpan, fromTime, timeSpan) {
const abltonMajorVersion = await ableton.application.get('major_version', true);
if (abltonMajorVersion < 11) {
return clip.removeNotes(fromTime, fromPitch, timeSpan, pitchSpan);
}
return clip.removeNotesExtended(fromTime, fromPitch, timeSpan, pitchSpan);
}
export async function removeAllNotes(clip) {
return removeNotesExtended(clip, 0, 127, 0, 9999);
}
export async function getAllNotes(clip) {
const liveVersion = await ableton.application.get('major_version', true);
if (liveVersion >= 11) {
return clip.getNotesExtended(0, 0, 9999, 127);
}
return clip.getNotes(0, 0, 9999, 127);
}
export async function getNotes(clip, fromPitch, pitchSpan, fromTime, timeSpan) {
const liveVersion = await ableton.application.get('major_version', true);
if (liveVersion >= 11) {
return clip.getNotesExtended(fromTime, fromPitch, timeSpan, pitchSpan);
}
return clip.getNotes(fromTime, fromPitch, timeSpan, pitchSpan);
}
export async function createNoteSnapshot(clip, historyId) {
const data = {
clip_id: clip.raw.id,
notes: await getAllNotes(clip),
};
const snapshot = {
history_id: historyId,
snapshot_data: JSON.stringify(data),
snapshot_type: SnapshotType.NOTE,
};
return createSnapshot(snapshot);
}
// only use for replace_clip_notes and rollback_by_history_id
export async function setNotesExtended(clip, notes) {
const noteToSet = notes.map(note => NoteExtendedToNote(note));
// throw new Error(`note: ${noteToSet.map(note => JSON.stringify(note))}`)
await clip.setNotes(noteToSet);
const getNotes = await getAllNotes(clip);
if (getNotes.length !== notes.length) {
throw ErrorTypes.INTERNAL_ERROR('setNotesExtended failed');
}
notes.forEach((note, index) => {
note.note_id = getNotes[index].note_id;
});
await clip.applyNoteModifications(notes);
}
export async function replaceClipNotes(clip, notes) {
await removeAllNotes(clip);
await clip.setNotes(notes);
}
// only apply note modifications if live version is 11
export async function replaceClipNotesExtended(clip, notes) {
await removeAllNotes(clip);
await setNotesExtended(clip, notes);
}
//# sourceMappingURL=clip-utils.js.map