# Which way is more efficient?



## UCAudio (Mar 28, 2012)

I'm working on an instruments which contains about 200 controls on multiple pages and I'm trying to figure out which of the approaches below is more efficient/easier on the cpu/less buggy/etc:

Approach 1 example:
- Display 60 controls (switches and sliders)
- Hit the "next page" button
- Hide those initial 60 controls, and unhide 60 new controls in the same position as the first 60.

Approach 2 example:
- Display 60 controls (switches and sliders)
- Hit the "next page" button
- Dump all 60 controller values into an array... and load values into the 60 controllers from another array... basically swapping out what the controllers control.

I've started downthe path of Approach 2 but now that my instrument is becoming more complex, it seems I can probably simplify my code if I just create more controls instead of reusing them. Anyone have any thoughts on the pros and cons on each approach?


----------



## Raptor4 (Mar 28, 2012)

> - Dump all 60 controller values into an array... and load values into the 60 controllers from another array...


That's interesting. I'm a novice in the KSP but I know very well what is this. Could you show me a simple example using 2-3 sliders and two arrays.
Thanks !


----------



## gregjazz (Mar 28, 2012)

One thing to bear in mind is that if you use the second approach, automating the controls won't work. If that's not an issue, you might also just disallow the automation just in case.


----------



## UCAudio (Mar 28, 2012)

What about using midi cc automation to control whichever control is actually on the screen at a given time... can that be done with either approach. And what about purely from an efficiency standpoint... is either approach more taxing on resources (cpu, memory, instrument performance, etc)?


----------



## mk282 (Mar 28, 2012)

Well, MIDI learning is the same thing as automating controls. So in that case approach 1 would be better if you don't want to automate a multiplexed control (and you don't want to do that, trust me).


----------



## Tod (Mar 28, 2012)

I was recently in this situation with 4 separate Toms. Each tom had 5 mic positions and 4 round robins. There were a total of 26 parameters controls (knobs, menus, buttons) for each tom. I ended up using arrays with array sub-indexs because it made the most sense to me since the controls were the same for each tom. Not being an expert scripter it took me a little time to get it together but thanks to mk282 and especially Big Bob, it's working pretty well.



gregjazz @ Wed Mar 28 said:


> One thing to bear in mind is that if you use the second approach, automating the controls won't work. If that's not an issue, you might also just disallow the automation just in case.



I know you're way over my head and you're an expert scripter greg so I have to ask, why would automating the controls be any different as long as the arrays and/or pages are updated at the same time? 



UCAudio @ Wed Mar 28 said:


> What about using midi cc automation to control whichever control is actually on the screen at a given time... can that be done with either approach. And what about purely from an efficiency standpoint... is either approach more taxing on resources (cpu, memory, instrument performance, etc)?



I'm not sure which approach would be best as far as resources goes. I think a bigger question might be, "what's going to happen when the arrays or pages are changed while implimenting those changes in a DAW while it's running using midi"? In my case with the Toms I didn't have to worry about that because there's no reason to automate any of the controls. 

Incidently, here's an old thread that Justin gave me on some clever ways to deal with pages.
http://vi-control.net/forum/viewtopic.php?t=3538

I used arrays mainly because I thouht it took less scripting lines. The way you impliment the arrays and sub-index arrays is the key although for this old brain of mine, can also be a little confusing. :mrgreen:

Edit: Aah, I see mk282 got here before me. Just to let you know mk282, I got the phase working perfectly using the inverter FX, thankyou. :D


----------



## mk282 (Mar 28, 2012)

Well, if you're using multiplexed controls, then all the parameters that are tied to ONE control are all controlled by just ONE CC. You cannot select a different CC for the different parameters that are tied to that control. That sucks.

A workaround for that would be disabling MIDI CC learning by $ENGINE_PAR_ALLOW_AUTOMATION, and then script the MIDI learning manually. But that's not really what you should do...


----------



## UCAudio (Mar 29, 2012)

Let's say I have an instrument GUI with 8 faders (control volume of groups 0 through 7) and a "next bank" button... if I click the next bank button the faders now control the volume of groups 8 through 15. 

