# Controlling Outputs via Script



## jkleban (Dec 9, 2016)

I don't want to offend anyone here but I have a simple question:

Is it possible to control what KONTAKT output tracks to use? 

For example, if someone has 16 outputs routed to 16 tracks in there DAW, can a SCRIPT decide which output to use for a given instrument?

I read the reference manual and user manual and I know I can do this manually, but can't see what $ENGINE_PAR or $SYS_PAR determines the OUTPUT channels.

Thanks in advance.


----------



## EvilDragon (Dec 9, 2016)

You cannot do this on instrument level, but you can decide where to route individual groups or busses within an instrument, and for that the command is listed in KSP Reference, section Engine Parameter Values -> Instrument, Source and Amp Module.


----------



## geronimo (Dec 9, 2016)

Otherwise with the KSP is easier .

https://support.native-instruments....KONTAKT-5-and-Route-Them-to-my-Host-Sequencer


----------



## jkleban (Dec 9, 2016)

Thank you folks, E.D.'s response to my somewhat kyptic question was spot on. I wanted to do this within the script and I am coming to the conclusion that there is a constant variable for any of the controls one would find within the Kontakt interface? Not sure yet if this is true or not.

I want to be able to query available output channels that are set up in the user's environment and let the user change the instrument's outputs, limited but inclusive of the outputs that they have set up in their Kontakt environment. To give them more control if they include the instrument in one of their own MULTI's.

Sounds like there is a way, now to go figure out what data elements need to be queried and/or set by the script.

Thanks again guys.


----------



## Stiltzkin (Dec 9, 2016)

If you just want to add a button which includes a list of all the available kontakt outputs, based on how many outputs the user has added, you can use this macro:


```
macro set_mic_output_outputs(uiname, uipicture, uipicturewidth, uipictureheight, uitextposition, uiposx, uiposy, busoffset)
    declare ui_menu uiname
    set_control_par_str(get_ui_id(uiname), $CONTROL_PAR_PICTURE, uipicture)
    set_control_par(get_ui_id(uiname), $CONTROL_PAR_WIDTH, uipicturewidth)
    set_control_par(get_ui_id(uiname), $CONTROL_PAR_HEIGHT, uipictureheight)
    set_control_par(get_ui_id(uiname), $CONTROL_PAR_TEXTPOS_Y, uitextposition)
    move_control_px(uiname, uiposx, uiposy)

    for i := 0 to $NUM_OUTPUT_CHANNELS-1
        add_menu_item(uiname, output_channel_name(i), i)
    end for

    uiname := get_engine_par($ENGINE_PAR_OUTPUT_CHANNEL, -1, -1, $NI_BUS_OFFSET +busoffset)
end macro
```

Then of course add the appropriate on ui control as required, this is for a bus, but you can edit that as you need to.


----------



## EvilDragon (Dec 10, 2016)

jkleban said:


> I am coming to the conclusion that there is a constant variable for any of the controls one would find within the Kontakt interface?



MOST of them, yeah. And it's all listed in KSP reference.


----------



## jkleban (Dec 10, 2016)

Thanks guys....

So, NI_BUS_OFFSET is a ver 5 system variable, is there a way to do this in Ver 4.xx?

Also, what is the macro command? Is it KSP or Sublime editor feature and where can I learn how to use this.

Thanks for your patience. Just trying to learn.


----------



## EvilDragon (Dec 10, 2016)

No, because K4 doesn't have instrument busses.

Macros are a SublimeKSP feature. http://nilsliberg.se/ksp/scripts/tutorial/editor.html


----------



## jkleban (Dec 10, 2016)

ED: thanks for the link to the editor tutorial. Much appreciated.


----------



## Stiltzkin (Dec 10, 2016)

A macro basically allows you to use a lot of shorthand by having one sort of main "library" of macros that you make over time, that allow you to write chunks of code you'll likely have to repeat a lot.

So where you'd normally have to write that whole code out for every single mic output, instead the shorthand code would read something like:


```
set_mic_output_outputs(micoutput1, picture, 20, 20, -1, 10, 10, 0)
set_mic_output_outputs(micoutput2, picture, 20, 20, -1, 10, 30, 1)
set_mic_output_outputs(micoutput3, picture, 20, 20, -1, 10, 50, 2)
```

etc etc, so it saves a lot of time and makes your shorthand code look a bit neater - very good habit to get in to, just make sure you comment everything on your library so you can quickly read over how it works when you need to reuse an old bit of code!


----------



## jkleban (Dec 10, 2016)

Thanks Stiltz..... I knew about MACROs from other languages, I just didn't know if KSP implemented them or if it was a SUBLIME editor feature. I have some reading to do on NILs tutorial of the editor so I can understand the mechanics of using them.

I really do appreciate the assistance from users on this forum. There is a lot to get your head around with K Scripts and since I am a dinosaur, a lot to try and remember (I am at the stage that I have to forget something to remember something new).


----------

