playNote targeting multiple layers at once

Post topics about HALion scripting.
Post Reply
Kerphelio
New Member
Posts: 23
Joined: Sun Feb 03, 2013 12:18 am
Contact:

playNote targeting multiple layers at once

Post by Kerphelio » Sat Apr 13, 2019 4:13 am

The playNote() function allows to specify which layer the midi note is sent to, which obviously is useful for articulation-switching etc.
I was wondering though if anyone knows a good way to play multiple, select layers at once. From what I see, playNote() expects a single layer object, not a table with layers or anything like that.
So if I want to target multiple layers at once, I can do something like the following code snippet, and it does work. However it creates performance issues very quickly. Like in my example with just 3 layers it already swallows notes when I play moderately fast, which makes sense given that it has to iterate through that for loop.

Code: Select all

local targetLayer1 = this.parent:getLayer("firstLayer")
local targetLayer2 = this.parent:getLayer("secondLayer")
local targetLayer3 = this.parent:getLayer("thirdLayer")
layerTable = {targetLayer1, targetLayer2, targetLayer3}

function onNote(event)
	for i, targetLayer in ipairs(layerTable)  do
        	local id1 = playNote(event.note, event.velocity, -1, targetLayer)
	end
end
Any suggestions for a better, more efficient way of doing this?
Maybe I should mention that I'm looking for a general solution - meaning that I don't always know how many or which layers will be played, hence hard-coding, say, 3 calls to playNote isn't an option. The 'layerTable' from my example just happens to have 3 items here, another time it might be 5, and yet another one it might be only 2 items.
Also, the layers could (and likely would) live in separate sections of my program tree, so a otherwise good trick such as targeting the parent layer holding all of them will not work in my case. Imagine that you have a bunch of microphones that recorded the same audio event, each living in its own layer, but you only want to 'switch on'/ aka trigger some of them.
Cubase 9.5, HALion 6, Wavelab 9
Windows 10 64 Bit,
4 core, 16GB Ram, Steinberg UR 242

misohoza
Member
Posts: 860
Joined: Sun Oct 05, 2014 12:18 am
Contact:

Re: playNote targeting multiple layers at once

Post by misohoza » Sat Apr 13, 2019 1:26 pm

Hi Kerphelio,

How do you determine which layers should be played?
Does it depend on the note being played so it can change from one note to another?

If not then maybe you could target the LayerMidiMute parameter instead to choose which layers should play.
Win 10 Home, 64 bit, 8 gb ram,
Cubase Pro 9, Wavelab Pro 9, Halion 6, Dorico,
NI Komplete 10 Ultimate, Ozone 7,
UR 44

Post Reply

Return to “Halion Scripting”

Who is online

Users browsing this forum: No registered users and 1 guest