ableton-mcp-server-rag
Version:
Ableton Live MCP depend on Ableton JS
46 lines • 1.69 kB
JavaScript
import { Browser } from 'ableton-js/ns/browser.js';
import { ableton } from '../ableton.js';
import { getBrowserItemById } from './obj-utils.js';
// A simple in-memory cache for raw browser items
export const browserItemCache = new Map(); // key: id, value: item.raw
export var ResourceType;
(function (ResourceType) {
ResourceType["AUDIO_EFFECTS"] = "audio_effects";
ResourceType["INSTRUMENTS"] = "instruments";
ResourceType["PLUGINS"] = "plugins";
ResourceType["DRUMS"] = "drums";
ResourceType["SAMPLES"] = "samples";
ResourceType["MIDI_EFFECTS"] = "midi_effects";
ResourceType["SOUNDS"] = "sounds";
})(ResourceType || (ResourceType = {}));
export async function loadDevice(deviceId, trackId) {
const item = getBrowserItemById(deviceId);
const browser = new Browser(ableton);
// select track
if (trackId) {
const songView = ableton.song.view;
await songView.set('selected_track', trackId);
}
await browser.loadItem(item);
}
async function getItemsRecursively(items) {
const result = {};
for (const item of items) {
if (item.raw.is_folder) {
const children = await item.get('children');
result[item.raw.name] = await getItemsRecursively(children);
}
else {
// Store the real raw item in cache
browserItemCache.set(item.raw.id, item.raw);
result[item.raw.name] = item.raw;
}
}
return result;
}
export async function listResources(type) {
const browser = new Browser(ableton);
const items = await browser.get(type);
return await getItemsRecursively(items);
}
//# sourceMappingURL=browser-utils.js.map