How to link Knob value with the sample played

Hi guys,

I’m still so beginner and ignorant. But I’m learning by hands-on examples while Im going through the official references, so be patient with please :pray:.

What I’m trying to do with this homework is the following:

I have 4 samples and 1 knob, I want that knob to control the panning of each sample that I play in my MIDI Keyboard, for example , if I played the first note , the knob will give me the pan value of that sample associated with that Midi note so I can adjust the panning value of that sample only , and so on with the rest of the samples. (I hope I managed to explain what I mean)

I managed to write a script to filter and get the sample name of the played note, but I failed to link it with the knob.

This is my homework, and feel free to improve the code or the approach, I would love to learn from your ways :green_heart:.

My Instrument.zip (152.2 KB)

Take a look at Skylab instrument and its sample display.

Check the zoneScope parameter in the program tree script. It’s connected to ui script parameter called - zoneScope, which is used to set the scope for the macro page group. Then put the knob in the group and only use the parameter id to connect the knob. The rest of the path (scope) is already delivered by the script parameter.

You’re halfway there already. You already know which zone is being played. So the scope should be something like:

"@0:Samples/@0:" .. sampleName[i] .. "/"

This is really a good reference, thank you.

defineParameter("zoneScope", nil, "")
defineParameter("zoneName", nil, "")

function updateSampleDisplay(note)
	local zones = this.parent:findZones()
	for i, zone in pairs(zones) do
		if note >= zone.keyLow and note <= zone.keyHigh then
			zoneScope = "@0:Samples/@0:"..zone.name.."/"
            zoneName = zone.name
            print("zoneScope : ", zoneScope, "zone.name : ", zone.name)
			break
		end
	end
end

function onNote(ev)
	updateSampleDisplay(ev.note)
	postEvent(ev)
end

I also put the knob into a group, then I put the scope there , what is missing now is the knob value, I tried to put this “@id:320014” , but it doesn’t work, what am I missing?

and by the way , Im not using any ui script, is that still ok?

I figured it out, in the scope I should not put the whole path , instead of putting this:

@inst/@bank/@prg:0/@0:Samples/@0:samplesScript/@par:zoneScope

I should put only this:

@0:Samples/@0:samplesScript/@par:zoneScope

Thank you again

This is the result for the reference , maybe it will help others:
Link Knob with Samples.vstpreset (9.4 KB)

Note: the knob doesn’t move while playing in the Midi Keyboard!