Swithc pages on midi note

Hello all,
Is it possible to swith between macro pages with when a midi note is received?

1 Like

Hi @solocky

Yes, it is possible. You need a script parameter that will be connected to the stack. Then you can use onNote() to change the parameter if certain midi note is received.

defineParameter("pages", nil, 0, 0, 2, 1)

function onNote(e)
	if e.note == 36 then
		pages = 0
	elseif e.note == 38 then
		pages = 1
	elseif e.note == 40 then
		pages = 2
	else
		postEvent(e)
	end
end

If you have a lot of pages you may use a “look up” table instead.

defineParameter("pages", nil, 0, 0, 2, 1)

pageNotes = {
	[36] = 0,
	[38] = 1,
	[40] = 2,
	}

function onNote(e)
	if pageNotes[e.note] then
		pages = pageNotes[e.note]
	else
		postEvent(e)
	end
end

Another consideration is if you want the pages parameter to be persistent. By default it is which means its state will be saved with the preset. If you have buttons or a menu that can switch the pages too connected to this parameter they will also write in undo history. So you may want to make it non persistent to be consistent with other macro page elements.

defineParameter{
	name = "pages",
	default = 0,
	max = 2,
	increment = 1,
	persistent = false,
	automatable = false,
}

keys = getKeyProperties()
keys[36] = {color = 6,	tooltip = "Page 1"}
keys[38] = {color = 6,	tooltip = "Page 2"}
keys[40] = {color = 6,	tooltip = "Page 3"}

pageNotes = {
	[36] = 0,
	[38] = 1,
	[40] = 2,
	}

function onNote(e)
	if pageNotes[e.note] then
		pages = pageNotes[e.note]
	else
		postEvent(e)
	end
end
1 Like

Hey Misohoza,
Thanks for the in depth explanation and code.
Ill try as soon as I’m home.:+1:t5:
Basically its 16 pages which never change.
At first I thought I would simply bind the radio buttons to midi direct from the macro page but it seems radio buttons can’t recive midi.
I’ll let you know the outcome…:+1:t5::slightly_smiling_face:

Hi again, Today i sat down and got more into the script you provided and found that where it works correctly as in switching a page whennit receives a midi note.
The midi not is not playable afterwards.
An example.
If i switch to “Page 4” using midi note “0” then midi note “0” is not recived on “Page 4”.
If I turn on “Bypass” in the script then midi note “0” is recived.
Any thoughts?

That’s on purpose. I thought you wanted to use the midi notes like key switches.

But it’s easy to change if you want the note also to play. Just change the onNote() slightly.

function onNote(e)
	if pageNotes[e.note] then
		pages = pageNotes[e.note]
	end	
	postEvent(e)	
end

Or like this if you are using the first example:

function onNote(e)
	if e.note == 36 then
		pages = 0
	elseif e.note == 38 then
		pages = 1
	elseif e.note == 40 then
		pages = 2
	end
	postEvent(e)
end
1 Like