1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Need a simple script for group volume

Discussion in 'Scripting Workshop' started by IlMolto, Mar 7, 2012.

  1. IlMolto

    IlMolto NI Product Owner

    Messages:
    236
    Hey guys,

    Hoping someone can help me out. I've sampled two raw oscillators from a synth. I've mapped them into their own group in Kontakt. Now I'd just like a UI to change each group's volume from -∞ to 0 dB. Just like it would be in a synth. Can someone help me out here?
     
  2. Dissident_Penguin

    Dissident_Penguin New Member

    Messages:
    1
    The easiest way to accomplish what you want using groups is using directly the volume knob of each group in the Amplifier module, right under the Source module.

    To do this, first unselect the Edit all groups button to make sure you don't modulate both groups with the same control signal.

    Then click on the name of the first group (group 0)

    Then right/click on the volume knob and then you can select a variety of sources, including midi controllers.

    Do the same for the other group and you are set to go.

    Alternatively you can also accomplish it in KSP using the command:

    set_engine_par ($ENGINE_PAR_VOLUME, $new_volume, $group_index, -1,-1)

    group indexes start from 0.

    If you need more help just let me know.

    DP
     
  3. IlMolto

    IlMolto NI Product Owner

    Messages:
    236
    Hi and thanks for your reply. Some time ago EvilDragon helped me with a script to control two parameters with a single knob. This is the thread where he helped me:

    http://www.native-instruments.com/forum/showthread.php?t=147682

    So I tried copying the script and just changing a few things so it would do what I wanted. Here's what I ended up with:


    Code:
    on init
    	declare ui_knob $Volume (0,1000000,1)
    
    	set_knob_unit($Volume,$KNOB_UNIT_DB)
    	set_knob_label($Volume,get_engine_par_disp($ENGINE_PAR_VOLUME,0,0,-1))
    	$Volume := get_engine_par($ENGINE_PAR_VOLUME,0,0,-1)
    
    	make_persistent($Volume)
    
    	message("")
    end on
    
    on ui_control ($Volume)
    	set_engine_par($ENGINE_PAR_VOLUME,$Volume,0,0,-1)
    	set_knob_label($Volume,get_engine_par_disp($ENGINE_PAR_VOLUME,0,0,-1))
    end on
    After clicking apply, a Volume knob appears but when I tweak it, nothing happens. It doesn't change the volume of group 1. Tried looking the KSP manual but I still have no idea. I could use MIDI CC to control each group volume, but I want to try a script first to see if I can get two knobs side by side. Or one knob that mixes between the two group volumes.
     
  4. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    For group volumes, use 0,-1,-1 instead of 0,0,-1. 0 means first group here. 1 means second group, 2 means third group, etc.
     
  5. IlMolto

    IlMolto NI Product Owner

    Messages:
    236
    Hi EvilDragon,

    Thanks for helping me out. You mean like this?

    Code:
    on init
    	declare ui_knob $Volume (0,1000000,1)
    
    	set_knob_unit($Volume,$KNOB_UNIT_DB)
    	set_knob_label($Volume,get_engine_par_disp($ENGINE_PAR_VOLUME,0,-1,-1))
    	$Volume := get_engine_par($ENGINE_PAR_VOLUME,0,-1,-1)
    
    	make_persistent($Volume)
    
    	message("")
    end on
    
    on ui_control ($Volume)
    	set_engine_par($ENGINE_PAR_VOLUME,$Volume,0,-1,-1)
    	set_knob_label($Volume,get_engine_par_disp($ENGINE_PAR_VOLUME,0,-1,-1))
    end on
    Same thing happens. A knob appears but it doesn't do anything.
     
  6. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    That should adjust the volume of the first group. It works here alright.
     
  7. IlMolto

    IlMolto NI Product Owner

    Messages:
    236
    For some reason the script only works when I'm using Kontakt as a plugin and not as standalone. Weird. Anyway, so now I want to add another knob beside it so it changes the volume of group 2. Then I want to label the knobs "SubOsc" and "SquareOsc". How would I go about doing that?
     
  8. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Works both in plugin and standalone over here.

    Simply duplicate the code for the $Volume knob, except call it $SubOsc and the duplicate $SquareOsc. Make one go 0,-1,-1, and the other 1,-1,-1.
     
  9. IlMolto

    IlMolto NI Product Owner

    Messages:
    236
    Like so?

    Code:
    on init
    	declare ui_knob $SubOsc (0,1000000,1)
    
    	set_knob_unit($SubOsc,$KNOB_UNIT_DB)
    	set_knob_label($SubOsc,get_engine_par_disp($ENGINE_PAR_VOLUME,0,-1,-1))
    	$SubOsc := get_engine_par($ENGINE_PAR_VOLUME,0,-1,-1)
    
    	make_persistent($SubOsc)
    
    	message("")
    
    	declare ui_knob $SquareOsc (0,1000000,1)
    
    	set_knob_unit($SquareOsc,$KNOB_UNIT_DB)
    	set_knob_label($SquareOsc,get_engine_par_disp($ENGINE_PAR_VOLUME,1,-1,-1))
    	$SquareOsc := get_engine_par($ENGINE_PAR_VOLUME,1,-1,-1)
    
    	make_persistent($SquareOsc)
    
    	message("")
    end on
    
    on ui_control ($SubOsc)
    	set_engine_par($ENGINE_PAR_VOLUME,$SubOsc,0,-1,-1)
    	set_knob_label($SubOsc,get_engine_par_disp($ENGINE_PAR_VOLUME,0,-1,-1))
    end on
    
    on ui_control ($SquareOsc)
    	set_engine_par($ENGINE_PAR_VOLUME,$SquareOsc,1,-1,-1)
    	set_knob_label($SquareOsc,get_engine_par_disp($ENGINE_PAR_VOLUME,1,-1,-1))
    end on
    
     
  10. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Yeah, that should do it. Provided you have sub oscillator samples in the first group, and square oscillator samples in the second group. :)
     
  11. IlMolto

    IlMolto NI Product Owner

    Messages:
    236
    Haha yep indeed I do. Now one more question. Is it possible to create a single knob rather than two knobs to control the group volumes? For example; fully panned left will sound only the SubOsc. Then as you pan it to the middle, the SquareOsc will start to fade in. Dead centre will sound both of the Osc's at full volume. Then as you pan towards the right, SubOsc will fade out until fully at the right only the SquareOsc sounds.
     
  12. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    It's possible, but you'll need some additional math as the crossfade won't be equal power.
     
  13. IlMolto

    IlMolto NI Product Owner

    Messages:
    236
    Is it something I can learn by reading the manual? What words or phrases should I search for?
     
  14. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Not really... You just have to experiment. Knob range for volumes -oo to 0 dB is (0,631000). -6 dB is 500000.

    If you want equal power crossfade between two volumes, it's definitely easier using a CC modulator on both groups, with modulation shaper set to exponential curve, and inverting the modulation amount in one group. Much easier to do - then you'd just send the respective CC from the script, instead of engine parameter values.
     
  15. IlMolto

    IlMolto NI Product Owner

    Messages:
    236
    Alright, no worries. Thanks again for your help.
     
  16. Andreas Hald

    Andreas Hald NI Product Owner

    Messages:
    74
    I know this is an old thread - but just stumbled across it. When using the first code from IlMolto, it sure works and I can control group 1 with a knob. However, when trying to copy/paste the code and change the zero to 1 - in order to make another knob for group-volume 2, iI simply can't get it to work. ANyone knows why I'm not able to make another knob? I'm indeed a novice....

    This works for group one. But I can't make one for group 2...

    on init
    declare ui_knob $Volume (0,1000000,1)

    set_knob_unit($Volume,$KNOB_UNIT_DB)
    set_knob_label($Volume,get_engine_par_disp($ENGINE_PAR_VOLUME,0,-1,-1))
    $Volume := get_engine_par($ENGINE_PAR_VOLUME,0,-1,-1)

    make_persistent($Volume)

    message("")
    end on

    on ui_control ($Volume)
    set_engine_par($ENGINE_PAR_VOLUME,$Volume,0,-1,-1)
    set_knob_label($Volume,get_engine_par_disp($ENGINE_PAR_VOLUME,0,-1,-1))
    end on
     
  17. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Easy enough.

    Code:
    on init
        declare ui_knob $Vol1 (0,631000,1)
        declare ui_knob $Vol2 (0,631000,1)
    
        set_knob_unit($Vol1,$KNOB_UNIT_DB)
        set_knob_unit($Vol2,$KNOB_UNIT_DB)
    
        set_knob_defval($Vol1,500000)
        set_knob_defval($Vol2,500000)
    
        set_knob_label($Vol1,get_engine_par_disp($ENGINE_PAR_VOLUME,0,-1,-1))
        set_knob_label($Vol2,get_engine_par_disp($ENGINE_PAR_VOLUME,1,-1,-1))
    
        $Vol1 := get_engine_par($ENGINE_PAR_VOLUME,0,-1,-1)
        $Vol2 := get_engine_par($ENGINE_PAR_VOLUME,1,-1,-1)
    
        make_persistent($Vol1)
        make_persistent($Vol2)
    
        message("")
    end on
    
    on ui_control ($Vol1)
        set_engine_par($ENGINE_PAR_VOLUME,$Vol1,0,-1,-1)
        set_knob_label($Vol1,get_engine_par_disp($ENGINE_PAR_VOLUME,0,-1,-1))
    end on
    
    on ui_control ($Vol2)
        set_engine_par($ENGINE_PAR_VOLUME,$Vol2,1,-1,-1)
        set_knob_label($Vol2,get_engine_par_disp($ENGINE_PAR_VOLUME,1,-1,-1))
    end on
     
  18. Andreas Hald

    Andreas Hald NI Product Owner

    Messages:
    74
    Ahh, thanks a ton EvilDragon! I sure hope NI is paying you with all your good advice I see around this forum! Thanks for all your inputs.
     
  19. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Wouldn't that be nice of them? But no, they are not. :(
     
  20. young peter

    young peter New Member

    Messages:
    11
    Just stumbled across this thread as well. I'm after a similar bit of script (multiple volume controls for different groups), however I have a Round Robin system implemented, so each group contains 1 of ten different versions of my samples.
    Is there any easy way around this so that the volume control effects only the first sample in each group, rather than all ten of them?