Compartmentalizing large scripts?

Is it in any way possible to compartmentalize scripts, using something akin to @import like CSS stylesheets? I thought maybe the tabbed scripting workflow was designed for just this, but I soon discovered you can only have one “active” script at a time.

The reason being, some scripts can get pretty long and difficult to navigate; it would be nice if you could have code snippets that you go to often and inject them into your script using just a single line or some such.

I am not an experienced coder, which is probably why my scripts end up unnecessarily long!

What do your scripts do? Do you have a lot of repetition? Can you post some examples ?

Sure! For example, I use widgets to control OSC parameters on a Behringer Wing digital desk.

var mike_vox, jg_vox, andrew_vox, jimmy_vox, ja_vox: OSCMessage
var mike_vox_ch, jg_vox_ch, andrew_vox_ch, jimmy_vox_ch, ja_vox_ch, osc_dest_port, verb_bus, delay_bus, verb2_bus, delay2_bus: Integer
var mike_vox_fader, fantom_bank, fantom_program: Widget
//VerbSends
var mike_verb_snd, jg_verb_snd, andrew_verb_snd, jimmy_verb_snd, ja_verb_snd: Widget
osc_dest_ip: String

Initialization
mike_vox_ch = 1 
jg_vox_ch = 2
andrew_vox_ch = 3
jimmy_vox_ch = 4
ja_vox_ch = 5
verb_bus = 13
delay_bus = 14
verb2_bus = 15
delay2_bus = 16
osc_dest_ip = "127.0.0.1"
osc_dest_port = 8001
OSC_SetAddress(mike_vox, "/ch/"+mike_vox_ch+"/")
OSC_SetAddress(jg_vox, "/ch/"+jg_vox_ch+"/")
OSC_SetAddress(andrew_vox, "/ch/"+andrew_vox_ch+"/")
OSC_SetAddress(jimmy_vox, "/ch/"+jimmy_vox_ch+"/")
OSC_SetAddress(ja_vox, "/ch/"+ja_vox_ch+"/")
End

//Reverb Sends
On WidgetValueChanged(newValue: Double) from mike_verb_snd
OSC_SendDoubleSpecific("/ch/"+mike_vox_ch+"/send/"+verb_bus+"/lvl", newValue, osc_dest_ip, osc_dest_port)
End
On WidgetValueChanged(newValue: Double) from jg_verb_snd
OSC_SendDoubleSpecific("/ch/"+jg_vox_ch+"/send/"+verb_bus+"/lvl", newValue, osc_dest_ip, osc_dest_port)
End
On WidgetValueChanged(newValue: Double) from andrew_verb_snd
OSC_SendDoubleSpecific("/ch/"+andrew_vox_ch+"/send/"+verb_bus+"/lvl", newValue, osc_dest_ip, osc_dest_port)
End
On WidgetValueChanged(newValue: Double) from jimmy_verb_snd
OSC_SendDoubleSpecific("/ch/"+jimmy_vox_ch+"/send/"+verb_bus+"/lvl", newValue, osc_dest_ip, osc_dest_port)
End
On WidgetValueChanged(newValue: Double) from ja_verb_snd
OSC_SendDoubleSpecific("/ch/"+ja_vox_ch+"/send/"+verb_bus+"/lvl", newValue, osc_dest_ip, osc_dest_port)
End

I try to declare the variables in the beginning, so that I can change the value in one spot if I ever decide to move the sources to different channels on the mixer (i.e., Mike’s vocal channel from ch 1 to ch 15). In the middle section, where I am controlling reverb sends with widget value changes, I have only included 5 channels for demonstration purposes. However, this could be 10, 12, 15, 20 or more channels depending on how many reverb sends I want to automate with GP. It would be lovely if I could condense that section down and reference it with a line of code, or possibly even “hide” it with a drill down arrow or something?

First of all, you don’t need those OSCMessage variables since you’re using the OSC “Send Specific” functions

Secondly, manually writing everything the way you did does not leverage GP Script properly (GP Script is not CSS :slight_smile: )

Here’s an improved version that’s far more extensible (Hint: general rule, whenever you’re duplicating stuff that’s almost identical, create a function and parameterize things properly)

var 
    // Channels
    mike_vox_ch : integer = 1
    jg_vox_ch : integer = 2
    andrew_vox_ch : integer = 3 
    jimmy_vox_ch : integer = 4
    ja_vox_ch : integer = 5
    
var
   ChannelList : integer array = [mike_vox_ch, jg_vox_ch, andrew_vox_ch, jimmy_vox_ch, ja_vox_ch]
        
var
    // Effect bus numbers
    verb_bus : integer = 13
    delay_bus : integer = 14
    verb2_bus : integer = 15
    delay2_bus : Integer = 16
    
var 
   mike_vox_fader, fantom_bank, fantom_program: Widget  // I don't know what these are for
   
//VerbSends widgets
var 
    mike_verb_snd, jg_verb_snd, andrew_verb_snd, jimmy_verb_snd, ja_verb_snd: Widget

// OSC address    
    osc_dest_ip: String = "127.0.0.1"
    osc_dest_port : integer = 8001


Function SendEffectMsg(effectBusNumber : Integer, channel : integer, newValue : Double)

   OSC_SendDoubleSpecific( "/ch/" + channel + "/send/" + effectBusNumber + "/lvl", newValue, osc_dest_ip, osc_dest_port)

End


//Reverb Sends
// Note, the order of the widgets in the 'from' list must be the same order as the items in the Channel list array

On WidgetValueChanged(w : Widget, index : integer, newValue: Double) from mike_verb_snd, jg_verb_snd,  andrew_verb_snd, jimmy_verb_snd, ja_verb_snd

   SendEffectMsg(verb_bus, ChannelList[index], newValue)
   
End

You can now support more vocal channels by simply declaring them at the top, adding them to the ChannelList array, and to the list of widgets

Wow! That’s really great. I hadn’t experimented yet with Functions but I can see the power. So your function declared a custom list of variables (effectBusNumber, channel, newValue), and next an OSC_SendDoubleSpecific function to leverage those declarations, correct? I’m assuming the function could have any number of declared variables and any number of nested functions? Thank you for taking the time to demonstrate this for me.

No, functions cannot be nested inside one another. Did you mean function calls? Do not confuse a function declaration with code that goes inside a function, which can be variables, statements and function calls (not function declarations)

No - it declared a list of parameters

I regret we cannot teach programming concepts here.

You might want to review some basic programming ideas (e.g, basic concepts of functions, function calls, parameter passing, etc) and perhaps then take a look at the language manual for GP Script which can be found on our main support page.

Fair enough…I won’t try to use this as a forum to understand coding, but I do appreciate the help specifically with GP Script. This will give me some concepts to practice with.

I have moved this thread to the Scripting category.

The Wing is a really nice mixing console!

1 Like

Yes, it makes me think to the Presonus Studiolive series (mixer, recorder, control surface).

The Wing plus OSC control with GP is a match made in heaven!

Yeah, I replaced my previous mixer with a Wing a few months ago – it has a dual purpose — I use it for both rehearsing with bands and separately for composing/recording/editing, etc

What I love about it is the separation of sources and channels. That is an amazing feature — allows me to reconfigure how people are plugged in but still keep the same channel faders, etc.

I agree! I don’t think that workflow gets enough credit/attention. I built a desk for it in my home studio and it gets a lot of use there.

I do hope for a more compact version eventually (hopefully a rack?) to travel out and perform with. The original version is a beast!