Korg nanoKontrol 2 Help

For those who have the nanoKontrol 2, you know that you can edit the MIDI faders, sliders, and buttons in the Korg Kontrol Editor. I’m trying to change the buttons to “toggle” mode, instead of “momentary”. I make the change in the editor, but how do I make those changes get reflected in SuperCollider? When I hit the buttons in SuperCollider, SC responds to the ‘hitting’ of the button and the ‘release’. I just want it to respond to the ‘hit’. I’d appreciate any help.

I have added both nanoKontrol extensions in my Extensions folder, so I can use those classes, if anybody can find a solution using those. I’ll link them below:
https://github.com/davidgranstrom/NanoKontrol2
https://github.com/gitmarek/supercollider-nanoKONTROL2

I haven’t messed much with the Kontrol Editor, but after you change the buttons to be in “toggle” mode, what MIDI messages are you seeing coming into SC? One would expect a noteOn message at pushing a button (but no message at the button release immediately after); and then a noteOff message at the next push of that same button.

If you just use MIDIFunc.trace(true) to see all incoming messages, is this what you are seeing? If not, maybe the Kontrol Editor is not making the buttons to be really a toggle.

After I changed it to “toggle” mode, it seems SC doesn’t recognize the change at all. I hit a button, and a MIDI message appears:

[ -1535229938, 0, 32, 127 ]

Then when I release the button, I get:

[ -1535229938, 0, 32, 0 ]

So, it’s responding to the hit, and the release, even when I changed the button to “toggle”. Yeah, I’m thinking the Kontrol Editor is not doing anything. I just got this, so I’m pretty new to this interface. I figured there’s something I’m missing, which is why I’m here.

One possibility is to just ignore the noteOff messages (the ones sent at button release) from the device, and write into your SC code the logic to keep state for each button. So for ex. when you get a noteOn for button 32, you update a variable to 1 (“on”), then next time you get another noteOn for button 32, the variable gets a 0 (“off”), etc.

It may be worth to play with the Kontrol Editor a bit more though. If the manual says there is a toggle mode, it should work and it would be easier to use it than to write custom SC code for the job.

I dusted my old nanoKONTROL2 here out of curiosity, and noticed that all buttons are actually sending MIDI control messages (with alternating values of 127 and 0 for on and off respectively), not noteOn and noteOff messages. I don’t remember if this is factory preset or if I did any editing in the past.

You can tell these are control messages from the output of MIDIFunc.trace(true) – in my case, I see something like this for the first S button:

MIDI Message Received:
	type: control
	src: 8454144
	chan: 0
	num: 32
	val: 127

MIDI Message Received:
	type: control
	src: 8454144
	chan: 0
	num: 32
	val: 0

Anyhow, if this is similar to the messages your nano is sending for buttons, you could make them work as toggle by using only the cc values for the button push (127) and ignoring the button releases (cc values = 0). Here’s a quick example you could adapt to your purposes:

(
~buttonStates = Array.fill(127, 0);

MIDIdef.cc(\toggle, { arg ccValue, ccNum;
	
	if(ccValue==127, { // we only care about the button pushes, not the releases
		if(~buttonStates[ccNum]==0, {
			~buttonStates[ccNum] = 1; // mark it as "on"
			[ccNum, "I am ON"].postln; // do your ON action
		}, {
			~buttonStates[ccNum] = 0; // mark it as "off"
			[ccNum, "I am OFF"].postln; // do your OFF action	
		})
	})
	
	
},
ccNum: (32..39) ++ (48..55) ++ (64..71) // all S, M, R buttons on my nano 
)
)

Edit: of course, this does not take care of the LEDs. If you want the LEDs to remain on until you push the button again to turn it off, you’d need to add extra code to control the LEDs from SuperCollider. Then again, if you figure out how to actually make the buttons work in toggle mode from the Korg Kontrol Editor, that would still be the best solution as I assume it would take care of the LEDs and of sending proper MIDI messages. You wouldn’t need do to any of the housekeeping like the example above does.

Thanks a bunch for this! I tested out that code and it seems to work. That’s a pretty clever way to work around the Kontrol Editor.

1 Like