# Group selector and octave transpose knobs?



## flextone (Jan 22, 2013)

Hi, first post, fantastic forum!


I fairly new to Kontakt. Up until now I've been mostly using hardware samplers (akai, emu). I've been having a lot of fun sampling my hardware monosynths and making polyphonic versions of them, but I have a few questions about using scripting to simplify the patches. 

1) I want to make a "wave selector" knob for two oscillators, to switch between sampled waveforms (tri/saw/squ...). As far as I can tell I can only do this by assigning each waveform sample set to its own group, and then using a CC to switch between groups. Can this be done more elegantly with KSP? preferably with the value display showing the waveform name. 

2) I also would like an octave transpose knob, and a volume knob for each of the two oscillators. 


Will this script do the trick for octave and volume? I found some info on other posts and I need to make it all work together. 


```
{----------- Octave Transpose ------------} 

declare ui_knob $Oct_Transpose (-6,6,1) 
set_text($Oct_Transpose, "Octave") 
$Oct_Transpose := 0 
set_knob_defval ($Oct_Transpose,0) 

move_control($Oct_Transpose,3,2) 
make_persistent($Oct_Transpose) 

{---------------- Volume -----------------} 

declare $Vol_Amount 

declare ui_knob $Volume (-100,20,1) 
set_text($Volume,"Volume") 
$Volume := 0 
set_knob_defval ($Volume, 0) 

move_control ($Volume,4,2) 
make_persistent ($Volume) 
end on 

on note 
change_note($EVENT_ID, $EVENT_NOTE + ($oct_transpose * 12)) 
$Vol_Amount := ($EVENT_VELOCITY-1 ) * ( $Volume * 5 ) 
change_vol ($EVENT_ID,$Vol_Amount,1) 
end on
```

thanks for your help


----------



## polypx (Jan 22, 2013)

This method will change the octave and the transpose for all the groups that are sounding. 

If you want to do it to selected groups only, then you need to read about disallow_group() and allow_group().


----------



## polypx (Jan 22, 2013)

Here's an example that might put you on the right track:


```
on init
declare ui_knob $Volume_1 (-100,20,1)
declare ui_knob $Volume_2 (-100,20,1)
declare ui_knob $Oct_1 (-6,6,1)
declare ui_knob $Oct_2 (-6,6,1)
declare $ID_1
declare $ID_2
declare $count
declare ui_menu $Osc_1
declare ui_menu $Osc_2
while ($count < $NUM_GROUPS)
add_menu_item ($Osc_1, group_name($count), $count)
add_menu_item ($Osc_2, group_name($count), $count)
inc($count)
end while
make_persistent($Volume_1)
make_persistent($Volume_2)
make_persistent($Oct_1)
make_persistent($Oct_2)
make_persistent($Osc_1)
make_persistent($Osc_2)
end on

on note
ignore_event($EVENT_ID)
disallow_group($ALL_GROUPS)
allow_group($Osc_1)
$ID_1 := play_note(($EVENT_NOTE + ($Oct_1 * 12)), $EVENT_VELOCITY, 0, -1)
disallow_group($ALL_GROUPS)
allow_group($Osc_2)
$ID_2 := play_note(($EVENT_NOTE + ($Oct_2 * 12)), $EVENT_VELOCITY, 0, -1)
change_vol ( $ID_1, ($EVENT_VELOCITY) * ( $Volume_1 * 5 ) , 1)
change_vol ( $ID_2, ($EVENT_VELOCITY) * ( $Volume_2 * 5 ), 1)
end on
```


----------



## flextone (Jan 23, 2013)

looks incredibly elegant. thanks!

I'll try to work this out today.


----------



## flextone (Jan 26, 2013)

The script worked beautifully Polypx, thank you. Didn't need a lot of tweaking to get it right where I wanted it. Here are two more questions, I hope I'm not pushing it:

1) I'm a bit confused about how this script handles the different groups. I currently have 4 groups, and the script allows me to choose a group for each voice (instant? osc? you get my drift). Now, let's say I want to add a fifth group (white noise), but take it out of the menus, and assign a button to turn it on or off and add a volume knob. How do I take that group out of the menu options? 

