Confused / String Array and Table Parameters

Post topics about HALion scripting.
Post Reply
AposMus
Junior Member
Posts: 180
Joined: Fri Nov 14, 2014 11:41 am
Contact:

Confused / String Array and Table Parameters

Post by AposMus » Mon Feb 20, 2017 11:29 am

String Array:

I made a parameter like this

Code: Select all

defineParameter("beatDiv", nil, 1, {"1/1", "1/2", "1/4", "1/8", "1/16"}, function() beatDivChange() end)
My plan was to use string.sub() and tonumber() to retrieve the denominator for use in calculations. The manual doesn't say parameter "array" values can be accessed, but I assumed this from reading about table parameters. In this case print(beatDiv[1]) returns an error. Print(beatDiv) does show the current index value though.

My question is, do I use the returned index values from the array parameter to access a second table with values for calculations when beatDivChange() is called.

It seemed clumsy at first, but it looks like the only way.


Table Parameter:

I made this as a test

Code: Select all

defineParameter("tabParam", nil, {10, 20, 30}, function() tabParamChange() end)
I tied this to a knob thinking it would give me 10, 20, 30 stepped values, but it didn't work. The knob is stuck either at min. or max position.

I then tied it to a menu, but this came out.

Image
I added 40, 50, 60 , but still only 2 menu options.

The manual says table parameter values can be accessed via indices, which works, print(tabParam[2]) => 20.
But I don't see how to do this on a variable basis if the parameter doesn't return either the table or index value.

I haven't been able to find an example of table parameter use, so if someone can point me in the right direction I would be extremely grateful.

I'm a cat's whisker away from completing my first instrument, I just need to figure this out.
Cubase Pro 8.5.2
Halion 6
HSO
Padshop Pro
Dark Planet
Windows 7 64bit, AMD Phenom IIx6 1055t, 8GB Ram, Gigabyte GA-880G-UD3H F2, Nvidia GeForce GTS450
https://dewetvanderspuy.co.za/

Matthias Klag
Steinberg Employee
Posts: 32
Joined: Sat Feb 23, 2013 9:33 am

Re: Confused / String Array and Table Parameters

Post by Matthias Klag » Mon Feb 20, 2017 3:07 pm

Hi AposMus,

the parameter beatDiv is a number and not a table. Try this with your original code:

Code: Select all

print(type(beatDiv))
>>>
number
The table with strings is used for the display. For example, if you connect beatDiv to a text field, HALion will display the strings and not the index.

If you create separate tables for the beat strings and beat lengthes, you can use beatDiv to reference them.

Try this code:

Code: Select all

local beatValue = { 4, 2, 1, 0.5, 0.25 }
local beatString = { "1/1", "1/2", "1/4", "1/8", "1/16" }

defineParameter("beatDiv", nil, 1, beatString, function() onBeatDivChanged() end )

function onBeatDivChanged()
	print(beatString[beatDiv].." = "..beatValue[beatDiv])
end
This is more tidy and more flexible, I think.

Cheers,

Matthias

[EDIT]: You must execute this code in the Lua Script module, btw.
[EDIT2]: Corrected beat values.
Matthias Klag - HALion Developer
Steinberg Media Technologies GmbH
Hamburg, Germany
Checkout Steinberg on YouTube, Twitter and Facebook!

User avatar
ggc
Senior Member
Posts: 1446
Joined: Thu Feb 17, 2011 6:17 am

Re: Confused / String Array and Table Parameters

Post by ggc » Tue Feb 21, 2017 12:27 am

good stuff, guys=)

please forgive my ignorance, but... what are the calculations for decimal values for triplets and dotted?

like 1/16t or 1/8d

thxZZZzzz n good night :P

AposMus
Junior Member
Posts: 180
Joined: Fri Nov 14, 2014 11:41 am
Contact:

Re: Confused / String Array and Table Parameters

Post by AposMus » Tue Feb 21, 2017 11:46 am

ggc wrote:good stuff, guys=)

please forgive my ignorance, but... what are the calculations for decimal values for triplets and dotted?

like 1/16t or 1/8d

thxZZZzzz n good night :P
Triplet = x / 3 * 2 or x * 0.666
Dotted = x / 2 * 3 or x * 1.5


@ Matthias Klag

Thanks for this. It's roughly what I had in mind. I didn't think of putting the parameter array outside the function, but I can see why you did it.

I forgot to mention it was connected to a menu controller, which is how the print function was triggered.

Is there any chance you can give us some insight as to how the number table parameter works. As you can see from my screen cap and previous explanation, I couldn't get it to work and haven't seen it in use in the provided macros.
Cubase Pro 8.5.2
Halion 6
HSO
Padshop Pro
Dark Planet
Windows 7 64bit, AMD Phenom IIx6 1055t, 8GB Ram, Gigabyte GA-880G-UD3H F2, Nvidia GeForce GTS450
https://dewetvanderspuy.co.za/

