Kontakt Scripting - Building an Instrument From Scratch

Discussion in 'AudioSex Academy' started by Clandestine, Aug 5, 2015.

  1. Clandestine

    Clandestine Platinum Record

    Joined:
    Nov 11, 2013
    Messages:
    717
    Likes Received:
    151
    [​IMG]

    Having read round there seemed to be quite a bit of interest regarding KSP and Kontakt Scripting.

    As they were dotted around the place here and there what I thought might be a good idea was to start a thread where we can go through building an instrument from scratch all the way through to a finished instrument. Every week or few days I will post the next step and then people can follow in a logical order the process used to create a library or instrument.

    As I have said many times previously in my opinion Kontakt is way ahead of any other sample manipulation tools and the ability to create your own interface and put into practice your own ideas only adds to making it a fantastic tool that anyone can utilise.
    Keep in mind that whilst there are basic rules and procedures that must be adhered to there are no MUST DO's with regards to the methodology and creative input.

    KSP combined with other features provides the platform on which to build a foundation and in the process turn creative ideas into reality.
    As there will be no definite idea in mind people can come up with ideas and suggestions as what to incorporate and if possible we can add them so that the end product is something not "set in stone" as such.
    My aim is that it may be of some use to those who want to start learning KSP or scripting and give them a starting point or introduction to the world of scripting.

    Also keep in mind that there will be mistakes that will need to be rectified and changed. This ALWAYS happens when designing a GUI or instrument.
    First of I would like to mention a couple of things. From my way of thinking one must is getting hold of the KSP reference manual.
    You will find a copy of it and other useful reference material by default normally at the location

    C:\Program Files\Native Instruments\Kontakt 5\Documentation

    Q - "why is it important to have this reference?"

    A - There are many reasons why you should have a copy of this reference at hand. Whilst explaining the building blocks and foundation of KSP with examples to work through it also contains ALL the relevant engine commands and parameters that you will need when building an instrument. As you become familiarised with the manual you will of course learn many of these and it will become second nature.

    Another thing worth noting is that for this exercise I will be using Kontakt version 5.0.3.5812 rather than the latest version of Kontakt which is 5.5.1.451
    This is simply to ensure that other users can open the project in other versions of Kontakt.
    If I need to use 5.5.1.451 for any features I will make copies of both

    Q- Why DO this?

    A- Kontakt and all NI software is "Backward Compatible" rather than "Forward Compatible"

    "A new version program is said to be backward compatible if it can use files and data created with an older version of the same program."

    Backward compatibility is important because it eliminates the need to start again when you upgrade to a newer version of the product.
    Another term for backward compatible is downward compatible.

    "Forward Compatibility"

    "The ability to accept input from later versions of itself. "
    Forward compatibility is harder to achieve, since, in the backward case, the input format is know whereas a forward compatible system needs to cope the unknown future features.

    Put simply

    Backwards compatibility means the new program version can load older program versions.
    Forwards compatibility old program version can load newer program versions.

    Q -Why isn't Kontakt Forward Compatible?

    A- Amongst other things, forwards compatibility usually creates and would mean that any features introduced in later versions would not work.

    However as I will be providing the script & method and any samples there should be no problems as the whole point is to build the instrument from scratch in whatever version of kontakt you have available.
    Right I will now start with basic things to consider and things to think about when creating a library.


    AIMS

    a.) To study & note the structure of the resource container.

    The Resource Container is a useful tool for library developers -

    It is a dedicated location to store scripts, graphics, .nka files and impulse response files that can be referenced by any NKI or group of NKIs that are linked to the container.
    Another benefit is that you can create a resource container monolith file containing all the scripts, graphics etc. so that you can easily move them around or send them to other team members.
    When loading an NKI, the resource container is treated like a sample, so if it is not found it will appear
    in the Samples Missing dialogue.

    b.) The one sample we are starting with & how and where to map it out.

    c.) The contents of the pictures folder & the accompanying text files.

    Important things to consider -

    a.) When you map out a sample in Kontakt, you should open the mapping editior and drag & drop the sample to the corresponding Key you wish to start with.
    Remember when you press the key Kontakt will play the sample from the start to the end depending on how long the sample is in length.

    b.) As long as the key is depressed Kontakt will play th sample and once the key is released playback will end. The sample playback will be affected by the length in that all the parameters of the modulation section i.e Curve, Attack, Hold, Decay, Sustain & Release.

    c.) Click on the modulation (mod) tabs to display the setings or parameters you wish to modulate.

    d.) By default Kontakt has modulation controls in the SOURCE MODULE for Pitch Bend. This value is set again by default to 2 steps up or down.
    This is linked to the pitch bend wheel of your Midi controller. The number of steps you wish the Pitch bend wheel to affect the note can be changed to any desired value between zero and 12 i.e a value of 12 will affect the pitch bend up & down in both directions by 1 octave.
    By default this value is set to 2 giving a range of 1 whole step.
    You can delete the default modulation parameters by right clicking on the section and choosing DELETE.
    The sections can also be renamed to any name you desire which
    can then be declared in the script. We will touch on this later.

    e.) Also you will find numbered in the modulation sections values for

    1.) GRP (GROUP)

    2.) IDX (INDEX)

    3.) GEN (GENERIC)

    This is important detail for finding & returning values and telling Kontakt where & what to look for and affect

    For example if we consider Engine Parameters then the following format should be noted -
    get_engine_par(<parameter>,<group>,<slot>,<generic>
    This command would return the value of a specific engine parameter i.e

    <parameter> Specifies the engine parameter by using one of the built in engine parameter variables.

    <group> The index (zero based) of the group in which the specified parameter resides.
    If the specified parameter resides on an Instrument level, enter -1.

    <slot> The slot index (zero based) of the specified parameter.

    This applies only to group/instrument effects, modulators and modulation intensities.
    For group/instrument effects, this parameter specifies the slot in which the effect resides (zero-based).
    For modulators and modulation intensities, this parameters specifies the index which you can retrieve by using:

    the command - find_mod(<group-idx>,<mod-name>)

    <generic> This parameter applies to instrument effects and to internal modulators.
    For instrument effects, this parameter distinguishes between 1: Insert Effect 0: Send Effect

    For busses, this parameter specifies the actual bus: $NI_BUS_OFFSET + [0-15] one of the 16 busses
    For internal modulators, this parameter specifies the modulation slider which you can retrieve by
    using find_target(<group-idx>,<mod-idx>,<target-name>)

    For all other applications, set this parameter to -1
    We will discuss this in more detail at a later relevant stage.

    f.) If you then navigate to the Group Insert FX level & hit the grey modulation tab you will find that by default Kontakt affects two values on this level.

    1.) ENVELOPE (AHSDR) set by default to 100% & corresponding to the Modulation parameters for selected groups i.e Curve, Attack, Hold, Decay, Sustain & Release.

    It is important to consider which groups will be affected by changing these values.

    For example - An instrument in Kontakt can be made up of many Groups of samples.
    This is an important concept to understand.
    When you map a sample in the mapping editior this will make a group.

    This group can then be renamed
    You can add further samples to the group or then create a new group. If for example you have an instrument made up of 6 groups of samples you should remember that your script must reflect which groups you wish the modulation controls to affect i.e do you want changes in controls to affect just one group or all groups of samples?

    We will discuss this in much greater detail later on and reflect upon how to write a script that will consider this.

    2) VELOCITY - Velocity is simply a measure of how hard you press a key and different Velocities can be reflected in different ways.

    The most common is that the higher the velocity then the higher the resulting volume level. This is especially important when considering realism and how an instrument plays and sounds. ie the harder you hit the keys the louder the playback and vice-versa.
    It is important also to consider and understand why it is impossible in theory to have negative values with regards to velocity.

    MODULATION is a complex topic and can get pretty complicated in Kontakt. It is an essential tool however and it is possible to do many things.
    It is even possible for example to "modulate a modulation!"
    Once again we will consider this in much greater detail at a later stage.

    SO TO START - KEEP THINGS BASIC! This may sound self explanatory but it is really important to think along these lines at first.

    For example the first thing to consider are the basics, i.e What instrument do we want to make?
    How many groups of samples do we want to use?
    What performance view controls do we want to script in?
    How do we want to affect these controls?

    All simple but these factors will all dictate to some degree the nature of the scriptwe need to write.
    In the package I have only included 1 sample!
    This however is enough to start building a GUI around and always remember that we can at any time add more samples/groups
    and modify the script to suit our purposes.

    SO STEP BY STEP THE BASICS COME FIRST.

    STEP 1

    OPEN KONTAKT, Navigate to the FILES tab at the top and from the dropdown menu select "NEW INSTRUMENT."
    When pressed a new tab will appear and then it's time to start adding samples and writing the script.

    STEP 2

    In the top left hand corner click on the wrench (spanner) icon.
    Once opened all the various Source Module, Group Insert FX, Instrument Insert FX ETC will appear.

    STEP 3

    Click on the MAPPING EDITOR tab and the mapping editor will open.

    Familiarise yourself with the layout as you will spend lots of time here.

    Open the Instrument folder you downloaded and look inside the folder Instrument 1 Samples -
    Inside you will find one NCW file named "Space Flute".
    NCW is a format developed specifically for Kontakt which utilises "Lossless Compression."

    By using samples in this format you can load around 40-50% more samples into RAM. The compressed sample is then decompressed in real time playback i.e when the key is depressed.

    Drag and drop the "Space Flute" sample into the mapping editior on the desired key or location. This normally would correspond to the relevant pitch of the recorded sample.
    For this example I am just going to use C2 as the root note.
    If you press the Key C2 Kontakt will playback the sample for as long as you hold the key down.

    The modulation characteristics can then be set to whatever you like.
    Navigate to the bottom where you will find the relevant controls & a diagram to show the AHDSR controls.
    Hover over the controls with info tab clicked to get a description of what each control represents or affects.
    For this example as it is a PAD Type change the ADSR values as follows

    CURVE = -33
    ATTACK = 0ms
    HOLD = 0ms
    DECAY = 0ms
    SUSTAIN = 0 dB
    RELEASE = 2500 (2.5K) ms


    Default settings can be selected by clicking on the "preset tab" in the left hand corner and selcting a desired profile for the Modulation Curve.
    Once changed, Press the C2 control either via your midi controller or Kontakts keyboard and listen to the difference in playback.
    Now upon releasing the C2 Key it will take 2.5K ms for the envelope to fall from it's sustain level back to zero after the key has been released.

    STEP 4

    EXTEND THE RANGE of the SAMPLE

    An important thing to consider when extending the range of the sample is that when Tracking is selected the playback speed of the sample will change with pitch.

    As we extend the range i.e the higher the range selection the faster the sample will be played back and vice versa.

    SO EXTEND THE range of the sample i.e Drag the left hand edge to C0 and the right hand edge to C7.

    As you do this the yellow range in the mapping editor will increase in size and the corresponding Keys on Kontakts keyboard will turn BLUE by default.

    This now means that upon hitting any key between C0 - C7 Kontakt will playback the sample.
    However as Tracking is selected the playback will be changed with regards to pitch ie C3 will play back the sample 1 octave higher in pitch.
    However as stated earlier the speed of playback will be increased.
    Now we must choose whether we want to LOOP our sample.

    If we open the wave editor (next to mapping editor) we will see a blue section open with a picture of the sample waveform.
    Consult the KSP reference and learn the controls for this section as here we must LOOP our sample so that as long as the Key remains depressed in Kontakt then the sample will Loop and playback will be continuous until the key is released.

    If we hit the play button in the wave editot kontakt will play back the sample and we can note the progress of playback.
    If we then click the continual control next to play Kontakt will then loop the sample.

    We must however define which segment of the wave we wish to loop. This is done by going to the bottom left of the Wave editor and setting sections to Loop within the waveform.
    Hit number 1 and the waveform will turn yellow Move the left hand edge and the right hand edge to define the section of the waveform you wish to loop.
    Hit play and Kontakt will play back the waveform but now will LOOP the selected section so that playback is continual until the key is released. You will find that you will get a clicking noise when the sample loops.

    The best way to get rid of this noise is to hit the loop edit button below loop start. This will then magnify the waveform and it is here you must line up the waveform edges so that no audible clicking
    is noticable upon playback.
    Magnify the waveform by using the +/- symbols on the right hand bottom side of the Wave editor. Once done correctly we will then have a Looped Sample that will playback in a continual fashion in Kontakt until the key is released.

    FOR CONVENIENCE I HAVE LOOPED THE SAMPLE BUT FEEL FREE TO MESS AROUND WITH THE SAMPLE IN THE WAVE EDITOR.

    NOW YOU CAN START WRITING THE SCRIPT!

    Close the Wave editor and the Mapping editor and then open the SCRIPT EDITOR.
    Once opened you will see 5 spaces that all say empty in which you can start writing your script.
    Hit the edit button and the space below will open up into which you can write your script.
    Normally the first thing to consider is the size of the GUI or performance view area.

    This can be set by PIXELS or set by grid size. Refer to KSP MANUAL to see a table with Grid Spacing & values.

    I am going to use Pixels as placement as it allows for more precise placement of controls.

    The FIRST control I am going to create is a Knob that controls MASTER VOLUME & A LABEL to SHOW THE VALUE IN dB.

    ALL scripts start with an initialization command "on init" and finish with the command "end on"

    Between these we place all the necessary code to describe the functions we wish to implement.
    The code will describe what parameters to affect & how we want to go about it.
    Place the following script in the first script slot and hit apply if you are building your own instrument or use the prebuilt one I have made and study the code.
    Remember if building your own in a more up to date version of Kontakt you will need to create a resource container and place in it the necessary text & picture files.

    Code:
    
    on init {Initialisation Command}
    make_perfview {Makes Performance View For Controls}
    set_ui_height_px(319) {Sets the Height of the Performance View by Pixels. Can be written in Grid Units}
    set_script_title("Instrument 1") {Sets the Title of the Script Via Script as opposed to Edit Box}
    set_control_par_str($INST_WALLPAPER_ID,$CONTROL_PAR_PICTURE,"Background") {Sets the Background Image for Perfview again via script rather than Edit Box}
    set_control_par_str($INST_ICON_ID,$CONTROL_PAR_PICTURE,"Icon") {Sets the Logo Graphic Via Script rather than Edit Box}
    message ("") {Clears any messages Displayed by Kontakt}
    {declare constants}
    declare $LABEL_id:=14 {Sets the FONT for all Visible labels, Instead of Font=, Declare $LABEL_id}
    {---MASTER VOLUME---}
    declare ui_slider $volume(0,629959) {Declare a slider as using custom graphics, sets range of slider -inf (0) to 0 dB (629959)}
    set_knob_defval($volume,500000) {Sets the Default value for Volume at 0 dB (500000), Default set in Kontakt by cntrl clicking}
    set_control_par_str(get_ui_id($volume),$CONTROL_PAR_TEXT,"MASTERmim") {Sets instruction for Slider i.e Number of animations etc}
    set_control_par_str(get_ui_id($volume),$CONTROL_PAR_PICTURE,"MASTERmim") {Tells Kontakt which Graphic to use for Slider, looks in Resources Folder, Format PNG or JPEG}
    set_control_par(get_ui_id($volume),$CONTROL_PAR_MOUSE_BEHAVIOUR,-350) {Sets Mouse Behaviour for Knob}
    $volume := get_engine_par($ENGINE_PAR_VOLUME,-1,-1,-1) {Points Kontakt towards Engine Parameter for Knob to affect Numbers declare Group, Index etc}
    move_control_px($Volume,547,12) {Moves Knob by Pixels to desired location. Can use Grid Units}
    make_persistent($volume) {Sets Knob Persistency}
    declare ui_label $MASTERL(1,1) {Declares a label & Label Size}
    move_control_px($MASTERL,531,16) {Moves label by pixels to desired location. Again grid units can be used}
    set_control_par_str(get_ui_id($MASTERL),$CONTROL_PAR_TEXT,"MASTERvol") {Describes Graphic}
    set_control_par_str(get_ui_id($MASTERL),$CONTROL_PAR_PICTURE,"MASTERvol") {Tells Kontakt which Graphic to use}
    set_text($MASTERL,"") {Sets the text displayed on Label}
    declare ui_label $MASTER(1,1) {Declares a label & Label Size}
    move_control_px($MASTER,537,0) {Moves label by pixels to desired location. Again grid units can be used}
    set_text($MASTER,"MASTER VOL") {Sets the text displayed on Label}
    set_control_par(get_ui_id($MASTER),$CONTROL_PAR_FONT_TYPE,$label_id) {Sets Font type of Label. $label_id declared as constant font type 14}
    hide_part($MASTER,$HIDE_PART_BG) {Hides the background of the label}
    {---LABEL DISPLAY TO MASTER VOLUME DB---}
    declare ui_label $volumeval(1,1) {Declares a label & Label Size}
    set_control_par_str(get_ui_id($volumeval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_VOLUME,-1,-1,-1)) {Points Kontakt towards correct value for label to display}
    set_control_par(get_ui_id($volumeval),$CONTROL_PAR_FONT_TYPE,$label_id) {Sets Font type of Label. $label_id declared as constant font type 14}
    move_control_px($volumeval,557,66) {Moves label by pixels to desired location. Again grid units can be used}
    read_persistent_var($volumeval) {Sets label to read persistent}
    make_persistent($volumeval) {makes label persistent}
    hide_part($volumeval,$HIDE_PART_BG) {Hides the background of the label}
    {---SCREEN FOR MASTER VOLUME DB---}
    declare ui_label $SCEEN1(1,1) {Declares a label & Label Size}
    set_control_par_str(get_ui_id($SCEEN1),$CONTROL_PAR_TEXT,"") {Sets the text displayed on Label to Nothing}
    set_control_par_str(get_ui_id($SCEEN1),$CONTROL_PAR_PICTURE,"SCREEN") {Tells Kontakt what graphic to display from resources folder}
    move_control_px($SCEEN1,543,57) {Moves label by pixels to desired location. Again grid units can be used}
    end on
    {---CALBACKS---}
    {---MASTER VOLUME KNOB & LABEL---}
    on ui_control($volume) {Tells kontakt when Knob is moved, initialise the following}
    set_engine_par($ENGINE_PAR_VOLUME,$volume,-1,-1,-1) {Points Kontakt towards engine parameter to affect}
    set_control_par_str(get_ui_id($volumeval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_VOLUME,-1,-1,-1)) {Tells Kontakt what value label should display when knob is moved}
    end on {End Of Script}
    
    After applying the script you should get a GUI or Performance view as shown below. The knob will control the master volume with a range of -inf - 0DB and a default setting of -6dB.

    [​IMG]

    I will stop here as there is enough to digest for the moment.

    Try and make sure you read the KSP and understand it.

    Any parts you don't understand or have trouble with just ask and I will do my best to explain.

    Next time we will insert some more code and functions and continue building the instrument.

    If anyone has any specific ideas or things they would like to include just shout and I will try and incorporate them into the build.

    Hope this helps someone a little and forgive the huge post any mistakes that I will rectify and GOOD LUCK! :wink:
     
    Last edited: Oct 8, 2015
    • Interesting x 7
    • Winner x 4
    • Like x 3
    • Love it! x 2
    • Useful x 2
    • List

    Attached Files:

  2.  
  3. Clandestine

    Clandestine Platinum Record

    Joined:
    Nov 11, 2013
    Messages:
    717
    Likes Received:
    151
    PART 2a - ADSR & declaring controls

    For the second part I thought a good starting place would be to take a basic look at modulating the ADSR
    characteristics of the sample or waveform.

    An ADSR envelope is a component of many synthesizers, samplers, and other electronic musical instruments.
    Its function is to modulate some aspect of the instrument's sound. Often it is the loudness over time.
    The envelope may be a discrete circuit or module in the case of analog devices or implemented as part of the
    unit's software in the case of digital devices.
    If you look in Kontakt at the bottom you will see a section that contains the controls that are used for adjusting the ADSR parameters. It also contains "Curve" and "Hold" controls.
    The ASDR characteristics are especially important and in changing them you can totally re-define or shape the waveform
    to produce the desired sound.
    A synthesizer's ADSR envelope is a way to tailor the timbre for the synth, sometimes to make it sound more like a mechanical instrument.
    A quick attack with little decay helps it sound more like an organ whereas a longer decay and zero sustain makes it sound more like a stringed instrument.
    While envelopes are most often applied to volume, they are also commonly used to control other sound elements, such as filter frequencies
    or oscillator pitches.
    While ADSR envelopes are a useful first approximation to the volumes of real instruments, they are not a complete substitute.
    Woodwind and brass instruments give the player the ability to vary the sound arbitrarily throughout a note.
    Many synthesizers offer more flexible utilities with regards to controlling volume.

    The first thing to consider and have a basic understanding of is what the controls in this section actually do.

    CURVE

    This control adjusts the shape of the attack phase. A value of of zero results in a linear attack curve, negative values
    make the shape more concave and positive values make it more convex.
    The values range from -100 to +100 (units: none). Listen to what effect changing these values has upon the resulting sound.

    ATTACK

    This control adjusts the initial time it will take the envelope to reach it's maximum level after it has been
    triggered (the key is pressed). The values range from 0 to 15.0K (units: ms).
    For most mechanical instruments, this period is virtually instantaneous. However, for some popular synthesized
    voices that don't mimic real instruments, this parameter is slowed down.
    Slow attack is commonly part of sounds called pads.

    HOLD

    On older synthesizers, such as the Korg MS-20, a common variation on the ADSR was ADSHR (attack, decay, sustain, hold, release).
    By adding a "hold" parameter, the system allowed notes to be held at the sustain level for a length of time before decaying.
    The General Instruments AY-3-8912 sound chip included the hold time only and the sustain level was not programmable.
    This control adjusts the (fixed) time the envelope will remain at it's maximum level AFTER it has completed the
    attack phase and before it enters the decay phase. Again the values the range from 0 to 15.0K (units: ms).

    DECAY

    This control adjusts the time it will take the envelope to fall from it's maximum level to the level set by the Sustain
    control. The values range from 0 to 25.0K (units: ms).
    Basically this value defines how quickly the sound drops to the sustain level after the initial peak.

    SUSTAIN

    This control adjusts the level at which the envelope will stay as long as the key is being held,
    after it has completed it's attack, hold and decay phases. The values range from -inf to 0 (units: dB)
    Another way of describing the sustain would be "constant" volume that the sound takes after decay until the note is released.
    An important aspect to consider here is the units of measurement (dB)
    which tell us that this parameter specifies a volume level as opposed to a time period.

    RELEASE

    This control adjusts the time it will take the envelope to fall from it's sustain level back to zero after the
    key has been released. The values range from 0 to 25.0K (units: ms).
    Basically the release defines how quickly the sound fades when a note ends (the key is released).
    Quite often the release time is very short.
    An example where the release is longer could be a piano played with the sustain pedal pressed.
    As opposed to Sustain the units in this case tell us that the Release defines a time period rather than a volume level.
    SO when considering modulating the ADSHR characteristics of a waveform in Kontakt the first thing to consider is which controls
    to actually include in the performance view and how you wish to view & control them.

    An incredibly important thing to consider when defining controls in performance view is that space in this case is finite or
    limited and therefore it is especially important that you learn to fully utilise ALL the space on offer.
    There are several tricks & methodologies to follow in order that you can fully utilise all the space and indeed extend it
    when it comes to controls and displays in performance view.

    The method I will utilise in this part is MOVING to controls.

    In kontakt you can move controls by grid reference or by Pixels.
    As I explained earlier movement by Pixels can allow you too make more precise movements.
    IMPORTANT to remember - A control moved by pixels to the location 0,0 in effect will be HIDDEN. However limitations apply.

    THEREFORE if I declare a knob to control ATTACK -

    Remember as we are use custom graphics we must declare a knob as a slider and define the range.

    Another important aspect to consider here is that to cover the FULL
    range of the knob we should declare to 1000000. This range is standard in Kontakt for engine parameters but it is also especially
    important to remember that some knobs in Kontakt are also EXPONENTIAL in function. This put simply means knob follows an exponential
    function rather than being linear in function.

    A graphical illustration would describe exponential as curved rather than linear (a straight line).

    Command in Kontakt - Knob name, "ATTACK", (range 0, 1000000).

    declare ui_slider $Attack(0,1000000)

    The next step I want to follow is to set the DEFAULT value at which the knob is set. In this case -

    set_knob_defval($Attack,0)

    This sets the default Attack value to 0

    Next I need to define or tell Kontakt what graphic and accompanying text file I want to use for
    this Knob to control. Remember the text file should correctly describe the number of steps (movement) and other
    important characteristics such as Alpha channel components etc (SEE KSP REFERENCE for illustrated examples)
    i.e
    Has Alpha Channel: yes
    Number of Animations: 96
    Horizontal Animation: no
    Vertical Resizable: no
    Horizontal Resizable: no
    Fixed Top: 0
    Fixed Bottom: 0
    Fixed Left: 0
    Fixed Right: 0

    Later we will spend a whole chapter considering how we encode these files & contols into the NKR with regards to
    portability and custom standard formats and encoding in Kontakt

    Example Commands in Kontakt (refer to KSP for more examples) -

    set_control_par_str(get_ui_id($Name),$CONTROL_PAR_TEXT,"Name")

    set_control_par_str(get_ui_id($Name),$CONTROL_PAR_PICTURE,"Name")

    SO to hide the control BY DEFAULT one way would be to move it to 0,0 i.e

    move_control($Attack,0,0)

    make_persistent($Attack) would set knob Persistency.

    Therefore the commands
    Code:
    declare ui_slider $Attack(0,1000000)
    set_knob_defval($Attack,0)
    set_control_par_str(get_ui_id($Attack),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par(get_ui_id($Attack),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    move_control($Attack,0,0)
    make_persistent($Attack)
    read_persistent_var($Attack)
    
    would declare a slider/knob $Attack with specified range/default setting (0) with descriptions of Text/Graphics, place
    the control by default at (0,0 {hidden}) and set Knob persistency and Mouse behaviour (how easily the control can be moved)
    Then later the next logical step would be to MOVE the control with a switch/button or some other control i.e
    Code:
    {---CONTROL HIDES---}
    {---AHDSR---}
    
    declare ui_switch $AHDSR
    set_text($AHDSR,"")
    set_control_par(get_ui_id($AHDSR),$CONTROL_PAR_HEIGHT,20)
    set_control_par(get_ui_id($AHDSR),$CONTROL_PAR_WIDTH,20)
    set_control_par_str(get_ui_id($AHDSR),$CONTROL_PAR_PICTURE,"Name of control")
    move_control_px($AHDSR,557,80)
    hide_part($AHDSR,$HIDE_PART_BG)
    $AHDSR:= 0
    
    This would declare a switch with default state 0 ($AHDSR:= 0), Text set hidden i.e "", Height & width of switch set to
    20 Pixels. Graphic to be used i.e "set_control_par_str(get_ui_id($AHDSR),$CONTROL_PAR_PICTURE,"Name of control")", where the
    control placed by default i.e "move_control_px($AHDSR,557,80)"
    "hide_part($AHDSR,$HIDE_PART_BG)" would hide the background of the switch (See KSP reference).

    Next I NEED the Callback where I then tell Kontakt what to do when the switch $AHDSR is pressed (Mouse Down, State = 1)
    i.e
    Code:
    on ui_control ($AHDSR)
    
    if ($AHDSR=1)
    
    {function AHDSR gui}
    move_control_px($attack,280,70)
    move_control_px($attval,279,116)
    set_control_par_str(get_ui_id($attval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATTACK,$grp_idx,$env_idx,0))
    
    else
    
    if ($AHDSR=0)
    {function AHDSR gui}
    move_control($attack,0,0)
    move_control($attval,0,0)
    
    end if
    end if
    end on
    
    Tells Kontakt when switch $AHDSR is pressed, moves the control for attack & value from hidden 0,0 by pixels to Reference
    (Visible) and then returns them to 0,0 (hidden) when the switch once more value = 0 i.e default state (not active, mouse up or =0)

    SO I CAN NOW EXTEND MY INITIAL SCRIPT to incorporate all the controls that I want to declare and parameters they control.

    SO I take the first script from TUT 01 & extend it as follows -
    Code:
    on init 
    make_perfview 
    set_ui_height_px(319) 
    set_script_title("Instrument 1") 
    set_control_par_str($INST_WALLPAPER_ID,$CONTROL_PAR_PICTURE,"Background") 
    set_control_par_str($INST_ICON_ID,$CONTROL_PAR_PICTURE,"Icon") 
    message ("") 
    
    declare $env_idx
    declare $grp_idx
    declare $labelID:=14
    declare $menuid:=19
    
    {---MASTER VOLUME---}
    
    declare ui_slider $volume(0,629959)
    declare $volume_id
    set_knob_defval($volume,500000)
    $volume_id:= get_ui_id ($volume)
    set_control_par_str(get_ui_id($volume),$CONTROL_PAR_TEXT,"MASTERmim")
    set_control_par_str(get_ui_id($volume),$CONTROL_PAR_PICTURE,"MASTERmim")
    set_control_par(get_ui_id($volume),$CONTROL_PAR_MOUSE_BEHAVIOUR,-350)
    set_control_par_str ($volume_id,$CONTROL_PAR_LABEL,...
    get_engine_par_disp($ENGINE_PAR_VOLUME,-1,-1,-1) & " dB")
    move_control_px($Volume,565,12)
    make_persistent($volume)
    
    declare ui_label $vol_label (1,1)
    set_text ($vol_label,get_engine_par_disp($ENGINE_PAR_VOLUME,-1,-1,-1) & " dB")
    move_control_px($vol_label,570,65)
    set_control_par(get_ui_id($vol_label),$CONTROL_PAR_FONT_TYPE,$labelID)
    hide_part($vol_label,$HIDE_PART_BG)
    
    declare ui_label $MASTERL(1, 1)
    move_control_px($MASTERL,549,16)
    set_control_par_str(get_ui_id($MASTERL),$CONTROL_PAR_TEXT,"MASTERvol")
    set_control_par_str(get_ui_id($MASTERL),$CONTROL_PAR_PICTURE,"MASTERvol")
    set_text($MASTERL,"")
    
    declare ui_label $MASTER(1,1)
    move_control_px($MASTER,553,0)
    set_text($MASTER,"MASTER VOL")
    set_control_par(get_ui_id($MASTER),$CONTROL_PAR_FONT_TYPE,$labelID)
    hide_part($MASTER,$HIDE_PART_BG)
    
    {---SCREEN FOR MASTER VOLUME DB---}
    
    declare ui_label $SCEEN1(1,1) 
    set_control_par_str(get_ui_id($SCEEN1),$CONTROL_PAR_TEXT,"") 
    set_control_par_str(get_ui_id($SCEEN1),$CONTROL_PAR_PICTURE,"SCREEN") 
    move_control_px($SCEEN1,563,57)
    
    {---PRESETS---}
    
    declare ui_label $PreSets(1,1)
    move_control_px($PreSets,410,55)
    set_control_par(get_ui_id($PreSets),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_text($PreSets,"")
    hide_part($PreSets,$HIDE_PART_BG)
    make_persistent($PreSets)
    
    {---MOD PRESET ARRAY---}
    
    declare $MOD_selected
    declare %MOD_preset_array[6*10+1] := (1,0,334000,0,0,1000000,754883,...
                        0,334000,0,0,1000000,718219,...
                        0,334000,0,955880,0,206327,...
                        0,334000,120000,629563,1000000,73333,...
                         579469,334000,0,489223,1000000,699219,...
                        745117,334000,0,0,1000000,805783,...
                        0,334000,268555,775305,0,610817,...
                        200787,334000,696711,658988,793701,537564,...
                        607493,334000,541992,865234,833333,731445,...
                        742188,280237, 0, 540285, 963867, 778320)
    
    declare ui_menu $MOD_presets
    
    add_menu_item($MOD_presets,"Default",1)
    add_menu_item($MOD_presets,"Long Release",2)
    add_menu_item($MOD_presets,"Clavinet",3)
    add_menu_item($MOD_presets,"Organ",4)
    add_menu_item($MOD_presets,"Pad",5)
    add_menu_item($MOD_presets,"Space",6)
    add_menu_item($MOD_presets,"Decay",7)
    add_menu_item($MOD_presets,"Dry",8)
    add_menu_item($MOD_presets,"Strings",9)
    add_menu_item($MOD_presets,"Alone",10)
    
    set_control_par_str(get_ui_id($MOD_presets),$CONTROL_PAR_PICTURE,"Drop1")
    set_control_par(get_ui_id($MOD_presets),$CONTROL_PAR_FONT_TYPE,$labelID)
    move_control($MOD_presets,0,0)
    make_persistent($MOD_presets)
    
    {---CONTROL HIDES---}
    {---AHDSR---}
    
    declare ui_switch $AHDSR
    set_text($AHDSR,"")
    set_control_par(get_ui_id($AHDSR),$CONTROL_PAR_HEIGHT,20)
    set_control_par(get_ui_id($AHDSR),$CONTROL_PAR_WIDTH,20)
    set_control_par_str(get_ui_id($AHDSR),$CONTROL_PAR_PICTURE,"tinyswitch2")
    move_control_px($AHDSR,557,85)
    hide_part($AHDSR,$HIDE_PART_BG)
    $AHDSR:= 0
    
    declare ui_label $AHDSRback(1,1)
    move_control_px($AHDSRback,553,89)
    set_text($AHDSRback,"")
    set_control_par_str(get_ui_id($AHDSRback),$CONTROL_PAR_PICTURE,"labbutton")
    
    declare ui_label $AHDSRlbl(1,1)
    set_text($AHDSRlbl,"          AHDSR")
    hide_part($AHDSRlbl,$HIDE_PART_BG)
    set_control_par(get_ui_id($AHDSRlbl),$CONTROL_PAR_FONT_TYPE,$labelID)
    move_control_px($AHDSRlbl,553,88)
    make_persistent($AHDSRlbl)
    
    {---MODULATION CONTROLS---}
    
    declare ui_slider $Attack(0,1000000)
    set_knob_defval($Attack,0)
    set_control_par_str(get_ui_id($Attack),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par(get_ui_id($Attack),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    move_control($Attack,0,0)
    make_persistent($Attack)
    read_persistent_var($Attack)
    
    declare ui_label $attname(1, 1)
    move_control_px($attname,278,55)
    set_control_par(get_ui_id($attname),$CONTROL_PAR_FONT_TYPE,$labelID)
    hide_part($attname,$HIDE_PART_BG)
    set_text($attname,"")
    
    declare ui_label $screen6(1, 1)
    set_control_par_str(get_ui_id($screen6),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen6),$CONTROL_PAR_PICTURE,"screen")
    move_control($screen6,0,0)
    set_text($screen6,"")
    
    declare ui_label $attval(1, 1)
    move_control($attval,0,0)
    set_control_par_str(get_ui_id($attval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATTACK,$grp_idx,$env_idx,0))
    set_control_par(get_ui_id($attval),$CONTROL_PAR_FONT_TYPE,$labelID)
    hide_part($attval,$HIDE_PART_BG)
    set_text($attval,"")
    make_persistent($attval)
    read_persistent_var($attval)
    
    declare ui_slider $MODCurve(0, 1000000)
    set_knob_defval($MODCurve,334000)
    set_control_par_str(get_ui_id($MODCurve),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par(get_ui_id($MODCurve),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    move_control($MODCurve,0,0)
    make_persistent($MODCurve)
    read_persistent_var($MODCurve)
    
    declare ui_label $screen7(1, 1)
    set_control_par_str(get_ui_id($screen7),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen7),$CONTROL_PAR_PICTURE,"screen")
    move_control($screen7,0,0)
    set_text($screen7,"")
    
    declare ui_label $curval(1, 1)
    move_control($curval,0,0)
    set_control_par_str(get_ui_id($curval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATK_CURVE,$grp_idx,$env_idx,0))
    set_control_par(get_ui_id($curval),$CONTROL_PAR_FONT_TYPE,$labelID)
    hide_part($curval,$HIDE_PART_BG)
    set_text($curval,"")
    make_persistent($curval)
    read_persistent_var($curval)
    
    declare ui_label $curname(1, 1)
    move_control_px($curname,208,55)
    set_control_par(get_ui_id($curname),$CONTROL_PAR_FONT_TYPE,$labelID)
    hide_part($curname,$HIDE_PART_BG)
    set_text($curname,"")
    
    declare ui_slider $Hold(0,1000000)
    set_knob_defval($Hold,0)
    set_control_par_str(get_ui_id($Hold),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par(get_ui_id($Hold),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    move_control($Hold,0,0)
    make_persistent($Hold)
    read_persistent_var($Hold)
    
    declare ui_label $holdname(1, 1)
    move_control_px($holdname,350,55)
    set_control_par(get_ui_id($holdname),$CONTROL_PAR_FONT_TYPE,$labelID)
    hide_part($holdname,$HIDE_PART_BG)
    set_text($holdname,"")
    declare ui_label $screen8(1, 1)
    set_control_par_str(get_ui_id($screen8),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen8),$CONTROL_PAR_PICTURE,"screen")
    move_control($screen8,0,0)
    set_text($screen8,"")
    
    declare ui_label $holdval(1, 1)
    move_control($holdval,0,0)
    set_control_par_str(get_ui_id($holdval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_HOLD,$grp_idx,$env_idx,0))
    set_control_par(get_ui_id($holdval),$CONTROL_PAR_FONT_TYPE,$labelID)
    hide_part($holdval,$HIDE_PART_BG)
    set_text($holdval,"")
    make_persistent($holdval)
    read_persistent_var($holdval)
    
    declare ui_slider $Decay(0,1000000)
    set_knob_defval($Decay,0)
    set_control_par_str(get_ui_id($Decay),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par(get_ui_id($Decay),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    move_control($Decay,0,0)
    make_persistent($Decay)
    read_persistent_var($Decay)
    
    declare ui_label $decname(1, 1)
    move_control_px($decname,208,155)
    set_control_par(get_ui_id($decname),$CONTROL_PAR_FONT_TYPE,$labelID)
    hide_part($decname,$HIDE_PART_BG)
    set_text($decname,"")
    
    declare ui_label $screen9(1, 1)
    set_control_par_str(get_ui_id($screen9),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen9),$CONTROL_PAR_PICTURE,"screen")
    move_control($screen9,0,0)
    set_text($screen9,"")
    
    declare ui_label $decval(1, 1)
    move_control($decval,0,0)
    set_control_par_str(get_ui_id($decval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_DECAY,$grp_idx,$env_idx,0))
    set_control_par(get_ui_id($decval),$CONTROL_PAR_FONT_TYPE,$labelID)
    hide_part($decval,$HIDE_PART_BG)
    set_text($decval,"")
    make_persistent($decval)
    read_persistent_var($decval)
    
    declare ui_slider $Sustain(0,1000000)
    set_knob_defval($Sustain,1000000)
    set_control_par_str(get_ui_id($Sustain),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par(get_ui_id($Sustain),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    move_control($Sustain,0,0)
    make_persistent($Sustain)
    read_persistent_var($Sustain)
    
    declare ui_label $susname(1,1)
    move_control_px($susname,275,155)
    set_control_par(get_ui_id($susname),$CONTROL_PAR_FONT_TYPE,$labelID)
    hide_part($susname,$HIDE_PART_BG)
    set_text($susname,"")
    
    declare ui_label $screen10(1,1)
    set_control_par_str(get_ui_id($screen10),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen10),$CONTROL_PAR_PICTURE,"screen")
    move_control($screen10,0,0)
    set_text($screen10,"")
    
    declare ui_label $sustval(1, 1)
    move_control($sustval,0,0)
    set_control_par_str(get_ui_id($sustval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_SUSTAIN,$grp_idx,$env_idx,0))
    set_control_par(get_ui_id($sustval),$CONTROL_PAR_FONT_TYPE,$labelID)
    hide_part($sustval,$HIDE_PART_BG)
    set_text($sustval,"")
    make_persistent($sustval)
    read_persistent_var($sustval)
    
    declare ui_slider $Release(0,1000000)
    set_knob_defval($Release,754883)
    set_control_par_str(get_ui_id($Release),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par(get_ui_id($Release),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    move_control($Release,0,0)
    make_persistent($Release)
    read_persistent_var($Release)
    
    declare ui_label $relname(1, 1)
    move_control_px($relname,345,155)
    set_control_par(get_ui_id($relname),$CONTROL_PAR_FONT_TYPE,$labelID)
    hide_part($relname,$HIDE_PART_BG)
    set_text($relname,"")
    declare ui_label $screen11(1, 1)
    set_control_par_str(get_ui_id($screen11),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen11),$CONTROL_PAR_PICTURE,"screen")
    move_control($screen11,0,0)
    set_text($screen11,"")
    
    declare ui_label $relval(1, 1)
    move_control($relval,0,0)
    set_control_par_str(get_ui_id($relval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_RELEASE,$grp_idx,$env_idx,0))
    set_control_par(get_ui_id($relval),$CONTROL_PAR_FONT_TYPE,$labelID)
    hide_part($relval,$HIDE_PART_BG)
    set_text($relval,"")
    make_persistent($relval)
    read_persistent_var($relval)
    
    end on
    on ui_control ($AHDSR)
    
    if ($AHDSR=1)
    
    {function AHDSR gui}
    move_control_px($MODCurve,205,70)
    move_control_px($attack,275,70)
    move_control_px($hold,345,70)
    move_control_px($decay,205,170)
    move_control_px($sustain,275,170)
    move_control_px($release,345,170)
    move_control_px($MOD_presets,400,70)
    move_control_px($curval,211,126)
    move_control_px($attval,277,126)
    move_control_px($holdval,345,126)
    move_control_px($decval,206,226)
    move_control_px($sustval,281,226)
    move_control_px($relval,345,226)
    move_control_px($screen6,196,118)
    move_control_px($screen7,266,118)
    move_control_px($screen8,336,118)
    move_control_px($screen9,196,218)
    move_control_px($screen10,266,218)
    move_control_px($screen11,336,218)
    set_control_par_str(get_ui_id($attval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATTACK,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($curval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATK_CURVE,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($holdval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_HOLD,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($decval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_DECAY,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($sustval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_SUSTAIN,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($relval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_RELEASE,$grp_idx,$env_idx,0))
    set_text($PreSets,"PRESETS")
    set_text($curname,"Curve")
    set_text($attname,"Attack")
    set_text($holdname,"Hold")
    set_text($decname,"Decay")
    set_text($susname,"Sustain")
    set_text($relname,"Release")
    
    else
    
    if ($AHDSR=0)
    {function AHDSR gui}
    move_control($MODCurve,0,0)
    move_control($attack,0,0)
    move_control($hold,0,0)
    move_control($decay,0,0)
    move_control($sustain,0,0)
    move_control($release,0,0)
    set_text($PreSets,"")
    move_control($MOD_presets,0,0)
    move_control($attval,0,0)
    move_control($curval,0,0)
    move_control($holdval,0,0)
    move_control($decval,0,0)
    move_control($sustval,0,0)
    move_control($relval,0,0)
    move_control($screen6,0,0)
    move_control($screen7,0,0)
    move_control($screen8,0,0)
    move_control($screen9,0,0)
    move_control($screen10,0,0)
    move_control($screen11,0,0)
    set_text($curname,"")
    set_text($attname,"")
    set_text($holdname,"")
    set_text($decname,"")
    set_text($susname,"")
    set_text($relname,"")
    
    end if
    end if
    
    end on
    
    {---MODULATION PRESET ARRAY---}
    
    on ui_control($MOD_presets)
    $MOD_selected := get_control_par(get_ui_id($MOD_presets),$CONTROL_PAR_SELECTED_ITEM_IDX)+1
    set_engine_par($ENGINE_PAR_ATTACK,%MOD_preset_array[1 +(6*($MOD_selected-1))],0,$env_idx,0)
    set_engine_par($ENGINE_PAR_ATK_CURVE,%MOD_preset_array[2 +(6*($MOD_selected-1))],0,$env_idx,0)
    set_engine_par($ENGINE_PAR_HOLD,%MOD_preset_array[3 +(6*($MOD_selected-1))],0,$env_idx,0)
    set_engine_par($ENGINE_PAR_DECAY,%MOD_preset_array[4 +(6*($MOD_selected-1))],0,$env_idx,0)
    set_engine_par($ENGINE_PAR_SUSTAIN,%MOD_preset_array[5 +(6*($MOD_selected-1))],0,$env_idx,0)
    set_engine_par($ENGINE_PAR_RELEASE,%MOD_preset_array[6 +(6*($MOD_selected-1))],0,$env_idx,0)
    
    $Attack := get_engine_par($ENGINE_PAR_ATTACK,0,0,0)
    $MODCurve := get_engine_par($ENGINE_PAR_ATK_CURVE,0,0,0)
    $Hold := get_engine_par($ENGINE_PAR_HOLD,0,0,0)
    $Decay := get_engine_par($ENGINE_PAR_DECAY,0,0,0)
    $Sustain := get_engine_par($ENGINE_PAR_SUSTAIN,0,0,0)
    $Release := get_engine_par($ENGINE_PAR_RELEASE,0,0,0)
    
    set_control_par_str(get_ui_id($attval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATTACK,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($curval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATK_CURVE,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($holdval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_HOLD,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($decval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_DECAY,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($sustval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_SUSTAIN,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($relval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_RELEASE,$grp_idx,$env_idx,0))
    end on
    
    {---MODULATION CONTROLS---}
    
    on ui_control($Attack)
    set_engine_par($ENGINE_PAR_ATTACK,$Attack,0,$env_idx,0)
    set_control_par_str(get_ui_id($attval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATTACK,$grp_idx,$env_idx,0))
    end on
    
    on ui_control($MODCurve)
    set_engine_par($ENGINE_PAR_ATK_CURVE,$MODCurve,0,$env_idx,0)
    set_control_par_str(get_ui_id($curval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATK_CURVE,$grp_idx,$env_idx,0))
    end on
    
    on ui_control($Hold)
    set_engine_par($ENGINE_PAR_HOLD,$Hold,0,$env_idx,0)
    set_control_par_str(get_ui_id($holdval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_HOLD,$grp_idx,$env_idx,0))
    end on
    
    on ui_control($Decay)
    set_engine_par($ENGINE_PAR_DECAY,$Decay,0,$env_idx,0)
    set_control_par_str(get_ui_id($decval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_DECAY,$grp_idx,$env_idx,0))
    end on
    
    on ui_control($Sustain)
    set_engine_par($ENGINE_PAR_SUSTAIN,$Sustain,0,$env_idx,0)
    set_control_par_str(get_ui_id($sustval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_SUSTAIN,$grp_idx,$env_idx,0))
    end on
    
    on ui_control($Release)
    set_engine_par($ENGINE_PAR_RELEASE,$Release,0,$env_idx,0)
    set_control_par_str(get_ui_id($relval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_RELEASE,$grp_idx,$env_idx,0))
    end on
    
    {---MASTER VOLUME CALLBACKS---}
    
    on ui_control($volume)
    set_engine_par($ENGINE_PAR_VOLUME,$volume,-1,-1,-1)
    set_control_par_str ($volume_id,$CONTROL_PAR_LABEL,...
    get_engine_par_disp($ENGINE_PAR_VOLUME,-1,-1,-1) & " dB")
    set_text ($vol_label,get_engine_par_disp($ENGINE_PAR_VOLUME,-1,-1,-1) & " dB")
    end on
    
    {------------------}
    
    Make sure to read the script and follow -

    In this script I have used an ARRAY to describe the values for the controls which
    I can then control with a menu. Put simply I declare a menu whose entries set the values for the controls I want to affect.
    Rather than make this one chapter too long I will end it here and in the next part 2b we will look at how we can use ARRAYS
    & menus to affect controls. The important thing to take from this tutorial is how we now have declared a switch that when
    pressed moves the controls for modulating the waveform from 0,0 (hidden) to visible and back to hidden.
    Another important aspect to remember is that here we are only changing the parameters of 1 GROUP rather than SEVERAL GROUPS.

    We will look at this in part 2b in more detail.

    Again remember that if backwards compatibility an issue it is not a problem as simply ise the script in your version and copy
    the controls to your resource folder and apply. There should be no problems and in fact it will actually be a good way of
    learning how to apply a script and also understand the nature and
    set-up of the resource folder.

    Please forgive any mistakes which I will rectify as soon as they are realised.

    Good luck! :yes:
     
    Last edited: Oct 8, 2015
    • Like x 7
    • Love it! x 2
    • Useful x 2
    • Winner x 1
    • Interesting x 1
    • List

    Attached Files:

  4. Zenarcist

    Zenarcist Audiosexual

    Joined:
    Jan 1, 2012
    Messages:
    3,915
    Likes Received:
    2,500
    Location:
    Planet Earth
    Very interesting, thanks for taking the trouble to do this :wink:
     
    Last edited: Aug 12, 2015
  5. fiction

    fiction Audiosexual

    Joined:
    Jun 21, 2011
    Messages:
    1,889
    Likes Received:
    687
    Fantastic! Thanks a lot!
     
  6. Olymoon

    Olymoon MODERATOR Staff Member

    Joined:
    Jan 31, 2012
    Messages:
    5,813
    Likes Received:
    4,459
    Ohhhh really fantastic, thank you !!!!
     
  7. Clandestine

    Clandestine Platinum Record

    Joined:
    Nov 11, 2013
    Messages:
    717
    Likes Received:
    151
    Tutorial 03 - Script Revision & Declaring VELOCITY controls


    BE AWARE this instrument encoded with latest version of Kontakt so if Backward compatibility an issue just use the resources from this package and simply build in your own version of Kontakt.
    Should work without any problems :yes:

    For the start of this tutorial I have decided to revise the script I wrote in tutorial 02.
    The script works fine and there are no problems but if you study it the LOGICAL numbering doesn't make sense and a few other names don't.

    Of course they don't have too but for demonstrative purposes it is possibly better to have them in a more ordered fashion.

    Also an important part of writing scripts is that you develop your OWN style.
    As long as you are aware of what is what and where the commands are declared that is all that matters.
    However as you become more familiar with writing scripts it will become easier to say declare ALL your GUI controls at once in a logical ordered fashion. As with everything, more practise usually pays dividends.
    The script below does exactly the same job as the one in Tutorial 02 except that it is written in a different fashion.

    See what discernable differences you can make out and familiarise yourself with the commands.
    As long as you stick to the same basic principles there should be no problems you cannot overcome.
    Code:
    on init 
    make_perfview 
    set_ui_height_px(319) 
    set_script_title("Instrument 1") 
    set_control_par_str($INST_WALLPAPER_ID,$CONTROL_PAR_PICTURE,"Background") 
    set_control_par_str($INST_ICON_ID,$CONTROL_PAR_PICTURE,"Icon") 
    message ("")
    {DECLARE CONSTANTS}
    declare $env_idx
    declare $grp_idx
    declare $labelID
    declare $menuid
    declare $volume_id
    $labelID:=14
    {---MOD PRESET ARRAY---}
    declare $MOD_selected
    declare %MOD_preset_array[6*10+1]:=(1,0,334000,0,0,1000000,754883,...
                        0,334000,0,0,1000000,718219,...
                        0,334000,0,955880,0,206327,...
                        0,334000,120000,629563,1000000,73333,...
                         579469,334000,0,489223,1000000,699219,...
                        745117,334000,0,0,1000000,805783,...
                        0,334000,268555,775305,0,610817,...
                        200787,334000,696711,658988,793701,537564,...
                        607493,334000,541992,865234,833333,731445,...
                        742188,280237, 0, 540285, 963867, 778320)
    declare ui_menu $MOD_presets
    add_menu_item($MOD_presets,"Default",1)
    add_menu_item($MOD_presets,"Long Release",2)
    add_menu_item($MOD_presets,"Clavinet",3)
    add_menu_item($MOD_presets,"Organ",4)
    add_menu_item($MOD_presets,"Pad",5)
    add_menu_item($MOD_presets,"Space",6)
    add_menu_item($MOD_presets,"Decay",7)
    add_menu_item($MOD_presets,"Dry",8)
    add_menu_item($MOD_presets,"Strings",9)
    add_menu_item($MOD_presets,"Alone",10)
    set_control_par_str(get_ui_id($MOD_presets),$CONTROL_PAR_PICTURE,"Drop1")
    set_control_par(get_ui_id($MOD_presets),$CONTROL_PAR_FONT_TYPE,$labelID)
    move_control($MOD_presets,0,0)
    make_persistent($MOD_presets)
    {DECLARE CONTROLS}
    {---MASTER VOL---}
    declare ui_slider $volume(0,629959)
    declare ui_switch $AHDSR
    declare ui_label $AHDSRlbl(1,1)
    {---MODULATION CONTROLS---}
    declare ui_slider $MODCurve(0,1000000)
    declare ui_slider $Attack(0,1000000)
    declare ui_slider $Hold(0,1000000)
    declare ui_slider $Decay(0,1000000)
    declare ui_slider $Sustain(0,1000000)
    declare ui_slider $Release(0,1000000)
    {---CONTROL LABELS---}
    declare ui_label $vol_label(1,1)
    declare ui_label $MASTERL(1,1)
    declare ui_label $MASTER(1,1)
    declare ui_label $curname(1,1)
    declare ui_label $curval(1,1)
    declare ui_label $attname(1,1)
    declare ui_label $attval(1,1)
    declare ui_label $holdname(1,1)
    declare ui_label $holdval(1,1)
    declare ui_label $decname(1,1)
    declare ui_label $decval(1,1)
    declare ui_label $susname(1,1)
    declare ui_label $sustval(1,1)
    declare ui_label $relname(1,1)
    declare ui_label $relval(1,1)
    {---SCREENS---}
    declare ui_label $SCREEN1(1,1)
    declare ui_label $screen2(1,1)
    declare ui_label $screen3(1,1)
    declare ui_label $screen4(1,1)
    declare ui_label $screen5(1,1)
    declare ui_label $screen6(1,1)
    declare ui_label $screen7(1,1)
    {---PRESET MENU---}
    declare ui_label $PreSets(1,1)
    declare ui_label $AHDSRback(1,1)
    {---CONTROL ID---}
    $volume_id:= get_ui_id($volume)
    set_control_par_str(get_ui_id($volume),$CONTROL_PAR_TEXT,"MASTERmim")
    set_control_par_str(get_ui_id($volume),$CONTROL_PAR_PICTURE,"MASTERmim")
    set_text ($vol_label,get_engine_par_disp($ENGINE_PAR_VOLUME,-1,-1,-1) & " dB")
    {---AHDSR---}
    set_control_par_str(get_ui_id($AHDSR),$CONTROL_PAR_PICTURE,"tinyswitch2")
    set_control_par_str(get_ui_id($AHDSRback),$CONTROL_PAR_PICTURE,"labbutton")
    set_control_par_str(get_ui_id($MODCurve),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par_str(get_ui_id($Attack),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par_str(get_ui_id($Hold),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par_str(get_ui_id($Decay),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par_str(get_ui_id($Sustain),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par_str(get_ui_id($Release),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par(get_ui_id($AHDSR),$CONTROL_PAR_HEIGHT,20)
    set_control_par(get_ui_id($AHDSR),$CONTROL_PAR_WIDTH,20)
    {---LABEL ID---}
    set_control_par(get_ui_id($vol_label),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($MASTER),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($PreSets),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($AHDSRlbl),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($curname),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($attname),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($holdname),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($decname),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($susname),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($relname),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($curval),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($attval),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($decval),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($holdval),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($sustval),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($relval),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par_str(get_ui_id($curval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATK_CURVE,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($attval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATTACK,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($holdval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_HOLD,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($decval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_DECAY,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($sustval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_SUSTAIN,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($relval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_RELEASE,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($MASTERL),$CONTROL_PAR_TEXT,"MASTERvol")
    set_control_par_str(get_ui_id($SCREEN1),$CONTROL_PAR_TEXT,"")
    set_control_par_str(get_ui_id($screen2),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen3),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen4),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen5),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen6),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen7),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($MASTERL),$CONTROL_PAR_PICTURE,"MASTERvol")
    set_control_par_str(get_ui_id($SCREEN1),$CONTROL_PAR_PICTURE,"SCREEN")
    set_control_par_str(get_ui_id($screen2),$CONTROL_PAR_PICTURE,"screen")
    set_control_par_str(get_ui_id($screen3),$CONTROL_PAR_PICTURE,"screen")
    set_control_par_str(get_ui_id($screen4),$CONTROL_PAR_PICTURE,"screen")
    set_control_par_str(get_ui_id($screen5),$CONTROL_PAR_PICTURE,"screen")
    set_control_par_str(get_ui_id($screen6),$CONTROL_PAR_PICTURE,"screen")
    set_control_par_str(get_ui_id($screen7),$CONTROL_PAR_PICTURE,"screen")
    {---TEXT ID---}
    set_text($MASTERL,"")
    set_text($PreSets,"")
    set_text($AHDSR,"")
    set_text($AHDSRback,"")
    set_text($AHDSRlbl,"          AHDSR")
    set_text($MASTER,"MASTER VOL")
    set_text($PreSets,"")
    set_text($AHDSRback,"")
    set_text($curname,"")
    set_text($attname,"")
    set_text($holdname,"")
    set_text($decname,"")
    set_text($relname,"")
    set_text($susname,"")
    set_text($curval,"")
    set_text($attval,"")
    set_text($holdval,"")
    set_text($decval,"")
    set_text($relval,"")
    set_text($sustval,"")
    set_text($screen2,"")
    set_text($screen3,"")
    set_text($screen4,"")
    set_text($screen5,"")
    set_text($screen6,"")
    set_text($screen7,"")
    {---HIDE BG---}
    hide_part($vol_label,$HIDE_PART_BG)
    hide_part($MASTER,$HIDE_PART_BG)
    hide_part($AHDSRlbl,$HIDE_PART_BG)
    hide_part($PreSets,$HIDE_PART_BG)
    hide_part($AHDSR,$HIDE_PART_BG)
    hide_part($AHDSRlbl,$HIDE_PART_BG)
    hide_part($curname,$HIDE_PART_BG)
    hide_part($attname,$HIDE_PART_BG)
    hide_part($holdname,$HIDE_PART_BG)
    hide_part($decname,$HIDE_PART_BG)
    hide_part($susname,$HIDE_PART_BG)
    hide_part($relname,$HIDE_PART_BG)
    hide_part($curval,$HIDE_PART_BG)
    hide_part($attval,$HIDE_PART_BG)
    hide_part($holdval,$HIDE_PART_BG)
    hide_part($decval,$HIDE_PART_BG)
    hide_part($sustval,$HIDE_PART_BG)
    hide_part($relval,$HIDE_PART_BG)
    {---MOUSE BEHAVIOUR---}
    set_control_par(get_ui_id($MODCurve),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    set_control_par(get_ui_id($Attack),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    set_control_par(get_ui_id($Hold),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    set_control_par(get_ui_id($Decay),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    set_control_par(get_ui_id($Sustain),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    set_control_par(get_ui_id($Release),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    {---MOVE CONTROLS---}
    move_control_px($AHDSR,557,85)
    move_control_px($AHDSRback,553,89)
    move_control_px($AHDSRlbl,553,88)
    move_control_px($Volume,565,12)
    move_control_px($vol_label,570,65)
    move_control_px($MASTERL,549,16)
    move_control_px($MASTER,553,0)
    move_control_px($PreSets,410,55)
    move_control($MODCurve,0,0)
    move_control($Attack,0,0)
    move_control($Hold,0,0)
    move_control($Decay,0,0)
    move_control($Sustain,0,0)
    move_control($Release,0,0)
    move_control_px($curname,208,55)
    move_control_px($attname,278,55)
    move_control_px($holdname,350,55)
    move_control_px($decname,208,155)
    move_control_px($susname,275,155)
    move_control_px($relname,345,155)
    move_control($curval,0,0)
    move_control($attval,0,0)
    move_control($holdval,0,0)
    move_control($decval,0,0)
    move_control($sustval,0,0)
    move_control($relval,0,0)
    move_control_px($SCREEN1,563,57)
    move_control($screen2,0,0)
    move_control($screen3,0,0)
    move_control($screen4,0,0)
    move_control($screen5,0,0)
    move_control($screen6,0,0)
    move_control($screen7,0,0)
    {---SET DEFAULTS---}
    $AHDSR:= 0
    set_knob_defval($volume,500000)
    set_knob_defval($MODCurve,334000)
    set_knob_defval($Attack,0)
    set_knob_defval($Hold,0)
    set_knob_defval($Decay,0)
    set_knob_defval($Sustain,1000000)
    set_knob_defval($Release,754883)
    {---MAKE PERSISTENT---}
    make_persistent($volume)
    make_persistent($PreSets)
    make_persistent($AHDSRlbl)
    make_persistent($MODCurve)
    make_persistent($Attack)
    make_persistent($Hold)
    make_persistent($Decay)
    make_persistent($Sustain)
    make_persistent($Release)
    make_persistent($curval)
    make_persistent($attval)
    make_persistent($holdval)
    make_persistent($decval)
    make_persistent($sustval)
    make_persistent($relval)
    {---READ PERSISTENT---}
    read_persistent_var($MODCurve)
    read_persistent_var($Attack)
    read_persistent_var($Hold)
    read_persistent_var($Decay)
    read_persistent_var($Sustain)
    read_persistent_var($Release)
    read_persistent_var($curval)
    read_persistent_var($attval)
    read_persistent_var($holdval)
    read_persistent_var($decval)
    read_persistent_var($sustval)
    read_persistent_var($relval)
    end on
    
    {---MODULATION PRESET ARRAY---}
    on ui_control($MOD_presets)
    
    $MOD_selected := get_control_par(get_ui_id($MOD_presets),$CONTROL_PAR_SELECTED_ITEM_IDX)+1
        set_engine_par($ENGINE_PAR_ATTACK,%MOD_preset_array[1 +(6*($MOD_selected-1))],0,$env_idx,0)
        set_engine_par($ENGINE_PAR_ATK_CURVE,%MOD_preset_array[2 +(6*($MOD_selected-1))],0,$env_idx,0)
        set_engine_par($ENGINE_PAR_HOLD,%MOD_preset_array[3 +(6*($MOD_selected-1))],0,$env_idx,0)
        set_engine_par($ENGINE_PAR_DECAY,%MOD_preset_array[4 +(6*($MOD_selected-1))],0,$env_idx,0)
        set_engine_par($ENGINE_PAR_SUSTAIN,%MOD_preset_array[5 +(6*($MOD_selected-1))],0,$env_idx,0)
        set_engine_par($ENGINE_PAR_RELEASE,%MOD_preset_array[6 +(6*($MOD_selected-1))],0,$env_idx,0)
    
    $Attack := get_engine_par($ENGINE_PAR_ATTACK,0,0,0)
    $MODCurve := get_engine_par($ENGINE_PAR_ATK_CURVE,0,0,0)
    $Hold := get_engine_par($ENGINE_PAR_HOLD,0,0,0)
    $Decay := get_engine_par($ENGINE_PAR_DECAY,0,0,0)
    $Sustain := get_engine_par($ENGINE_PAR_SUSTAIN,0,0,0)
    $Release := get_engine_par($ENGINE_PAR_RELEASE,0,0,0)
    
        set_control_par_str(get_ui_id($attval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATTACK,$grp_idx,$env_idx,0))
        set_control_par_str(get_ui_id($curval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATK_CURVE,$grp_idx,$env_idx,0))
        set_control_par_str(get_ui_id($holdval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_HOLD,$grp_idx,$env_idx,0))
        set_control_par_str(get_ui_id($decval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_DECAY,$grp_idx,$env_idx,0))
        set_control_par_str(get_ui_id($sustval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_SUSTAIN,$grp_idx,$env_idx,0))
        set_control_par_str(get_ui_id($relval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_RELEASE,$grp_idx,$env_idx,0))
    end on
    
    {---MASTER VOLUME CALLBACKS---}
    
    on ui_control($volume)
    
        set_engine_par($ENGINE_PAR_VOLUME,$volume,-1,-1,-1)
        set_control_par_str ($volume_id,$CONTROL_PAR_LABEL,...
        get_engine_par_disp($ENGINE_PAR_VOLUME,-1,-1,-1) & " dB")
        set_text ($vol_label,get_engine_par_disp($ENGINE_PAR_VOLUME,-1,-1,-1) & " dB")
    
    end on
    
    on ui_control ($AHDSR)
    
        if ($AHDSR=1)
    
    {function AHDSR gui}
    
        move_control_px($MODCurve,205,70)
        move_control_px($attack,275,70)
        move_control_px($hold,345,70)
        move_control_px($decay,205,170)
        move_control_px($sustain,275,170)
        move_control_px($release,345,170)
        move_control_px($MOD_presets,400,70)
        move_control_px($curval,211,126)
        move_control_px($attval,277,126)
        move_control_px($holdval,345,126)
        move_control_px($decval,206,226)
        move_control_px($sustval,281,226)
        move_control_px($relval,345,226)
        move_control_px($screen2,196,118)
        move_control_px($screen3,266,118)
        move_control_px($screen4,336,118)
        move_control_px($screen5,196,218)
        move_control_px($screen6,266,218)
        move_control_px($screen7,336,218)
    
        set_control_par_str(get_ui_id($attval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATTACK,$grp_idx,$env_idx,0))
        set_control_par_str(get_ui_id($curval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATK_CURVE,$grp_idx,$env_idx,0))
        set_control_par_str(get_ui_id($holdval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_HOLD,$grp_idx,$env_idx,0))
        set_control_par_str(get_ui_id($decval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_DECAY,$grp_idx,$env_idx,0))
        set_control_par_str(get_ui_id($sustval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_SUSTAIN,$grp_idx,$env_idx,0))
        set_control_par_str(get_ui_id($relval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_RELEASE,$grp_idx,$env_idx,0))
    
            set_text($PreSets,"PRESETS")
            set_text($curname,"Curve")
            set_text($attname,"Attack")
            set_text($holdname,"Hold")
            set_text($decname,"Decay")
            set_text($susname,"Sustain")
            set_text($relname,"Release")
    else
    if ($AHDSR=0)
    
    {function AHDSR gui}
    
        move_control($MODCurve,0,0)
        move_control($attack,0,0)
        move_control($hold,0,0)
        move_control($decay,0,0)
        move_control($sustain,0,0)
        move_control($release,0,0)
        move_control($MOD_presets,0,0)
        move_control($attval,0,0)
        move_control($curval,0,0)
        move_control($holdval,0,0)
        move_control($decval,0,0)
        move_control($sustval,0,0)
        move_control($relval,0,0)
        move_control($screen2,0,0)
        move_control($screen3,0,0)
        move_control($screen4,0,0)
        move_control($screen5,0,0)
        move_control($screen6,0,0)
        move_control($screen7,0,0)
            set_text($PreSets,"")
            set_text($curname,"")
            set_text($attname,"")
            set_text($holdname,"")
            set_text($decname,"")
            set_text($susname,"")
            set_text($relname,"")
            end if
        end if
    end on
    {---MODULATION CONTROLS---}
    on ui_control($Attack)
        set_engine_par($ENGINE_PAR_ATTACK,$Attack,0,$env_idx,0)
        set_control_par_str(get_ui_id($attval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATTACK,$grp_idx,$env_idx,0))
    end on
    on ui_control($MODCurve)
        set_engine_par($ENGINE_PAR_ATK_CURVE,$MODCurve,0,$env_idx,0)
        set_control_par_str(get_ui_id($curval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATK_CURVE,$grp_idx,$env_idx,0))
    end on
    on ui_control($Hold)
        set_engine_par($ENGINE_PAR_HOLD,$Hold,0,$env_idx,0)
        set_control_par_str(get_ui_id($holdval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_HOLD,$grp_idx,$env_idx,0))
    end on
    on ui_control($Decay)
        set_engine_par($ENGINE_PAR_DECAY,$Decay,0,$env_idx,0)
        set_control_par_str(get_ui_id($decval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_DECAY,$grp_idx,$env_idx,0))
    end on
    on ui_control($Sustain)
        set_engine_par($ENGINE_PAR_SUSTAIN,$Sustain,0,$env_idx,0)
        set_control_par_str(get_ui_id($sustval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_SUSTAIN,$grp_idx,$env_idx,0))
    end on
    on ui_control($Release)
        set_engine_par($ENGINE_PAR_RELEASE,$Release,0,$env_idx,0)
        set_control_par_str(get_ui_id($relval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_RELEASE,$grp_idx,$env_idx,0))
    end on
    
    Right so now we are going to add some controls that will allow us to shape the velocity curve of the waveform.

    Firstly we should consider what is VELOCITY?

    Velocity can be described as a measure of how rapidly and forcefully a key on a keyboard is pressed when the player
    initially presses the key.
    For example a note struck on a piano is louder if the key is struck more forcefully.
    There are other changes in the note sound of a piano as the velocity varies.
    In the MIDI standard, a velocity value is transmitted with each note on message.
    If a given keyboard does not support sensing of velocity, a fixed , non-zero velocity value is sent in its outgoing note on messages.
    The MIDI standard allows notes to be released by sending a note on message with a velocity value of 0,
    instead of using a note off message.
    Some feel that the 127 possible values of velocity in the note on message does not provide sufficient resolution to express all of the subtlety of certain large-sample-set instruments.
    For this reason the high resolution velocity prefix extension to the MIDI standard was developed, although few keyboards implement it.
    The main messages are the NOTE ON and NOTE OFF messages.
    The NOTE ON message is sent when the performer hits a key of the music keyboard.
    It contains parameters to specify the pitch of the note as well as the velocity.
    When a synthesizer receives this message, it starts playing that note with the correct pitch and force level.
    When the NOTE OFF message is received, the corresponding note is switched off by the synthesizer.
    Every NOTE ON message requires its corresponding NOTE OFF message, otherwise the note will play forever.
    The only exception is for percussion instruments, where it can happen that only the NOTE ON is sent,
    as the percussion note stops by itself automatically.
    HOWEVER it is better practice to send the NOTE OFF in every case because you are not sure how it could be interpreted.

    The NOTE ON message is structured as follows:

    •Status byte : 1001 CCCC
    •Data byte 1 : 0PPP PPPP
    •Data byte 2 : 0VVV VVVV
    where:
    "CCCC" is the MIDI channel (from 0 to 15)
    "PPP PPPP" is the pitch value (from 0 to 127)
    "VVV VVVV" is the velocity value (from 0 to 127)

    The NOTE OFF message is structured as follows:

    •Status byte : 1000 CCCC
    •Data byte 1 : 0PPP PPPP
    •Data byte 2 : 0VVV VVVV
    where CCCC and PPPPPPP have the same meaning as above.
    The VVVVVVV is the release velocity, which is very rarely used. By default, set it to zero.

    ON NOTE

    The note callback is performed whenever a note is pressed.
    This gives your script a chance to change the properties of the note (eg. pitch, velocity, volume, panning, tuning), or generate new notes.
    Code:
    on note
    play_note($EVENT_NOTE+12, $EVENT_VELOCITY, 0,-1)    {play transposed note }    
    end on
    
    OR THE COMMAND ignore_event ($EVENT_ID) will ignore the original note i.e
    Code:
    on note
    ignore_event($EVENT_ID)                                 {stop original note   }
    play_note($EVENT_NOTE+12, $EVENT_VELOCITY, 0,-1)       {play transposed note }
    end on
    
    OTHER USEFUL FUNCTIONS:- (apply this in an empty script slot)
    Code:
    on note
      change_note($EVENT_ID, $EVENT_NOTE + 12)     { change pitch, transpose 12 steps upwards }
      change_velo($EVENT_ID, $EVENT_VELOCITY / 2)  { change velocity to half or original      }
      change_pan($EVENT_ID,  1000, 0)              { change panning, pan RIGHT                }
      change_vol($EVENT_ID,  5000, 0)              { change volume, turn it up 5000 milli-dB  }
      change_tune($EVENT_ID, 50000, 0)             { change tuning, tune up 50000 millicents  }
    end on
    
    FOR OUR SCRIPT
    Many velocity scripts are variations of the standard PRESET CHANGE VELOCITY script written by Josef Natterer & Nicki Marinic
    To access these FACTORY scripts you can open the script editor, click on Preset & apply.
    The script we will vary is as follows :-
    Code:
    {***********************************************
    Change Velocity
    Author: Native Instruments
    Written by: Josef Natterer, Nicki Marinic
    Modified: July 30, 2009
    *************************************************}
    
    on init
      
    set_script_title("Change Velocity")
    set_ui_height(4)
    message("")
      
    declare $count
    declare $new_vel
      
    declare ui_table %velo_display[128] (4,1,1)
    move_control (%velo_display,2,6)
    set_control_help (%velo_display,"Velocity Display: Displays incoming velocities.")
      
    declare ui_label $out_label (1,1)
    set_text ($out_label,"Out:")
    move_control ($Out_label,6,6)
    set_control_help ($out_label,"Velocity Out Display: Displays outgoing velocities.")
          
    {CHANGE VELOCITY}
      
    declare ui_table %table[128] (4,4,127)
    set_control_help (%table,"Velocity Curve: Displays the velocity curve.")
      
    declare ui_knob $CShow (-50,127,1)
    set_knob_defval ($Cshow,0)
    make_persistent($CShow)
    set_text($CShow,"Curve")
      
    declare ui_knob $MinS (1,127,1)
    make_persistent($MinS)
    set_text($MinS,"Min")
      
    declare ui_knob $MaxS (1,127,1)
    make_persistent($MaxS)
    set_text($MaxS,"Max")
      
    declare ui_knob $Randomize (0,64,1)
    make_persistent($Randomize)
    set_text($Randomize,"Random")
    move_control ($Randomize,1,4)
    set_control_help ($Randomize,"Randomize Velocities: Randomizes velocities in the specified range.")
      
    declare $a
    declare %table_2[128]
    declare $Min
    $Min := 1
    declare $Min_c
    $Min_c := 1
    declare $Max
    $Max := 127  
    declare ui_menu $mode
    add_menu_item ($mode,"Linear",0)
    add_menu_item ($mode,"Shelf",1)
    add_menu_item ($mode,"Comp/Expd",2)
    add_menu_item ($mode,"Fix",3)
    set_control_help ($mode,"Velocity Curve Mode: Choose a velocity curve mode.")
    make_persistent ($mode)
      
    declare $Curve
    make_persistent ($Curve)
    $Curve := 0
      
    declare $Fix
    make_persistent ($Fix)
    $Fix := 100
      
    declare $Threshold
    make_persistent ($Threshold)
    $Threshold := 64  
      
    declare $Ratio
    make_persistent ($Ratio)
    $Ratio := 0
      
    declare $Shape
    make_persistent ($Shape)
    $Shape := 35
      
    declare $helper
    declare %helper_2[128]
    declare $helper_3
    declare $helper_4
    declare $knob_helper
    $a := 1
    while ($a < 128)
    %table[$a] := $a
    inc ($a)
    end while
    $Curve := 0
      
    make_persistent (%table)
    make_persistent ($Curve)
    make_persistent ($Min)
    make_persistent ($Min_c)
    make_persistent ($Max)
      
    _read_persistent_var($mode)
    select ($mode)
    case 0 {Linear }
    move_control ($MinS,6,4)
    move_control ($CShow,1,2)
    move_control ($MaxS,6,2)
    set_text($CShow,"Curve")
    set_text($MaxS,"Max")
    $MaxS := $max
    case 1 {Shelf }
    move_control ($MinS,6,4)
    move_control ($CShow,1,2)
    move_control ($MaxS,6,2)
    set_text($CShow,"Shape")
    set_text($MaxS,"Max")
    $MaxS := $max
    case 2 {Comp/Expd }
    move_control ($MinS,6,4)
    move_control ($CShow,1,2)
    move_control ($MaxS,6,2)
    set_text($CShow,"Ratio")
    set_text($MaxS,"Thresh.")
    $MaxS := $threshold
    case 3 {Fix }
    move_control ($MinS,0,0)
    move_control ($MaxS,0,0)
    move_control ($CShow,1,2)
    set_text($CShow,"Fix")
    end select
    declare %shape_form[128]
    declare %curve_form[128]
    declare %comp_form[128]
    $a := 0
    while($a < 128)
    %shape_form[$a] := $a*100
    %curve_form[$a] := $a*100
    %comp_form[$a] := $a  
    inc($a)
    end while
    make_persistent(%curve_form)
    make_persistent(%shape_form)
    make_persistent(%comp_form)
    declare %curve_table_helper[128]
    declare %curve_deriv[128]
    declare $kurven_hoehe
    $shape := 35
    $knob_helper := ($Shape *(-1) + 1000)
    $a := 0
    $helper := 1000
    $kurven_hoehe := 0
    while($a < 64)
    $helper := ($helper * $knob_helper)/1000
    %curve_deriv[$a] := $helper
    %curve_deriv[127-$a] := $helper
    $kurven_hoehe := $kurven_hoehe + (%curve_deriv[$a]*2)
    inc($a)
    end while
    $a := 1
    %curve_table_helper[0] := 0
    while ($a <128)
    %curve_table_helper[$a] := ((%curve_table_helper[$a-1]+%curve_deriv[$a]))
    inc($a)
    end while
    $a := 0
    while ($a <128)
    %shape_form[$a] := ((%curve_table_helper[$a]*128)/(($kurven_hoehe)/100))
    inc($a)
    end while
    $a := 0
    while ($a <128)
    %shape_form[$a] := (%shape_form[$a]*12700)/%shape_form[127]
    inc($a)
    end while
    move_control(%table,2,2)
    move_control($mode,2,1)
      
    end on
    
    on ui_control ($mode)
    {show/hide controls}
    select ($mode)
    case 0 {Linear }
    move_control ($CShow,1,2)
    move_control ($MinS,6,4)
    move_control ($MaxS,6,2)
    set_text($CShow,"Curve")
    set_text($MaxS,"Max")
    $MaxS := $max
    $CShow := $Curve
    $MinS := $min
    $a := 0
    while ($a <128)
    %table[$a] := $Min + ((%curve_form[$a]*($Max-$Min))/12700)
    inc($a)
    end while              
    case 1 {Shelf }
    move_control ($CShow,1,2)
    move_control ($MinS,6,4)
    move_control ($MaxS,6,2)
    set_text($CShow,"Shape")
    set_text($MaxS,"Max")
    $MaxS := $max
    $CShow := $Shape
    $MinS := $min
    $a := 0
    while ($a <128)
    %table[$a] := $Min + ((%shape_form[$a]*($Max-$Min))/12700)
    inc($a)
    end while  
    case 2 {Comp/Expd }
    move_control ($CShow,1,2)
    move_control ($MinS,6,4)
    move_control ($MaxS,6,2)
    set_text($CShow,"Ratio")
    set_text($MaxS,"Thresh.")
    $MaxS := $threshold
    $CShow := $Ratio
    if ($MinS > 64)
    $MinS := 64
    end if
    $MinS := $min_c
    $a := 0
    while ($a <128)
    %table[$a] := %comp_form[$a]
    inc($a)
    end while
    case 3 {Fix }
    move_control ($CShow,1,2)
    move_control ($MinS,0,0)
    move_control ($MaxS,0,0)
    set_text($CShow,"Fix")
    $CShow := $Fix
    $a := 0
    while ($a <128)
    %table[$a] := $fix
    inc($a)
    end while
    end select
    end on
    
    on note
    
    %velo_display[$EVENT_VELOCITY] := 1  
    $new_vel := %table[$EVENT_VELOCITY]+ random(-$Randomize,$Randomize)  
    if ($new_vel < 1)
    $new_vel := 1
    end if
    if ($new_vel > 127)
    $new_vel := 127
    
    end if
      
    change_velo ($EVENT_ID, $new_vel)  
    set_text ($out_label,"Out: " & $EVENT_VELOCITY)
      
    end on
    on ui_control (%velo_display)
    $count := 0
    while ($count < 128)
    %velo_display[$count] := 0
    inc($count)
    end while
    end on
    
    on release
    $count := 0
    while ($count < 128)
    %velo_display[$count] := 0
    inc($count)
    end while
    set_text ($out_label,"Out:")
    end on
    
    on ui_control ($CShow)
    select($mode)
    case 0
    if ($CShow > 50)
    $CShow := 50
    end if
    $curve := $CShow
    $knob_helper := ($Curve*(-1) + 1000)
    $a := 0
    $helper := 1000
    $kurven_hoehe := 0
    while($a < 128)
    $helper := ($helper * $knob_helper)/1000
    %curve_deriv[$a] := $helper
    $kurven_hoehe := $kurven_hoehe + %curve_deriv[$a]
    inc($a)
    end while
    $a := 2
    %curve_table_helper[0] := 0
    %curve_table_helper[1] := 0
    while ($a <128)
    %curve_table_helper[$a] := ((%curve_table_helper[$a-1]+%curve_deriv[$a]))
    inc($a)
    end while
    $a := 0
    while ($a <128)
    %curve_form[$a] := ((%curve_table_helper[$a]*128)/(($kurven_hoehe)/100))
    inc($a)
    end while
    $a := 0
    while ($a <128)
    %curve_form[$a] := (%curve_form[$a]*12700)/%curve_form[127]
    inc($a)
    end while
    $a := 0
    while ($a <128)
    %table[$a] := $Min + (((%curve_form[$a])*($Max-$Min))/12700)
    inc($a)
    end while
    case 1
    if ($CShow > 50)
    $CShow := 50
    end if
    $Shape := $CShow
    $knob_helper := ($Shape *(-1) + 1000)
    $a := 0
    $helper := 1000
    $kurven_hoehe := 0
    while($a < 64)
    $helper := ($helper * $knob_helper)/1000
    %curve_deriv[$a] := $helper
    %curve_deriv[127-$a] := $helper
    $kurven_hoehe := $kurven_hoehe + (%curve_deriv[$a]*2)
    inc($a)
    end while
    $a := 2
    %curve_table_helper[0] := 0
    %curve_table_helper[1] := 0
    while ($a <128)
    %curve_table_helper[$a] := ((%curve_table_helper[$a-1]+%curve_deriv[$a]))
    inc($a)
    end while
    $a := 0
    while ($a <128)
    %shape_form[$a] := ((%curve_table_helper[$a]*128)/(($kurven_hoehe)/100))
    inc($a)
    end while
    $a := 0
    while ($a <128)
    %shape_form[$a] := (%shape_form[$a]*12700)/%shape_form[127]
    inc($a)
    end while
              
    $a := 0
    while ($a <128)
    %table[$a] := $Min + ((%shape_form[$a]*($Max-$Min))/12700)
    inc($a)
    end while  
    case 2
    if ($CShow > 50)
    $CShow := 50
    end if
    $Ratio := $CShow
    $a := 0
    while($a < $threshold)
    %comp_form[$a] := $Min_c + (($a*(64-$Min_c))/($Threshold))
    inc($a)
    end while
    if ($Ratio <= 0)
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a - $threshold)*($Ratio+50))/50
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    else
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a-$Threshold)*(51))/(51-$Ratio)
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    end if
    $a := 0
    while ($a <128)
    %table[$a] := %comp_form[$a]
    inc($a)
    end while
    case 3
    if ($CShow < 1)
    $CShow := 1
    end if
    $Fix := $CShow
    $a := 0
    while ($a <128)
    %table[$a] := $fix
    inc($a)
    end while      
    end select
    end on
    
    on ui_control ($MinS)
    select ($mode)
    case 0
    $min := $MinS
    $min_c := $MinS
    $a := 0
    while ($a <128)
    %table[$a] := $Min + ((%curve_form[$a]*($Max-$Min))/12700)
    inc($a)
    end while              
    if ($min > 64)
    $min_c := 64
    else
    $min_c := $min  
    end if
    $a := 0
    while($a < $threshold)
    %comp_form[$a] := $Min_c + (($a*(64-$Min_c))/($Threshold))
    inc($a)
    end while
    if ($Ratio <= 0)
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a - $threshold)*($Ratio+50))/50
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    else
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a-$Threshold)*(51))/(51-$Ratio)
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    end if
    case 1
    $min := $MinS
    $min_c := $MinS
    $a := 0
    while ($a <128)
    %table[$a] := $Min + ((%shape_form[$a]*($Max-$Min))/12700)
    inc($a)
    end while  
    if ($min > 64)
    $min_c := 64
    else
    $min_c := $min  
    end if
    $a := 0
    while($a < $threshold)
    %comp_form[$a] := $Min_c + (($a*(64-$Min_c))/($Threshold))
    inc($a)
    end while
    if ($Ratio <= 0)
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a - $threshold)*($Ratio+50))/50
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    else
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a-$Threshold)*(51))/(51-$Ratio)
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    end if
    case 2
    if ($MinS > 64)
    $MinS := 64
    end if
    $min_c := $MinS
    $min := $min_c
    $a := 0
    while($a < $threshold)
    %comp_form[$a] := $Min_c + (($a*(64-$Min_c))/($Threshold))
    inc($a)
    end while
    if ($Ratio <= 0)
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a - $threshold)*($Ratio+50))/50
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    else
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a-$Threshold)*(51))/(51-$Ratio)
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    end if
    $a := 0
    while ($a <128)
    %table[$a] := %comp_form[$a]
    inc($a)
    end while
    case 3
    $min_c := $MinS
    $min := $min_c          
    end select
    end on
    
    on ui_control ($MaxS)
    select ($mode)
    case 0
    $Max := $MaxS
    $a := 0
    while ($a <128)
    %table[$a] := $Min + ((%curve_form[$a]*($Max-$Min))/12700)
    inc($a)
    end while              
    case 1
    $Max := $MaxS
    $a := 0
    while ($a <128)
    %table[$a] := $Min + ((%shape_form[$a]*($Max-$Min))/12700)
    inc($a)
    end while  
    case 2
    $threshold := $MaxS
    $a := 0
    while($a < $threshold)
    %comp_form[$a] := $Min_c + (($a*(64-$Min_c))/($Threshold))
    inc($a)
    end while
    if ($Ratio <= 0)
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a - $threshold)*($Ratio+50))/50
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    else
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a-$Threshold)*(51))/(51-$Ratio)
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    end if
    $a := 0
    while ($a <128)
    %table[$a] := %comp_form[$a]
    inc($a)
    end while
    end select
    end on
    
    The above script declares the controls and provides a graphical representation of the VELOCITY CURVE.
    It also defines the mathematical functions necessary in order that we are able to change the shape of the VELOCITY PROFILE.
    SO A LOGICAL starting point is to modify the script in order that we can display the CONTROLS we want.
    REMEMBER ANYTHING WRITTEN BETWEEN {.....} will be ignored by KONTAKT and when modifying a standard script this is important.
    So put simply ANY controls we want to hide we can simply move to 0,0 (remember to remove _px or they will be displayed!)
    ANY lines of code that describes functions or callbacks etc we want to ignore we simply put the code between {.....} and Kontakt will ignore it.
    HOWEVER the basic rules still apply and the script must still follow logical order : -

    on init
    end on

    on note
    end on

    on release
    end on

    on controller
    end on

    WHILST simply copying & pasting scripts wholesale is definitely COUNTER PRODUCTIVE it is very handy to have some BASIC
    Building blocks such as the PRESET factory scripts around which you can build your own scripts.
    It is of course better to understand the process complete but Modifying a standard script can save huge amounts of time.
    ALL original authors should of course be credited wherever possible as it is only courteous and if they ask a script should NOT be used then this should be respected.
    Many script writers do not "HARD LOCK" their scripts even though they are fully aware of how too and some even do not password protect them which means you can learn from studying them.
    However simply COPYING them probably won't work as they are instrument specific in general and at the end of the day it is as stated counter productive in terms of progressing your script writing ability.

    SO NOW WE INSERT THE MODIFIED SCRIPT INTO OUR SCRIPT whilst observing the rules and keeping the basic structure
    intact
    SO again we can DECLARE a switch that shows the performance view controls we want to display with regards to controls that
    enable us to modify the parameters of the VELOCITY CURVE.
    BY DEFAULT Kontakt has controls for AHDSR & VELOCITY already present.
    These can be DELETED or if so desired renamed to suit.
    BY DEFAULT, VELOCITY is named VEL_VOLUME (group:0,idx 16,gen:-1).
    To delete or rename them simply right click and delete or rename to suit.
    However your script should of course accommodate any renaming or it won't work!
    AS we discussed earlier it is IMPORTANT to understand what (group:0, idx 16, gen:-1) describes.
    THE SLIDER ranges from 0 to 100% and controls the modulation intensity i.e "How large the parameter changes caused by the
    modulation signal changes will be."
    SO in the first script slot I am going to put a small script for a simple DYNAMIC EXPANDER to expand the sound further.
    This will be as follows :-
    Code:
    on init
    set_script_title("Dynamic Expander")  
    declare $vol_amount
    end on
    
    on note
    $vol_amount:=(($EVENT_VELOCITY-1)*12000/126)-6000
    change_vol($EVENT_ID,$vol_amount,1)
    end on
    
    NOTE as we have set the GUI height in our main script to 319 pixels this script will be HIDDEN.
    IT will however be active and functioning.

    THEREFORE OUR SCRIPT NOW READS AS FOLLOWS :- (Insert in SLOT 3 & apply)
    Code:
    on init
    make_perfview
    set_ui_height_px(319)
    set_script_title("Instrument 1")
    set_control_par_str($INST_WALLPAPER_ID,$CONTROL_PAR_PICTURE,"Background")
    set_control_par_str($INST_ICON_ID,$CONTROL_PAR_PICTURE,"Icon")
    message ("")
    
    {DECLARE CONSTANTS}
    
    declare $count
    declare $env_idx
    declare $grp_idx
    declare $labelID
    declare $menuid
    declare $volume_id
    $labelID:=14
    
    {---MOD PRESET ARRAY---}
    
    declare $MOD_selected
    
    declare %MOD_preset_array[6*10+1]:=(1,0,334000,0,0,1000000,754883,...
    0,334000,0,0,1000000,718219,...
    0,334000,0,955880,0,206327,...
    0,334000,120000,629563,1000000,73333,...
    579469,334000,0,489223,1000000,699219,...
    745117,334000,0,0,1000000,805783,...
    0,334000,268555,775305,0,610817,...
    200787,334000,696711,658988,793701,537564,...
    607493,334000,541992,865234,833333,731445,...
    742188,280237, 0, 540285, 963867, 778320)
    
    declare ui_menu $MOD_presets
    add_menu_item($MOD_presets,"Default",1)
    add_menu_item($MOD_presets,"Long Release",2)
    add_menu_item($MOD_presets,"Clavinet",3)
    add_menu_item($MOD_presets,"Organ",4)
    add_menu_item($MOD_presets,"Pad",5)
    add_menu_item($MOD_presets,"Space",6)
    add_menu_item($MOD_presets,"Decay",7)
    add_menu_item($MOD_presets,"Dry",8)
    add_menu_item($MOD_presets,"Strings",9)
    add_menu_item($MOD_presets,"Alone",10)
    
    set_control_par_str(get_ui_id($MOD_presets),$CONTROL_PAR_PICTURE,"Drop1")
    set_control_par(get_ui_id($MOD_presets),$CONTROL_PAR_FONT_TYPE,$labelID)
    move_control($MOD_presets,0,0)
    make_persistent($MOD_presets)
    
    {DECLARE CONTROLS}
    
    declare ui_slider $volume(0,629959)
    declare ui_switch $AHDSR
    declare ui_switch $VELOCITY
    
    {---MODULATION CONTROLS---}
    
    declare ui_slider $MODCurve(0,1000000)
    declare ui_slider $Attack(0,1000000)
    declare ui_slider $Hold(0,1000000)
    declare ui_slider $Decay(0,1000000)
    declare ui_slider $Sustain(0,1000000)
    declare ui_slider $Release(0,1000000)
    
    {---CONTROL LABELS---}
    
    declare ui_label $AHDSRlbl(1,1)
    declare ui_label $VELOCITYlbl(1,1)
    declare ui_label $AHDSRON(1,1)
    declare ui_label $VELOCITYON(1,1)
    declare ui_label $vol_label(1,1)
    declare ui_label $MASTERL(1,1)
    declare ui_label $MASTER(1,1)
    declare ui_label $curname(1,1)
    declare ui_label $curval(1,1)
    declare ui_label $attname(1,1)
    declare ui_label $attval(1,1)
    declare ui_label $holdname(1,1)
    declare ui_label $holdval(1,1)
    declare ui_label $decname(1,1)
    declare ui_label $decval(1,1)
    declare ui_label $susname(1,1)
    declare ui_label $sustval(1,1)
    declare ui_label $relname(1,1)
    declare ui_label $relval(1,1)
    
    {---SCREENS---}
    
    declare ui_label $SCREEN1(1,1)
    declare ui_label $screen2(1,1)
    declare ui_label $screen3(1,1)
    declare ui_label $screen4(1,1)
    declare ui_label $screen5(1,1)
    declare ui_label $screen6(1,1)
    declare ui_label $screen7(1,1)
    
    {---PRESET MENU---}
    
    declare ui_label $PreSets(1,1)
    declare ui_label $AHDSRback(1,1)
    declare ui_label $VELOCITYback(1,1)
    
    {---CONTROL ID---}
    
    $volume_id:= get_ui_id($volume)
    set_control_par_str(get_ui_id($volume),$CONTROL_PAR_TEXT,"MASTERmim")
    set_control_par_str(get_ui_id($volume),$CONTROL_PAR_PICTURE,"MASTERmim")
    set_text ($vol_label,get_engine_par_disp($ENGINE_PAR_VOLUME,-1,-1,-1) & " dB")
    
    {---AHDSR---}
    
    set_control_par_str(get_ui_id($AHDSR),$CONTROL_PAR_PICTURE,"tinyswitch2")
    set_control_par_str(get_ui_id($VELOCITY),$CONTROL_PAR_PICTURE,"tinyswitch2")
    set_control_par_str(get_ui_id($AHDSRback),$CONTROL_PAR_PICTURE,"labbutton")
    set_control_par_str(get_ui_id($AHDSRON),$CONTROL_PAR_PICTURE,"labbutton2")
    set_control_par_str(get_ui_id($VELOCITYON),$CONTROL_PAR_PICTURE,"labbutton2")
    set_control_par_str(get_ui_id($MODCurve),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par_str(get_ui_id($Attack),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par_str(get_ui_id($Hold),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par_str(get_ui_id($Decay),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par_str(get_ui_id($Sustain),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par_str(get_ui_id($Release),$CONTROL_PAR_PICTURE,"knob 2")
    set_control_par(get_ui_id($AHDSR),$CONTROL_PAR_HEIGHT,20)
    set_control_par(get_ui_id($AHDSR),$CONTROL_PAR_WIDTH,20)
    
    {---VELOCITY---}
    
    set_control_par_str(get_ui_id($VELOCITYback),$CONTROL_PAR_PICTURE,"labbutton")
    
    {---LABEL ID---}
    
    set_control_par(get_ui_id($vol_label),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($MASTER),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($PreSets),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($AHDSRlbl),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($VELOCITYlbl),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($curname),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($attname),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($holdname),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($decname),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($susname),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($relname),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($curval),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($attval),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($decval),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($holdval),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($sustval),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par(get_ui_id($relval),$CONTROL_PAR_FONT_TYPE,$labelID)
    set_control_par_str(get_ui_id($curval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATK_CURVE,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($attval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATTACK,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($holdval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_HOLD,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($decval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_DECAY,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($sustval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_SUSTAIN,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($relval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_RELEASE,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($MASTERL),$CONTROL_PAR_TEXT,"MASTERvol")
    set_control_par_str(get_ui_id($SCREEN1),$CONTROL_PAR_TEXT,"")
    set_control_par_str(get_ui_id($screen2),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen3),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen4),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen5),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen6),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($screen7),$CONTROL_PAR_TEXT,"screen")
    set_control_par_str(get_ui_id($MASTERL),$CONTROL_PAR_PICTURE,"MASTERvol")
    set_control_par_str(get_ui_id($SCREEN1),$CONTROL_PAR_PICTURE,"SCREEN")
    set_control_par_str(get_ui_id($screen2),$CONTROL_PAR_PICTURE,"screen")
    set_control_par_str(get_ui_id($screen3),$CONTROL_PAR_PICTURE,"screen")
    set_control_par_str(get_ui_id($screen4),$CONTROL_PAR_PICTURE,"screen")
    set_control_par_str(get_ui_id($screen5),$CONTROL_PAR_PICTURE,"screen")
    set_control_par_str(get_ui_id($screen6),$CONTROL_PAR_PICTURE,"screen")
    set_control_par_str(get_ui_id($screen7),$CONTROL_PAR_PICTURE,"screen")
    
    {---TEXT ID---}
    
    set_text($MASTERL,"")
    set_text($PreSets,"")
    set_text($AHDSR,"")
    set_text($VELOCITY,"")
    set_text($AHDSRback,"")
    set_text($AHDSRlbl,"           ADSR")
    set_text($VELOCITYlbl,"         Velocity")
    
    set_text($AHDSRON,"")
    set_text($VELOCITYON,"")
    set_text($MASTER,"MASTER VOL")
    set_text($PreSets,"")
    set_text($AHDSRback,"")
    set_text($curname,"")
    set_text($attname,"")
    set_text($holdname,"")
    set_text($decname,"")
    set_text($relname,"")
    set_text($susname,"")
    set_text($curval,"")
    set_text($attval,"")
    set_text($holdval,"")
    set_text($decval,"")
    set_text($relval,"")
    set_text($sustval,"")
    set_text($screen2,"")
    set_text($screen3,"")
    set_text($screen4,"")
    set_text($screen5,"")
    set_text($screen6,"")
    set_text($screen7,"")
    
    {---VELOCITY---}
    
    set_text($VELOCITYback,"")
    
    {---HIDE BG---}
    
    hide_part($vol_label,$HIDE_PART_BG)
    hide_part($MASTER,$HIDE_PART_BG)
    hide_part($AHDSRlbl,$HIDE_PART_BG)
    hide_part($PreSets,$HIDE_PART_BG)
    hide_part($AHDSR,$HIDE_PART_BG)
    hide_part($VELOCITY,$HIDE_PART_BG)
    hide_part($VELOCITYlbl,$HIDE_PART_BG)
    hide_part($curname,$HIDE_PART_BG)
    hide_part($attname,$HIDE_PART_BG)
    hide_part($holdname,$HIDE_PART_BG)
    hide_part($decname,$HIDE_PART_BG)
    hide_part($susname,$HIDE_PART_BG)
    hide_part($relname,$HIDE_PART_BG)
    hide_part($curval,$HIDE_PART_BG)
    hide_part($attval,$HIDE_PART_BG)
    hide_part($holdval,$HIDE_PART_BG)
    hide_part($decval,$HIDE_PART_BG)
    hide_part($sustval,$HIDE_PART_BG)
    hide_part($relval,$HIDE_PART_BG)
    
    {---MOUSE BEHAVIOUR---}
    
    set_control_par(get_ui_id($MODCurve),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    set_control_par(get_ui_id($Attack),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    set_control_par(get_ui_id($Hold),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    set_control_par(get_ui_id($Decay),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    set_control_par(get_ui_id($Sustain),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    set_control_par(get_ui_id($Release),$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    
    {---MOVE CONTROLS---}
    
    move_control_px($AHDSR,557,85)
    move_control_px($VELOCITY,557,105)
    move_control_px($AHDSRback,553,89)
    move_control_px($AHDSRlbl,553,88)
    move_control_px($VELOCITYlbl,553,107)
    move_control_px($Volume,565,12)
    move_control_px($vol_label,570,65)
    move_control_px($MASTERL,549,16)
    move_control_px($MASTER,553,0)
    move_control_px($PreSets,410,55)
    move_control($VELOCITYON,0,0)
    move_control($AHDSRON,0,0)
    move_control($MODCurve,0,0)
    move_control($Attack,0,0)
    move_control($Hold,0,0)
    move_control($Decay,0,0)
    move_control($Sustain,0,0)
    move_control($Release,0,0)
    move_control_px($curname,208,55)
    move_control_px($attname,278,55)
    move_control_px($holdname,350,55)
    move_control_px($decname,208,155)
    move_control_px($susname,275,155)
    move_control_px($relname,345,155)
    move_control($curval,0,0)
    move_control($attval,0,0)
    move_control($holdval,0,0)
    move_control($decval,0,0)
    move_control($sustval,0,0)
    move_control($relval,0,0)
    move_control_px($SCREEN1,563,57)
    move_control($screen2,0,0)
    move_control($screen3,0,0)
    move_control($screen4,0,0)
    move_control($screen5,0,0)
    move_control($screen6,0,0)
    move_control($screen7,0,0)
    
    {---VELOCITY---}
    
    move_control_px($VELOCITYback,553,109)
    
    {---SET DEFAULTS---}
    
    $AHDSR:= 0
    $VELOCITY:= 0
    
    set_knob_defval($volume,500000)
    set_knob_defval($MODCurve,334000)
    set_knob_defval($Attack,0)
    set_knob_defval($Hold,0)
    set_knob_defval($Decay,0)
    set_knob_defval($Sustain,1000000)
    set_knob_defval($Release,754883)
    {---MAKE PERSISTENT---}
    make_persistent($volume)
    make_persistent($PreSets)
    make_persistent($AHDSRlbl)
    make_persistent($MODCurve)
    make_persistent($Attack)
    make_persistent($Hold)
    make_persistent($Decay)
    make_persistent($Sustain)
    make_persistent($Release)
    make_persistent($curval)
    make_persistent($attval)
    make_persistent($holdval)
    make_persistent($decval)
    make_persistent($sustval)
    make_persistent($relval)
    {---READ PERSISTENT---}
    read_persistent_var($MODCurve)
    read_persistent_var($Attack)
    read_persistent_var($Hold)
    read_persistent_var($Decay)
    read_persistent_var($Sustain)
    read_persistent_var($Release)
    read_persistent_var($curval)
    read_persistent_var($attval)
    read_persistent_var($holdval)
    read_persistent_var($decval)
    read_persistent_var($sustval)
    read_persistent_var($relval)
    
    {---VELOCITY---}
    
    declare ui_label $CAGE_label2(1, 1)
    set_text ($CAGE_label2,"")
    set_control_par_str(get_ui_id($CAGE_label2),$CONTROL_PAR_PICTURE,"Cage2")
    move_control($CAGE_label2,0,0)
    make_persistent($CAGE_label2)
    
    declare $new_vel
    declare ui_table %velo_display[128] (1,1,1)
    move_control (%velo_display,0,0)
    declare ui_label $out_label (1,1)
    move_control ($Out_label,0,0)
    
    declare ui_label $Velcurve (1,1)
    set_text ($Velcurve,"")
    set_control_par_str(get_ui_id($Velcurve), $CONTROL_PAR_PICTURE,"Velocity")
    move_control($Velcurve,0,0)
    set_control_par(get_ui_id( $Velcurve), $CONTROL_PAR_FONT_TYPE, 19)
     
    declare ui_table %table[128] (4,4,127)
    set_control_par(get_ui_id(%table), $CONTROL_PAR_BAR_COLOR,9000066h)
    set_control_par(get_ui_id(%table),$CONTROL_PAR_WIDTH,315)
    set_control_par(get_ui_id(%table),$CONTROL_PAR_HEIGHT,103)
    hide_part(%table,$HIDE_PART_BG)
    set_control_par_str(get_ui_id(%table), $CONTROL_PAR_PICTURE,"null")
    move_control(%table,0,0)
     
    declare ui_slider $CShow (-50,50)
    set_knob_defval ($Cshow,0)
    make_persistent($CShow)
    set_control_par_str(get_ui_id($CShow), $CONTROL_PAR_PICTURE,"knob 2")
    set_knob_defval($CShow,0)
    set_control_par(get_ui_id($CShow), $CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
    move_control($CShow,0,0)
     
    declare ui_slider $MinS (1,127)
    make_persistent($MinS)
    move_control($MinS,0,0)
    set_control_par_str(get_ui_id($MinS), $CONTROL_PAR_PICTURE,"knob 2")
    set_knob_defval($MinS,1)
    set_control_par(get_ui_id($MinS), $CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
     
    declare ui_slider $MaxS (1,127)
    make_persistent($MaxS)
    move_control ($MaxS,0,0)
    set_control_par_str(get_ui_id($MaxS), $CONTROL_PAR_PICTURE,"knob 2")
    set_knob_defval($MaxS,127)
    set_control_par(get_ui_id($MaxS), $CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
     
    declare ui_knob $Randomize (0,64,1)
    make_persistent($Randomize)
    move_control($Randomize,0,0)
    declare $a
    declare %table_2[128]
    declare $Min
    $Min := 1
    declare $Min_c
    $Min_c := 1
    declare $Max
    $Max:= 127
    declare ui_menu $mode
    add_menu_item ($mode,"Linear",0)
    add_menu_item ($mode,"Shelf",1)
    make_persistent ($mode)
    declare $Curve
    make_persistent ($Curve)
    $Curve:= 0
    declare $Fix
    make_persistent ($Fix)
    $Fix:= 100
    declare $Threshold
    make_persistent ($Threshold)
    $Threshold := 64
    declare $Ratio
    make_persistent ($Ratio)
    $Ratio:= 0
    declare $Shape
    make_persistent ($Shape)
    $Shape:= 35
    declare $helper
    declare %helper_2[128]
    declare $helper_3
    declare $helper_4
    declare $knob_helper
    $a := 1
    while ($a < 128)
    %table[$a] := $a
    inc ($a)
    end while
    $Curve := 0
    make_persistent (%table)
    make_persistent ($Curve)
    make_persistent ($Min)
    make_persistent ($Min_c)
    make_persistent ($Max)
    _read_persistent_var($mode)
    select ($mode)
    
    case 0 {Linear }
    move_control ($MinS,0,0)
    move_control ($MaxS,0,0)
    $MaxS := $max
     
    case 1 {Shelf }
    move_control($MinS,0,0)
    move_control($MaxS,0,0)
    $MaxS := $max
    end select
     
    declare %shape_form[128]
    declare %curve_form[128]
    declare %comp_form[128]
    $a := 0
    while($a < 128)
    %shape_form[$a] := $a*100
    %curve_form[$a] := $a*100
    %comp_form[$a] := $a
    inc($a)
    end while
    
    make_persistent(%curve_form)
    make_persistent(%shape_form)
    make_persistent(%comp_form)
    declare %curve_table_helper[128]
    declare %curve_deriv[128]
    declare $kurven_hoehe
    $shape := 35
    $knob_helper := ($Shape *(-1) + 1000)
    $a:= 0
    $helper := 1000
    $kurven_hoehe := 0
    while($a < 64)
    $helper := ($helper * $knob_helper)/1000
    %curve_deriv[$a] := $helper
    %curve_deriv[127-$a] := $helper
    $kurven_hoehe := $kurven_hoehe + (%curve_deriv[$a]*2)
    inc($a)
    end while
    $a := 1
    %curve_table_helper[0] := 0
    while ($a <128)
    %curve_table_helper[$a] := ((%curve_table_helper[$a-1]+%curve_deriv[$a]))
    inc($a)
    end while
    $a := 0
    while ($a <128)
    %shape_form[$a] := ((%curve_table_helper[$a]*128)/(($kurven_hoehe)/100))
    inc($a)
    end while
    $a := 0
    while ($a <128)
    %shape_form[$a] := (%shape_form[$a]*12700)/%shape_form[127]
    inc($a)
    end while
    
    move_control($mode,0,0)
    
    declare ui_label $CURVE_Label (1,1)
    set_text($CURVE_Label,"")
    set_control_par(get_ui_id($CURVE_Label), $CONTROL_PAR_FONT_TYPE, 14)
    move_control($CURVE_Label,0,0)
    set_control_par_str(get_ui_id($CURVE_Label), $CONTROL_PAR_PICTURE,"Curve")
    
    declare ui_label $Min_Label (1,1)
    set_text($Min_Label,"")
    set_control_par(get_ui_id($Min_Label), $CONTROL_PAR_FONT_TYPE, 14)
    move_control($Min_Label,0,0)
    set_control_par_str(get_ui_id($Min_Label), $CONTROL_PAR_PICTURE,"Minimum")
     
    declare ui_label $Max_Label (1,1)
    set_text($Max_Label,"")
    set_control_par(get_ui_id($Max_Label), $CONTROL_PAR_FONT_TYPE, 14)
    move_control($Max_Label,0,0)
    set_control_par_str(get_ui_id($Max_Label), $CONTROL_PAR_PICTURE,"Maximum")
    
    {******************** SET CONTROL HELP ****************************************}
    
    
    
    {******************** SET CONTROL HELP ****************************************}
    
    end on
    
    {========================================}
    
    on note
    
    {---VELOCITY---}
    
    %velo_display[$EVENT_VELOCITY] := 1
    $new_vel := %table[$EVENT_VELOCITY]+ random(-$Randomize,$Randomize)
    if ($new_vel < 1)
    $new_vel := 1
    end if
    if ($new_vel > 127)
    $new_vel := 127
    end if
    change_velo ($EVENT_ID, $new_vel)
    set_text ($out_label,"Out: " & $EVENT_VELOCITY)
    
    end on
    
    {---MODULATION PRESET ARRAY---}
    
    on ui_control($MOD_presets)
    $MOD_selected := get_control_par(get_ui_id($MOD_presets),$CONTROL_PAR_SELECTED_ITEM_IDX)+1
    set_engine_par($ENGINE_PAR_ATTACK,%MOD_preset_array[1 +(6*($MOD_selected-1))],0,$env_idx,0)
    set_engine_par($ENGINE_PAR_ATK_CURVE,%MOD_preset_array[2 +(6*($MOD_selected-1))],0,$env_idx,0)
    set_engine_par($ENGINE_PAR_HOLD,%MOD_preset_array[3 +(6*($MOD_selected-1))],0,$env_idx,0)
    set_engine_par($ENGINE_PAR_DECAY,%MOD_preset_array[4 +(6*($MOD_selected-1))],0,$env_idx,0)
    set_engine_par($ENGINE_PAR_SUSTAIN,%MOD_preset_array[5 +(6*($MOD_selected-1))],0,$env_idx,0)
    set_engine_par($ENGINE_PAR_RELEASE,%MOD_preset_array[6 +(6*($MOD_selected-1))],0,$env_idx,0)
    $Attack := get_engine_par($ENGINE_PAR_ATTACK,0,0,0)
    $MODCurve := get_engine_par($ENGINE_PAR_ATK_CURVE,0,0,0)
    $Hold := get_engine_par($ENGINE_PAR_HOLD,0,0,0)
    $Decay := get_engine_par($ENGINE_PAR_DECAY,0,0,0)
    $Sustain := get_engine_par($ENGINE_PAR_SUSTAIN,0,0,0)
    $Release := get_engine_par($ENGINE_PAR_RELEASE,0,0,0)
    set_control_par_str(get_ui_id($attval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATTACK,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($curval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATK_CURVE,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($holdval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_HOLD,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($decval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_DECAY,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($sustval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_SUSTAIN,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($relval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_RELEASE,$grp_idx,$env_idx,0))
    end on
    
    {---VELOCITY---}
    
    on ui_control (%velo_display)
    $count := 0
    while ($count < 128)
    %velo_display[$count] := 0
    inc($count)
    end while 
    end on
    
    {---MASTER VOLUME CALLBACKS---}
    on ui_control($volume)
    set_engine_par($ENGINE_PAR_VOLUME,$volume,-1,-1,-1)
    set_control_par_str ($volume_id,$CONTROL_PAR_LABEL,...
    get_engine_par_disp($ENGINE_PAR_VOLUME,-1,-1,-1) & " dB")
    set_text ($vol_label,get_engine_par_disp($ENGINE_PAR_VOLUME,-1,-1,-1) & " dB")
    
    end on
    
    on ui_control ($AHDSR)
    
    if ($AHDSR=1)
    move_control($AHDSRback,0,0)
    move_control_px($AHDSRON,553,89)
    move_control_px($VELOCITYback,553,109)
    move_control($VELOCITYON,0,0)
    $VELOCITY:=0
    
    message ("MODULATION")
    
    {function AHDSR gui}
    
    move_control_px($MODCurve,205,70)
    move_control_px($attack,275,70)
    move_control_px($hold,345,70)
    move_control_px($decay,205,170)
    move_control_px($sustain,275,170)
    move_control_px($release,345,170)
    move_control_px($MOD_presets,400,70)
    move_control_px($curval,211,126)
    move_control_px($attval,277,126)
    move_control_px($holdval,345,126)
    move_control_px($decval,206,226)
    move_control_px($sustval,281,226)
    move_control_px($relval,345,226)
    move_control_px($screen2,196,118)
    move_control_px($screen3,266,118)
    move_control_px($screen4,336,118)
    move_control_px($screen5,196,218)
    move_control_px($screen6,266,218)
    move_control_px($screen7,336,218)
    set_control_par_str(get_ui_id($attval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATTACK,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($curval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATK_CURVE,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($holdval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_HOLD,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($decval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_DECAY,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($sustval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_SUSTAIN,$grp_idx,$env_idx,0))
    set_control_par_str(get_ui_id($relval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_RELEASE,$grp_idx,$env_idx,0))
    set_text($PreSets,"PRESETS")
    set_text($curname,"Curve")
    set_text($attname,"Attack")
    set_text($holdname,"Hold")
    set_text($decname,"Decay")
    set_text($susname,"Sustain")
    set_text($relname,"Release")
    
    {function VELOCITY gui}
    
    move_control($CAGE_label2,0,0)
    move_control($Velcurve,0,0)
    move_control(%table,0,0)
    move_control($CShow,0,0) 
    move_control($MinS,0,0)
    move_control($MaxS,0,0)
    move_control($CURVE_Label,0,0)
    move_control($Min_Label,0,0)
    move_control($Max_Label,0,0)
    
    else
    
    if ($AHDSR=0)
    move_control_px($AHDSRback,553,89)
    move_control($AHDSRON,0,0)
    
    message ("")
    
    {function AHDSR gui}
    
    move_control($MODCurve,0,0)
    move_control($attack,0,0)
    move_control($hold,0,0)
    move_control($decay,0,0)
    move_control($sustain,0,0)
    move_control($release,0,0)
    move_control($MOD_presets,0,0)
    move_control($attval,0,0)
    move_control($curval,0,0)
    move_control($holdval,0,0)
    move_control($decval,0,0)
    move_control($sustval,0,0)
    move_control($relval,0,0)
    move_control($screen2,0,0)
    move_control($screen3,0,0)
    move_control($screen4,0,0)
    move_control($screen5,0,0)
    move_control($screen6,0,0)
    move_control($screen7,0,0)
    set_text($PreSets,"")
    set_text($curname,"")
    set_text($attname,"")
    set_text($holdname,"")
    set_text($decname,"")
    set_text($susname,"")
    set_text($relname,"")
    end if
    end if
    end on
    
    {---MODULATION CONTROLS---}
    
    on ui_control($Attack)
    set_engine_par($ENGINE_PAR_ATTACK,$Attack,0,$env_idx,0)
    set_control_par_str(get_ui_id($attval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATTACK,$grp_idx,$env_idx,0))
    end on
    
    on ui_control($MODCurve)
    set_engine_par($ENGINE_PAR_ATK_CURVE,$MODCurve,0,$env_idx,0)
    set_control_par_str(get_ui_id($curval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_ATK_CURVE,$grp_idx,$env_idx,0))
    end on
    
    on ui_control($Hold)
    set_engine_par($ENGINE_PAR_HOLD,$Hold,0,$env_idx,0)
    set_control_par_str(get_ui_id($holdval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_HOLD,$grp_idx,$env_idx,0))
    end on
    
    on ui_control($Decay)
    set_engine_par($ENGINE_PAR_DECAY,$Decay,0,$env_idx,0)
    set_control_par_str(get_ui_id($decval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_DECAY,$grp_idx,$env_idx,0))
    end on
    
    on ui_control($Sustain)
    set_engine_par($ENGINE_PAR_SUSTAIN,$Sustain,0,$env_idx,0)
    set_control_par_str(get_ui_id($sustval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_SUSTAIN,$grp_idx,$env_idx,0))
    end on
    
    on ui_control($Release)
    set_engine_par($ENGINE_PAR_RELEASE,$Release,0,$env_idx,0)
    set_control_par_str(get_ui_id($relval),$CONTROL_PAR_TEXT,get_engine_par_disp($ENGINE_PAR_RELEASE,$grp_idx,$env_idx,0))
    end on
    
    {---VELOCITY---}
    
    on ui_control($VELOCITY)
    
    if($VELOCITY = 1)
    
    move_control_px($AHDSRback,553,89)
    move_control($AHDSRON,0,0)
    move_control($VELOCITYback,0,0)
    move_control_px($VELOCITYON,553,109)
    
    message ("VELOCITY")
    
    $AHDSR:=0
    
    {function VELOCITY gui}
    
    move_control_px($CAGE_label2,170,37)
    move_control_px($Velcurve,170,15)
    move_control_px(%table,173,45)
    move_control_px($CShow,202,173) 
    move_control_px($MinS,302,173)
    move_control_px($MaxS,402,173)
    move_control_px($CURVE_Label,190,157)
    move_control_px($Min_Label,290,157)
    move_control_px($Max_Label,390,157)
    
    {function AHDSR gui}
    
    move_control($MODCurve,0,0)
    move_control($attack,0,0)
    move_control($hold,0,0)
    move_control($decay,0,0)
    move_control($sustain,0,0)
    move_control($release,0,0)
    move_control($MOD_presets,0,0)
    move_control($attval,0,0)
    move_control($curval,0,0)
    move_control($holdval,0,0)
    move_control($decval,0,0)
    move_control($sustval,0,0)
    move_control($relval,0,0)
    move_control($screen2,0,0)
    move_control($screen3,0,0)
    move_control($screen4,0,0)
    move_control($screen5,0,0)
    move_control($screen6,0,0)
    move_control($screen7,0,0)
    set_text($PreSets,"")
    set_text($curname,"")
    set_text($attname,"")
    set_text($holdname,"")
    set_text($decname,"")
    set_text($susname,"")
    set_text($relname,"")
     
    else
    
    if ($VELOCITY=0)
    
    move_control_px($VELOCITYback,553,109)
    move_control($VELOCITYON,0,0)
    message ("")
    
    {function VELOCITY gui}
    
    move_control($CAGE_label2,0,0)
    move_control($Velcurve,0,0) 
    move_control(%table,0,0)
    move_control($CShow,0,0)
    move_control($MinS,0,0)
    move_control($MaxS,0,0)
    move_control($CURVE_Label,0,0)
    move_control($Min_Label,0,0)
    move_control($Max_Label,0,0)
    end if
    end if 
    end on
    
    {---VELOCITY FUNCTION---}
    
    on ui_control ($mode)
    select ($mode)
    
    case 0 {Linear }
    move_control ($MinS,0,0)
    move_control ($MaxS,0,0)
    $MaxS := $max
    $CShow := $Curve
    $MinS := $min
    $a := 0
    while ($a <128)
    %table[$a] := $Min + ((%curve_form[$a]*($Max-$Min))/12700)
    inc($a)
    end while
    
    case 1 {Shelf }
    move_control ($MinS,0,0)
    move_control ($MaxS,0,0)
    $MaxS := $max
    $CShow := $Shape
    $MinS := $min
    $a := 0
    while ($a <128)
    %table[$a] := $Min + ((%shape_form[$a]*($Max-$Min))/12700)
    inc($a)
    end while
    end select
    end on
    
    on ui_control ($CShow)
    
    select($mode)
    
    case 0
    if ($CShow > 50)
    $CShow := 50
    end if
    $curve := $CShow
    $knob_helper := ($Curve*(-1) + 1000)
    $a := 0
    $helper := 1000
    $kurven_hoehe := 0
    while($a < 128)
    $helper := ($helper * $knob_helper)/1000
    %curve_deriv[$a] := $helper
    $kurven_hoehe := $kurven_hoehe + %curve_deriv[$a]
    inc($a)
    end while
    $a := 2
    %curve_table_helper[0] := 0
    %curve_table_helper[1] := 0
    while ($a <128)
    %curve_table_helper[$a] := ((%curve_table_helper[$a-1]+%curve_deriv[$a]))
    inc($a)
    end while
    $a := 0
    while ($a <128)
    %curve_form[$a] := ((%curve_table_helper[$a]*128)/(($kurven_hoehe)/100))
    inc($a)
    end while
    $a := 0
    while ($a <128)
    %curve_form[$a] := (%curve_form[$a]*12700)/%curve_form[127]
    inc($a)
    end while
    $a := 0
    while ($a <128)
    %table[$a] := $Min + (((%curve_form[$a])*($Max-$Min))/12700)
    inc($a)
    end while
    
    case 1
    
    if ($CShow > 50)
    $CShow := 50
    end if
    $Shape := $CShow
    $knob_helper := ($Shape *(-1) + 1000)
    $a := 0
    $helper := 1000
    $kurven_hoehe := 0
    while($a < 64)
    $helper := ($helper * $knob_helper)/1000
    %curve_deriv[$a] := $helper
    %curve_deriv[127-$a] := $helper
    $kurven_hoehe := $kurven_hoehe + (%curve_deriv[$a]*2)
    inc($a)
    end while
    $a := 2
    %curve_table_helper[0] := 0
    %curve_table_helper[1] := 0
    while ($a <128)
    %curve_table_helper[$a] := ((%curve_table_helper[$a-1]+%curve_deriv[$a]))
    inc($a)
    end while
    $a := 0
    while ($a <128)
    %shape_form[$a] := ((%curve_table_helper[$a]*128)/(($kurven_hoehe)/100))
    inc($a)
    end while
    $a := 0
    while ($a <128)
    %shape_form[$a] := (%shape_form[$a]*12700)/%shape_form[127]
    inc($a)
    end while
    
    $a := 0
    while ($a <128)
    %table[$a] := $Min + ((%shape_form[$a]*($Max-$Min))/12700)
    inc($a)
    end while
    
    case 2
    
    if ($CShow > 50)
    $CShow := 50
    end if
    $Ratio := $CShow
    $a := 0
    while($a < $threshold)
    %comp_form[$a] := $Min_c + (($a*(64-$Min_c))/($Threshold))
    inc($a)
    end while
    
    if ($Ratio <= 0)
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a - $threshold)*($Ratio+50))/50
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    else
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a-$Threshold)*(51))/(51-$Ratio)
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    end if
    $a := 0
    while ($a <128)
    %table[$a] := %comp_form[$a]
    inc($a)
    end while
    
    case 3
    if ($CShow < 1)
    $CShow := 1
    end if
    $Fix := $CShow
    $a := 0
    while ($a <128)
    %table[$a] := $fix
    inc($a)
    end while
    end select
     
    end on
    
    on ui_control ($MaxS)
    select ($mode)
    
    case 0
    $Max := $MaxS
    $a := 0
    while ($a <128)
    %table[$a] := $Min + ((%curve_form[$a]*($Max-$Min))/12700)
    inc($a)
    end while
    
    case 1
    $Max := $MaxS
    $a := 0
    while ($a <128)
    %table[$a] := $Min + ((%shape_form[$a]*($Max-$Min))/12700)
    inc($a)
    end while
    
    case 2
    $threshold := $MaxS
    $a := 0
    while($a < $threshold)
    %comp_form[$a] := $Min_c + (($a*(64-$Min_c))/($Threshold))
    inc($a)
    end while
    if ($Ratio <= 0)
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a - $threshold)*($Ratio+50))/50
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    else
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a-$Threshold)*(51))/(51-$Ratio)
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    end if
    $a := 0
    while ($a <128)
    %table[$a] := %comp_form[$a]
    inc($a)
    end while
    end select
    end on
    
    on ui_control ($MinS)
    
    select ($mode)
    
    case 0
    $min := $MinS
    $min_c := $MinS
    $a := 0
    while ($a <128)
    %table[$a] := $Min + ((%curve_form[$a]*($Max-$Min))/12700)
    inc($a)
    end while
    if ($min > 64)
    $min_c := 64
    else
    $min_c := $min
    end if
    $a := 0
    while($a < $threshold)
    %comp_form[$a] := $Min_c + (($a*(64-$Min_c))/($Threshold))
    inc($a)
    end while
    if ($Ratio <= 0)
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a - $threshold)*($Ratio+50))/50
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    else
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a-$Threshold)*(51))/(51-$Ratio)
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    end if
    
    case 1
    $min := $MinS
    $min_c := $MinS
    $a := 0
    while ($a <128)
    %table[$a] := $Min + ((%shape_form[$a]*($Max-$Min))/12700)
    inc($a)
    end while
    if ($min > 64)
    $min_c := 64
    else
    $min_c := $min
    end if
    $a := 0
    while($a < $threshold)
    %comp_form[$a] := $Min_c + (($a*(64-$Min_c))/($Threshold))
    inc($a)
    end while
    if ($Ratio <= 0)
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a - $threshold)*($Ratio+50))/50
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    else
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a-$Threshold)*(51))/(51-$Ratio)
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    end if
    
    case 2
    if ($MinS > 64)
    $MinS := 64
    end if
    $min_c := $MinS
    $min := $min_c
    $a := 0
    while($a < $threshold)
    %comp_form[$a] := $Min_c + (($a*(64-$Min_c))/($Threshold))
    inc($a)
    end while
    if ($Ratio <= 0)
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a - $threshold)*($Ratio+50))/50
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    else
    $a := $threshold
    while($a < 128)
    %comp_form[$a] := 64+ (($a-$Threshold)*(51))/(51-$Ratio)
    if (%comp_form[$a] > 127)
    %comp_form[$a] := 127
    end if
    inc($a)
    end while
    end if
    $a := 0
    while ($a <128)
    %table[$a] := %comp_form[$a]
    inc($a)
    end while
    
    case 3
    $min_c := $MinS
    $min := $min_c
    
    end select
    
    end on
    
    
    HOW the GUI should now look:-

    DEFAULT GUI

    DEFAULT 1.png

    AHDSR SELECTED

    AHDSR.png

    VELOCITY SELECTED

    VELOCITY.png


    NOTE for this particular control I have used TEXT in the form of graphics instead of simply declaring Text using label-ID.

    It is just to demonstrate the different ways in which you can do things. I have also added an icon and some highlight graphicsaround the switches to highlight when they are active and which one is selected.

    The controls themselves are self explanatory and later on we will incorporate "HELP" sections into the script to give us info text as we hover over a control with the mouse. Try changing them to see how they affect the velocity of the sound.

    SO now we have a sample & have performance view controls for the Master Volume, AHDSR characteristcs and also the ability to vary the shape of the velocity curve.

    Note that if these controls were not hidden at times we would already be running short of space in performance view.

    This only serves to highlight the fact that it is very important to have the ability to utilise fully all the space in performance view

    Good luck, please forgive any typos & any problems just shout :wink:
     
    Last edited: Oct 8, 2015
    • Like Like x 4
    • Useful Useful x 2
    • List
  8. Kookaboo

    Kookaboo Rock Star

    Joined:
    Jun 17, 2011
    Messages:
    1,457
    Likes Received:
    428
    Location:
    Here and there.
    Q -Why isn't Kontakt Forward Compatible?
    Sincere Answer: Because Native Instruments want to push users to buy always the newest versions!:crazy:
    Like Apple does with their PROFIT-only mentality. :deep_facepalm:
     
  9. Clandestine

    Clandestine Platinum Record

    Joined:
    Nov 11, 2013
    Messages:
    717
    Likes Received:
    151
    Possibly Kook there some truth in that.
    Think many businesses/Corporations that grow so large look at such as the primary focal point.
    Especially when you consider such stupid things like if the company been floated they may get sued for not upholding the shareholders interests & such.

    Is pretty sad but also inevitable to a degree & pretty much commonplace in such large scale industries with huge running costs i guess.

    Also then consider Inertia, they don't need to change at the moment to keep their place as industry leader.

    For example, imagine the scenario, NI been floated & the panel turns round & says we want to make Kontakt forward compatible.
    Good idea, :yes:, that is until the shareholders hear about the proposal & say were going to sue you if that's the case because your not holding our interests as paramount.

    They say we want profit & couldn't care one iota as towards the product itself.

    What NI going to do :dunno:

    Still the best sample manipulator tho imho & with very little competition then the situation probably unlikely to change.
     
    Last edited: Aug 22, 2015
  10. Jedi_Knight

    Jedi_Knight Kapellmeister

    Joined:
    Jan 28, 2012
    Messages:
    153
    Likes Received:
    51
    Location:
    Mustafar
    Truly interesting read Clandestine! Ive always been curious. Thank you for sharing.
     
Loading...
Similar Threads - Kontakt Scripting Building Forum Date
KSP Kontakt scripting issues with custom knob and velocity value to mirror on play note (visual FX) Kontakt Mar 21, 2023
Kontakt Scripting Kontakt Jul 27, 2017
Tutorials for Kontakt Scripting? Kontakt Jun 26, 2017
Scripting Tools For Kontakt 5 Kontakt Jul 26, 2015
Kontakt Scripting - Kontakt Custom Script Collection AudioSex Academy Nov 7, 2014
Loading...