leolabs / ableton-js

Control Ableton Live with Node.js
MIT License
368 stars 46 forks source link

Forward requested midi cc and note messages #48

Closed devthane closed 2 years ago

devthane commented 2 years ago

For: #47

Allows forwarding of midi message from Ableton.

To register a list of midi notes or control changes to forward:

await ableton.midi.set("midi_outputs", [
    {type: "note", channel: 0, target: 60},
    {type: "cc", channel: 0, target: 25},
])

Right now only notes and control changes are mappable.

Then you could add a listener to receive the requested midi messages:

await ableton.midi.addListener("midi", (msg) => {
    switch (msg.command) {
        case MidiCommand.NoteOn:
        case MidiCommand.NoteOff:
            const note = msg.toNote()
            console.log(`midi key: '${note.key}' velocity: '${note.velocity}'`)
            break
        case MidiCommand.ControlChange:
            const cc = msg.toCC()
            console.log(`midi controller: '${cc.controller}' value: '${cc.value}'`)
            break
        default:
            console.log(`unhandled command: '${msg.command}'`)
    }
})

As long as the midi signals you are requesting aren't mapped elsewhere in Ableton, the messages should get forwarded.

If you have the midi signals mapped to a control, they will not get sent however.

leolabs commented 2 years ago

Thank you so much for the PR!

I'll test it thoroughly on Sunday, but the code already looks great :)

leolabs commented 2 years ago

Thank you so much for the PR!

I'll test it thoroughly on Sunday, but the code already looks great :)

leolabs commented 2 years ago

Hey @devthane,

I'm so sorry for the delay. The PR looks great, I'll merge it and release it as part of the next version!