# Adjust sample start offset via UI?



## argitoth (Jun 12, 2013)

How do I adjust sample start offset with a UI knob? (circled in pink in the attached image below)

I know how to add a UI knob, assign parameters, display values, etc. But I just need a quick introduction to controlling stuff like this. What commands will I need to make use of? What built-in variables? Can I calculate sample offset by getting the length of the sample and allow the user to set a percentage value rather than a microsecond value?

play_note(<note-number>,<velocity>,<sample-offset>,<duration>)

Thank you!


----------



## argitoth (Jun 12, 2013)

I found this topic to shed some light: http://www.northernsounds.com/forum/showthread.php/49605-Sample-start-script-for-Kontakt (http://www.northernsounds.com/forum/sho ... or-Kontakt)

The last post in the thread mentions a "sampler module" which allows you to adjust sample offset in DFD mode. Here's the post



> Yes, you cannot use sample start modulation when using DFD - so it is not really interesting to use sample start modulation for big libraries (of at all, as RAM fills up too quickly).
> And well, of course you can modulate it via the sampler module directly for non DFD mode.
> 
> best



I don't know what the "sampler module" is.


----------



## argitoth (Jun 12, 2013)

I think sampler module = Wave Editor

I think I found the next clue.

Page 97 of the KSP manual says


> <sample-offset> this parameter specifies an offset in the sample in microseconds
> 
> In DFD mode, the sample offset is dependent on the S. Mod value of the respective zones. Sample offset value greater than the zone's S.Mod setting are clipped to this value.
> 
> You can retrieve the event ID of the played note by writing: <variable> := play_note(<note>,<velocity>,<sample-offset>,<duration>)



Also, if you go into the wave editor, you can adjust the S. Mod value. Then, go to the options button --> to all selected zones --> copy current start-mod settings (have all zones selected [while the focus is on a single zone] to copy the settings to all zones).

Does this mean that the start-mod settings tells Kontakt how much sample content to load into RAM? So, ideally I want to keep the sample start mod to a minimum?


----------



## argitoth (Jun 12, 2013)

GOT IT! Here's the simplest way to do it, after setting your S.Mod of course.

```
on note
  ignore_event($EVENT_ID)
  play_note($EVENT_NOTE,$EVENT_VELOCITY,<# sample start in microseconds>,-1)
end on
```
And indeed, more S.Mod results in more RAM usage.

YEAH FIGURED IT OUT MYSELF FTW! _-)


----------



## mk282 (Jun 13, 2013)

Sampler module is the part of Kontakt's edit mode where you can see the Tune knob, the sampler mode dropdown, the HQI dropdown, the Tracking and Release Trigger buttons, etc.


By the way, you can dynamically change sample startpoint by assigning a Constant modulator to modulate sample start, then changing the modulation amount of that modulation source.


----------



## argitoth (Jun 13, 2013)

Ahhh, took me a while to find it, so just want to explain to everyone else how to find it.

-Open the instrument edit window (wrench).
-Find the word "Source" it's next to the DFD/Sampler dropdown menu.
-Under Source is Preset dropdown menu and under that is "Mod"
-Add a constant modulator (or other modulator), then set it to sample start.

-Different sample modes offer different modulation targets, DFD mode only offers two: Pitch and Sample Start.

ONCE AGAIN YOU MUST SET YOUR S.MOD TO SOME AMOUNT!

Thanks, *mk282*.


----------



## argitoth (Jun 22, 2013)

(((((1/<samplerate>)*<s.mod>)*1000000))/100) = the multiplier for a knob that goes from 0 to 100

example: (((((1/48000)*2000)*1000000))/100) = 416

Create a knob or slider that goes from 0 to 100, make the label display as slider value & "%"

Set your s.mod value, use the eqation above, now the offset value should = knob value * the multiplier, round down to nearest 10.

If you don't round down, you risk the offset value going over the max, which will cause the offset not to work.

Esentially you are creating a knob that shows a percentage value that goes from 0% to 100% sample offset based on your s.mod value (your max sample offset in DFD mode). This ensures proper use of sample offset modulation.


```
{uncompiled kscript example}
on init
  declare offset_max := 2080 {you must use the equation to get this number, kontakt cannot process the equation}
  declare store_env_offset
  
  {insert all the necessary knob/slider/label code here}
end on

on ui_control(slider_env_offset)
  set_text(label_env_offset,slider_env_offset & "%")
  store_env_offset := slider_env_offset
  store_env_offset := store_env_offset * offset_max
  message(store_env_offset)
end on

on note 
  ignore_event($EVENT_ID) 
  play_note($EVENT_NOTE,$EVENT_VELOCITY,store_env_offset,-1) 
end on
```


----------



## mk282 (Jun 22, 2013)

Why not just use a Constant modulator to modulate sample start and then control the amount of this modulation via KSP? It is much easier, and Kontakt will take care of sample rate calculation internally for you.


By the way, this way of modulating startpoint will include S.Mod. in its calculation. Which means if you're in DFD mode, it will go from 0 to S.Mod samples. If you're in sampler mode, it will have the whole sample length as its range.


----------



## argitoth (Jun 22, 2013)

mk282 @ Sat Jun 22 said:


> Why not just use a Constant modulator to modulate sample start and then control the amount of this modulation via KSP? It is much easier, and Kontakt will take care of sample rate calculation internally for you.


I'm all for easier!  Will have to explore this way of doing it.


----------



## argitoth (Jun 22, 2013)

aww man... :( can't seem to understand how to connect the knob to the modulation intensity of the sample start modulator constant.

what might the group,slot,generic numbers look like?


----------



## Big Bob (Jun 22, 2013)

Here's an example for a SS constant modulator in Group 0.

*on init*
``message('')
``*declare* ui_slider Offset (0,1000000)
*end* on

*on ui_control*(Offset)
``set_engine_par(ENGINE_PAR_MOD_TARGET_INTENSITY,Offset,0,find_mod(0,"CV_PITCH"),-1)
*end* on


If you need linear control, you can use the Math Library routine named ModInt_to_ep.

Rejoice,

Bob


----------



## argitoth (Jun 22, 2013)

YES got it workin, thank you *Big Bob*!


----------



## Big Bob (Jun 22, 2013)

Glad you got it worked out but, I'm about ready to quit for the day so here's an example of linear control in case you decide later you need that and I'm sound asleep. :lol: 

*import* "KSPMathV450.txt"

*on init*
``message('')
``SetMathMode(0)
``*declare* ui_slider Offset (0,1000000)
``*declare* ep
*end* on

*on ui_control*(Offset)
``message(Offset)
``ep := ModInt_to_ep(TARG,Offset)
``set_engine_par(ENGINE_PAR_MOD_TARGET_INTENSITY,ep,0,find_mod(0,"CV_PITCH"),-1)
*end* on



Rejoice,

Bob


----------



## mk282 (Jun 23, 2013)

Also if you have the script editor area open, you can right-click the modulator strip to rename it. This is the "CV_PITCH" part, by default. I usually name this STARTPOINT.


----------



## argitoth (Jun 23, 2013)

Ah yes, so you right click on the modulator then click on "name: CV_PITCH" and a popup window will appear for renaming the modulator. Thanks for the tip! Didn't realize this.


----------

