# A simple KSP controlled dynamics slider?



## thesteelydane (Jan 28, 2019)

Newbie here, so bear with me. I have an instrument that uses an external modular (CC 1) to fade groups in and out through some custom modulation shapers, essentially dynamics crossfading. This works great on it's own, but now I want to make a GUI with a slider that does the same thing, but let's the user assign the slider to whatever CC he or she wants. 

I've found a really simple way to do it, by remapping my CC 1 inside Kontakt to a rarely used one (CC 110). Here's the relevant bits of the code:

```
on init
declare ui_slider $sli_dyn (0, 127)
        move_control_px($sli_dyn, 500, 64)
        make_persistent($sli_dyn)
end on

on ui_control ($sli_dyn)
    set_controller(110, $sli_dyn)
end on
```

This works great, the user can now map the slider to the mod wheel or anything else they want, EXCEPT if the user accidentally maps the slider to CC 110, which I imagine creates some sort of loop, because it crashes Kontakt when I try. So I imagine this is not the best way to do this? Surely there's a better way?

I read through @EvilDragon's post on modulation via KSP, and I can figure out how to get the slider to control for example the intensity slider, but that's not what I want - I want the slider on the GUI to control my crossfading without risking the user accidentally using one of my internal CCs and crashing Kontakt.


----------



## Levitanus (Jan 28, 2019)

ignore_controller


----------



## thesteelydane (Jan 28, 2019)

Levitanus said:


> ignore_controller


So this IS the way to do it, I just need to prevent the user from using CC 110?


----------



## Levitanus (Jan 28, 2019)

wait for...


----------



## thesteelydane (Jan 28, 2019)

The Dragon...I know...


----------



## Levitanus (Jan 28, 2019)

ahh, true, I've done the same way...
Well, You can write about that in manual like audiobro
or use constant modulator, with loosing curve settigns
P.S.
Or make reassignement menu, write case statements in on controller and lock automation on slider


----------



## EvilDragon (Jan 28, 2019)

Constant modulator is always value of 1, mod shaper curves don't influence it.

My suggestion would be to use aftertouch modulator instead of MIDI CC modulator, then you can ignore aftertouch and literally allow user to assign any MIDI CC to your scripted slider (which should send aftertouch events).


----------



## thesteelydane (Jan 29, 2019)

EvilDragon said:


> Constant modulator is always value of 1, mod shaper curves don't influence it.
> 
> My suggestion would be to use aftertouch modulator instead of MIDI CC modulator, then you can ignore aftertouch and literally allow user to assign any MIDI CC to your scripted slider (which should send aftertouch events).



Thanks, that worked great! Only problem is now I want to have a second slider controlling expression, as an extra volume control...so there really is no better way to do it?


----------



## P.N. (Jan 29, 2019)

thesteelydane said:


> Only problem is now I want to have a second slider controlling expression, as an extra volume control...so there really is no better way to do it?



If you're going with the aftertouch modulator solution (this would also apply to a MIDI CC modulator), you can simply add another one.
You only need to rename the modulators so they can be properly adressed independently in the script.

Edit: In order to rename a modulator, make sure the script tab is in edit mode and right click on the modulator you wish to rename.

Cheers.


----------



## thesteelydane (Jan 29, 2019)

P.N. said:


> If you're going with the aftertouch modulator solution (this would also apply to a MIDI CC modulator), you can simply add another one.
> You only need to rename the modulators so they can be properly adressed independently in the script.
> 
> Edit: In order to rename a modulator, make sure the script tab is in edit mode and right click on the modulator you wish to rename.
> ...



Thanks, that makes sense. But its outside my current level of understanding of scripting (only been at it a few days). I don't know how make sure the correct aftertouch events gets send to the correct modulation target, since all I know how to do is use the set_controller command to change what my slider sends. I know how to get it to send a specific midi CC, but there's only one aftertouch, so to speak...How do I tell it to go to the correct modulation target?

Sorry for being stupid....


----------



## EvilDragon (Jan 29, 2019)

P.N. said:


> If you're going with the aftertouch modulator solution (this would also apply to a MIDI CC modulator), you can simply add another one.
> You only need to rename the modulators so they can be properly adressed independently in the script.



That won't work because you would have two CCs remapping themselves to aftertouch, which would then act on all active AT modulators. Doesn't help the man's cause at all.

OP, do you need to have mod shaper curves on expression, or do you really just want to scale the volume with it? In the latter case, you can just use Constant modulator for this, and then adjust its modulation amount with the scripted slider.


