UNPKG

ableton-mcp-server-rag

Version:
175 lines 7.1 kB
// src/tools/track-tools.ts 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, TrackGettableProps, TrackSettableProp } from '../types/zod-types.js'; import { batchModifyTrackProp, getTrackProps } from '../utils/obj-utils.js'; import { Result } from '../utils/common.js'; import { getTrackById } from '../utils/obj-utils.js'; class TrackTools { async getTracksProperty({ track_id, properties }) { const track = getTrackById(track_id); return await getTrackProps(track, properties); } async createEmptyMidiClip({ track_id, length, time }) { // Get track object const track = getTrackById(track_id); // Get all clip slots from the track const clipSlots = await track.get('clip_slots'); const lastClipSlot = clipSlots.at(-1); // Check if there is an available clip slot if (!lastClipSlot) { throw new Error('No clip slot available'); } // Check if last slot has clip, delete if exists const hasExistingClip = await lastClipSlot.get('has_clip'); if (hasExistingClip) { await lastClipSlot.deleteClip(); } // Create new empty MIDI clip await lastClipSlot.createClip(length); // Get newly created clip and duplicate to arrangement view const newlyCreatedClip = await lastClipSlot.get('clip'); if (newlyCreatedClip) { const clip = await track.duplicateClipToArrangement(newlyCreatedClip, time); return Result.data(clip.raw); } throw new Error('Failed to create MIDI clip'); } async setTracksProperty({ tracks }) { await batchModifyTrackProp(tracks); return Result.ok(); } async duplicateClipToTrack({ clip_id, track_id, time }) { const track = getTrackById(track_id); const clip = await track.duplicateClipToArrangement(clip_id, time); return Result.data(clip.raw); } async deleteClipById({ track_id, clip_id }) { const track = getTrackById(track_id); await track.deleteClip(clip_id); return Result.ok(); } async deleteDeviceByIndex({ track_id, index }) { const track = getTrackById(track_id); await track.deleteDevice(index); return Result.ok(); } async createAudioClip({ track_id, file_path, position }) { const track = getTrackById(track_id); await track.createAudioClip(file_path, position); return Result.ok(); } } __decorate([ tool({ name: 'get_track_properties', description: 'get track properties. To get specific properties, set the corresponding property name to true in the properties parameter', paramsSchema: { track_id: z.string(), properties: TrackGettableProps, } }), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], TrackTools.prototype, "getTracksProperty", null); __decorate([ tool({ name: 'create_midi_clip', description: 'Creates an empty MIDI clip on the track and returns the created clip information', paramsSchema: { track_id: z.string(), length: z.number().describe('Length is given in beats and must be a greater value than 0.0.'), time: commomProp.time, } }), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], TrackTools.prototype, "createEmptyMidiClip", null); __decorate([ tool({ name: 'set_tracks_property', description: 'batch set tracks property', paramsSchema: { tracks: z.array(z.object({ track_id: z.string().describe('get track id by get_all_tracks'), property: TrackSettableProp, })) } }), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], TrackTools.prototype, "setTracksProperty", null); __decorate([ tool({ name: 'duplicate_clip_to_track', description: 'duplicate clip to track and return the duplicated clip information', paramsSchema: { clip_id: z.string(), track_id: z.string(), time: z.number(), } }), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], TrackTools.prototype, "duplicateClipToTrack", null); __decorate([ tool({ name: 'delete_clip', description: 'delete clip by id', paramsSchema: { track_id: z.string(), clip_id: z.string(), } }), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], TrackTools.prototype, "deleteClipById", null); __decorate([ tool({ name: 'delete_device', description: 'delete device by index, start from 0', paramsSchema: { track_id: z.string(), index: z.number(), } }), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], TrackTools.prototype, "deleteDeviceByIndex", null); __decorate([ tool({ name: 'create_audio_clip', description: `Create audio clip on track. Given an absolute path to a valid audio file in a supported format, creates an audio clip that references the file at the specified position in the arrangement view. Prints an error if: - The track is not an audio track - The track is frozen - The track is being recorded into`, paramsSchema: { track_id: z.string(), file_path: z.string().describe('absolute path to audio file'), position: z.number().min(0).max(1576800).describe('position in beats'), } }), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], TrackTools.prototype, "createAudioClip", null); export default TrackTools; //# sourceMappingURL=track-tools.js.map