How to toggle MIDI CC from controller so it stays at value 127 then 0 when pressed again

All your LV2 and LADSPA goodness and more.

Moderators: MattKingUSA, khz

Post Reply
asbak
Established Member
Posts: 897
Joined: Thu Sep 11, 2014 3:04 pm
Has thanked: 71 times
Been thanked: 64 times

How to toggle MIDI CC from controller so it stays at value 127 then 0 when pressed again

Post by asbak »

I have a keyboard which can send some CC's with switch presses but the problem is that it sends value 127 when pressed and value 0 when released.
In this case it is not ideal, it would have been more useful if the keyboard held value 127 or 0 until the next keypress. (To toggle between the on / off state of the CC.)

I've had a look at some LV2 MIDI plugins but haven't been able to find a way to get this to work, does anybody know of a way?

ssj71 Explains it better in this post from another forum.
https://forum.moddevices.com/t/midi-cc- ... tion/410/3
ssj71
Aug '16

a control change must send a value. The problem is that (most likely) when you press the button it sends CC (control change) with a value 127 and as soon as you release it it sends CC value 0 again. You want it to toggle so that it doesn’t send the 0 until you press the button again. If your device can’t be configured to do that then perhaps a midifilter could be written to do this, but I’m not sure if we can do midi parameter control like this through a filter.
Some Focal / 20.04 audio packages and resources https://midistudio.groups.io/g/linuxaudio
asbak
Established Member
Posts: 897
Joined: Thu Sep 11, 2014 3:04 pm
Has thanked: 71 times
Been thanked: 64 times

Re: How to toggle MIDI CC from controller so it stays at value 127 then 0 when pressed again

Post by asbak »

Found some more relevant info here on this keyboard behaviour

http://www.rncbc.org/drupal/node/1787
Some Focal / 20.04 audio packages and resources https://midistudio.groups.io/g/linuxaudio
asbak
Established Member
Posts: 897
Joined: Thu Sep 11, 2014 3:04 pm
Has thanked: 71 times
Been thanked: 64 times

Re: How to toggle MIDI CC from controller so it stays at value 127 then 0 when pressed again

Post by asbak »

I lifted the mididings python code from the previous post & added a jack-rt backend to it. You'll need to have mididings installed.

Paste this into a file and save as a python script ex. "latch-on-off.py" and run with python latch-on-off.py.
Then route your keyboard controller through this MIDI processor and out to your softsynth.

A warning is displayed but oh well, it seems to work.

Code: Select all

from mididings       import *
from mididings.event import *

config(
      backend='jack-rt',
      client_name='Latch On Off',
      )


buttonState = [0] * 128;

####################################################################################################
# buttonCtrl:  Toggle outgoing CC event value when the incoming value is non-zero
####################################################################################################
#
# Convert the momentary on/off buttons to mode toggle events when the button press occurs
#

def buttonCtrl (event):
  button = event.ctrl;
  value  = event.value;

  if (value != 0):
    state = buttonState [button] = value if (buttonState [button] == 0) else 0;
    event = CtrlEvent (event.port, event.channel, button, state);
    print (" - Ctrl (%d, %d) => Ctrl (%d, %d)" % (button, value, button, state));
    return event;
  else:
    print (" - Ctrl (%d, %d) => *IGNORED*" % (button, value));
    return None;

####################################################################################################
# midiCtrl:  Route the incoming MIDI messages to the event filter
####################################################################################################

def midiCtrl (event):
  button = event.ctrl;
  if   (button >=  51 and button <=  59):  return (buttonCtrl (event));
  elif (button == 104 or  button == 105):  return (buttonCtrl (event));
  elif (button >= 112 and button <= 117):  return (buttonCtrl (event));
  return event;

run (
  Filter (CTRL) % Process (midiCtrl)
)
Some Focal / 20.04 audio packages and resources https://midistudio.groups.io/g/linuxaudio
User avatar
milkii
Established Member
Posts: 477
Joined: Tue Jan 05, 2016 9:08 am
Location: Edinburgh
Has thanked: 92 times
Been thanked: 91 times
Contact:

Re: How to toggle MIDI CC from controller so it stays at value 127 then 0 when pressed again

Post by milkii »

they/them ta / libreav.org / wiki.thingsandstuff.org/Audio and related pages / gh

asbak
Established Member
Posts: 897
Joined: Thu Sep 11, 2014 3:04 pm
Has thanked: 71 times
Been thanked: 64 times

Re: How to toggle MIDI CC from controller so it stays at value 127 then 0 when pressed again

Post by asbak »

Tried it earlier but couldn't get it to work or understand how to use it
Some Focal / 20.04 audio packages and resources https://midistudio.groups.io/g/linuxaudio
User avatar
milkii
Established Member
Posts: 477
Joined: Tue Jan 05, 2016 9:08 am
Location: Edinburgh
Has thanked: 92 times
Been thanked: 91 times
Contact:

Re: How to toggle MIDI CC from controller so it stays at value 127 then 0 when pressed again

Post by milkii »

does the linked documentation file help?

though if what you've got works then yay, nae worries, as, in some instances, cpython is quicker than c++

they/them ta / libreav.org / wiki.thingsandstuff.org/Audio and related pages / gh

asbak
Established Member
Posts: 897
Joined: Thu Sep 11, 2014 3:04 pm
Has thanked: 71 times
Been thanked: 64 times

Re: How to toggle MIDI CC from controller so it stays at value 127 then 0 when pressed again

Post by asbak »

In the interests of science I had another go at midiCCToggle.

It turns out that it does indeed work..... when the meatware remembers to tick the "send control changes" box which in this case (Carla) is not enabled by default. :oops:

Oh well, many ways to skin a cat, thanks for the suggestion. :D
Some Focal / 20.04 audio packages and resources https://midistudio.groups.io/g/linuxaudio
User avatar
milkii
Established Member
Posts: 477
Joined: Tue Jan 05, 2016 9:08 am
Location: Edinburgh
Has thanked: 92 times
Been thanked: 91 times
Contact:

Re: How to toggle MIDI CC from controller so it stays at value 127 then 0 when pressed again

Post by milkii »

A-ha, done that many a time myself also :)

they/them ta / libreav.org / wiki.thingsandstuff.org/Audio and related pages / gh

Post Reply