@xiaolaa2/ableton-copilot-mcp
Version:
Ableton Live MCP depend on Ableton JS
164 lines • 6.75 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { z } from 'zod';
import { tool } from '../mcp/decorators/tool.js';
import { commomProp, SongGettableProps, SongSettableProp, SongViewGettableProps, SongViewSettableProp, TrackType, ZodTrackType } from '../types/zod-types.js';
import { Result } from '../utils/common.js';
import { getSongProperties, getSongViewProps, modifySongProp, modifySongViewProp } from '../utils/obj-utils.js';
import { ableton } from '../ableton.js';
import { recordByTimeRange } from '../utils/record-utils.js';
class SongTools {
async getSongProperties(propertys) {
return await getSongProperties(ableton.song, propertys);
}
async getSongViewProperties(propertys) {
return await getSongViewProps(ableton.song, propertys);
}
async setSongProperties(propertys) {
return await modifySongProp(ableton.song, propertys);
}
async setSongViewProperties(propertys) {
return await modifySongViewProp(ableton.song, propertys);
}
async createTrack({ type, index = 0 }) {
let track;
switch (type) {
case TrackType.midi:
track = await ableton.song.createMidiTrack(index);
break;
case TrackType.audio:
track = await ableton.song.createAudioTrack(index);
break;
case TrackType.return:
track = await ableton.song.createReturnTrack();
break;
}
return track.raw;
}
async deleteTrack({ index, type }) {
switch (type) {
case TrackType.midi:
case TrackType.audio:
await ableton.song.deleteTrack(index);
break;
case TrackType.return:
await ableton.song.deleteReturnTrack(index);
break;
default:
throw new Error('Invalid track type');
}
return Result.ok();
}
async duplicateTrack({ index }) {
await ableton.song.duplicateTrack(index);
return Result.ok();
}
async recordAudio({ start_time, end_time }) {
return recordByTimeRange(ableton.song, start_time, end_time);
}
}
__decorate([
tool({
name: 'get_song_properties',
description: 'get song properties. To get specific properties, set the corresponding property name to true in the properties parameter.',
paramsSchema: SongGettableProps.shape
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [void 0]),
__metadata("design:returntype", Promise)
], SongTools.prototype, "getSongProperties", null);
__decorate([
tool({
name: 'get_song_view_properties',
description: 'get song view properties. To get specific properties, set the corresponding property name to true in the properties parameter.',
paramsSchema: SongViewGettableProps.shape
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [void 0]),
__metadata("design:returntype", Promise)
], SongTools.prototype, "getSongViewProperties", null);
__decorate([
tool({
name: 'set_song_property',
description: 'set song basic properties',
paramsSchema: SongSettableProp.shape,
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [void 0]),
__metadata("design:returntype", Promise)
], SongTools.prototype, "setSongProperties", null);
__decorate([
tool({
name: 'set_song_view_property',
description: 'set song view properties',
paramsSchema: SongViewSettableProp.shape,
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [void 0]),
__metadata("design:returntype", Promise)
], SongTools.prototype, "setSongViewProperties", null);
__decorate([
tool({
name: 'create_track',
description: 'create track and return raw track',
paramsSchema: {
type: ZodTrackType,
index: z.number().optional().default(0).describe('[int] index of track default 0, range [0, track count]'),
}
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], SongTools.prototype, "createTrack", null);
__decorate([
tool({
name: 'delete_track',
description: 'delete track by index',
paramsSchema: {
index: z.number().describe('[int] index of track'),
type: ZodTrackType,
}
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], SongTools.prototype, "deleteTrack", null);
__decorate([
tool({
name: 'duplicate_track',
description: 'duplicate midi or audio track by index',
paramsSchema: {
index: z.number().describe('[int] index of track'),
}
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], SongTools.prototype, "duplicateTrack", null);
__decorate([
tool({
name: 'record_by_time_range',
description: `Opens Ableton's audio record button and starts playback from start_time to end_time.
Before recording, please:
ENSURE:
1. Set the recording track to record mode
2. Set the recording track's input routing to Resample or a specific audio track/input routing(get from get_track_available_input_routings tool)
3. After recording, disable the track's record mode`,
paramsSchema: {
start_time: commomProp.time,
end_time: z.number().describe('[int] end time of record'),
}
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], SongTools.prototype, "recordAudio", null);
export default SongTools;
//# sourceMappingURL=song-tools.js.map