----------



## thesteelydane (Jan 29, 2019)

EvilDragon said:


> That won't work because you would have two CCs remapping themselves to aftertouch, which would then act on all active AT modulators. Doesn't help the man's cause at all.
> 
> OP, do you need to have mod shaper curves on expression, or do you really just want to scale the volume with it? In the latter case, you can just use Constant modulator for this, and then adjust its modulation amount with the scripted slider.



No, I only need the mod shaper curves on one of my modulators, the other is just volume scaling. So I would use a set_engine_par command to address the intensity slider in that modulation target?


----------



## Levitanus (Jan 29, 2019)

thesteelydane said:


> set_engine_par command to address the intensity slider in that modulation target?


True.
Later, if You need some simple curve it's quite easy to precalculate it from sine, for example)
Definitely, simple app for generating KSP array from curve has to be made))


----------



## EvilDragon (Jan 29, 2019)

thesteelydane said:


> So I would use a set_engine_par command to address the intensity slider in that modulation target?



Yes. But I definitely recommend renaming the modulator to make it clearer for usage with find_mod().


----------



## P.N. (Jan 29, 2019)

EvilDragon said:


> That won't work because you would have two CCs remapping themselves to aftertouch, which would then act on all active AT modulators. Doesn't help the man's cause at all.



No, what i meant was using the mono after touch for one slider, and the poly for the other.
Maybe that's not possible (and my mind set was really on MIDI CCs when i posted).

Edit: I see this one solution would still not work. 
@thesteelydane, sorry for the confusion.


----------



## thesteelydane (Jan 30, 2019)

Thanks everyone, it's all working now. My dynamics controller with the custom shaper curves is on aftertouch internally, and I have disabled external aftertouch with ignore_controller, so there will be no conflicts. Overall volume is using a constant modulator.

This was a bit tricky (at least for me with my current level of understanding), so here's the solution for anyone else:


```
on ui_control ($sli_expression)
    $i := 0
    while ($i < $NUM_GROUPS)
        set_engine_par($ENGINE_PAR_MOD_TARGET_INTENSITY, $sli_expression, $i, find_mod($i,"CONSTANT_VOLUME"), -1)
        inc ($i)
    end while
  
end on
```

Easy enough, my slider is now moving the intensity slider in the modulation slot. Problem is, for this to scale the volume, the "invert" button has to be pressed. So now my slider is functioning in reverse. I tried various ways of flipping the value from the slider, but in the end the solution was dead simple: Change the range of the slider when you declare it. First I tried going from 1000000 to 0, which made whatever hardware controller you attach to control the volume the way you expect, but the slider on the GUI was still moving in the wrong direction. The solution was stupidly simple: set the range from -1000000 to 0. Ta-Daaaaaa!

Everything works! Thanks everyone, I'm excited to dig deeper into scripting!


----------



## EvilDragon (Jan 30, 2019)

In fact, you could've just left the Invert button enabled by itself internally in the NKI, and then just use the regular (0, 1000000) range for the slider.


----------



## thesteelydane (Jan 31, 2019)

EvilDragon said:


> In fact, you could've just left the Invert button enabled by itself internally in the NKI, and then just use the regular (0, 1000000) range for the slider.



The invert IS on internally, otherwise it doesn't affect volume at all. 

Edit: Now it does work without the invert button on for some reason, but I still have to set a negative range for slider either way or it functions in reverse. Now I'm perplexed...


----------



## EvilDragon (Jan 31, 2019)

Right, because modulating amplitude is a multiplicative thing, not additive. So with Constant mod at max, you get no change, but at 0% you get silence. That just means you need to declare your slider as (0, 1000000) and subtract the value of the slider _from_ 1000000, when doing set_engine_par()  But I guess setting the slider to -1000000, 0 range does about the same thing, because $ENGINE_PAR_MOD_TARGET_INTENSITY is abs()'d internally.


----------



## thesteelydane (Jan 31, 2019)

EvilDragon said:


> Right, because modulating amplitude is a multiplicative thing, not additive. So with Constant mod at max, you get no change, but at 0% you get silence. That just means you need to declare your slider as (0, 1000000) and subtract the value of the slider _from_ 1000000, when doing set_engine_par()  But I guess setting the slider to -1000000, 0 range does about the same thing, because $ENGINE_PAR_MOD_TARGET_INTENSITY is abs()'d internally.



I understand it now. Thanks for your help, I really appreciate it!


----------