Now, if I want to control those 8 on screen faders with the 8 faders on my Novation remote midi controller, and I want to control the "next bank" button with a button on my midi controller... wouldn't it make more sense to multiplex so I can just quickly hit a button my my controller and have the 8 faders on my controller automatically map to control the next bank of 8 groups?


----------



## Tod (Mar 29, 2012)

UCAudio @ Thu Mar 29 said:


> Let's say I have an instrument GUI with 8 faders (control volume of groups 0 through 7) and a "next bank" button... if I click the next bank button the faders now control the volume of groups 8 through 15.
> 
> Now, if I want to control those 8 on screen faders with the 8 faders on my Novation remote midi controller, and I want to control the "next bank" button with a button on my midi controller... wouldn't it make more sense to multiplex so I can just quickly hit a button my my controller and have the 8 faders on my controller automatically map to control the next bank of 8 groups?



That's basically what I was getting at, if you update the main arrays, index arrays, and UI when you switch banks and also update the main arrays + UI while making adjustments, it should work. I don't know if you would consider this multiplexing or not?

The big question for me is whether this would work in real time with the DAW or not with out stuttering or lagging when you make the bank switch? Is Kontakt fast enough to do this, there's quite a bit of data to update? Maybe.


----------



## polypx (Mar 29, 2012)

It's multiplexing if the same knob does different things. That's the automation problem. If you want to be safe I'd say just hide/display seperate knobs.


----------



## mk282 (Mar 30, 2012)

UCAudio @ 29.3.2012 said:


> Let's say I have an instrument GUI with 8 faders (control volume of groups 0 through 7) and a "next bank" button... if I click the next bank button the faders now control the volume of groups 8 through 15.
> 
> Now, if I want to control those 8 on screen faders with the 8 faders on my Novation remote midi controller, and I want to control the "next bank" button with a button on my midi controller... wouldn't it make more sense to multiplex so I can just quickly hit a button my my controller and have the 8 faders on my controller automatically map to control the next bank of 8 groups?



In that case, yes, that would work, if you would also MIDI learn the prev/next buttons.

However automating (from your DAW) the volume of group 1 and group 12 won't work, since group 12 is in the next "bank" of sliders.


----------



## UCAudio (Mar 31, 2012)

Tod @ Thu Mar 29 said:


> That's basically what I was getting at, if you update the main arrays, index arrays, and UI when you switch banks and also update the main arrays + UI while making adjustments, it should work. I



Can you elaborae on using the arrays with sunarrays... are you basically storing entire arrays in each index of another array? Do you have an example?


----------



## UCAudio (Mar 31, 2012)

Raptor4 @ Wed Mar 28 said:


> > - Dump all 60 controller values into an array... and load values into the 60 controllers from another array...
> 
> 
> That's interesting. I'm a novice in the KSP but I know very well what is this. Could you show me a simple example using 2-3 sliders and two arrays.
> Thanks !



Hey Raptor, here's the function I'm using to do that. It basically swaps out the 60 controls... does some other unrelated stuff where you see level map.


```
function AMPDIR
    
    if (get_control_par(get_ui_id($Button_AMPDIR),$CONTROL_PAR_VALUE) = 0)
      for i := 0 to 59 
        %Dir_Controls[i] := get_control_par((get_ui_id($B_groupsel_00) + i),$CONTROL_PAR_VALUE)
        set_control_par((get_ui_id($B_groupsel_00) + i),$CONTROL_PAR_VALUE,%Amp_Controls[i])
      end for  
      for i := 0 to 19 
        %Level_Map[i] := 0 + i
      end for  
    end if
    
    if (get_control_par(get_ui_id($Button_AMPDIR),$CONTROL_PAR_VALUE) = 1)
      for i := 0 to 59 
        %Amp_Controls[i] := get_control_par((get_ui_id($B_groupsel_00) + i),$CONTROL_PAR_VALUE)
        set_control_par((get_ui_id($B_groupsel_00) + i),$CONTROL_PAR_VALUE,%Dir_Controls[i])
      end for
      for i := 0 to 19 
        %Level_Map[i] := 20 + i
      end for        
    end if    

end function
```


