UNPKG

@mseep/ableton-copilot-mcp

Version:
147 lines 5.83 kB
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/decorator.js'; import { commomProp, TrackSettableProp } from '../types/types.js'; import { Track } from 'ableton-js/ns/track.js'; import { modifyTrackProp } from '../utils/obj-utils.js'; import { getRawTrackById, getTrackById, Result } from '../utils/common.js'; import { ableton } from '../ableton.js'; class TrackTools { async getClipByTrack(track_id) { const track = getTrackById(track_id); const clips = await track.get('arrangement_clips'); return clips.map((clip) => clip.raw); } async getTrackInfo(track_id) { const track = getTrackById(track_id); return track.raw; } 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) { await track.duplicateClipToArrangement(newlyCreatedClip, time); return Result.ok(); } throw new Error('Failed to create MIDI clip'); } async setTrackProperty(track_id, property) { const raw_track = getRawTrackById(track_id); const track = new Track(ableton, raw_track); await modifyTrackProp(track, property); return Result.ok(); } async duplicateClipToTrack(clip_id, track_id, time) { const track = getTrackById(track_id); await track.duplicateClipToArrangement(clip_id, time); return Result.ok(); } async getTrackAvailableInputRoutings(track_id) { const track = getTrackById(track_id); const input_routings = await track.get('available_input_routing_types'); return input_routings.map((routing) => routing.display_name); } } __decorate([ tool({ name: 'get_clips_by_track_id', description: 'get all clip by track id', paramsSchema: { track_id: z.string(), } }), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], TrackTools.prototype, "getClipByTrack", null); __decorate([ tool({ name: 'get_track_info_by_id', description: 'get track info by id', paramsSchema: { track_id: z.string(), } }), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], TrackTools.prototype, "getTrackInfo", null); __decorate([ tool({ name: 'create_empty_midi_clip', description: 'create empty midi clip on track', 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", [String, Number, Number]), __metadata("design:returntype", Promise) ], TrackTools.prototype, "createEmptyMidiClip", null); __decorate([ tool({ name: 'set_track_property', description: 'set track property', paramsSchema: { track_id: z.string(), property: TrackSettableProp, } }), __metadata("design:type", Function), __metadata("design:paramtypes", [String, void 0]), __metadata("design:returntype", Promise) ], TrackTools.prototype, "setTrackProperty", null); __decorate([ tool({ name: 'duplicate_clip_to_track', description: 'duplicate clip to track', paramsSchema: { clip_id: z.string(), track_id: z.string(), time: z.number(), } }), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String, Number]), __metadata("design:returntype", Promise) ], TrackTools.prototype, "duplicateClipToTrack", null); __decorate([ tool({ name: 'get_track_available_input_routings', description: 'get track available input routings', paramsSchema: { track_id: z.string(), } }), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], TrackTools.prototype, "getTrackAvailableInputRoutings", null); export default TrackTools; //# sourceMappingURL=track-tools.js.map