User Script Examples - II

The new functions in 6.4 are going to be very handy.

Load a beat into a zone and this script should slice the beat and map it from midC.
The script deletes all zone except the first when running, so use an empty program.
The extra zones are deleted so you can adjust the threshold value and get new results and zones.

zones = this.parent:findZones()

function deleteSlices()
	for i, zone in ipairs(zones) do
		if i > 1 then zone:removeFromParent() end
	end
end

if #zones > 1 then deleteSlices() end

zone = this.parent:getZone()
file = zone:getParameter('SampleOsc.Filename')
af = AudioFile.open(file)
threshold = 12
peak = 20 * math.log(af:getPeak(0, -1, 0), 10)
root = 60

onsets = af:getOnsets(0, -1, peak - threshold, 0, 10)

function cutSample()
	for i, onset in ipairs(onsets) do
		local newZone = Zone()

		local sampleEnd = af.length
		if i < #onsets then sampleEnd = onsets[i + 1] end
		this.program:appendZone(newZone)

		newZone:setName(zone.name .. ' ' .. i)
		newZone:setParameter('SampleOsc.Filename', file)
		newZone:setParameter('SampleOsc.SampleStart', onset)
		newZone:setParameter('SampleOsc.SampleEnd', sampleEnd)
		newZone:setParameter('ZoneType', 1)
		newZone:setParameter('SampleOsc.Rootkey', root + i)
		
		newZone.keyLow, newZone.keyHigh = root + i, root + i
	end
	zone:setParameter('SampleOsc.SampleEnd', onsets[1])
	zone:setParameter('SampleOsc.Rootkey', root)
	zone.keyLow, zone.keyHigh = root, root
end

cutSample()

Old and new threads merged, topic pinned! Thanks @misohoza

2 Likes

Thank you very much, misohoza. :heart_eyes:
I had found a problem that skipping-strum in “Strumming.halmod” in my cheap environment. :sweat_smile:
But I’d fixed it. If there were somebody same probrem, try this.

– Replace “function waitForBeat” as see below –

function waitForBeat()
  if not isPlaying() then
    return 1
  else
    checkTimeSignature()
    local position = getBeatTimeInBar()
    if position == 0 then
      return 1
    else
      position = position - 0.00001  -- adjust time (try change near this value)
      local b, f = math.modf(position)
      waitBeat(1-f)
      local beatfactor = 2*BeatDiv
      local step = beatfactor*math.ceil(position) + 1
      if step > numberOfSteps then
        step = 1
      end      
      return step
    end
  end
end

Great you managed to work that out.

If I did that now I would probably do some things differently. I would use spawn for the strumming. So that the time offset of individual chord notes doesn’t mess with timing. Then you can use simply waitBeat to wait for the next step. Also the syncing to host would only need to be done when the playback of the sequence starts. The waitForBeat function could be done more simply. I’d probably do something like:

position = (getBeatTime() / stepDuration) % numberOfSteps
waitBeat(stepDuration - position % 1)

And I would use stepmodulator instead of individual sliders.

4 Likes

I don’t know if this has been mentioned, but if someone is looking on this thread, and cant find the how-to it is here:

https://developer.steinberg.help/display/HTG/Getting+Started

HALion seems more complex than others at first glance, but that initial confusion is worth it when it comes to the simplicity of being creative.

I spent some time trying to find the link above so I thought I would pass this on.

1 Like

Hello!

I’ve created a footsteps instrument containing layers (surfaces) that get switched via key switches (notes from C-2 to C-1). I would like to add corresponding buttons for the every surfaces on a macro page. But there are no way to assing a note to a button. Is it possible to do so with a script? Can somebody help me?

If you scroll up a few posts there is a keyswitch script example. You can connect the parameter to menu or radio buttons if you want.

1 Like

Thank you!
Could you please explain it a bit more please? If I undestand correctly I need to add my data to that script. So if I have a layers like Tiles, Concrete and their keyswitches are C-2, C#-2, what and where should I add?

Hello. How to set the default switch so that the program will remember it? Regards

Is it possible to script custom audio filters? Or is this outside of what is possible currently?

As far as I know you can manipulate midi events, note expression, fx parameters but you cannot process audio directly.

One would think, it wouldn’t be too hard for Steinberg to provide a filter “sandbox” where people can create their own curve sets and behavior… I wanted to emulate my Nord filters…

Multi; Vocal; Filter Frequency; Filter Resonance - Clavia Nord Wave User Manual [Page 29] | ManualsLib

1 Like

This would be cool, but the current integration of LUA focuses purely on controller and view. As HALion is still mainly an environment for developing huge instrument libraries, performance is important. This is why LUA controllers are only updated every few samples. As soon as we would put an interpreter into the signal chain, this would be even more expensive in CPU.

That said, HALion does already come with a wide range of filters built in. The default filter algorithm is bass preserving even in high resonances and has a huge frequency range. The range is much higher as many analogue filters out there.
So when you want to emulate a specific hardware, you first need to find out the range and if the signal is influenced by the resonance cutoff relation (beyond the obvious). Once you have some curves and values, you can choose a filter combination and script parameter remapping to match that hardware behaviour. Check out the RAST-A. VSTSound instrument library. It comes pretty close to the original hardware it is modelled on. There are some pretty convincing sounds in the demo videos.

This does not mean that we will never do such a thing in the future :wink:

Edit: Adding RAST-A Link:

Edit2: The guy is crazy BTW, such a detailed GUI, completely rendered in Blender:

Wow! Now we can use external files from lua on HALion 7.
See here!

What is this all about? I didn’t know anything like this was possible!

There are some very clever people here obviously, this being the case, can any of you tell me if there is a way to get midi out of Halion once it enters? I know officially there isn’t (which i think is bullSh&t) but im hoping there is.