justlep / bitwig

Some MIDI controller scripts for Bitwig
Other
58 stars 9 forks source link

GenericKeysV2 won't filter CC by channel #10

Closed macramole closed 6 years ago

macramole commented 6 years ago

Hi !

I'd like to map an Electribe's knob to some Bitwig fader but only for an specific channel. I understand CC messages have a channel associated so I should be able to do this. Is this possible?

Thanks in advance, Leandro.

justlep commented 6 years ago

Hi!

Chances are you don't need the GenericKeys script for that at all. All you need is a controller script letting all incoming midi data pass through directly, so you can map the raw midi to your Bitwig devices (which then will be channel-specific).

My suggestion: remove the GenericKeysV2 script and try this one for your Electribe instead: https://github.com/justlep/bitwig/blob/master/tmp/MidiPassthru.control.js

Hope it works, good luck! Lennart

macramole commented 6 years ago

Hey, thanks for your reply ! I will try this. I was hoping to get both things: channel specific MIDI notes and channel specific CC. Is it possible to get both things ?

Thanks again for your time ! Leandro.

justlep commented 6 years ago

I guess with "channel-specific notes" you probably mean Bitwig's lack of a midi channel selector/filter?

I just added a multi-channel version of the passthru script, so you can explicitly decide which channnel you want to receive notes from (Ch-1 .. Ch-16 or Omni).

https://github.com/justlep/bitwig/blob/master/tmp/MidiPassthruMulti.control.js

Good luck! Lennart

macramole commented 6 years ago

Hey man, thanks for the help, but I couldn't make it work, maybe I wasn't explaining myself well. I started digging into other scripts and craft myself this solution editing your GenericKeysV2 script:

first:

var LOWEST_CC = 1,
    HIGHEST_CC = 119,
    MIDI_CHANNELS = 15,
    NUMBER_OF_CCS = (HIGHEST_CC - LOWEST_CC + 1) * MIDI_CHANNELS,
    userControls;

and then:

 midiInPort.setMidiCallback(function(status, data1, data2) {
        //MIDIChannel(status) this was what I was looking for
        if (isChannelController(status) && data1 >= LOWEST_CC && data1 <= HIGHEST_CC ) {
            var index = (data1 - LOWEST_CC) + HIGHEST_CC * MIDIChannel(status);
            userControls.getControl(index).value().set(data2, 128);
        }
    });

Thanks for your time !

justlep commented 6 years ago

That's of course an obvious solution, but I wouldn't do it like that since it requires creating almost 2000 UserControl objects while only a fraction of them will be relevant for your Electribe probably. If I were you, I'd rather write an Electribe-specific script that creates resources it actually needs. But if this just works four you, why not ;)

There are some errors in your code though.

First, it should be MIDI_CHANNELS = 16:

var LOWEST_CC = 1,
    HIGHEST_CC = 119,
    MIDI_CHANNELS = 16,
    CCS_PER_CHANNEL = HIGHEST_CC - LOWEST_CC + 1,
    NUMBER_OF_CCS = CCS_PER_CHANNEL * MIDI_CHANNELS,
    userControls;

And the index in your midi callback needs to be

 var index = MIDIChannel(status) * CCS_PER_CHANNEL + data1 - LOWEST_CC;

Cheers!

macramole commented 6 years ago

Thanks for your feedback !

justlep commented 6 years ago

You're welcome!