----------



## Tod (Mar 31, 2012)

UCAudio @ Sat Mar 31 said:


> Can you elaborae on using the arrays with sunarrays... are you basically storing entire arrays in each index of another array? Do you have an example?




Heh heh, I'm not the guy to best explain this, hopefully Big Bob might step in here. :D 

Lets say I have four Toms at 5 mic positions and 4 round robins for each mic with volume knobs, thats a total of 5 Volume values for each Tom multiplied 4 for a total of 20 values.


```
declare $Ttl_Grps_Per_RR = 4 <<RR for each Mic
declare %Vol_Data [20]  <<The array that stores all volume values for each mic and each Tom.

declare %Data_Index [4]  <<The array that accesses the %Vol_Data array at the correct position for each Tom.
    %Data_Index [0] := 0
    %Data_Index [1] := 5
    %Data_Index [2] := 10
    %Data_Index [3] := 15

All together there are 80 groups, 20 for each Tom so I also have indexes for their start positions and I also use a Temp group start that changes as I change Toms.  I should add that allthough there are 80 groups only the data for the first group of each RR needs to be saved or stored.

declare %Grp_Start [4]  <<Group starts for each Tom.  
    %Grp_Start [0] := 0
    %Grp_Start [1] := 20
    %Grp_Start [2] := 40
    %Grp_Start [3] := 60

declare %Temp_Grp_Start [5]  <<Temporary group starts that gets updated as the different Toms are selected.
    %Temp_Grp_Start [0] := 0
    %Temp_Grp_Start [1] := 4
    %Temp_Grp_Start [2] := 8
    %Temp_Grp_Start [3] := 12
    %Temp_Grp_Start [4] := 16

on ui_control ($Vol_Mic_1)  <<First out of the 5 Mics
    $cnt2 := %Temp_Grp_Start [0]  
    $cnt1 := ($cnt2 + $Ttl_Grps_Per_RR)
  while ($cnt2 < $cnt1)
    _set_engine_par($ENGINE_PAR_VOLUME,$Vol_Mic_1,$cnt2,-1,-1)
      inc ($cnt2)
  end while
  set_knob_label($Vol_Mic_1,_get_engine_par_disp($ENGINE_PAR_VOLUME,%Temp_Grp_Start [0] ,0 ,-1))
  %Vol_Data[%Data_Index [$Slct_Tom_Mn]] := _get_engine_par($ENGINE_PAR_VOLUME,%Temp_Grp_Start [0] ,0 ,-1)
end on

on ui_control ($Slct_Tom_Mn)  <<The select Tom menu
  
  {===<<This updates the %Temp_Grp_Start array>>===}
  $cnt2 := %Tom_Grp_Strt [$Slct_Tom_Mn]
  $cnt1 := 0
  while ($cnt1 < 5)
    %Temp_Grp_Start [$cnt1] := $cnt2
      $cnt2 := ($cnt2 + $Ttl_Grps_Per_RR)
      inc ($cnt1)
  end while

{==<Loads data and sets knob for firat Mic.  There are 5 of these>==}
    $Cur_Count := 0 
    $cnt3 := %Vol_Data [%Data_Index [$Slct_Tom_Mn]]
    $cnt2 := %Temp_Grp_Start [$Cur_Count]  
    $cnt1 := ($cnt2 + $Ttl_Grps_Per_RR)
  while ($cnt2 < $cnt1)
    _set_engine_par($ENGINE_PAR_VOLUME,$cnt3,$cnt2,-1,-1)
      inc ($cnt2)
  end while
  set_knob_label($Vol_Mic_1,_get_engine_par_disp($ENGINE_PAR_VOLUME,%Temp_Grp_Start [$Cur_Count] ,0 ,-1))
  $Vol_Mic_1 := $cnt3
end on
```

This vastly over simplified and as I said, someone else might have a better explanation or way of doing it. Anyway this the direction I took and hope it helps. :D


----------

