Help with a script please

I would appreciate any help with this scripting task please, I did try to search the forums but still at a complete loss since I totally suck at scripting and from what I understand the task isn’t that trivial in Halion. The task as follows:
There are several layers with their own sub-layers inside like on the attached image.
Is it possible to easily make macro page drop down menus for each of the topmost layer (kicks, snares) where one could select from one of the respective layers inside (i.e. snare 1 or snare 2) so only this chosen layer will sound and the rest of sub-layers are muted? It’s for a drum kit where I’d like to choose from different type of snares, kicks, toms which are all mapped on the same keys.

I would probably add a lua script module inside each of the main layers. Then you can choose which sublayer should play like this:

local layers = this.parent:findLayers()
local layerNames = {}

for i = 1, #layers do
	layerNames[i] = layers[i].name
end

defineParameter("activeLayer", nil, 1, layerNames)

function onNote(e)
	playNote(e.note, e.velocity, -1, layers[activeLayer])
end

1 Like

Thank so much for your help, Misohoza! Would you mind to attach your example as vstsound preset so I could understand how to embed this script into the menus?

I think I have figured this one out, thanks again for your help!

This is awesome! Thanks a lot misohoza! :smiling_face_with_three_hearts:
I was just about to post exactly the same question as savinoff but then I found this thread and your solution is exactly what I needed.

Now I have one more question: is it possible to have an image (displayed above that menu for example) and when you select a layer from the dropdown menu not only to send midi data only to that layer (like your script above does) but to change that image as well? So for example: let’s say I have three layers (Layer 1, 2 and 3) and for each layer I create a suggestive image. When I select the Layer 1 from the menu I want to have the first image displayed above the menu; when I select Layer 2 I want to have the second image above the menu, and so on. Something like this:

ex-layers

Is there a script that does that?

You can do that by creating a single animation that contains all the images and connect the animation to the activeLayer script parameter.

Or create a stack on macro page. Add required number of groups. Put one image in each group. In this case connect the stack to the activeLayer parameter.

1 Like

Yes, I tried this method and it works perfectly! And it’s much more easy than I thought it would be. Great! Thanks a lot misohoza! :hugs:

Hello, thanks for this script.
I have a question please: I have added a “zone sample display” to show the sample waveform.
How can I automatically update the sample waveform based on the layer selected?

I have tried with this in the “zone sample display” scope:
@0:Kick/0:Active Layer/@type:Zone
But is not working, no waveform is displayed…

Difficult to tell without seeing the program.

You could try like this:
Sample Display.vstpreset (12.8 KB)

You could also use stack with multiple sample displays and connect the stack to activeLayer parameter.

Thanks, it works!
Sorry, I have another question:

My instrument is made of two Layers/Pages (each Layer/Page has Its own zone sample display.)
Page/Layer 1 is the Grain Engine, Page/Layer 2 is the Sample Engine.

As you can see in the screenshot I tried to move your Lua script Inside the “GRAIN ENGINE” and the 'SAMPLE ENGINE" layer but is not working… How I can modify it to make it works in my situation?

Basically, I want to put one menu in the Grain Engine page to select the samples for that page, and another menu in the Sample Engine Page to select the samples for that page.

Thanks a lot in advance for your help!

Screen Shot 2022-03-20 at 17.45.03 PM

You could try like this:

local layer = this.parent
local zones = layer:findZones()

local zoneNames = {}
for i = 1, #zones do
	zoneNames[i] = zones[i].name
end

function setScope()
	local layerName = layer.name
	local zoneName = zones[activeZone].name
	scope = "@0:"..layerName.."/@0:"..zoneName
end

defineParameter("activeZone", nil, 1, zoneNames, setScope)
defineParameter("scope", nil, "")

setScope()

function onNote(e)
	playNote(e.note, e.velocity, -1, zones[activeZone])
end

Assuming the macro page is attached to New Instrument

1 Like

Thanks a lot!