Switch page with external midi message | Intech Studio
💬 general GridRequest

Switch page with external midi message

Dr. Bensmir
Dr. Bensmir · · 85 replies

Hello I can send à midi message from keyboard maestro or stream deck and I wonder how I could switch page like that, which message to send etc so that I can free a button on my unit

Thanks

Replies (50)

Hybrid Hybrid ·

You'll probably get a better answer from the Intech guys but I was curious about this for myself and I was able to get it working by putting the following code in the Setup event of the System element:

function self.midirx_cb(self, event, header)
    local ch, msg, cc, val = event[1]+1, event[2], event[3], event[4]
    if ch == 1 and cc == 20 and msg == 176 and val >= 0 and val <= 3 and header[1] == 13 then
        page_load(val)
    end
end

Note: you need to repeat this on every page where you want this MIDI trigger to work. I put this on all 4 pages in my setup. If you have multiple Grid modules, you should only need this on one of the modules because it will trigger the page change for the other connected modules.

Quick code explanation:

In my case I'm sending on channel 1 with a CC of 20 and the value is the page number to change to. Page numbers in the page_load() function start at 0, so if you want to go to page 1, you send 0 and for page 2, send a value of 1. If that's confusing, you could adapt the code so the page number you send matches the physical page numbers (just subtract 1 from the value received before you pass it into the page_load() function).

The code also has some checks to make sure the channel, CC and page number is valid. It will ignore anything that is out of range.

See more docs about MIDI RX and page changing.

I know you're going to use Keyboard Maestro to send the MIDI messages but if you're interested, I used the command line tool SendMIDI. The command looks like this: sendmidi dev "Grid" ch 1 cc 20 3 ⬅️ this will send the message to Grid and the value is 3, which changes to page 4 with my code above. Since this is a command line tool, it can easily be triggered from other apps like Raycast).

Dr. Bensmir Dr. Bensmir ·

thank you I am going to try

Hybrid Hybrid ·

De rien 🙂 Let me know if you get stuck on anything...

Dr. Bensmir Dr. Bensmir ·

@user hello again, I am trying your code with my stream deck

Dr. Bensmir Dr. Bensmir ·
image.png
Dr. Bensmir Dr. Bensmir ·
image.png
Dr. Bensmir Dr. Bensmir ·

trying to send CC20 on chan1

Dr. Bensmir Dr. Bensmir ·

on the port grid (not sure about in and out port in the streamdeck)

Dr. Bensmir Dr. Bensmir ·

but it doesn't trigger anything

Dr. Bensmir Dr. Bensmir ·

I updated the CC20 to send the value 0 but still no luck

Dr. Bensmir Dr. Bensmir ·

since I am also using Bome Midi Translator, I tried to keep my original streamdeck port configuration which look like this

then that message is grabbed by bome midi translator and redirected to the "grid" port

image.png
Dr. Bensmir Dr. Bensmir ·

but still not working

Dr. Bensmir Dr. Bensmir ·
image.png
Hybrid Hybrid ·

Hi @user, I'm not familiar with Bome MIDI Translator but the first thing we need to check is if the Grid Editor is actually receiving any messages – can you see what it shows in the MIDI Monitor inside the Grid Editor? In mine, this is what I see after sending a few different CC messages...

image.png
Hybrid Hybrid ·

In your last screenshot, where it says MIDI OUT [Grid]: 90 14 00, do you know what those numbers represent? I'm trying to understand them 🤔

Dr. Bensmir Dr. Bensmir ·

I am dumb, midi bome translator was set to send midi note instead of midi cc on the output

image.png
Dr. Bensmir Dr. Bensmir ·

now grid does receive the midi cc

image.png
Dr. Bensmir Dr. Bensmir ·

it's still not switching page tho

image.png
Hybrid Hybrid ·

That's a good sign it's receiving those messages now 👍

Is the code you showed on the System element for every single page (1, 2, 3, 4)?

