@ulm0/ableton-live-mcp 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{Ableton-Live-MCP-1.0.0.ablx → Ableton-Live-MCP-1.1.0.ablx} +0 -0
- package/README.md +7 -2
- package/SECURITY.md +2 -2
- package/SHA256SUMS +1 -1
- package/dist/extension.cjs +1 -1
- package/manifest.json +1 -1
- package/package.json +2 -1
- package/skills/ableton-live/SKILL.md +429 -0
|
Binary file
|
package/README.md
CHANGED
|
@@ -464,6 +464,9 @@ instructions anyway; the full skill adds the detailed workflows. Install it for
|
|
|
464
464
|
mkdir -p ~/.claude/skills && cp -r skills/ableton-live ~/.claude/skills/
|
|
465
465
|
```
|
|
466
466
|
|
|
467
|
+
The skill is also in the npm package (`npm pack @ulm0/ableton-live-mcp`, then copy
|
|
468
|
+
`package/skills/ableton-live`), and the server serves it as the `live://guide` resource.
|
|
469
|
+
|
|
467
470
|
Typical things you can ask a connected assistant to do:
|
|
468
471
|
|
|
469
472
|
- "Create a 4-bar house drum pattern on a new MIDI track with a Drum Rack"
|
|
@@ -539,8 +542,10 @@ git tag v1.0.0 && git push origin v1.0.0
|
|
|
539
542
|
|
|
540
543
|
`.github/workflows/release.yml` then checks that the tag matches both versions, runs the tests,
|
|
541
544
|
builds the `.ablx` and `SHA256SUMS`, publishes `@ulm0/ableton-live-mcp` to npm with provenance,
|
|
542
|
-
and creates the GitHub Release with both files attached. It authenticates to npm with
|
|
543
|
-
|
|
545
|
+
and creates the GitHub Release with both files attached. It authenticates to npm with trusted
|
|
546
|
+
publishing (OIDC), so no npm token is stored in the repository. The workflow can run again for
|
|
547
|
+
the same tag: a version already on npm is skipped, and an existing release gets its assets
|
|
548
|
+
replaced.
|
|
544
549
|
|
|
545
550
|
## Extension Host quirks (worth knowing)
|
|
546
551
|
|
package/SECURITY.md
CHANGED
package/SHA256SUMS
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
b246d8615ab67a4fe20ced0e55b878fe2bd97aeb2029d88b4e68001a02bca9bd Ableton-Live-MCP-1.1.0.ablx
|
package/dist/extension.cjs
CHANGED
|
@@ -165,7 +165,7 @@ data:
|
|
|
165
165
|
`)+`
|
|
166
166
|
Pick one file each (try a shorter query, or ask the user, when nothing fits), then build the kit in one call (it inserts the Drum Rack when there is none and imports the files into the project): `+gt("drum_kit_build",{track_name:s,pads:c.map(p=>({note:Zi[p].note,sample_path:`<${Zi[p].label.toLowerCase()} file>`}))}),o!==void 0?`Set the tempo: ${gt("song_set",{tempo:o})}.`:`${n[0].toUpperCase()}${n.slice(1)} usually runs at about ${i.tempo} BPM: suggest it, and set it with ${gt("song_set",{tempo:i.tempo})} only if the user agrees.`,`Create the clip with the whole beat in one call (${I1}):
|
|
167
167
|
${gt("clip_create",l)}`];return a&&u.push(`Swing it: ${gt("midi_clip_edit_notes",{clip_id:"<id of the new clip>",swing:{amount:a,grid:.25}})}.`),u.push('Tell the user what was created. On request: fills or extra hits with `midi_clip_set_notes` {"mode": "merge", patterns}, a looser feel with `midi_clip_edit_notes` {humanize}.'),[`Program a ${n} drum beat in the open Ableton Live Set with the ableton-live tools: ${r} bars, a one-bar pattern repeated (4/4: Live's API cannot read the song's time signature).`,"","Pattern, one bar of sixteenth steps (x = hit, X = accent, . = rest; pads by receiving note, C1 = 36):",...i.lines.map(p=>`- ${Zi[p.pad].label} (${Zi[p.pad].note}): ${p.steps}`),"","Steps:",Yw(u)].join(`
|
|
168
|
-
`)}},E1=[oq,vq,yq];var mn=1e-9,O1=1e5;function _q(e,t,n){let i=e.loopEnd-e.loopStart,r=e.endMarker-e.startMarker;if(e.looping?!(i>mn):!(r>mn))return[];let o=e.looping?Math.max(0,e.loopEnd-e.startMarker):0,a=e.looping?i:r,s=e.looping?e.loopStart:e.startMarker,c=[],l=t+n;for(let u=t;u<l-mn;){let p,h;if(u<o-mn)p=0,h=e.startMarker;else{let k=Math.floor((u-o)/a+mn);p=o+k*a,h=s}let g=u<o-mn?o:p+a,_=Math.min(l,g);if(c.length>=O1)throw new j(`The copy would repeat the clip's ${e.looping?"loop":"region"} more than ${O1} times: give a shorter length.`);c.push({clipFrom:h+(u-p),clipTo:h+(_-p),at:u-t}),u=_}return c}function j1(e,t){let n=e.loopEnd-e.loopStart;if(!e.looping||!(n>mn))return;let i=a=>`${a} beat${a===1?"":"s"}`,r=e.loopStart-e.startMarker;if(r>mn)return`the source's start before its loop: the copy loops its whole ${i(t)}, so the part before the source's loop start (its first ${i(r)}) comes back on every pass, while the source plays it once`;let o=t/n;if(Math.round(o)<1||Math.abs(o-Math.round(o))>1e-6)return`the loop length: the copy loops its whole ${i(t)}, not a whole number of the source's ${n}-beat loops, so its repeats differ from the source's`}function R1(e){return e.looping?Math.max(0,e.loopStart-e.startMarker)+(e.loopEnd-e.loopStart):e.endMarker-e.startMarker}function Qw(e,t,n,i,r){let o=[],a=e.map(s=>({pitch:Number(s.pitch),startTime:Number(s.startTime),duration:Number(s.duration),velocity:s.velocity===void 0?void 0:Number(s.velocity),muted:s.muted,probability:s.probability===void 0?void 0:Number(s.probability),velocityDeviation:s.velocityDeviation===void 0?void 0:Number(s.velocityDeviation),releaseVelocity:s.releaseVelocity===void 0?void 0:Number(s.releaseVelocity)})).filter(s=>Number.isFinite(s.startTime));a.sort((s,c)=>s.startTime-c.startTime);for(let s of _q(t,n,i)){let c=0,l=a.length;for(;c<l;){let u=c+l>>>1;a[u].startTime<s.clipFrom-mn?c=u+1:l=u}for(let u=c;u<a.length&&a[u].startTime<s.clipTo-mn;u++){let p=a[u],h=Math.min(p.duration,s.clipTo-p.startTime);if(!(h>mn))continue;if(o.length>=r)throw new j(`The copy would hold more than ${r} notes: give a shorter length.`);let g={...p,startTime:s.at+(p.startTime-s.clipFrom),duration:h};for(let _ of Object.keys(g))g[_]===void 0&&delete g[_];o.push(g)}}return o.sort((s,c)=>s.startTime-c.startTime||s.pitch-c.pitch)}var En=Sr(require("node:fs/promises"),1),ek=Sr(require("node:os"),1),kt=Sr(require("node:path"),1);var tk=[".wav",".aif",".aiff",".flac",".mp3",".ogg",".m4a"];function C1(e=ek.homedir()){let t=[];for(let n of["Music","Documents"])for(let i of["User Library","Factory Packs"])t.push({name:i,path:kt.join(e,n,"Ableton",i),source:"library"});return t}function A1(e){let t=[];if(!e)return{roots:[],problems:t};let n;try{n=JSON.parse(qw(e))}catch(o){return o.code!=="ENOENT"&&t.push(`${e} could not be read: ${o.message}`),{roots:[],problems:t}}let i=n?.sample_roots;if(i===void 0)return{roots:[],problems:t};if(!Array.isArray(i))return t.push(`sample_roots in ${e} is not a list of folder paths`),{roots:[],problems:t};let r=[];for(let o of i){if(typeof o!="string"||!o.trim()){t.push(`sample_roots entry ${JSON.stringify(o)} is not a folder path`);continue}let a=/^~(?=$|[\\/])/.test(o)?kt.join(ek.homedir(),o.slice(1)):o;if(!kt.isAbsolute(a)){t.push(`sample_roots entry ${JSON.stringify(o)} is not an absolute path`);continue}r.push({name:kt.basename(kt.resolve(a))||a,path:kt.resolve(a),source:"config"})}return{roots:r,problems:t}}function D1(e,t){let n=kt.relative(t,e);return n===""||n!==".."&&!n.startsWith(`..${kt.sep}`)&&!kt.isAbsolute(n)}async function N1(e,t){let n=Date.now(),i=[],r=[];for(let g of e){let _;try{_=await En.realpath(g.path),(await En.stat(_)).isDirectory()||(_=void 0)}catch{_=void 0}r.push({name:g.name,path:g.path,source:g.source,exists:_!==void 0}),_!==void 0&&i.push({root:g,real:_})}let o=g=>i.find(_=>D1(g,_.real)),a=[],s=new Set,c=new Set,l=0,u,p=0,h=[];for(let g of i)i.some(_=>_.real!==g.real&&D1(g.real,_.real))||h.push({dir:g.real,depth:0});e:for(;h.length;){let g=h.shift(),_=g.depth,k;try{k=await En.realpath(g.dir)}catch{continue}if(!o(k)||c.has(k))continue;if(c.add(k),Date.now()-n>t.timeLimitMs){u="time";break}if(l>=t.maxDirectories){u="directories";break}l++;let T;try{T=await En.readdir(k,{withFileTypes:!0})}catch{p++;continue}T.sort((z,S)=>z.name<S.name?-1:z.name>S.name?1:0);for(let z of T){if(z.name.startsWith("."))continue;let S=kt.join(k,z.name),A=z.isDirectory(),Q=z.isFile();if(z.isSymbolicLink())try{if(S=await En.realpath(S),!o(S))continue;let ye=await En.stat(S);A=ye.isDirectory(),Q=ye.isFile()}catch{continue}if(A){_<t.maxDepth&&h.push({dir:S,depth:_+1});continue}if(!Q||!t.extensions.includes(kt.extname(S).toLowerCase()))continue;let X=o(S);if(!X)continue;let ge=kt.relative(X.real,S).split(kt.sep).join("/");if(!(!t.terms.every(ye=>ge.toLowerCase().includes(ye))||s.has(S))){if(s.add(S),a.length>=t.limit){u="limit";break e}a.push({path:S,name:kt.basename(S),root:X.root.name,relative_path:ge})}}}return await Promise.all(a.map(async g=>{try{g.size_bytes=(await En.stat(g.path)).size}catch{}})),{roots:r,results:a,complete:u===void 0,stopped:u,directories_searched:l,unreadable_directories:p||void 0,elapsed_ms:Date.now()-n}}var bq=["AudioClip","AudioTrack","ClipSlot","DrumRack","MidiClip","MidiTrack","Sample","Scene","Simpler","ClipSlotSelection","AudioTrack.ArrangementSelection","MidiTrack.ArrangementSelection"],$q="MCP: Use as selection",wq=e=>`ableton-live-mcp.select.${e}`,rk=1e3,kq=e=>typeof e=="object"&&e!==null&&typeof e.id=="bigint",M1=e=>typeof e=="number"&&Number.isFinite(e)||typeof e=="bigint",$h=class{constructor(t){this.context=t}context;last;seq=0;waiters=new Set;latest(){return this.last}get latestSeq(){return this.last?.seq??0}capture(t,n){let i=t==="ClipSlotSelection"?"clip_slots":t.endsWith(".ArrangementSelection")?"arrangement":"object",r=[],o=typeof n=="object"&&n!==null?n:void 0,a=[],s;if(i==="object")a=Array.isArray(n)?n:[n];else{let l=o?.[i==="clip_slots"?"selected_clip_slots":"selected_lanes"];if(Array.isArray(l)?a=l:r.push(`the argument has no ${i==="clip_slots"?"selected_clip_slots":"selected_lanes"} list`),i==="arrangement"){let u=o?.time_selection_start,p=o?.time_selection_end;M1(u)&&M1(p)?s={start:Math.min(q(u),q(p)),end:Math.max(q(u),q(p))}:r.push("the argument has no numeric time_selection_start / time_selection_end")}}a.length>rk&&(r.push(`only the first ${rk} of ${a.length} selected objects were kept`),a=a.slice(0,rk));let c={seq:++this.seq,capturedAt:Date.now(),scope:t,kind:i,objects:a.map(l=>this.resolve(l)),time:s,problems:r.length?r:void 0};this.last=c,console.log(`[ableton-live-mcp] selection ${c.seq} captured from ${t}: ${c.objects.length} object(s)`);for(let l of[...this.waiters])l();return c}resolve(t){if(!kq(t))return{error:`Live passed ${t===void 0?"nothing":t===null?"null":typeof t=="object"?"an object without a bigint id":`a ${typeof t}`} where an object handle was expected`};try{let n=this.context.getObjectFromHandle(t,Ot);return{object:n,id:Y(n)}}catch(n){return{error:`Live could not resolve the object: ${n instanceof Error?n.message:String(n)}`}}}wait(t,n,i){let r=()=>this.last&&this.last.seq>t?this.last:void 0;return r()||i?.aborted?Promise.resolve(r()):new Promise(o=>{let a=()=>{clearTimeout(c),this.waiters.delete(s),i?.removeEventListener("abort",a),o(r())},s=()=>{r()&&a()},c=setTimeout(a,n);this.waiters.add(s),i?.addEventListener("abort",a,{once:!0})})}};function L1(e,t){for(let n of bq){let i=wq(n);try{e.commands.registerCommand(i,(...r)=>{try{t.capture(n,r[0])}catch(o){console.error(`[ableton-live-mcp] could not capture the ${n} selection:`,o)}}),e.ui.registerContextMenuAction(n,$q,i).catch(r=>console.error(`[ableton-live-mcp] could not add the ${n} menu entry:`,r))}catch(r){console.error(`[ableton-live-mcp] could not register the ${n} selection command:`,r)}}}var Z1=Sr(require("node:fs/promises"),1),Wn=32,nk=-80,xq=1<<20,wh=1,On=3,Sq=65534,zs=e=>e>0?Math.round(2e3*Math.log10(e))/100:null;async function Fi(e,t,n){let i=new Uint8Array(n),{bytesRead:r}=await e.read(i,0,n,t);return new DataView(i.buffer,0,r)}var su=(e,t)=>String.fromCharCode(e.getUint8(t),e.getUint8(t+1),e.getUint8(t+2),e.getUint8(t+3));async function Iq(e,t){let n=await Fi(e,0,12),i=n.byteLength>=12?su(n,0):"",r=n.byteLength>=12?su(n,8):"";if((i==="RIFF"||i==="RF64")&&r==="WAVE")return Tq(e,t,i==="RF64");if(i==="FORM"&&(r==="AIFF"||r==="AIFC"))return Pq(e,t,r==="AIFC");throw new Error("not a WAV or AIFF file (no RIFF/RF64 WAVE or FORM AIFF/AIFC header)")}function F1(e,t){let{code:n,bits:i,channels:r,blockAlign:o}=e;if(!(n===wh&&[8,16,24,32].includes(i)||n===On&&[32,64].includes(i)))throw new Error(`unsupported sample format (${n===On?"float":"PCM"}, ${i} bits): PCM 8/16/24/32-bit and float 32/64-bit are supported`);if(!r||o!==r*i/8)throw new Error(`inconsistent format (${r} channels, ${i} bits, block size ${o})`);return{format:e,data:t}}async function Tq(e,t,n){let i,r,o;for(let a=12;a+8<=t&&(!i||!r);){let s=await Fi(e,a,8);if(s.byteLength<8)break;let c=su(s,0),l=s.getUint32(4,!0),u=a+8;if(c==="ds64"){let p=await Fi(e,u,16);p.byteLength>=16&&(o=Number(p.getBigUint64(8,!0)))}else if(c==="fmt "){let p=await Fi(e,u,Math.min(l,40));if(p.byteLength<16)throw new Error("the fmt chunk is truncated");let h=p.getUint16(0,!0),g=p.getUint16(14,!0),_=g;if(h===Sq){if(p.byteLength<26)throw new Error("the WAVE_FORMAT_EXTENSIBLE fmt chunk is truncated");_=p.getUint16(18,!0)||g,h=p.getUint16(24,!0)}i={fileType:"wav",code:h,channels:p.getUint16(2,!0),sampleRate:p.getUint32(4,!0),blockAlign:p.getUint16(12,!0),bits:g,validBits:_,littleEndian:!0,unsigned8:!0}}else c==="data"&&(n&&l===4294967295&&o!==void 0&&(l=o),r={offset:u,size:Math.min(l,t-u)});a=u+l+l%2}if(!i)throw new Error("no fmt chunk");if(!r)throw new Error("no data chunk");return F1(i,r)}function zq(e,t){let n=e.getUint16(t)&32767,i=e.getBigUint64(t+2);return n===0&&i===0n?0:(e.getUint8(t)&128?-1:1)*Number(i)*2**(n-16383-63)}var U1={NONE:{code:wh,littleEndian:!1},twos:{code:wh,littleEndian:!1},sowt:{code:wh,littleEndian:!0},fl32:{code:On,littleEndian:!1},FL32:{code:On,littleEndian:!1},fl64:{code:On,littleEndian:!1},FL64:{code:On,littleEndian:!1}};async function Pq(e,t,n){let i,r=0,o;for(let a=12;a+8<=t&&(!i||!o);){let s=await Fi(e,a,8);if(s.byteLength<8)break;let c=su(s,0),l=s.getUint32(4),u=a+8;if(c==="COMM"){let p=await Fi(e,u,Math.min(l,22));if(p.byteLength<18||n&&p.byteLength<22)throw new Error("the COMM chunk is truncated");let h=n?su(p,18):"NONE",g=U1[h];if(!g)throw new Error(`unsupported AIFF-C compression ${JSON.stringify(h)}: ${Object.keys(U1).join(", ")} are supported`);let _=p.getInt16(0),k=p.getInt16(6),T=g.code===On?h.toLowerCase()==="fl64"?64:32:Math.ceil(k/8)*8;r=p.getUint32(2),i={fileType:"aiff",code:g.code,channels:_,sampleRate:zq(p,8),blockAlign:_*T/8,bits:T,validBits:g.code===On?T:k,littleEndian:g.littleEndian,unsigned8:!1}}else if(c==="SSND"){let p=await Fi(e,u,8);if(p.byteLength<8)throw new Error("the SSND chunk is truncated");let h=u+8+p.getUint32(0);o={offset:h,size:Math.max(0,Math.min(u+l,t)-h)}}a=u+l+l%2}if(!i)throw new Error("no COMM chunk");if(!o)throw new Error("no SSND chunk");return i.blockAlign&&(o.size=Math.min(o.size,r*i.blockAlign)),F1(i,o)}function Eq(e){let t=e.littleEndian;if(e.code===On)return{read:e.bits===32?(o,a)=>o.getFloat32(a,t):(o,a)=>o.getFloat64(a,t),isFull:o=>Math.abs(o)>=1};let n=2**(e.bits-1),i=(n-1)/n,r=o=>o>=i||o<=-1;switch(e.bits){case 8:return e.unsigned8?{read:(o,a)=>(o.getUint8(a)-128)/n,isFull:r}:{read:(o,a)=>o.getInt8(a)/n,isFull:r};case 16:return{read:(o,a)=>o.getInt16(a,t)/n,isFull:r};case 24:return{read:t?(o,a)=>(o.getUint8(a)|o.getUint8(a+1)<<8|o.getInt8(a+2)<<16)/n:(o,a)=>(o.getInt8(a)<<16|o.getUint8(a+1)<<8|o.getUint8(a+2))/n,isFull:r};default:return{read:(o,a)=>o.getInt32(a,t)/n,isFull:r}}}async function V1(e){let t=await Z1.open(e,"r");try{let n=(await t.stat()).size,{format:i,data:r}=await Iq(t,n),{channels:o,blockAlign:a}=i,s=i.bits/8,c=Math.floor(r.size/a),{read:l,isFull:u}=Eq(i),p=new Array(o).fill(0),h=new Array(o).fill(0),g=new Array(o).fill(0),_=new Array(Wn).fill(0),k=new Array(Wn).fill(0),T=new Array(Wn).fill(0),z=Math.max(a,Math.floor(xq/a)*a),S=0;for(let ye=0;S<c;){let Le=await Fi(t,r.offset+ye,Math.min(z,(c-S)*a)),Dt=Math.floor(Le.byteLength/a);if(!Dt)break;for(let _t=0;_t<Dt;_t++,S++){let rt=Math.min(Wn-1,Math.floor(S*Wn/c));T[rt]++;for(let nt=0;nt<o;nt++){let qt=l(Le,_t*a+nt*s);if((u(qt)||!Number.isFinite(qt))&&g[nt]++,!Number.isFinite(qt))continue;let Dr=Math.abs(qt);Dr>p[nt]&&(p[nt]=Dr),Dr>_[rt]&&(_[rt]=Dr),h[nt]+=qt*qt,k[rt]+=qt*qt}}ye+=Dt*a}let A=(ye,Le)=>Le?Math.sqrt(ye/Le):0,Q=Math.max(0,...p),X=zs(Q),ge=h.reduce((ye,Le)=>ye+Le,0);return{file_type:i.fileType,format:i.code===On?"float":"pcm",bits_per_sample:i.bits,valid_bits_per_sample:i.validBits!==i.bits?i.validBits:void 0,sample_rate:i.sampleRate,channels:o,frames:S,duration_s:i.sampleRate?Math.round(S/i.sampleRate*1e3)/1e3:0,peak_dbfs:X,rms_dbfs:zs(A(ge,S*o)),clipped_samples:g.reduce((ye,Le)=>ye+Le,0),silent:X===null||X<nk,channel_levels:p.map((ye,Le)=>({channel:Le,peak_dbfs:zs(ye),rms_dbfs:zs(A(h[Le],S)),clipped_samples:g[Le]})),envelope:{buckets:Wn,bucket_s:i.sampleRate?Math.round(c/Wn/i.sampleRate*1e4)/1e4:0,peak_dbfs:_.map((ye,Le)=>T[Le]?zs(ye):null),rms_dbfs:k.map((ye,Le)=>T[Le]?zs(A(ye,T[Le]*o)):null)}}}finally{await t.close()}}var ik={name:"ableton-live",version:"1.0.0"},Oq=m1.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n+/,""),jq=["Beats","Tones","Texture","Repitch","Complex","ComplexPro"],cj=e=>JSON.stringify(e,(t,n)=>typeof n=="bigint"?n.toString():n);function Rq(e){return{content:[{type:"text",text:cj(e)}]}}var q1=(e,t)=>Object.assign(new Error(t),{code:e}),B1="If this object was deleted or moved, or the Live Set changed, its id is stale \u2014 re-fetch ids via song_get / track_get.",Et={readOnlyHint:!0,openWorldHint:!1},Xn={readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},H1={...Xn,idempotentHint:!1},Gr={readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},jn={readOnlyHint:!1,destructiveHint:!0,idempotentHint:!0,openWorldHint:!1},Vi={...jn,idempotentHint:!1},Dq={readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0},Cq={readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0},Aq=new Set(["show_dialog","dialog_result","selection_wait","render_track_audio","audio_track_consolidate","batch","batch_read"]),Nq=1e4;async function Ps(e,t,n){let i=e._meta?.progressToken;if(i===void 0)return n();let r=Date.now(),o=0,a=()=>{let l=Math.round((Date.now()-r)/1e3);e.sendNotification({method:"notifications/progress",params:{progressToken:i,progress:++o,message:t(l)}}).catch(()=>{})};a();let s=setInterval(a,Nq),c=()=>clearInterval(s);e.signal.addEventListener("abort",c,{once:!0});try{return await n()}finally{c(),e.signal.removeEventListener("abort",c)}}var Po=e=>y.union([y.number().int().min(0).max(127),y.string().min(1)]).describe(`${e}: 0-127, or a note name such as "C3" (= 60), "F#1" or "Bb2"`),J1={pitch:Po("MIDI pitch"),start_time:y.number().describe("Start in beats, relative to clip start"),duration:y.number().positive().describe("Length in beats"),velocity:y.number().min(0).max(127).optional(),muted:y.boolean().optional(),probability:y.number().min(0).max(1).optional().describe("Play probability, 0-1"),velocity_deviation:y.number().optional(),release_velocity:y.number().min(0).max(127).optional()};function Mq(e,t="pitch"){return{pitch:Ai(e.pitch,t),startTime:e.start_time,duration:e.duration,velocity:e.velocity,muted:e.muted,probability:e.probability,velocityDeviation:e.velocity_deviation,releaseVelocity:e.release_velocity}}var G1=()=>y.object({note:Po("Pitch of every hit"),steps:y.string().min(1).describe('One character per step: "x" a hit, "X" an accented hit, "." or "-" a rest; spaces and "|" are ignored, e.g. "x...x...|x...x.x."'),step:y.number().positive().default(.25).describe("Length of one step in beats (0.25 = 1/16)"),start_time:y.number().min(0).default(0).describe("Where the first step starts, in beats"),velocity:y.number().min(1).max(127).default(100).describe('Velocity of "x" hits'),accent_velocity:y.number().min(1).max(127).default(127).describe('Velocity of "X" hits'),duration:y.number().positive().optional().describe("Length of each hit in beats; default one step")}),K1=()=>y.object({length:y.number().positive().describe("Beats the given notes span, e.g. 4 = one 4/4 bar: copy k starts k \xD7 length later"),times:y.number().int().min(1).optional().describe("Copies in total, counting the original (written even past the clip's end); omitted = fill the clip: copies up to its end, without the notes that would start at or after it")}).describe("Repeat the notes and patterns of this write"),js=5e4;function W1(e,t){let n=(e.notes??[]).map((l,u)=>Mq(l,`notes[${u}].pitch`));for(let[l,u]of(e.patterns??[]).entries()){let p=Ai(u.note,`patterns[${l}].note`),h=0;for(let g of u.steps)if(!(g==="|"||/\s/.test(g))){if(g==="x"||g==="X")n.push({pitch:p,startTime:u.start_time+h*u.step,duration:u.duration??u.step,velocity:g==="X"?u.accent_velocity:u.velocity});else if(g!=="."&&g!=="-")throw new j(`patterns[${l}].steps: unexpected ${JSON.stringify(g)}; use x, X, . or - (spaces and | are ignored).`);h++}}let i=l=>Math.max(1,Math.ceil(t/l.length-1e-9)),r=e.repeat?e.repeat.times??i(e.repeat):1,o=n.length*r;if(o>js&&o>(e.notes?.length??0))throw new j(`patterns and repeat would write ${o} notes; at most ${js} are allowed.`);if(!e.repeat)return{notes:n};if(!n.length)throw new j("repeat needs notes or patterns to repeat.");let{length:a,times:s}=e.repeat,c=[...n];for(let l=1;l<r;l++)for(let u of n){let p=u.startTime+l*a;s===void 0&&p>=t-1e-9||c.push({...u,startTime:p})}return{notes:c,copies:r}}var X1=()=>y.object({pitch_min:Po("Lowest pitch").optional(),pitch_max:Po("Highest pitch").optional(),time_min:y.number().optional().describe("Earliest start time, in beats"),time_max:y.number().optional().describe("Latest start time, in beats"),in_scale:y.boolean().optional().describe("true: only notes in the scale, false: only notes outside it. The scale is the song's (in midi_clip_edit_notes: snap_to_scale's, when given)"),only_selected:y.boolean().optional().describe("Only the notes selected in Live's MIDI editor. Whether Live reports the selection to extensions is unverified: a `warning` says when it reported none"),every_nth:y.union([y.number().int().min(1),y.object({n:y.number().int().min(1),offset:y.number().int().min(0).default(0)})]).optional().describe("Every n-th of the notes the other filters match, in time order (start, then pitch): 2 = the 1st, 3rd, 5th, ...; {n: 2, offset: 1} = the 2nd, 4th, ...")}),Lq=()=>y.union([y.literal("song"),y.object({root:y.union([y.number().int().min(0).max(11),y.string().min(1)]).describe('Root as 0-11 (C = 0) or a note name such as "D" or "F#"'),intervals:y.array(y.number().int()).min(1).describe("Semitone offsets from the root, e.g. [0, 2, 3, 5, 7, 8, 10] (natural minor)")})]),lj=(e,t)=>((e-t)%12+12)%12,ok=(e,t)=>t.intervals.includes(lj(e,t.root_note));function Uq(e,t){for(let n=0;n<12;n++){if(e-n>=0&&ok(e-n,t))return e-n;if(e+n<=127&&ok(e+n,t))return e+n}return e}var Y1=e=>y.union([y.number().positive(),y.literal("song")]).describe(`${e} in beats (0.25 = 1/16), or "song" for Live's grid setting (the arrangement grid, not the clip editor's; bar grids assume the first scene's time signature)`),uj=e=>e.map((t,n)=>n).sort((t,n)=>q(e[t].startTime)-q(e[n].startTime)||q(e[t].pitch)-q(e[n].pitch)||t-n);function Q1(e,t){let n=e.pitch_min===void 0?0:Ai(e.pitch_min,"select.pitch_min"),i=e.pitch_max===void 0?127:Ai(e.pitch_max,"select.pitch_max"),r=typeof e.every_nth=="number"?{n:e.every_nth,offset:0}:e.every_nth,o=a=>{let s=q(a.pitch),c=q(a.startTime);return s>=n&&s<=i&&(e.time_min===void 0||c>=e.time_min)&&(e.time_max===void 0||c<=e.time_max)&&(e.in_scale===void 0||ok(s,t)===e.in_scale)&&(!e.only_selected||a.selected===!0)};return a=>{let s=a.map(o);if(r){let c=0;for(let l of uj(a))s[l]&&(s[l]=c>=r.offset&&(c-r.offset)%r.n===0,c++)}return s}}function ej(e){if(!(!e.length||e.some(t=>t.selected===!0)))return e.some(t=>typeof t.selected=="boolean")?"No note of this clip is selected in Live.":"Live reported no selection state for this clip's notes, so none counts as selected."}function Zq(e){let t=n=>n===void 0?void 0:q(n);return{pitch:q(e.pitch),start_time:q(e.startTime),duration:q(e.duration),velocity:t(e.velocity),muted:e.muted,probability:t(e.probability),velocity_deviation:t(e.velocityDeviation),release_velocity:t(e.releaseVelocity),selected:e.selected}}var ak={muted:!1,probability:1,velocity_deviation:0,release_velocity:64,selected:!1},tj=Object.keys(ak);function Fq(e){let t=(i,r)=>i[r]??ak[r],n={...ak};for(let i of tj){let r=new Map;for(let a of e)r.set(t(a,i),(r.get(t(a,i))??0)+1);let o=0;for(let[a,s]of r)s>o&&(o=s,n[i]=a)}return{format:"compact",fields:["pitch","start_time","duration","velocity"],defaults:n,notes:e.map(i=>{let r=[i.pitch,i.start_time,i.duration,i.velocity??null],o=tj.filter(a=>t(i,a)!==n[a]);return o.length&&r.push(Object.fromEntries(o.map(a=>[a,t(i,a)]))),r})}}function Vq(e,t,n){let i=2*t,r=Math.floor(e/i)*i,o=e-r,a=t*(1+n/2);return r+(o<=t?o*a/t:a+(o-t)*(i-a)/t)}var qq=1/64,dj=1/256;function Bq(e){let t=[];for(let n of[...e].sort((i,r)=>i.startTime-r.startTime)){let i=t[t.length-1];i&&n.startTime-i[0].startTime<qq?i.push(n):t.push([n])}for(let n=0;n+1<t.length;n++)for(let i of t[n])i.duration=Math.max(dj,t[n+1][0].startTime-i.startTime)}function Hq(e){let t=e>>>0;return()=>{t=t+1831565813>>>0;let n=t;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}var Jq=y.object({looping:y.boolean(),start_marker:y.number(),end_marker:y.number(),loop_start:y.number(),loop_end:y.number()}).describe("Initial clip region/loop, all positions in beats. Loop must be >= 0.25 beats. When looping is false, loop_start/loop_end must equal start_marker/end_marker. Unwarped clips require looping=false and non-negative positions.");function Ie(e){return e instanceof Error?e.message:e===void 0?"the Live host rejected the operation without details \u2014 check argument values (device name spelling, index ranges, file paths, clip overlaps).":String(e)}var ht=()=>({track_id:y.string().optional().describe("Track id"),track_index:y.number().int().min(0).optional().describe("0-based index among the regular tracks"),track_name:y.string().optional().describe("Track name, exact match first, then case-insensitive (regular, return and main tracks)")}),Es=()=>({scene_id:y.string().optional().describe("Scene id"),scene_index:y.number().int().min(0).optional().describe("0-based scene index"),scene_name:y.string().optional().describe("Scene name, exact match first, then case-insensitive")}),Gq=y.string().optional().describe("Exact track name (case-sensitive)"),Kq=y.string().optional().describe("Exact scene name (case-sensitive)"),Wq=y.union([y.object({chain:y.number().int().min(0).describe("0-based chain index in the rack")}).strict(),y.object({pad:Po("Drum Rack pad: the chain's receiving MIDI note")}).strict()]),rj=()=>y.union([y.string().min(1).describe("Device name, exact match first, then case-insensitive"),y.number().int().min(0).describe("0-based position in the device list")]),cu={device_id:y.string().optional().describe("Device id"),...ht(),device:y.union([rj(),y.array(y.union([rj(),Wq])).min(1)]).optional().describe(`With a track instead of device_id: the device's name or 0-based index on the track, or a path into racks, e.g. ["Drum Rack", {"pad": 36}, "Simpler"] or [0, {"chain": 1}, "Reverb"]`)},nj={parameter_id:y.string().optional().describe("Parameter id (from device_get, mixer_get, parameter_find, ...)"),...cu,parameter:y.string().min(1).optional().describe("Instead of parameter_id: the parameter's name on the device (device_id, or track + device); exact match first, then case-insensitive, then unique substring")},sk={value:y.number().optional().describe("Internal units within [min, max]; a quantized parameter takes its value_items index"),value_item:y.string().min(1).optional().describe('Quantized parameters: the choice by value_items name or short name (exact, then case-insensitive, then unique substring), e.g. "Saw"'),reset:y.boolean().optional().describe("true: set the parameter to its default value"),delta:y.number().optional().describe("Add this to the current value, clamped to [min, max] (whole steps for quantized parameters)")},pj=y.string().min(1).describe("Parameter name: exact match first, then case-insensitive, then unique substring"),ij=y.object({name:pj,...sk}),Yn=(e,t)=>t.some(n=>e[n]!==void 0),fn=e=>Yn(e,["track_id","track_index","track_name"]),Xq=e=>Yn(e,["scene_id","scene_index","scene_name"]);function zo(e,t,n){if(t===void 0)return{list:[e],batch:!1};let i=n.filter(r=>Yn(e,[r]));if(i.length)throw new j(`Give either items or ${i.join(", ")} at the top level, not both.`);return{list:t,batch:!0}}var qi=(e,t)=>e?`items[${t}]`:void 0;function yt(e,t){try{return t()}catch(n){throw e&&n instanceof Error&&(n.message=`${typeof e=="function"?e():e}: ${n.message}`),n}}var mj="ableton-live-mcp/device-preset",Yq=y.object({format:y.literal(mj),version:y.literal(1),name:y.string(),device_name:y.string().min(1),device_class:y.string().optional(),saved_at:y.string().optional(),parameters:y.array(y.object({name:y.string(),value:y.number()})),sample:y.object({file_path:y.string().min(1)}).nullable().optional()}),Qq=/^[\p{L}\p{N}][\p{L}\p{M}\p{N} _\-.,()'+&#]*$/u,e9=/^(con|prn|aux|nul|com[0-9\u00b9\u00b2\u00b3]|lpt[0-9\u00b9\u00b2\u00b3]) *(\..*)?$/i;function oj(e){let t=e.normalize("NFC").trim();if(!t||t.length>64)throw new j("Preset names are 1-64 characters long.");if(!Qq.test(t)||/[. ]$/.test(t)||e9.test(t))throw new j(`Invalid preset name ${JSON.stringify(e)}: use letters, digits, spaces and - _ . , ( ) ' + & #, starting with a letter or digit and not ending with a dot.`);return t}function fj(e){let t=Rt.lstatSync(e);if(!t.isFile())throw new Error(`${e} is not a regular file.`);if(t.size>4e6)throw new Error(`${e} is too large for a preset.`);let n;try{n=JSON.parse(Rt.readFileSync(e,"utf8"))}catch(r){throw new Error(`${e} is not valid JSON: ${Ie(r)}`)}let i=Yq.safeParse(n);if(!i.success){let r=i.error.issues[0],o=r.path.join(".")||"file";throw new Error(`${e} is not a device preset of this server (${o}: ${r.message}).`)}return i.data}function t9(e){if(!e)throw new Error("Live provides no storage directory for this extension, so presets cannot be stored.");let t=Kr.join(e,"presets"),n=a=>{let s=Kr.resolve(t,a);if(Kr.dirname(s)!==Kr.resolve(t))throw new Error(`Refusing a preset path outside ${t}.`);return s},i=()=>{let a;try{a=Rt.readdirSync(t)}catch(s){if(s.code==="ENOENT")return[];throw s}return a.filter(s=>{if(!s.endsWith(".json")||s.startsWith("."))return!1;try{return Rt.lstatSync(n(s)).isFile()}catch{return!1}}).sort()},r=a=>Kr.basename(a,".json").normalize("NFC"),o=a=>{let s=i(),c=s.find(l=>r(l)===a)??s.find(l=>r(l).toLowerCase()===a.toLowerCase());return c===void 0?void 0:n(c)};return{dir:t,find:o,list(){let a=[],s=[];for(let c of i())try{a.push({name:r(c),preset:fj(n(c))})}catch(l){s.push({file:c,error:Ie(l)})}return{presets:a,unreadable:s}},write(a,s,c){let l=o(a);if(l&&!c)throw new j(`A preset named ${JSON.stringify(r(l))} already exists. Pass overwrite:true to replace it.`);Rt.mkdirSync(t,{recursive:!0});let u=l?r(l):a,p=`${JSON.stringify({...s,name:u},null,2)}
|
|
168
|
+
`)}},E1=[oq,vq,yq];var mn=1e-9,O1=1e5;function _q(e,t,n){let i=e.loopEnd-e.loopStart,r=e.endMarker-e.startMarker;if(e.looping?!(i>mn):!(r>mn))return[];let o=e.looping?Math.max(0,e.loopEnd-e.startMarker):0,a=e.looping?i:r,s=e.looping?e.loopStart:e.startMarker,c=[],l=t+n;for(let u=t;u<l-mn;){let p,h;if(u<o-mn)p=0,h=e.startMarker;else{let k=Math.floor((u-o)/a+mn);p=o+k*a,h=s}let g=u<o-mn?o:p+a,_=Math.min(l,g);if(c.length>=O1)throw new j(`The copy would repeat the clip's ${e.looping?"loop":"region"} more than ${O1} times: give a shorter length.`);c.push({clipFrom:h+(u-p),clipTo:h+(_-p),at:u-t}),u=_}return c}function j1(e,t){let n=e.loopEnd-e.loopStart;if(!e.looping||!(n>mn))return;let i=a=>`${a} beat${a===1?"":"s"}`,r=e.loopStart-e.startMarker;if(r>mn)return`the source's start before its loop: the copy loops its whole ${i(t)}, so the part before the source's loop start (its first ${i(r)}) comes back on every pass, while the source plays it once`;let o=t/n;if(Math.round(o)<1||Math.abs(o-Math.round(o))>1e-6)return`the loop length: the copy loops its whole ${i(t)}, not a whole number of the source's ${n}-beat loops, so its repeats differ from the source's`}function R1(e){return e.looping?Math.max(0,e.loopStart-e.startMarker)+(e.loopEnd-e.loopStart):e.endMarker-e.startMarker}function Qw(e,t,n,i,r){let o=[],a=e.map(s=>({pitch:Number(s.pitch),startTime:Number(s.startTime),duration:Number(s.duration),velocity:s.velocity===void 0?void 0:Number(s.velocity),muted:s.muted,probability:s.probability===void 0?void 0:Number(s.probability),velocityDeviation:s.velocityDeviation===void 0?void 0:Number(s.velocityDeviation),releaseVelocity:s.releaseVelocity===void 0?void 0:Number(s.releaseVelocity)})).filter(s=>Number.isFinite(s.startTime));a.sort((s,c)=>s.startTime-c.startTime);for(let s of _q(t,n,i)){let c=0,l=a.length;for(;c<l;){let u=c+l>>>1;a[u].startTime<s.clipFrom-mn?c=u+1:l=u}for(let u=c;u<a.length&&a[u].startTime<s.clipTo-mn;u++){let p=a[u],h=Math.min(p.duration,s.clipTo-p.startTime);if(!(h>mn))continue;if(o.length>=r)throw new j(`The copy would hold more than ${r} notes: give a shorter length.`);let g={...p,startTime:s.at+(p.startTime-s.clipFrom),duration:h};for(let _ of Object.keys(g))g[_]===void 0&&delete g[_];o.push(g)}}return o.sort((s,c)=>s.startTime-c.startTime||s.pitch-c.pitch)}var En=Sr(require("node:fs/promises"),1),ek=Sr(require("node:os"),1),kt=Sr(require("node:path"),1);var tk=[".wav",".aif",".aiff",".flac",".mp3",".ogg",".m4a"];function C1(e=ek.homedir()){let t=[];for(let n of["Music","Documents"])for(let i of["User Library","Factory Packs"])t.push({name:i,path:kt.join(e,n,"Ableton",i),source:"library"});return t}function A1(e){let t=[];if(!e)return{roots:[],problems:t};let n;try{n=JSON.parse(qw(e))}catch(o){return o.code!=="ENOENT"&&t.push(`${e} could not be read: ${o.message}`),{roots:[],problems:t}}let i=n?.sample_roots;if(i===void 0)return{roots:[],problems:t};if(!Array.isArray(i))return t.push(`sample_roots in ${e} is not a list of folder paths`),{roots:[],problems:t};let r=[];for(let o of i){if(typeof o!="string"||!o.trim()){t.push(`sample_roots entry ${JSON.stringify(o)} is not a folder path`);continue}let a=/^~(?=$|[\\/])/.test(o)?kt.join(ek.homedir(),o.slice(1)):o;if(!kt.isAbsolute(a)){t.push(`sample_roots entry ${JSON.stringify(o)} is not an absolute path`);continue}r.push({name:kt.basename(kt.resolve(a))||a,path:kt.resolve(a),source:"config"})}return{roots:r,problems:t}}function D1(e,t){let n=kt.relative(t,e);return n===""||n!==".."&&!n.startsWith(`..${kt.sep}`)&&!kt.isAbsolute(n)}async function N1(e,t){let n=Date.now(),i=[],r=[];for(let g of e){let _;try{_=await En.realpath(g.path),(await En.stat(_)).isDirectory()||(_=void 0)}catch{_=void 0}r.push({name:g.name,path:g.path,source:g.source,exists:_!==void 0}),_!==void 0&&i.push({root:g,real:_})}let o=g=>i.find(_=>D1(g,_.real)),a=[],s=new Set,c=new Set,l=0,u,p=0,h=[];for(let g of i)i.some(_=>_.real!==g.real&&D1(g.real,_.real))||h.push({dir:g.real,depth:0});e:for(;h.length;){let g=h.shift(),_=g.depth,k;try{k=await En.realpath(g.dir)}catch{continue}if(!o(k)||c.has(k))continue;if(c.add(k),Date.now()-n>t.timeLimitMs){u="time";break}if(l>=t.maxDirectories){u="directories";break}l++;let T;try{T=await En.readdir(k,{withFileTypes:!0})}catch{p++;continue}T.sort((z,S)=>z.name<S.name?-1:z.name>S.name?1:0);for(let z of T){if(z.name.startsWith("."))continue;let S=kt.join(k,z.name),A=z.isDirectory(),Q=z.isFile();if(z.isSymbolicLink())try{if(S=await En.realpath(S),!o(S))continue;let ye=await En.stat(S);A=ye.isDirectory(),Q=ye.isFile()}catch{continue}if(A){_<t.maxDepth&&h.push({dir:S,depth:_+1});continue}if(!Q||!t.extensions.includes(kt.extname(S).toLowerCase()))continue;let X=o(S);if(!X)continue;let ge=kt.relative(X.real,S).split(kt.sep).join("/");if(!(!t.terms.every(ye=>ge.toLowerCase().includes(ye))||s.has(S))){if(s.add(S),a.length>=t.limit){u="limit";break e}a.push({path:S,name:kt.basename(S),root:X.root.name,relative_path:ge})}}}return await Promise.all(a.map(async g=>{try{g.size_bytes=(await En.stat(g.path)).size}catch{}})),{roots:r,results:a,complete:u===void 0,stopped:u,directories_searched:l,unreadable_directories:p||void 0,elapsed_ms:Date.now()-n}}var bq=["AudioClip","AudioTrack","ClipSlot","DrumRack","MidiClip","MidiTrack","Sample","Scene","Simpler","ClipSlotSelection","AudioTrack.ArrangementSelection","MidiTrack.ArrangementSelection"],$q="MCP: Use as selection",wq=e=>`ableton-live-mcp.select.${e}`,rk=1e3,kq=e=>typeof e=="object"&&e!==null&&typeof e.id=="bigint",M1=e=>typeof e=="number"&&Number.isFinite(e)||typeof e=="bigint",$h=class{constructor(t){this.context=t}context;last;seq=0;waiters=new Set;latest(){return this.last}get latestSeq(){return this.last?.seq??0}capture(t,n){let i=t==="ClipSlotSelection"?"clip_slots":t.endsWith(".ArrangementSelection")?"arrangement":"object",r=[],o=typeof n=="object"&&n!==null?n:void 0,a=[],s;if(i==="object")a=Array.isArray(n)?n:[n];else{let l=o?.[i==="clip_slots"?"selected_clip_slots":"selected_lanes"];if(Array.isArray(l)?a=l:r.push(`the argument has no ${i==="clip_slots"?"selected_clip_slots":"selected_lanes"} list`),i==="arrangement"){let u=o?.time_selection_start,p=o?.time_selection_end;M1(u)&&M1(p)?s={start:Math.min(q(u),q(p)),end:Math.max(q(u),q(p))}:r.push("the argument has no numeric time_selection_start / time_selection_end")}}a.length>rk&&(r.push(`only the first ${rk} of ${a.length} selected objects were kept`),a=a.slice(0,rk));let c={seq:++this.seq,capturedAt:Date.now(),scope:t,kind:i,objects:a.map(l=>this.resolve(l)),time:s,problems:r.length?r:void 0};this.last=c,console.log(`[ableton-live-mcp] selection ${c.seq} captured from ${t}: ${c.objects.length} object(s)`);for(let l of[...this.waiters])l();return c}resolve(t){if(!kq(t))return{error:`Live passed ${t===void 0?"nothing":t===null?"null":typeof t=="object"?"an object without a bigint id":`a ${typeof t}`} where an object handle was expected`};try{let n=this.context.getObjectFromHandle(t,Ot);return{object:n,id:Y(n)}}catch(n){return{error:`Live could not resolve the object: ${n instanceof Error?n.message:String(n)}`}}}wait(t,n,i){let r=()=>this.last&&this.last.seq>t?this.last:void 0;return r()||i?.aborted?Promise.resolve(r()):new Promise(o=>{let a=()=>{clearTimeout(c),this.waiters.delete(s),i?.removeEventListener("abort",a),o(r())},s=()=>{r()&&a()},c=setTimeout(a,n);this.waiters.add(s),i?.addEventListener("abort",a,{once:!0})})}};function L1(e,t){for(let n of bq){let i=wq(n);try{e.commands.registerCommand(i,(...r)=>{try{t.capture(n,r[0])}catch(o){console.error(`[ableton-live-mcp] could not capture the ${n} selection:`,o)}}),e.ui.registerContextMenuAction(n,$q,i).catch(r=>console.error(`[ableton-live-mcp] could not add the ${n} menu entry:`,r))}catch(r){console.error(`[ableton-live-mcp] could not register the ${n} selection command:`,r)}}}var Z1=Sr(require("node:fs/promises"),1),Wn=32,nk=-80,xq=1<<20,wh=1,On=3,Sq=65534,zs=e=>e>0?Math.round(2e3*Math.log10(e))/100:null;async function Fi(e,t,n){let i=new Uint8Array(n),{bytesRead:r}=await e.read(i,0,n,t);return new DataView(i.buffer,0,r)}var su=(e,t)=>String.fromCharCode(e.getUint8(t),e.getUint8(t+1),e.getUint8(t+2),e.getUint8(t+3));async function Iq(e,t){let n=await Fi(e,0,12),i=n.byteLength>=12?su(n,0):"",r=n.byteLength>=12?su(n,8):"";if((i==="RIFF"||i==="RF64")&&r==="WAVE")return Tq(e,t,i==="RF64");if(i==="FORM"&&(r==="AIFF"||r==="AIFC"))return Pq(e,t,r==="AIFC");throw new Error("not a WAV or AIFF file (no RIFF/RF64 WAVE or FORM AIFF/AIFC header)")}function F1(e,t){let{code:n,bits:i,channels:r,blockAlign:o}=e;if(!(n===wh&&[8,16,24,32].includes(i)||n===On&&[32,64].includes(i)))throw new Error(`unsupported sample format (${n===On?"float":"PCM"}, ${i} bits): PCM 8/16/24/32-bit and float 32/64-bit are supported`);if(!r||o!==r*i/8)throw new Error(`inconsistent format (${r} channels, ${i} bits, block size ${o})`);return{format:e,data:t}}async function Tq(e,t,n){let i,r,o;for(let a=12;a+8<=t&&(!i||!r);){let s=await Fi(e,a,8);if(s.byteLength<8)break;let c=su(s,0),l=s.getUint32(4,!0),u=a+8;if(c==="ds64"){let p=await Fi(e,u,16);p.byteLength>=16&&(o=Number(p.getBigUint64(8,!0)))}else if(c==="fmt "){let p=await Fi(e,u,Math.min(l,40));if(p.byteLength<16)throw new Error("the fmt chunk is truncated");let h=p.getUint16(0,!0),g=p.getUint16(14,!0),_=g;if(h===Sq){if(p.byteLength<26)throw new Error("the WAVE_FORMAT_EXTENSIBLE fmt chunk is truncated");_=p.getUint16(18,!0)||g,h=p.getUint16(24,!0)}i={fileType:"wav",code:h,channels:p.getUint16(2,!0),sampleRate:p.getUint32(4,!0),blockAlign:p.getUint16(12,!0),bits:g,validBits:_,littleEndian:!0,unsigned8:!0}}else c==="data"&&(n&&l===4294967295&&o!==void 0&&(l=o),r={offset:u,size:Math.min(l,t-u)});a=u+l+l%2}if(!i)throw new Error("no fmt chunk");if(!r)throw new Error("no data chunk");return F1(i,r)}function zq(e,t){let n=e.getUint16(t)&32767,i=e.getBigUint64(t+2);return n===0&&i===0n?0:(e.getUint8(t)&128?-1:1)*Number(i)*2**(n-16383-63)}var U1={NONE:{code:wh,littleEndian:!1},twos:{code:wh,littleEndian:!1},sowt:{code:wh,littleEndian:!0},fl32:{code:On,littleEndian:!1},FL32:{code:On,littleEndian:!1},fl64:{code:On,littleEndian:!1},FL64:{code:On,littleEndian:!1}};async function Pq(e,t,n){let i,r=0,o;for(let a=12;a+8<=t&&(!i||!o);){let s=await Fi(e,a,8);if(s.byteLength<8)break;let c=su(s,0),l=s.getUint32(4),u=a+8;if(c==="COMM"){let p=await Fi(e,u,Math.min(l,22));if(p.byteLength<18||n&&p.byteLength<22)throw new Error("the COMM chunk is truncated");let h=n?su(p,18):"NONE",g=U1[h];if(!g)throw new Error(`unsupported AIFF-C compression ${JSON.stringify(h)}: ${Object.keys(U1).join(", ")} are supported`);let _=p.getInt16(0),k=p.getInt16(6),T=g.code===On?h.toLowerCase()==="fl64"?64:32:Math.ceil(k/8)*8;r=p.getUint32(2),i={fileType:"aiff",code:g.code,channels:_,sampleRate:zq(p,8),blockAlign:_*T/8,bits:T,validBits:g.code===On?T:k,littleEndian:g.littleEndian,unsigned8:!1}}else if(c==="SSND"){let p=await Fi(e,u,8);if(p.byteLength<8)throw new Error("the SSND chunk is truncated");let h=u+8+p.getUint32(0);o={offset:h,size:Math.max(0,Math.min(u+l,t)-h)}}a=u+l+l%2}if(!i)throw new Error("no COMM chunk");if(!o)throw new Error("no SSND chunk");return i.blockAlign&&(o.size=Math.min(o.size,r*i.blockAlign)),F1(i,o)}function Eq(e){let t=e.littleEndian;if(e.code===On)return{read:e.bits===32?(o,a)=>o.getFloat32(a,t):(o,a)=>o.getFloat64(a,t),isFull:o=>Math.abs(o)>=1};let n=2**(e.bits-1),i=(n-1)/n,r=o=>o>=i||o<=-1;switch(e.bits){case 8:return e.unsigned8?{read:(o,a)=>(o.getUint8(a)-128)/n,isFull:r}:{read:(o,a)=>o.getInt8(a)/n,isFull:r};case 16:return{read:(o,a)=>o.getInt16(a,t)/n,isFull:r};case 24:return{read:t?(o,a)=>(o.getUint8(a)|o.getUint8(a+1)<<8|o.getInt8(a+2)<<16)/n:(o,a)=>(o.getInt8(a)<<16|o.getUint8(a+1)<<8|o.getUint8(a+2))/n,isFull:r};default:return{read:(o,a)=>o.getInt32(a,t)/n,isFull:r}}}async function V1(e){let t=await Z1.open(e,"r");try{let n=(await t.stat()).size,{format:i,data:r}=await Iq(t,n),{channels:o,blockAlign:a}=i,s=i.bits/8,c=Math.floor(r.size/a),{read:l,isFull:u}=Eq(i),p=new Array(o).fill(0),h=new Array(o).fill(0),g=new Array(o).fill(0),_=new Array(Wn).fill(0),k=new Array(Wn).fill(0),T=new Array(Wn).fill(0),z=Math.max(a,Math.floor(xq/a)*a),S=0;for(let ye=0;S<c;){let Le=await Fi(t,r.offset+ye,Math.min(z,(c-S)*a)),Dt=Math.floor(Le.byteLength/a);if(!Dt)break;for(let _t=0;_t<Dt;_t++,S++){let rt=Math.min(Wn-1,Math.floor(S*Wn/c));T[rt]++;for(let nt=0;nt<o;nt++){let qt=l(Le,_t*a+nt*s);if((u(qt)||!Number.isFinite(qt))&&g[nt]++,!Number.isFinite(qt))continue;let Dr=Math.abs(qt);Dr>p[nt]&&(p[nt]=Dr),Dr>_[rt]&&(_[rt]=Dr),h[nt]+=qt*qt,k[rt]+=qt*qt}}ye+=Dt*a}let A=(ye,Le)=>Le?Math.sqrt(ye/Le):0,Q=Math.max(0,...p),X=zs(Q),ge=h.reduce((ye,Le)=>ye+Le,0);return{file_type:i.fileType,format:i.code===On?"float":"pcm",bits_per_sample:i.bits,valid_bits_per_sample:i.validBits!==i.bits?i.validBits:void 0,sample_rate:i.sampleRate,channels:o,frames:S,duration_s:i.sampleRate?Math.round(S/i.sampleRate*1e3)/1e3:0,peak_dbfs:X,rms_dbfs:zs(A(ge,S*o)),clipped_samples:g.reduce((ye,Le)=>ye+Le,0),silent:X===null||X<nk,channel_levels:p.map((ye,Le)=>({channel:Le,peak_dbfs:zs(ye),rms_dbfs:zs(A(h[Le],S)),clipped_samples:g[Le]})),envelope:{buckets:Wn,bucket_s:i.sampleRate?Math.round(c/Wn/i.sampleRate*1e4)/1e4:0,peak_dbfs:_.map((ye,Le)=>T[Le]?zs(ye):null),rms_dbfs:k.map((ye,Le)=>T[Le]?zs(A(ye,T[Le]*o)):null)}}}finally{await t.close()}}var ik={name:"ableton-live",version:"1.1.0"},Oq=m1.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n+/,""),jq=["Beats","Tones","Texture","Repitch","Complex","ComplexPro"],cj=e=>JSON.stringify(e,(t,n)=>typeof n=="bigint"?n.toString():n);function Rq(e){return{content:[{type:"text",text:cj(e)}]}}var q1=(e,t)=>Object.assign(new Error(t),{code:e}),B1="If this object was deleted or moved, or the Live Set changed, its id is stale \u2014 re-fetch ids via song_get / track_get.",Et={readOnlyHint:!0,openWorldHint:!1},Xn={readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},H1={...Xn,idempotentHint:!1},Gr={readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},jn={readOnlyHint:!1,destructiveHint:!0,idempotentHint:!0,openWorldHint:!1},Vi={...jn,idempotentHint:!1},Dq={readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0},Cq={readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0},Aq=new Set(["show_dialog","dialog_result","selection_wait","render_track_audio","audio_track_consolidate","batch","batch_read"]),Nq=1e4;async function Ps(e,t,n){let i=e._meta?.progressToken;if(i===void 0)return n();let r=Date.now(),o=0,a=()=>{let l=Math.round((Date.now()-r)/1e3);e.sendNotification({method:"notifications/progress",params:{progressToken:i,progress:++o,message:t(l)}}).catch(()=>{})};a();let s=setInterval(a,Nq),c=()=>clearInterval(s);e.signal.addEventListener("abort",c,{once:!0});try{return await n()}finally{c(),e.signal.removeEventListener("abort",c)}}var Po=e=>y.union([y.number().int().min(0).max(127),y.string().min(1)]).describe(`${e}: 0-127, or a note name such as "C3" (= 60), "F#1" or "Bb2"`),J1={pitch:Po("MIDI pitch"),start_time:y.number().describe("Start in beats, relative to clip start"),duration:y.number().positive().describe("Length in beats"),velocity:y.number().min(0).max(127).optional(),muted:y.boolean().optional(),probability:y.number().min(0).max(1).optional().describe("Play probability, 0-1"),velocity_deviation:y.number().optional(),release_velocity:y.number().min(0).max(127).optional()};function Mq(e,t="pitch"){return{pitch:Ai(e.pitch,t),startTime:e.start_time,duration:e.duration,velocity:e.velocity,muted:e.muted,probability:e.probability,velocityDeviation:e.velocity_deviation,releaseVelocity:e.release_velocity}}var G1=()=>y.object({note:Po("Pitch of every hit"),steps:y.string().min(1).describe('One character per step: "x" a hit, "X" an accented hit, "." or "-" a rest; spaces and "|" are ignored, e.g. "x...x...|x...x.x."'),step:y.number().positive().default(.25).describe("Length of one step in beats (0.25 = 1/16)"),start_time:y.number().min(0).default(0).describe("Where the first step starts, in beats"),velocity:y.number().min(1).max(127).default(100).describe('Velocity of "x" hits'),accent_velocity:y.number().min(1).max(127).default(127).describe('Velocity of "X" hits'),duration:y.number().positive().optional().describe("Length of each hit in beats; default one step")}),K1=()=>y.object({length:y.number().positive().describe("Beats the given notes span, e.g. 4 = one 4/4 bar: copy k starts k \xD7 length later"),times:y.number().int().min(1).optional().describe("Copies in total, counting the original (written even past the clip's end); omitted = fill the clip: copies up to its end, without the notes that would start at or after it")}).describe("Repeat the notes and patterns of this write"),js=5e4;function W1(e,t){let n=(e.notes??[]).map((l,u)=>Mq(l,`notes[${u}].pitch`));for(let[l,u]of(e.patterns??[]).entries()){let p=Ai(u.note,`patterns[${l}].note`),h=0;for(let g of u.steps)if(!(g==="|"||/\s/.test(g))){if(g==="x"||g==="X")n.push({pitch:p,startTime:u.start_time+h*u.step,duration:u.duration??u.step,velocity:g==="X"?u.accent_velocity:u.velocity});else if(g!=="."&&g!=="-")throw new j(`patterns[${l}].steps: unexpected ${JSON.stringify(g)}; use x, X, . or - (spaces and | are ignored).`);h++}}let i=l=>Math.max(1,Math.ceil(t/l.length-1e-9)),r=e.repeat?e.repeat.times??i(e.repeat):1,o=n.length*r;if(o>js&&o>(e.notes?.length??0))throw new j(`patterns and repeat would write ${o} notes; at most ${js} are allowed.`);if(!e.repeat)return{notes:n};if(!n.length)throw new j("repeat needs notes or patterns to repeat.");let{length:a,times:s}=e.repeat,c=[...n];for(let l=1;l<r;l++)for(let u of n){let p=u.startTime+l*a;s===void 0&&p>=t-1e-9||c.push({...u,startTime:p})}return{notes:c,copies:r}}var X1=()=>y.object({pitch_min:Po("Lowest pitch").optional(),pitch_max:Po("Highest pitch").optional(),time_min:y.number().optional().describe("Earliest start time, in beats"),time_max:y.number().optional().describe("Latest start time, in beats"),in_scale:y.boolean().optional().describe("true: only notes in the scale, false: only notes outside it. The scale is the song's (in midi_clip_edit_notes: snap_to_scale's, when given)"),only_selected:y.boolean().optional().describe("Only the notes selected in Live's MIDI editor. Whether Live reports the selection to extensions is unverified: a `warning` says when it reported none"),every_nth:y.union([y.number().int().min(1),y.object({n:y.number().int().min(1),offset:y.number().int().min(0).default(0)})]).optional().describe("Every n-th of the notes the other filters match, in time order (start, then pitch): 2 = the 1st, 3rd, 5th, ...; {n: 2, offset: 1} = the 2nd, 4th, ...")}),Lq=()=>y.union([y.literal("song"),y.object({root:y.union([y.number().int().min(0).max(11),y.string().min(1)]).describe('Root as 0-11 (C = 0) or a note name such as "D" or "F#"'),intervals:y.array(y.number().int()).min(1).describe("Semitone offsets from the root, e.g. [0, 2, 3, 5, 7, 8, 10] (natural minor)")})]),lj=(e,t)=>((e-t)%12+12)%12,ok=(e,t)=>t.intervals.includes(lj(e,t.root_note));function Uq(e,t){for(let n=0;n<12;n++){if(e-n>=0&&ok(e-n,t))return e-n;if(e+n<=127&&ok(e+n,t))return e+n}return e}var Y1=e=>y.union([y.number().positive(),y.literal("song")]).describe(`${e} in beats (0.25 = 1/16), or "song" for Live's grid setting (the arrangement grid, not the clip editor's; bar grids assume the first scene's time signature)`),uj=e=>e.map((t,n)=>n).sort((t,n)=>q(e[t].startTime)-q(e[n].startTime)||q(e[t].pitch)-q(e[n].pitch)||t-n);function Q1(e,t){let n=e.pitch_min===void 0?0:Ai(e.pitch_min,"select.pitch_min"),i=e.pitch_max===void 0?127:Ai(e.pitch_max,"select.pitch_max"),r=typeof e.every_nth=="number"?{n:e.every_nth,offset:0}:e.every_nth,o=a=>{let s=q(a.pitch),c=q(a.startTime);return s>=n&&s<=i&&(e.time_min===void 0||c>=e.time_min)&&(e.time_max===void 0||c<=e.time_max)&&(e.in_scale===void 0||ok(s,t)===e.in_scale)&&(!e.only_selected||a.selected===!0)};return a=>{let s=a.map(o);if(r){let c=0;for(let l of uj(a))s[l]&&(s[l]=c>=r.offset&&(c-r.offset)%r.n===0,c++)}return s}}function ej(e){if(!(!e.length||e.some(t=>t.selected===!0)))return e.some(t=>typeof t.selected=="boolean")?"No note of this clip is selected in Live.":"Live reported no selection state for this clip's notes, so none counts as selected."}function Zq(e){let t=n=>n===void 0?void 0:q(n);return{pitch:q(e.pitch),start_time:q(e.startTime),duration:q(e.duration),velocity:t(e.velocity),muted:e.muted,probability:t(e.probability),velocity_deviation:t(e.velocityDeviation),release_velocity:t(e.releaseVelocity),selected:e.selected}}var ak={muted:!1,probability:1,velocity_deviation:0,release_velocity:64,selected:!1},tj=Object.keys(ak);function Fq(e){let t=(i,r)=>i[r]??ak[r],n={...ak};for(let i of tj){let r=new Map;for(let a of e)r.set(t(a,i),(r.get(t(a,i))??0)+1);let o=0;for(let[a,s]of r)s>o&&(o=s,n[i]=a)}return{format:"compact",fields:["pitch","start_time","duration","velocity"],defaults:n,notes:e.map(i=>{let r=[i.pitch,i.start_time,i.duration,i.velocity??null],o=tj.filter(a=>t(i,a)!==n[a]);return o.length&&r.push(Object.fromEntries(o.map(a=>[a,t(i,a)]))),r})}}function Vq(e,t,n){let i=2*t,r=Math.floor(e/i)*i,o=e-r,a=t*(1+n/2);return r+(o<=t?o*a/t:a+(o-t)*(i-a)/t)}var qq=1/64,dj=1/256;function Bq(e){let t=[];for(let n of[...e].sort((i,r)=>i.startTime-r.startTime)){let i=t[t.length-1];i&&n.startTime-i[0].startTime<qq?i.push(n):t.push([n])}for(let n=0;n+1<t.length;n++)for(let i of t[n])i.duration=Math.max(dj,t[n+1][0].startTime-i.startTime)}function Hq(e){let t=e>>>0;return()=>{t=t+1831565813>>>0;let n=t;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}var Jq=y.object({looping:y.boolean(),start_marker:y.number(),end_marker:y.number(),loop_start:y.number(),loop_end:y.number()}).describe("Initial clip region/loop, all positions in beats. Loop must be >= 0.25 beats. When looping is false, loop_start/loop_end must equal start_marker/end_marker. Unwarped clips require looping=false and non-negative positions.");function Ie(e){return e instanceof Error?e.message:e===void 0?"the Live host rejected the operation without details \u2014 check argument values (device name spelling, index ranges, file paths, clip overlaps).":String(e)}var ht=()=>({track_id:y.string().optional().describe("Track id"),track_index:y.number().int().min(0).optional().describe("0-based index among the regular tracks"),track_name:y.string().optional().describe("Track name, exact match first, then case-insensitive (regular, return and main tracks)")}),Es=()=>({scene_id:y.string().optional().describe("Scene id"),scene_index:y.number().int().min(0).optional().describe("0-based scene index"),scene_name:y.string().optional().describe("Scene name, exact match first, then case-insensitive")}),Gq=y.string().optional().describe("Exact track name (case-sensitive)"),Kq=y.string().optional().describe("Exact scene name (case-sensitive)"),Wq=y.union([y.object({chain:y.number().int().min(0).describe("0-based chain index in the rack")}).strict(),y.object({pad:Po("Drum Rack pad: the chain's receiving MIDI note")}).strict()]),rj=()=>y.union([y.string().min(1).describe("Device name, exact match first, then case-insensitive"),y.number().int().min(0).describe("0-based position in the device list")]),cu={device_id:y.string().optional().describe("Device id"),...ht(),device:y.union([rj(),y.array(y.union([rj(),Wq])).min(1)]).optional().describe(`With a track instead of device_id: the device's name or 0-based index on the track, or a path into racks, e.g. ["Drum Rack", {"pad": 36}, "Simpler"] or [0, {"chain": 1}, "Reverb"]`)},nj={parameter_id:y.string().optional().describe("Parameter id (from device_get, mixer_get, parameter_find, ...)"),...cu,parameter:y.string().min(1).optional().describe("Instead of parameter_id: the parameter's name on the device (device_id, or track + device); exact match first, then case-insensitive, then unique substring")},sk={value:y.number().optional().describe("Internal units within [min, max]; a quantized parameter takes its value_items index"),value_item:y.string().min(1).optional().describe('Quantized parameters: the choice by value_items name or short name (exact, then case-insensitive, then unique substring), e.g. "Saw"'),reset:y.boolean().optional().describe("true: set the parameter to its default value"),delta:y.number().optional().describe("Add this to the current value, clamped to [min, max] (whole steps for quantized parameters)")},pj=y.string().min(1).describe("Parameter name: exact match first, then case-insensitive, then unique substring"),ij=y.object({name:pj,...sk}),Yn=(e,t)=>t.some(n=>e[n]!==void 0),fn=e=>Yn(e,["track_id","track_index","track_name"]),Xq=e=>Yn(e,["scene_id","scene_index","scene_name"]);function zo(e,t,n){if(t===void 0)return{list:[e],batch:!1};let i=n.filter(r=>Yn(e,[r]));if(i.length)throw new j(`Give either items or ${i.join(", ")} at the top level, not both.`);return{list:t,batch:!0}}var qi=(e,t)=>e?`items[${t}]`:void 0;function yt(e,t){try{return t()}catch(n){throw e&&n instanceof Error&&(n.message=`${typeof e=="function"?e():e}: ${n.message}`),n}}var mj="ableton-live-mcp/device-preset",Yq=y.object({format:y.literal(mj),version:y.literal(1),name:y.string(),device_name:y.string().min(1),device_class:y.string().optional(),saved_at:y.string().optional(),parameters:y.array(y.object({name:y.string(),value:y.number()})),sample:y.object({file_path:y.string().min(1)}).nullable().optional()}),Qq=/^[\p{L}\p{N}][\p{L}\p{M}\p{N} _\-.,()'+&#]*$/u,e9=/^(con|prn|aux|nul|com[0-9\u00b9\u00b2\u00b3]|lpt[0-9\u00b9\u00b2\u00b3]) *(\..*)?$/i;function oj(e){let t=e.normalize("NFC").trim();if(!t||t.length>64)throw new j("Preset names are 1-64 characters long.");if(!Qq.test(t)||/[. ]$/.test(t)||e9.test(t))throw new j(`Invalid preset name ${JSON.stringify(e)}: use letters, digits, spaces and - _ . , ( ) ' + & #, starting with a letter or digit and not ending with a dot.`);return t}function fj(e){let t=Rt.lstatSync(e);if(!t.isFile())throw new Error(`${e} is not a regular file.`);if(t.size>4e6)throw new Error(`${e} is too large for a preset.`);let n;try{n=JSON.parse(Rt.readFileSync(e,"utf8"))}catch(r){throw new Error(`${e} is not valid JSON: ${Ie(r)}`)}let i=Yq.safeParse(n);if(!i.success){let r=i.error.issues[0],o=r.path.join(".")||"file";throw new Error(`${e} is not a device preset of this server (${o}: ${r.message}).`)}return i.data}function t9(e){if(!e)throw new Error("Live provides no storage directory for this extension, so presets cannot be stored.");let t=Kr.join(e,"presets"),n=a=>{let s=Kr.resolve(t,a);if(Kr.dirname(s)!==Kr.resolve(t))throw new Error(`Refusing a preset path outside ${t}.`);return s},i=()=>{let a;try{a=Rt.readdirSync(t)}catch(s){if(s.code==="ENOENT")return[];throw s}return a.filter(s=>{if(!s.endsWith(".json")||s.startsWith("."))return!1;try{return Rt.lstatSync(n(s)).isFile()}catch{return!1}}).sort()},r=a=>Kr.basename(a,".json").normalize("NFC"),o=a=>{let s=i(),c=s.find(l=>r(l)===a)??s.find(l=>r(l).toLowerCase()===a.toLowerCase());return c===void 0?void 0:n(c)};return{dir:t,find:o,list(){let a=[],s=[];for(let c of i())try{a.push({name:r(c),preset:fj(n(c))})}catch(l){s.push({file:c,error:Ie(l)})}return{presets:a,unreadable:s}},write(a,s,c){let l=o(a);if(l&&!c)throw new j(`A preset named ${JSON.stringify(r(l))} already exists. Pass overwrite:true to replace it.`);Rt.mkdirSync(t,{recursive:!0});let u=l?r(l):a,p=`${JSON.stringify({...s,name:u},null,2)}
|
|
169
169
|
`;if(!l)return Rt.writeFileSync(n(`${a}.json`),p,{flag:"wx"}),{name:u,replaced:!1};let h=n(`.tmp-${Date.now()}-${Math.random().toString(36).slice(2)}.json`);Rt.writeFileSync(h,p,{flag:"wx"});try{Rt.renameSync(h,l)}catch(g){throw Rt.rmSync(h,{force:!0}),g}return{name:u,replaced:!0}}}}function aj(e,t,n,i,r,o={}){let a=new Yf(ik,{instructions:o.note?`${Bw.trimEnd()}
|
|
170
170
|
${o.note}
|
|
171
171
|
`:Bw}),s=()=>e.application.song;a.server.onerror=d=>console.error("[ableton-live-mcp] MCP error:",d.message);let c=new Map,l=new Set;function u(d,m,f,v,$){if(l.add(d),o.allowed&&!o.allowed.has(d))return;c.set(d,{meta:m,shape:v,handler:$});let b={...m,description:f,inputSchema:v};a.registerTool(d,b,(async(w,x)=>{let P=Date.now();try{return Rq(await $(w??{},x))}catch(R){let I=Ie(R);return console.error(`[ableton-live-mcp] ${d} failed after ${Date.now()-P} ms: ${I}`),{content:[{type:"text",text:R instanceof j?`Error: ${I}`:`Error: ${I}
|
package/manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ulm0/ableton-live-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "MCP server for Ableton Live, embedded in a Live Extension",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"manifest.json",
|
|
27
27
|
"*.ablx",
|
|
28
28
|
"SHA256SUMS",
|
|
29
|
+
"skills/",
|
|
29
30
|
"SECURITY.md"
|
|
30
31
|
],
|
|
31
32
|
"engines": {
|
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ableton-live
|
|
3
|
+
description: Control Ableton Live via the ableton-live MCP server — compose MIDI, arrange tracks, edit clips, tweak devices and mix. Use whenever the user asks to do anything in Ableton Live (create tracks/clips/notes, change tempo, add devices, mix levels, warp audio, render stems).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Ableton Live via MCP
|
|
7
|
+
|
|
8
|
+
The `ableton-live` MCP server (streamable HTTP, `http://127.0.0.1:8722/mcp`) controls a running
|
|
9
|
+
Ableton Live 12. If tools fail to connect: Live is not running, the extension is not installed,
|
|
10
|
+
or the port was changed in the extension's `config.json` (default 8722). HTTP 401 means the
|
|
11
|
+
user set an `auth_token` in config.json and the client must send `Authorization: Bearer
|
|
12
|
+
<token>`; 503 means config.json has an invalid or misspelled security setting (`read_only`,
|
|
13
|
+
`disabled_tools`, `auth_token`, including a `disabled_tools` entry that names no tool), or exists
|
|
14
|
+
but cannot be read or parsed (the error says which, and the Status dialog in Live too). Ask the
|
|
15
|
+
user to fix their client or config; never guess a token.
|
|
16
|
+
|
|
17
|
+
## Core workflow
|
|
18
|
+
|
|
19
|
+
1. **Always start with `song_get`.** It returns the set with object ids. Every other tool
|
|
20
|
+
takes those ids. Pass `include` to fetch only some sections. To read the whole set in one
|
|
21
|
+
call, add the deep sections: `song_get {include:["tracks", "devices", "mixer", "clips"]}`
|
|
22
|
+
(see [Reading the whole set](#reading-the-whole-set)).
|
|
23
|
+
2. Drill down with `track_get` / `device_get` / `clip_get` — they return child ids (clips,
|
|
24
|
+
parameters, chains). `track_get` takes an `include` selector to skip sections you don't
|
|
25
|
+
need.
|
|
26
|
+
3. **Address tracks and scenes by name when the user does.** Every tool that acts on one track
|
|
27
|
+
(`track_get`, `track_set`, `track_delete`, `track_duplicate`, `track_clear_clips_in_range`,
|
|
28
|
+
`take_lane_create`, `render_track_audio`, `audio_track_consolidate`, `mixer_get`, `mixer_set`,
|
|
29
|
+
`device_insert`, `drum_kit_build`, `clip_create`, `clip_copy`) takes `track_id`, `track_index`
|
|
30
|
+
(0-based, regular tracks) or `track_name` (exact first, then case-insensitive; also finds
|
|
31
|
+
return and main tracks). The scene tools, `clip_create` and `clip_copy` take `scene_id`,
|
|
32
|
+
`scene_index` or `scene_name`. "Mute the Drums" is one call:
|
|
33
|
+
`track_set {track_name:"Drums", mute:true}`. If you give several fields they must name
|
|
34
|
+
the same object. An ambiguous name fails with the matching candidates — pick one by id or
|
|
35
|
+
index. `track_delete` and `scene_delete` only accept the exact name. Parameters work the same
|
|
36
|
+
way: see [Devices & sound design](#devices--sound-design).
|
|
37
|
+
4. Ids become stale when objects are deleted/moved or a different set is loaded. On a stale-id
|
|
38
|
+
error, re-run `song_get` and re-resolve. Errors about your arguments (unknown name, index
|
|
39
|
+
out of range, missing or conflicting fields) come without the stale-id hint: fix the call
|
|
40
|
+
instead.
|
|
41
|
+
5. Writes apply asynchronously: a read right after a write can still return the old value.
|
|
42
|
+
6. The user can switch tools off in config.json: `read_only` leaves only the tools that read the
|
|
43
|
+
set, `disabled_tools` drops the ones it names. A switched-off tool is not listed at all (a
|
|
44
|
+
batch step naming it fails with "switched off"); the server instructions say which. Tell the
|
|
45
|
+
user that the action is switched off on their server instead of looking for a workaround.
|
|
46
|
+
A prompt (see below) is only offered when every tool it uses is available.
|
|
47
|
+
|
|
48
|
+
## Resources and prompts
|
|
49
|
+
|
|
50
|
+
- Resources, for clients that attach context: `live://song` (what `song_get` returns without
|
|
51
|
+
arguments), `live://tracks/{track}` (what `track_get` returns; `{track}` is the track name
|
|
52
|
+
percent-encoded with encodeURIComponent, so "Drums/Bus" is `live://tracks/Drums%2FBus`; names
|
|
53
|
+
that several tracks share are not listed — use `track_get` with an index or id) and
|
|
54
|
+
`live://guide` (this guide). They are snapshots: read again for fresh data, there are no
|
|
55
|
+
subscriptions.
|
|
56
|
+
- Prompts the user can pick in the client, each expanding into steps with exact tool calls:
|
|
57
|
+
`song_skeleton {sections?, tempo?, beats_per_bar?, tracks?}` (scenes and locators per section,
|
|
58
|
+
e.g. sections "Intro:8, Verse:16, Chorus:16"), `chord_progression {progression?, key?,
|
|
59
|
+
bars_per_chord?, beats_per_bar?, octave?, voicing?, track?}` (Roman numerals in a key —
|
|
60
|
+
default Live's current scale — or chord names, voiced by the server) and `drum_beat {style?, bars?, track?, tempo?,
|
|
61
|
+
swing?}` (house, techno, hip_hop, trap, dnb, breakbeat, rock, reggaeton). Follow their steps;
|
|
62
|
+
values written as "<...>" are yours to fill in.
|
|
63
|
+
|
|
64
|
+
## Reading the whole set
|
|
65
|
+
|
|
66
|
+
- `song_get` tracks carry `index` (the `track_index`), `depth` in the group hierarchy and
|
|
67
|
+
`group_track_id`; group tracks have `is_group: true` and `child_track_ids` ("the drum bus" is
|
|
68
|
+
the group whose children are the drums) — their `type` is `"other"`. Return tracks have
|
|
69
|
+
`type: "return"` and the main track `"main"` here (`track_get` and `selection_get` report both
|
|
70
|
+
as `"other"`).
|
|
71
|
+
Return tracks carry `send_index` (their send).
|
|
72
|
+
- Deep sections, only when listed in `include` (they imply the tracks): `devices` (each track's
|
|
73
|
+
device tree through racks — chains with `receiving_note_name` and their devices — and every
|
|
74
|
+
device's on-state `enabled`), `mixer` (volume, panning, sends labeled with `return_track`),
|
|
75
|
+
`clips` (session clips with `scene_index`, arrangement clips with start/end, in brief). They
|
|
76
|
+
stop at 500 devices / 500 clips: then `truncated` names the first track left out — read the
|
|
77
|
+
rest with `track_get` / `device_get`.
|
|
78
|
+
- One scene across all tracks ("what's in the chorus?"): `scene_get {scene_name:"Chorus",
|
|
79
|
+
only_clips?}`. The whole session at a glance: `session_grid` (a track × scene matrix, cells
|
|
80
|
+
`null` or a brief clip; narrow with `tracks` and `scene_index_min`/`scene_index_max`).
|
|
81
|
+
- A stretch of the arrangement ("what happens from bar 17 to bar 33?" = beats 64 to 128 at 4/4):
|
|
82
|
+
`arrangement_get {start_time:64, end_time:128, tracks?, include_take_lanes?}` returns the cue
|
|
83
|
+
points in the range and every track's overlapping clips, plus `song_end` (the end of the last
|
|
84
|
+
arrangement clip — the API has no song length). Without a range it covers the whole song.
|
|
85
|
+
- Housekeeping: `song_audit` lists missing media files (audio clips and Simpler samples whose file
|
|
86
|
+
is gone), Simplers without a sample, empty drum pads and duplicate track names, each with ids
|
|
87
|
+
and a location. It changes nothing; offer fixes (`simpler_replace_sample`, `track_set` names)
|
|
88
|
+
and confirm before deleting anything.
|
|
89
|
+
- `clip_get`, `device_get` and `chain_get` include a `location`: a clip's view (`session` with
|
|
90
|
+
track and scene, `arrangement`, `take_lane`), a device's track, path through racks
|
|
91
|
+
(`"Kit > Drum Rack > pad 36 > Simpler"`) and position.
|
|
92
|
+
|
|
93
|
+
## The user's selection ("this clip", "these slots", "the selected range")
|
|
94
|
+
|
|
95
|
+
- Live's API cannot read the selection. The extension adds **"MCP: Use as selection"** to Live's
|
|
96
|
+
context menus (clips, clip slots, tracks, scenes, Drum Racks, Simplers, samples, a selection of
|
|
97
|
+
clip slots, an arrangement time selection). When the user refers to something they selected,
|
|
98
|
+
ask them to right-click it and choose that entry, then call `selection_wait` (waits up to
|
|
99
|
+
`timeout_s`, at most 55 s; on `timed_out`, ask again). `selection_get` returns the last capture
|
|
100
|
+
without waiting — check `age_s` before trusting an old one.
|
|
101
|
+
- The result: `items` (the clicked object, or each selected clip slot) with ids, summaries and
|
|
102
|
+
`location`; for an arrangement time selection, `time_selection {start_time, end_time}` in
|
|
103
|
+
beats and `lanes` (the selected tracks or take lanes) with the clips overlapping it. Pass the
|
|
104
|
+
ids to the other tools: "quantize this" = `midi_clip_edit_notes {clip_id:<items[0].id>,
|
|
105
|
+
quantize:{grid:0.25}}`; "render the selected range" = `render_track_audio {track_id, start_time,
|
|
106
|
+
end_time}` from the time selection.
|
|
107
|
+
- An item with `error` was deleted or moved since, or Live passed something unexpected: ask the
|
|
108
|
+
user to select again. Don't guess ids instead.
|
|
109
|
+
|
|
110
|
+
## Batch edits (one call, one undo step)
|
|
111
|
+
|
|
112
|
+
- `track_set`, `scene_set`, `cue_point_set`, `clip_set`, `take_lane_set` and `mixer_set` take
|
|
113
|
+
`items: [...]` — one entry per object, each with its address and values:
|
|
114
|
+
`track_set {items:[{track_name:"Bass", mute:true}, {track_name:"Keys", solo:false}]}`,
|
|
115
|
+
`scene_set {items:[{scene_index:0, name:"Intro"}, {scene_index:1, name:"Verse"}]}`.
|
|
116
|
+
- `clip_set {select:{track_name:"Drums", scope:"all", name_contains?}, warp_mode:"ComplexPro"}`
|
|
117
|
+
changes every matching clip of one track (scope: `session`, `arrangement`, `take_lanes` or
|
|
118
|
+
`all`).
|
|
119
|
+
- Every entry is validated first: one bad entry (unknown name, bad color, warp settings on a
|
|
120
|
+
MIDI clip) fails the whole call and changes nothing; the error names the entry
|
|
121
|
+
(`items[2]: ...`). The user undoes the whole batch with one Cmd/Ctrl-Z — except
|
|
122
|
+
`cue_point_set` moves, which take up to three undo steps (creates, names, deletes).
|
|
123
|
+
- Prefer one batched call over a loop of single calls.
|
|
124
|
+
|
|
125
|
+
## Chaining dependent calls (`batch`, `batch_read`)
|
|
126
|
+
|
|
127
|
+
- When a call needs the result of the one before (create a track, then a clip on it, then its
|
|
128
|
+
notes) and no compound tool does it, send the whole chain in one `batch {steps:[{tool, args,
|
|
129
|
+
as?}]}` (up to 50 steps, run in order). `args` are exactly a direct call's arguments; a value
|
|
130
|
+
`{"$ref": "<step>.<path>"}` is taken from an earlier step's result — `<step>` is its 0-based
|
|
131
|
+
index or its `as` name, `<path>` keys and array indexes:
|
|
132
|
+
`batch {steps:[{tool:"track_create", args:{type:"midi", name:"Keys"}, as:"keys"},
|
|
133
|
+
{tool:"clip_create", args:{type:"midi", track_id:{"$ref":"keys.id"}, start_time:0, duration:4}},
|
|
134
|
+
{tool:"midi_clip_set_notes", args:{clip_id:{"$ref":"1.id"}, notes:[...]}}]}`.
|
|
135
|
+
- Unknown tools, bad `$ref`s and invalid arguments of steps without a `$ref` fail the call
|
|
136
|
+
before anything runs; steps with a `$ref` are checked when they run. The batch is NOT one undo
|
|
137
|
+
step and not atomic: with `on_error:"stop"` (default) it ends at the first failing step and
|
|
138
|
+
the earlier ones stay applied — read `results` (per step `result` or `error`), `completed`
|
|
139
|
+
and `not_run`, and tell the user what happened. `on_error:"continue"` runs the rest.
|
|
140
|
+
- Prefer the compound tools and `items` batches when they fit: they validate everything first
|
|
141
|
+
and are one undo step. `batch` cannot hold `show_dialog`, `execute_command` or another batch.
|
|
142
|
+
- `batch_read` is the read-only form (`*_get`, `midi_clip_get_notes`, `session_grid`,
|
|
143
|
+
`arrangement_get`, `parameter_find`, `sample_search`, `selection_wait`, ...): it refuses any
|
|
144
|
+
step that can change the set and continues after a failed step by default. E.g. a track by
|
|
145
|
+
name, then the notes of its first clip: `{steps:[{tool:"track_get", args:{track_name:"Bass",
|
|
146
|
+
include:["clip_slots"]}, as:"t"}, {tool:"midi_clip_get_notes",
|
|
147
|
+
args:{clip_id:{"$ref":"t.clip_slots.0.clip.id"}}}]}`.
|
|
148
|
+
|
|
149
|
+
## Units and conventions
|
|
150
|
+
|
|
151
|
+
- All times, positions, durations are **beats** (quarter notes), not seconds or bars.
|
|
152
|
+
At 4/4, one bar = 4 beats. Seconds → beats: `seconds * tempo / 60`.
|
|
153
|
+
- MIDI pitch: 0–127, C3 = 60 in Live's naming (C-2 = 0). Kick drum pad usually C1 = 36.
|
|
154
|
+
Wherever a pitch is taken (notes, patterns, `select` ranges, drum pads, `drum_chain_set`) a
|
|
155
|
+
note name works too: `"C1"`, `"F#1"`, `"Bb2"` (sharps `#`, flats `b`).
|
|
156
|
+
- Colors: `"#RRGGBB"` strings.
|
|
157
|
+
- Velocity 0–127, probability 0–1.
|
|
158
|
+
- Device parameters use internal units within each parameter's `min`/`max` (no dB/Hz/ms
|
|
159
|
+
display values). Quantized parameters (switches, choosers) take the `value_items` index, or
|
|
160
|
+
the choice by name with `value_item`.
|
|
161
|
+
|
|
162
|
+
## MIDI composition
|
|
163
|
+
|
|
164
|
+
- Create track: `track_create {type:"midi", name:"Bass", devices:["Operator"]}` names it and
|
|
165
|
+
inserts devices in the same call (`{name:"Auto Filter", parameters:[{name:"Frequency",
|
|
166
|
+
value:80}]}` sets initial values). Live inserts the new track after the selected one, so use
|
|
167
|
+
the returned `index`/`id`, not "the last track". A device that fails to insert is reported
|
|
168
|
+
in `errors` (and its `devices` entry); the track and the other devices are still created.
|
|
169
|
+
- Then create clip + notes in ONE call:
|
|
170
|
+
- Session: `clip_create {type:"midi", track_name:"Bass", scene_name:"Verse", duration:4, notes:[...], name, color}`
|
|
171
|
+
(or `target_id:<track_id>, scene_index:0`)
|
|
172
|
+
- Arrangement: `clip_create {type:"midi", target_id:<midi_track_id>, start_time, duration, notes:[...]}`
|
|
173
|
+
- Take lane: `clip_create {type:"midi", target_id:<take_lane_id>, start_time, duration, ...}`
|
|
174
|
+
- MIDI clips ignore the audio-only `file_path`, `is_warped` and `loop_settings` (the result's
|
|
175
|
+
`warning` says so): don't send them for MIDI.
|
|
176
|
+
- Drum lines and other repetitive parts: step `patterns` instead of one note per hit — one
|
|
177
|
+
pitch per string, `"x"` a hit, `"X"` an accent (`accent_velocity`, default 127), `"."` or `"-"`
|
|
178
|
+
a rest, spaces and `|` ignored; `step` is the beats per character (default 0.25 = 1/16).
|
|
179
|
+
`repeat {length}` copies the notes and patterns every `length` beats up to the clip's end
|
|
180
|
+
(`times` for an exact count). A two-bar beat in one call:
|
|
181
|
+
`clip_create {type:"midi", track_name:"Drums", scene_index:0, duration:8, repeat:{length:4},
|
|
182
|
+
patterns:[{note:"C1", steps:"x...x...x...x..."}, {note:"D1", steps:"....X.......X..."},
|
|
183
|
+
{note:"F#1", steps:"x.x.x.x.x.x.x.x.", velocity:80}]}`. `midi_clip_set_notes` takes the
|
|
184
|
+
same `patterns` and `repeat`.
|
|
185
|
+
- Layer more notes: `midi_clip_set_notes {mode:"merge", notes:[...]}` (default mode `replace`
|
|
186
|
+
wipes the clip — only use it when rewriting everything).
|
|
187
|
+
- Reading notes: `midi_clip_get_notes {select?, format?}`. `select` filters like the edit's
|
|
188
|
+
(below); `format:"compact"` returns `[pitch, start_time, duration, velocity]` tuples plus an
|
|
189
|
+
object of the fields that differ from the result's `defaults` — use it for dense clips.
|
|
190
|
+
- Mechanical edits: `midi_clip_edit_notes` — server-side, no need to read and resend the note
|
|
191
|
+
list. Note times are relative to the clip start.
|
|
192
|
+
- `select` (all filters must match): `pitch_min`/`pitch_max` (numbers or names),
|
|
193
|
+
`time_min`/`time_max` (start, beats), `in_scale` (true/false against the song's scale, or
|
|
194
|
+
`snap_to_scale`'s), `every_nth` (`2` = 1st, 3rd, ... in time order; `{n:2, offset:1}` = 2nd,
|
|
195
|
+
4th, ...), `only_selected` (the notes the user selected in Live's editor).
|
|
196
|
+
- Transforms, in this order: `transpose`; `snap_to_scale` (`"song"` or `{root:"D",
|
|
197
|
+
intervals:[0,2,3,5,7,9,10]}`; out-of-key notes move to the nearest scale note, ties go
|
|
198
|
+
down); `set {velocity, probability, velocity_deviation, release_velocity, muted}`;
|
|
199
|
+
`velocity_scale`, `velocity_offset`; `time_shift`; `quantize {grid, strength}`; `swing
|
|
200
|
+
{amount, grid}` (0 = straight, ~0.67 = triplet feel, 1 = dotted); `duration_set` or
|
|
201
|
+
`duration_scale`; `legato` (each note runs to the next start; notes starting together are
|
|
202
|
+
a chord and end together; the last keep their length); `humanize {timing, velocity, seed}`.
|
|
203
|
+
Or `delete:true`.
|
|
204
|
+
- A grid of `"song"` (quantize, swing) uses Live's grid setting — the arrangement grid, not
|
|
205
|
+
the clip editor's; bar grids assume the first scene's time signature, "No Grid" fails.
|
|
206
|
+
- `humanize` is reproducible: pass `seed`, or reuse the returned `humanize_seed`.
|
|
207
|
+
- `clip_ids:[...]` edits several clips alike in one undo step (one notes write per clip):
|
|
208
|
+
"humanize these 8 drum clips" is one call.
|
|
209
|
+
- "Fix the out-of-key notes" = `{clip_id, snap_to_scale:"song"}`; "mute every second hi-hat"
|
|
210
|
+
= `{select:{pitch_min:"F#1", pitch_max:"F#1", every_nth:{n:2, offset:1}}, set:{muted:true}}`.
|
|
211
|
+
- The user's note selection: `only_selected` (and each note's `selected` in reads) comes from
|
|
212
|
+
`NoteDescription.selected`. Whether Live fills it in for extensions is unverified: when no
|
|
213
|
+
note reports a selection, results carry a `warning` — then ask the user which notes they
|
|
214
|
+
mean instead of guessing.
|
|
215
|
+
- Respect the song scale from `song_get` (`scale.root_note`, `scale.intervals`) when composing.
|
|
216
|
+
- Notes the user selected inside a clip's editor are `only_selected` (above); which clip, slot or
|
|
217
|
+
range they mean is the context-menu selection (see [The user's selection](#the-users-selection-this-clip-these-slots-the-selected-range)).
|
|
218
|
+
|
|
219
|
+
## Devices & sound design
|
|
220
|
+
|
|
221
|
+
- `device_insert` takes built-in Live device names: "Operator", "Wavetable", "Drum Rack",
|
|
222
|
+
"Simpler", "Reverb", "Delay", "Auto Filter", "EQ Eight", "Compressor", "Saturator", ...
|
|
223
|
+
Third-party plug-ins cannot be inserted. One instrument per track — inserting a second
|
|
224
|
+
instrument fails.
|
|
225
|
+
- **Address parameters by name — no id lookup needed.** `parameter_get` and `parameter_set`
|
|
226
|
+
entries take `{track_name, device, parameter}` (or `{device_id, parameter}`, or the old
|
|
227
|
+
`{parameter_id}`):
|
|
228
|
+
- `device`: a name (exact, then case-insensitive), a 0-based index on the track, or a path
|
|
229
|
+
into racks: `["Drum Rack", {pad:36}, "Simpler"]` (a pad is the drum chain with that
|
|
230
|
+
receiving note) or `["Instrument Rack", {chain:1}, 0]` (chains by index; chains have no
|
|
231
|
+
names).
|
|
232
|
+
- `parameter`: exact name first, then case-insensitive, then a unique substring (`"freq"` →
|
|
233
|
+
"Frequency"). Ambiguous matches fail with the candidates and their ids.
|
|
234
|
+
- Each write gives exactly one of `value` (internal units), `value_item` (a quantized
|
|
235
|
+
parameter's choice by name or short name, matched like `parameter`: `"high"` →
|
|
236
|
+
"Highpass"), `reset:true` (back to the default) or `delta` (relative to the current value,
|
|
237
|
+
clamped).
|
|
238
|
+
- "Switch the bass filter to high-pass" is one call, e.g.
|
|
239
|
+
`parameter_set {values:[{track_name:"Bass", device:"Auto Filter", parameter:"Filter Type", value_item:"high"}]}`
|
|
240
|
+
(when unsure of the exact names, `parameter_find` first).
|
|
241
|
+
- `device_set {track_name, device, enabled?, parameters?:[{name, value|value_item|reset|delta}]}`
|
|
242
|
+
bypasses or enables a device and sets several of its parameters in one undo step. `enabled`
|
|
243
|
+
uses the "Device On" parameter (a Live convention, not an API field); a device without one
|
|
244
|
+
falls back to a two-state first parameter, and `on_parameter.fallback` says so. Some devices
|
|
245
|
+
have no switch at all — that fails with a clear error.
|
|
246
|
+
- Don't know the parameter name? `parameter_find {track_name, query:"cutoff"}` (or the whole set,
|
|
247
|
+
or one device; `value_item:"saw"` finds choosers with that choice) returns ids, device names and
|
|
248
|
+
paths like "Drums > Drum Rack > pad 36 > Simpler". Big devices have 100+ params: prefer
|
|
249
|
+
`parameter_find` or `device_get {parameter_filter, include_values:true}` over dumping all.
|
|
250
|
+
- `device_insert` and `track_create` devices take initial `parameters:[{name, value|value_item|…}]`.
|
|
251
|
+
- dB, Hz and ms are not available: values are internal units only. Read `min`/`max` and the
|
|
252
|
+
current value first, and say that any unit conversion is approximate.
|
|
253
|
+
- Drum racks: `device_get {include_chain_devices:true}` maps the whole kit (pad → note →
|
|
254
|
+
sample) in one call; drum chains report `receiving_note` and `receiving_note_name` (`"C1"`).
|
|
255
|
+
`drum_chain_set` maps a pad to a MIDI note (`receiving_note: 38` or `"D1"`), and pads in
|
|
256
|
+
device paths take names too (`["Drum Rack", {pad:"C1"}, "Simpler"]`);
|
|
257
|
+
`simpler_replace_sample` swaps samples. `rack_insert_chain {rack_device_id, index}` adds an empty
|
|
258
|
+
chain to a rack (fill it with `device_insert {target_id:<chain id>, device_name}`).
|
|
259
|
+
- **A kit from sample files is one call**: `drum_kit_build {track_name:"Drums", pads:[{note:"C1",
|
|
260
|
+
sample_path:"/abs/kick.wav"}, {note:"D1", sample_path:"/abs/snare.wav", volume:0.7},
|
|
261
|
+
{note:"F#1", sample_path:"/abs/hat.wav", panning:0.2}]}`. It uses the track's Drum Rack (or
|
|
262
|
+
inserts one on a MIDI track; `rack_device_id` for a specific rack), reuses the pad receiving
|
|
263
|
+
each note or creates a chain for it, inserts a Simpler (or keeps the pad's Simpler and REPLACES
|
|
264
|
+
its sample), imports the sample into the project and loads it; `volume` (0-1, 0.85 = 0 dB) and
|
|
265
|
+
`panning` set the pad's chain mixer. Every path is checked first; a pad that fails later
|
|
266
|
+
carries `error` in its entry while the others are built (Live cannot delete a chain, so a
|
|
267
|
+
created chain stays). Need the paths? `sample_search {query:"808 kick"}` first.
|
|
268
|
+
- Samples go into the project: `device_insert {device_name:"Simpler", sample_path}` and
|
|
269
|
+
`drum_kit_build` copy the file into the Live project by default and load the copy
|
|
270
|
+
(`imported_path`), so the set keeps working when moved; `import_into_project:false` loads the
|
|
271
|
+
original. `simpler_replace_sample` loads the file as it is unless you pass
|
|
272
|
+
`import_into_project:true` — do pass it.
|
|
273
|
+
|
|
274
|
+
## Copying, moving and presets (lossy)
|
|
275
|
+
|
|
276
|
+
- Live's API cannot move, reorder or copy devices. `device_copy {device_id, track_name |
|
|
277
|
+
target_id, index?}` inserts a fresh built-in device of the same name and copies its parameter
|
|
278
|
+
values by name (a Simpler also gets its sample). `move:true` deletes the original afterwards:
|
|
279
|
+
"move the compressor before the EQ" = `device_copy {device_id:<comp>, index:<EQ's index>,
|
|
280
|
+
move:true}` (target omitted = the same track or chain; `index` counts the current devices).
|
|
281
|
+
- It is lossy and you must say so: automation, modulation and MIDI/macro mappings, a custom
|
|
282
|
+
device name and any state that is not a parameter are lost, and the device gets a new id
|
|
283
|
+
(the old one is gone after a move). Racks are refused (use `device_duplicate` in place). If
|
|
284
|
+
some values could not be copied (`not_copied`), a move keeps the original.
|
|
285
|
+
- If the user renamed the device in Live, pass the built-in name as `device_name`.
|
|
286
|
+
- Presets: `device_preset_save {name, track_name, device}` stores the parameter values (and a
|
|
287
|
+
Simpler's sample path) as JSON in the extension's storage directory; `device_preset_load
|
|
288
|
+
{name, track_name}` inserts the device with those values (add `device` or `device_id` to
|
|
289
|
+
load onto an existing one); `device_preset_list` shows them. These are this server's
|
|
290
|
+
snapshots, not Live presets (`.adv`): no automation, mappings or other device state.
|
|
291
|
+
|
|
292
|
+
## Mixing
|
|
293
|
+
|
|
294
|
+
- `mixer_set {track_name | target_id, volume?, panning?, sends?}` sets levels in one call (one
|
|
295
|
+
undo step). Volume is normalized 0–1 (0.85 = 0 dB unity, 1.0 = +6 dB), panning -1..1.
|
|
296
|
+
- Sends are addressed by `index` (aligned with the return tracks) or `return_name`:
|
|
297
|
+
`sends:[{return_name:"A-Reverb", value:0.3}]`.
|
|
298
|
+
- Many mixers at once, still one undo step: `targets:[{track_name:"Bass"}, {track_name:"Keys"}]`
|
|
299
|
+
(same values), `items:[{track_name, volume}, ...]` (own values), or
|
|
300
|
+
`all_tracks:true, exclude:[{track_name:"Vocals"}]` (every regular track but those).
|
|
301
|
+
With `all_tracks`, volume is only set on the top-most tracks: a group covers its tracks
|
|
302
|
+
(they keep their volume, so it is not changed twice); panning and sends are set on every
|
|
303
|
+
track, grouped ones included (a grouped track's sends go straight to the returns), and a
|
|
304
|
+
covered track then says `volume_skipped`. Tracks inside an excluded group are left alone,
|
|
305
|
+
and a group holding an excluded track is skipped while its other tracks are set. The
|
|
306
|
+
result's `skipped` says why.
|
|
307
|
+
- There is no relative or dB setting: read the current values with `mixer_get` first if the
|
|
308
|
+
user asks for "3 dB quieter", and say that the dB mapping is approximate.
|
|
309
|
+
- `mixer_get` returns the same values with parameter ids (for `parameter_set` automation).
|
|
310
|
+
|
|
311
|
+
## Audio
|
|
312
|
+
|
|
313
|
+
- Audio clips: `clip_create {type:"audio", file_path:"/abs/path.wav", ...}` — the file is
|
|
314
|
+
imported into the project automatically (keep `import_into_project: true`).
|
|
315
|
+
- Warping: `clip_set {warping, warp_mode}` — modes: Beats, Tones, Texture, Repitch, Complex,
|
|
316
|
+
ComplexPro. For all clips of a track: `clip_set {select:{track_name:"Drums"}, warping:true,
|
|
317
|
+
warp_mode:"ComplexPro"}`.
|
|
318
|
+
- `render_track_audio` renders the pre-FX audio of an audio track (its clip audio before the
|
|
319
|
+
device chain: no effects, mixer or sends) to a WAV or AIFF file (Live's Record File Type
|
|
320
|
+
setting decides) and returns the path — useful for
|
|
321
|
+
analysis or resampling. Since Live 12.4.15 the render is not normalized. The file lives in
|
|
322
|
+
the extension's temp directory, which may be cleaned: `persist:true` copies it into the
|
|
323
|
+
project (`imported_path`; or `import_file` it, or `clip_create` with it).
|
|
324
|
+
- "Is this take clipping / silent / where is it loud?": `render_track_audio {track_name, start_time,
|
|
325
|
+
end_time, analyze:true}` returns `analysis` read from the render: `file_type` (`wav` or
|
|
326
|
+
`aiff`), `peak_dbfs` and `rms_dbfs`
|
|
327
|
+
(overall and per channel; `null` = digital silence), `clipped_samples` (at or over 0 dBFS),
|
|
328
|
+
`silent` (peak below -80 dBFS) and a 32-part `envelope` of peak and RMS dBFS. Pre-FX: it
|
|
329
|
+
measures the clips, not the track's output after its devices and fader (there is no metering).
|
|
330
|
+
`tracks:[...]` renders and analyzes several audio tracks over the same range.
|
|
331
|
+
- Consolidating a comp or a stretch of clips: `audio_track_consolidate {track_name, start_time,
|
|
332
|
+
end_time, name?, color?}` renders the range pre-FX, imports the render, clears the range and
|
|
333
|
+
puts one unwarped clip there (it then plays at the current tempo only). Destructive: confirm
|
|
334
|
+
first. The device chain stays on the track.
|
|
335
|
+
- Finding files: `sample_search {query:"kick 808", extensions?, roots?, limit?}` searches the
|
|
336
|
+
`sample_roots` of the extension's config.json plus Live's User Library and Factory Packs
|
|
337
|
+
folders (when they exist) — read-only, and nothing outside those folders. With no folder it
|
|
338
|
+
returns a `hint`: tell the user to add `"sample_roots": ["/path/to/samples"]` to config.json.
|
|
339
|
+
|
|
340
|
+
## Song structure
|
|
341
|
+
|
|
342
|
+
- Tempo: `song_set {tempo}` (BPM; the only song-level property Live lets extensions write).
|
|
343
|
+
- Scenes: `scene_create {items:[{name:"Intro"}, {name:"Verse"}, {name:"Chorus"}]}` appends
|
|
344
|
+
them in order (an entry's `index` refers to the list after the previous entries).
|
|
345
|
+
`scene_duplicate {scene_name}` duplicates a scene; the copy lands right after the original.
|
|
346
|
+
- Locators: `cue_point_create {items:[{time:0, name:"Intro"}, {time:32, name:"Verse"}]}`.
|
|
347
|
+
- Moving a locator: `cue_point_set {cue_point_id, time}`. Live cannot change a cue point's
|
|
348
|
+
time, so it is re-created at the new time with its name and the old one is deleted: use the
|
|
349
|
+
returned `id` from then on (`replaced_id` is the old, now invalid one). A move onto a beat
|
|
350
|
+
that already has a cue point is refused.
|
|
351
|
+
- Copying clips: `clip_copy {clip_id, track_name, start_time}` (arrangement), `{clip_id,
|
|
352
|
+
track_name, scene_name}` (an empty session slot) or `{clip_id, target_id:<take lane>,
|
|
353
|
+
start_time}`; `move:true` deletes the source afterwards; `duration` makes it longer (the loop
|
|
354
|
+
repeats). Live's API has no clip copy: the copy is a new clip with a new id. MIDI notes are
|
|
355
|
+
re-based to where the source plays them (`fidelity:"notes"`), so an arrangement copy plays the
|
|
356
|
+
same. A session copy loops its whole length: when the source starts before its loop, or the
|
|
357
|
+
copy is not whole loops, it repeats differently and `lost` says so — tell the user; audio
|
|
358
|
+
copies keep the file, warping and markers but Live warps them itself
|
|
359
|
+
(`fidelity:"approximate"`, check `warp_markers_match` and `differs`). Clip envelopes, groove
|
|
360
|
+
and launch settings are never copied (`lost`) — say so.
|
|
361
|
+
- "Repeat the chorus" / "copy bars 9-16 to bar 33": `arrangement_copy_range {start_time:32,
|
|
362
|
+
end_time:64, to_time:128, tracks?, include_cue_points?}`. It OVERWRITES the target range on
|
|
363
|
+
every selected track (cleared first, also where the source is empty); nothing after it moves
|
|
364
|
+
(the API cannot insert time). MIDI clips crossing the source edges are trimmed; audio clips
|
|
365
|
+
crossing them are skipped and listed in `skipped` — tell the user. Take-lane clips are not
|
|
366
|
+
copied. Confirm with the user before overwriting a range that holds clips.
|
|
367
|
+
|
|
368
|
+
## Interacting with the user in Live
|
|
369
|
+
|
|
370
|
+
- `show_dialog` opens a modal dialog in Live; it blocks Live's UI until the user closes it, so
|
|
371
|
+
use it sparingly: to confirm a destructive bulk edit, ask for a few values, or show a summary.
|
|
372
|
+
- Prefer a `form`: the server builds the page (all text escaped) and answers as JSON.
|
|
373
|
+
`show_dialog {form:{title:"Delete 12 clips?", message:"On Drums and Perc.\nUndo restores them.",
|
|
374
|
+
choices:["Delete", "Keep"]}, wait:false}` → `dialog_result {dialog_id}` → `{status:"closed",
|
|
375
|
+
choice:"Delete", choice_index:0}`. Fields (`text`, `textarea`, `number`, `checkbox`, `select`
|
|
376
|
+
with `options`; `name`, `label?`, `default?`) come back in `values` by name, with every button
|
|
377
|
+
(number: a number or null). Default buttons: OK, or OK and Cancel with fields. Act only on the
|
|
378
|
+
choice the user made; `choice: null` means the dialog closed without a button.
|
|
379
|
+
- Waiting: by default `show_dialog` returns when the dialog closes, but the client's request
|
|
380
|
+
timeout (often 60 s) can end the call first while the dialog stays open. For anything the user
|
|
381
|
+
has to think about, pass `wait:false` and poll `dialog_result {dialog_id, wait_s}` (≤ 50 s;
|
|
382
|
+
`timed_out:true` = still open: call again). After a cut-off call, `dialog_result` without an id
|
|
383
|
+
returns the last dialog's answer. Answers are kept 10 minutes.
|
|
384
|
+
- One dialog at a time: while one is open, `show_dialog` is refused with its `dialog_id` — get
|
|
385
|
+
its answer instead. Only when the user says it is closed already, retry with `force:true`.
|
|
386
|
+
- Own pages: `html` (it must post `close_and_send` itself, see the tool description) or `url`
|
|
387
|
+
(https:, file: or http://localhost) return the page's string as `result`. Dialogs keep no
|
|
388
|
+
state between calls: each one starts from what you pass. Live cannot close a dialog from code.
|
|
389
|
+
|
|
390
|
+
## What is NOT possible
|
|
391
|
+
|
|
392
|
+
The Extensions API (1.0.0) has no access to:
|
|
393
|
+
|
|
394
|
+
- transport (play/stop/record), song position, clip or scene launching;
|
|
395
|
+
- reading the user's selection or focused object directly (only the "MCP: Use as selection"
|
|
396
|
+
context-menu handoff);
|
|
397
|
+
- the song length (`arrangement_get` derives `song_end` from the clips);
|
|
398
|
+
- the browser, third-party plug-ins, Live's own device presets (`.adv`/`.adg`) — the
|
|
399
|
+
`device_preset_*` tools keep this server's JSON snapshots instead;
|
|
400
|
+
- moving, reordering or renaming devices (`device_copy` emulates move/reorder, lossily);
|
|
401
|
+
- automation envelopes, modulation, MIDI/macro mapping;
|
|
402
|
+
- track color, routing and sidechain sources, MIDI routing;
|
|
403
|
+
- reordering or grouping tracks, creating return tracks;
|
|
404
|
+
- metering (no level readouts; `render_track_audio {analyze:true}` measures an audio track's
|
|
405
|
+
clips pre-FX, not its output);
|
|
406
|
+
- editing clip start/end markers or loop positions after creation (a MIDI clip's loop can't
|
|
407
|
+
be set even at creation) — `clip_copy` re-bases a MIDI clip's notes instead;
|
|
408
|
+
- copying, moving or trimming clips natively (`clip_copy` / `arrangement_copy_range` create new
|
|
409
|
+
clips) and inserting time into the arrangement;
|
|
410
|
+
- the song time signature (scenes report theirs, read-only).
|
|
411
|
+
|
|
412
|
+
Don't pretend otherwise or improvise workarounds — tell the user when asked.
|
|
413
|
+
|
|
414
|
+
## Destructive operations
|
|
415
|
+
|
|
416
|
+
`track_delete`, `scene_delete`, `clip_delete`, `cue_point_delete`, `device_delete`,
|
|
417
|
+
`midi_clip_set_notes` (mode `replace`), `midi_clip_edit_notes` (with `delete`),
|
|
418
|
+
`track_clear_clips_in_range`, `simpler_replace_sample` (discards the current sample),
|
|
419
|
+
`device_copy` and `clip_copy` with `move` (delete the original; lossy), `device_preset_load` onto a
|
|
420
|
+
Simpler and `drum_kit_build` on existing pads (replace their samples), `arrangement_copy_range`
|
|
421
|
+
(overwrites its target range) and `audio_track_consolidate` (clears its range) change the user's
|
|
422
|
+
project (each step is undoable in Live). `execute_command` runs arbitrary Live commands, other
|
|
423
|
+
extensions' included, so it is destructive and open-world too.
|
|
424
|
+
`device_preset_save` with `overwrite` replaces a saved preset file. `track_delete` and `scene_delete`
|
|
425
|
+
by name need the exact name, so a case-insensitive guess can't delete the wrong object. They carry the MCP
|
|
426
|
+
`destructiveHint` annotation; read-only tools carry `readOnlyHint`. For bulk destructive edits
|
|
427
|
+
the user didn't explicitly enumerate, confirm first — in Live with a `show_dialog` form
|
|
428
|
+
(see [Interacting with the user in Live](#interacting-with-the-user-in-live)) or in the chat.
|
|
429
|
+
`batch` carries `destructiveHint` too (it runs whatever its steps do); `batch_read` is read-only.
|