ricardomatias / ableton-live

A library for communicating with Live via WebSockets, works both in NodeJS and in the Browser.
https://ricardomatias.net/ableton-live/
79 stars 10 forks source link

Issue with clip types #29

Closed jeffgca closed 1 month ago

jeffgca commented 2 months ago

Hey! First off, this project is amazing, thank you so much for doing all this heavy lifting, this is huge.

I think there's a mix-up with this ternary statement:

https://github.com/ricardomatias/ableton-live/blob/master/lib/Clip.ts#L524

constructor(ableton: AbletonLive, public raw: RawClip, path?: string) {
        super(ableton, 'clip', path ?? raw.path);

        this._id = parseInt(raw.id, 10);
        this._name = raw.name;
        this._type = raw.is_audio_clip ? ClipType.Midi : ClipType.Audio;
        this._length = raw.length;

        this.childrenTransformers = {
            clipView: () => new ClipView(this.ableton),
        };
    }

Shouldn't this:

this._type = raw.is_audio_clip ? ClipType.Midi : ClipType.Audio;

be instead:

this._type = raw.is_audio_clip ? ClipType.Audio : ClipType.Midi;

Currently when I run this code:

import _ from 'lodash-es'
import { AbletonLive } from 'ableton-live'

import WebSocket, { WebSocketServer } from 'ws'

const live = new AbletonLive()

const main = async () => {
    try {
        await live.connect()

        const tracks = await live.song.children('tracks')

        _.each(tracks, async (track) => {
            console.log(track.type, track.name)
            const clips = await track.getClips()
            console.log(
                _.map(clips, (clip) => {
                    return [clip.type, clip.name]
                }),
            )
        })
        // const clips = await tracks[0].getClips()
        // const notes = await clips[0].getNotes()

        // notes.forEach((note) => console.log(note.pitch))
    } catch (error) {
        console.error(error)
    }
}

main()

I get this output:

➜ m4l node index.js
[AbletonLive] Listening on 127.0.0.1/ableton-live:9001
midi 1-MIDI
audio 2-AUDIO CLIP
[ [ 'audio', 'MIDI CLIP' ] ]
[ [ 'midi', 'AUDIO CLIP' ] ]

This is my Ableton set:

Screenshot 2024-09-28 at 09 00 41
ricardomatias commented 1 month ago

Thanks for the effort, merged!

Closed via #30