Matthias Klag
Steinberg Employee
Posts: 32
Joined: Sat Feb 23, 2013 9:33 am

Re: Confused / String Array and Table Parameters

Post by Matthias Klag » Tue Feb 21, 2017 7:42 pm

Hi AposMus.

As far as I can tell, the table parameters are not for connecting them to a control on the MacroPage. I think, their main use is for storing data directly with the Lua Script module when the program is saved. If you use a normal Lua table to store some data, for example, some MIDI notes you played, this table won't get stored with the program. If you declare a table parameter with defineParameter, the data of this parameter will get stored with the Lua Script module when you save the program.

Please use the Indexed String Array, if you want to display different values in menus or text fields.

Cheers,

Matthias
Matthias Klag - HALion Developer
Steinberg Media Technologies GmbH
Hamburg, Germany
Checkout Steinberg on YouTube, Twitter and Facebook!

Matthias Klag
Steinberg Employee
Posts: 32
Joined: Sat Feb 23, 2013 9:33 am

Re: Confused / String Array and Table Parameters

Post by Matthias Klag » Tue Feb 21, 2017 7:48 pm

In an earlier post, I gave the following example for beat values and strings:

Code: Select all

local beatValue = { 1, 0.5, 0.25, 0.125, 0.0625 }
local beatString = { "1/1", "1/2", "1/4", "1/8", "1/16" }
I made a small error:

"1/1" refers to a whole bar, which equals 4 beats. So, the beat values should be 4 , 2, 1, and so on.

I edited this in my original post.

Cheers,

Matthias
Matthias Klag - HALion Developer
Steinberg Media Technologies GmbH
Hamburg, Germany
Checkout Steinberg on YouTube, Twitter and Facebook!

AposMus
Junior Member
Posts: 180
Joined: Fri Nov 14, 2014 11:41 am
Contact:

Re: Confused / String Array and Table Parameters

Post by AposMus » Wed Feb 22, 2017 5:19 pm

Thanks for all the great information, this is truly helping a lot.
Cubase Pro 8.5.2
Halion 6
HSO
Padshop Pro
Dark Planet
Windows 7 64bit, AMD Phenom IIx6 1055t, 8GB Ram, Gigabyte GA-880G-UD3H F2, Nvidia GeForce GTS450
https://dewetvanderspuy.co.za/

Matthias Klag
Steinberg Employee
Posts: 32
Joined: Sat Feb 23, 2013 9:33 am

Re: Confused / String Array and Table Parameters

Post by Matthias Klag » Wed Feb 22, 2017 5:47 pm

You're welcome :-)

Btw, in another post I read something from you about the controller functions. I think, you wrote that controller functions must be executed in the UI script. But, that's not the case.

Controller and processor function both can be called in the Lua Script MIDI module. That said, controller functions can be called in the Lua Script MIDI module and the UI script. Only the processor functions cannot be called in the UI script.

The scripts for the Lua Script MIDI module and the UI can be seen as two different worlds. The script in the MIDI module controls what's happening in the Program. The UI script controls what's happening on the UI. In our instruments we did the majority of the scripting in the MIDI module. The UI script was only used to control page switching, etc.

I'm not sure if that was clear. That's why i posted this here...

Cheers,

Matthias
Matthias Klag - HALion Developer
Steinberg Media Technologies GmbH
Hamburg, Germany
Checkout Steinberg on YouTube, Twitter and Facebook!

AposMus
Junior Member
Posts: 180
Joined: Fri Nov 14, 2014 11:41 am
Contact:

Re: Confused / String Array and Table Parameters

Post by AposMus » Thu Feb 23, 2017 8:29 am

Matthias Klag wrote: Btw, in another post I read something from you about the controller functions. I think, you wrote that controller functions must be executed in the UI script. But, that's not the case.

Controller and processor function both can be called in the Lua Script MIDI module. That said, controller functions can be called in the Lua Script MIDI module and the UI script. Only the processor functions cannot be called in the UI script.
Yes, I was trying to help with lulu m's script which didn't run in Sonic and was thinking of what you said about getElement(), but I wasn't sure I was right though.

The manual's thread section talks about "controller" and "processor", so I thought - UI and module. I ran a few versions of lulu m's script with initialisation functions to see if it helped and got some errors. I know where I wen't wrong now. A controller function can run in the Script Module, but not inside a processor function. (unless you use runAsync()).

I didn't pay attention to the block comment in the first example where this was explained.
In our instruments we did the majority of the scripting in the MIDI module. The UI script was only used to control page switching, etc.
I noticed this after a while when things became less confusing.
Cubase Pro 8.5.2
Halion 6
HSO
Padshop Pro
Dark Planet
Windows 7 64bit, AMD Phenom IIx6 1055t, 8GB Ram, Gigabyte GA-880G-UD3H F2, Nvidia GeForce GTS450
https://dewetvanderspuy.co.za/

Post Reply

Return to “Halion Scripting”

Who is online

Users browsing this forum: No registered users and 1 guest