2) I really enjoy using the factory "unison-portamento" script, but I didn't succeed in taking out only those parts of the scripts that I want and applying them to mine. I'm talking about the "unison", "detune" and "spread" part. I would actually prefer a detune setting independent of the unison, and this is where I start getting confused. If the script you gave me can double the same group (if both osc are set to the same group), how do I detune between those two oscillators? 

Thanks. I hope this isn't as confusing to you as it is to me o


----------



## polypx (Jan 27, 2013)

Ok, I probably could write the script for you, but I think it's better if you understand what's going on, and then you can customize the script the way you want it to work.

The part filling the menus is this, which is currently just filling them both with all groups:


```
while ($count < $NUM_GROUPS)
add_menu_item ($Osc_1, group_name($count), $count)
add_menu_item ($Osc_2, group_name($count), $count)
inc($count)
end while
```

You could either change the limit of the $count to be less than the number of all groups ($NUM_GROUPS), ie. (while ($count < $NUM_GROUPS - 1) will fill the menu with all but the last group.

OR you can simply add the menu items individually:
add_menu_item ($Osc_1, "Distorted Sawtooth", 3)
... where "3" is the number of the group, so be sure you understand that $Osc here is choosing the group number.

You can make a switch that will allow a noise group seperately, adding something like this to the note callback:


```
disallow_group($ALL_GROUPS)
if ($my_switch_for_white_noise = 1)
allow_group($number_of_the_white_noise_group)
$ID_3 := play_note(($EVENT_NOTE, $EVENT_VELOCITY, 0, -1) 
change_vol ( $ID_3, ($EVENT_VELOCITY) * ( $Volume_3 * 5 ) , 1) 
end if
```

Note that group numbers start from 0, and you need a new event ID for each "oscillator" or "voice" you want to create and manipulate ("$ID_3" here).

For detune you need to use yet another "voice", and use change tune to make it slightly different from the other.

ie.

```
$ID_1B := play_note(($EVENT_NOTE + ($Oct_1 * 12)), $EVENT_VELOCITY, 0, -1) 
change_vol ( $ID_1B, ($EVENT_VELOCITY) * ( $Volume_1 * 5 ) , 1) 
change_tune( $ID_1B,  $Detune_knob*1000, 1)
```

You might want to experiment with the detune in a separate script until you're confident how it works and then combine it with your existing script.

cheers, Dan


----------



## flextone (Jan 27, 2013)

Dan, I'm working on the script right now. Thanks for helping and keeping things at a level I can understand. 

Trickiest part seems to be the detune. 

I'll report back if I encounter problems.


----------



## flextone (Jan 27, 2013)

There seems to be a problem in the way the script handles the volume changes.

It is as if velocity has an inverted effect on the volume . This is most evident when all three volume knobs are set to their lowest position (-100). In this situation, only a max velocity value yields total silence. The less velocity I apply to the played note, the more volume is audible. 

I assume this is because the volume values are between -100 and 20, i.e, mostly negative values. when the volume knobs are in negative values, this makes higher velocities be quieter if I'm going by the equation in the change_vol lines. How can I change the script to work correctly? I guess I could just make the volume knobs operate for 0-120 (instead of -100,20) and lower the volume knob in the gui, but I'm curious about this... 

Here are the relevant code lines:

change_vol ( $ID_1, ($EVENT_VELOCITY) * ( $Volume_1 * 5 ) , 1) 
change_vol ( $ID_2, ($EVENT_VELOCITY) * ( $Volume_2 * 5 ) , 1)
change_vol ( $ID_3, ($EVENT_VELOCITY) * ( $Volume_3 * 5 ) , 1) 

btw, why is there a need to control the way velocity affects volume in the script and not through the regular gui?


----------



## polypx (Jan 27, 2013)

> why is there a need to control the way velocity affects volume in the script and not through the regular gui?



There isn't. Sorry, that was confusing. I had just copied and pasted it from a different example without thinking.

I would revise it so that the definition becomes:
declare ui_knob $Volume_1 (-100, 0, 1) 

and the note callback uses:
change_vol ( $ID_1, $Volume_1 * 1000, 1)


----------