Dr. Bensmir Dr. Bensmir ·

only on page 1 for testing purpose

Dr. Bensmir Dr. Bensmir ·

should I copy on all pages anyway

Hybrid Hybrid ·

If that code is only on page 1, it's ok for testing but you will need to send a different value than 0 – otherwise it is just trying to change to the page it is already on, so nothing will happen. Try sending a value of 1 and see if it switches to Page 2.

Hybrid Hybrid ·

If that works and it switches to page 2, then you can add the MIDI RX callback code to that page (otherwise there will be nothing on the new page to answer the MIDI RX messages)

Dr. Bensmir Dr. Bensmir ·

I copy pasted the code to all pages (without editing the code, should I?)

no switch whatsoever

image.png
Dr. Bensmir Dr. Bensmir ·

but my midi rx tab is empty on the config

Dr. Bensmir Dr. Bensmir ·

I only added a code block to the setup tab of the system element

Hybrid Hybrid ·

That should be all you need and the code is the same for every page because it changes the page based on the value it receives.

Hybrid Hybrid ·

It's possible that the if statement is evaluating to false because not all the values match...

if ch == 1 and cc == 20 and msg == 176 and val >= 0 and val <= 3 and header[1] == 13 then
Hybrid Hybrid ·

This code is maybe more complex than it needs to be because it is checking for a lot of details. Let's do a quick debug print statement to see what it is getting. I'll just prepare some code for you, hang on...

Dr. Bensmir Dr. Bensmir ·
image.png
Dr. Bensmir Dr. Bensmir ·

syntax error

Hybrid Hybrid ·

Sorry, that wasn't the code I meant you to copy...

Dr. Bensmir Dr. Bensmir ·

the intech team should take inspiration from the gui of bome midi translator, it would be really more straightforward, I find it a bit steep for beginners

Hybrid Hybrid ·

They're definitely working on improving it!

Hybrid Hybrid ·

Here's the replacement code for you to try:

function self.midirx_cb(self, event, header)
    local ch, msg, cc, val = event[1] + 1, event[2], event[3], event[4]
    print("MIDI RX - ch:" .. ch .. " | msg:" .. msg .. " | cc:" .. cc .. " | val:" .. val .. " | h:" .. header[1])
    if ch == 1 and cc == 20 and msg == 176 and val >= 0 and val <= 3 and header[1] == 13 then
        page_load(val)
    end
end
Hybrid Hybrid ·

⬆️ put that code in your System -> Setup block and replace with the one that is there.

Hybrid Hybrid ·

I just added the print statement to show us what all the values are to make sure they match. You will see this appear in the Debug monitor:

image.png
Dr. Bensmir Dr. Bensmir ·

my raw packet subwindow on the debug monitor is going crazy

Dr. Bensmir Dr. Bensmir ·

is it normal

Dr. Bensmir Dr. Bensmir ·

or am I in some kind of feedback

Hybrid Hybrid ·

Yes, it's normal 😅

Dr. Bensmir Dr. Bensmir ·
image.png
Dr. Bensmir Dr. Bensmir ·

I have this on my utility tab, not sure if it interfere

image.png
Hybrid Hybrid ·

Aha! I see the problem – "page change is disabled". You need to click "Store" on the Grid Editor to write the changes to the Page on the module.

Hybrid Hybrid ·

It's not letting you change pages with unsaved changes because if it did that, you'd lose your updates.

Hybrid Hybrid ·

There should be a more obvious message about that though

Hybrid Hybrid ·

This code in the Utility function is fine – if you remove it, the side utility button will stop working as a page switcher.

Dr. Bensmir Dr. Bensmir ·

where is "store"

Dr. Bensmir Dr. Bensmir ·
image.png
Dr. Bensmir Dr. Bensmir ·

I didn't change anything

Discord

View on Discord

This post is from the Intech Studio Discord community.

Open thread →