# Scripts vs Group Start Options



## Hans Adamson (Apr 19, 2006)

It seems to me there should definitely be a group playback condition to activate a certain script.

For example:

I am working on an upright bass. Pluck and Arco are loaded in the same instrument and can be switched between with keyswitching. The problem is that pluck and arco need separate specific scripts, so when I keyswitch to arco a certain set of scripts should apply, and when the pluck is on, a different set of script should be activated.

First I thought I would be able to write the keyswitching into the script, but I don't see a way to use separate scripts assigned by keyswitching. The KSP would have to have a memory of which keys have previously been played to be able to each time determine which set of groups to allow: Bowed, or plucked, depending on if the key for bowed, or the key for plucked was last depressed.

The most convenient would be if there were a module such as the group start options in the group editor where the scripts could be activated per group.

Does anyone have any advice for this dilemma?


----------



## kotori (Apr 20, 2006)

Hi Hans,
Thonex's solution is exactly what I too would have suggested. There's also an alternative if you don't want the script to handle keyswitching but instead set up group start options - you can then look into the %GROUPS_AFFECTED array to determine which group index where played.

But I prefer Thonex's solution for a couple of reasons:
* flexibility
* for keyswitches specified using group start options the active key switch isn't saved. If you save and load an arrangement the active key switch is reset. For some reason K2 insists on resetting the active keyswitch for all instruments when you load a new instrument (I consider this a bug). A script doing key-switching doesn't have these two shortcomings.

I suggest you use my extension to the scripting syntax: user-defined functions. You can then use one function for the pluck 'on note' and another function for the arco 'on note'. The following code, which is only an extension of Thonex's example, needs to be compiled using F5 in the editor before pasted into Kontakt:
*function* on_note_pluck
___{ anything you want to do in 'on note' }_
___{ when the active articulation is pluck }___
*end function*

*function* on_note_arco
___{ anything you want to do in 'on note' }_
___{ when the active articulation is arco }___
*end function*

*on init*
__*declare* *const* ARTICULATION_PLUCK := 1
__*declare* *const* ARTICULATION_ARCO__:= 2
__*declare* articulation := ARTICULATION_PLUCK___{ active articulation }_
__make_persistent(articulation)[tab][tab][tab]__ _{ this setting should be saved }_
*end on*

*on note*
___{ check if note was a keyswitch and change the articulation in that case }_
__*select* (EVENT_NOTE)
[tab]*case* 24
[tab]__articulation := ARTICULATION_PLUCK[tab]__
[tab]*case* 25
[tab]__articulation := ARTICULATION_ARCO
__*end select*
__
___{ depending on the active articulation we choose to invoke some function }_
__*select* (articulation)
[tab]*case* ARTICULATION_PLUCK[tab]__
[tab]__on_note_pluck___{ call the 'on note' for pluck }_
[tab]*case* ARTICULATION_ARCO
[tab]__on_note_arco__ _{ call the 'on note' for arco }_
__*end select*
*end on*


----------



## Thonex (Apr 20, 2006)

Yeah Hans,

definately download Nils' (Kotori's) Kontakt script editor. It allows you to set up functions like Nils did above.... then you can swap the order of functions and edit and whatnot without have to do a lot of typing.

Also, I have found it useful to have a text document with a sort of pool of my favorite functions and then just cut/past them into the sctipr I'm working on. Nils' Find/Replace/Replace ALL features in his editor are also a huge time saver for replacing variables that occur all over the place.

T


----------



## Big Bob (Apr 20, 2006)

Oh this looks like fun, can I join in? 

I notice that the proposed methods all assume that the group processing will be done witinh a single script that has two modes. When I first read Hans' post I thought he might be looking for a way to have two separate scripts (possibly already written) and add 'something' that would allow his keyswitch selection to choose which one of the two existing scripts would be activated. That also can be done but, maybe it isn't what you wanted. Did I read more into it than you meant Hans?

Bob


----------



## gmet (Apr 20, 2006)

Hi all,

I have just come across this K2 section of the forum and it will be added to my K2 favourites list!!

Bob - Thanks for the SIPS great work.

I would certainly be interested in what you are suggesting (accessing two separate scripts) as your SIPS deals with a single line melody and on occasion I might want to add effects such as Jays Ensemble maker on the same instrument. I have tried cascading them and switching on and off with CCs- with no joy. The method you describe sounds like my solution.


----------



## Thonex (Apr 20, 2006)

Big Bob @ Thu Apr 20 said:


> Oh this looks like fun, can I join in?
> 
> I notice that the proposed methods all assume that the group processing will be done witinh a single script that has two modes. When I first read Hans' post I thought he might be looking for a way to have two separate scripts (possibly already written) and add 'something' that would allow his keyswitch selection to choose which one of the two existing scripts would be activated. That also can be done but, maybe it isn't what you wanted. Did I read more into it than you meant Hans?
> 
> Bob



Yeah... since you made me hip to using CC data to communicate between scripts (being that shared variables get initialized in subsequent scripts)... it's opened a whole new world.... very creative solution!!!

T


----------



## Hans Adamson (Apr 20, 2006)

Big Bob @ Thu Apr 20 said:


> Oh this looks like fun, can I join in?
> 
> I notice that the proposed methods all assume that the group processing will be done witinh a single script that has two modes. When I first read Hans' post I thought he might be looking for a way to have two separate scripts (possibly already written) and add 'something' that would allow his keyswitch selection to choose which one of the two existing scripts would be activated. That also can be done but, maybe it isn't what you wanted. Did I read more into it than you meant Hans?
> 
> Bob



Bob,

Actually, both arco and pluck will need several scripts each, but I thought I could combine the scripts if necessary to fit all into the limited number of script slots that Kontakt provides.

Also, the scripts for arco will be unusable for pluck and vice versa, so they are specific for pluck, or arco articulation groups.

I have only started to try and write one of the scripts so far, and mostly you guys are talking over my head. Hopefully I will catch up at some point ...


----------



## Hans Adamson (Apr 20, 2006)

Thonex @ Wed Apr 19 said:


> example:
> 
> if ($EVENT_NOTE = 24)
> $Keyswitch := 1
> ...



Thonex,

Where did you find the variable $Keyswitch? I can't find it in my manual. Since it is not all caps I guess it is a user defined variable, but you didn't define the variable?

Will KSP understand variables that are not defined in the manual?


----------



## Big Bob (Apr 20, 2006)

Justin M @ Thu Apr 20 said:


> Hi all,
> 
> I have just come across this K2 section of the forum and it will be added to my K2 favourites list!!
> 
> ...



I should clarify that I didn't describe how to do it, I just asked if that might be what Hans wanted to do. But, I will outline the general idea. You can install up to 5 scripts in the KSP. But, unless they are specially designed to work cooperatively with each other, you may have problems. For example if two or more of the scripts operate on a note in a contradictory way such as one script asks the note to fade_out and another asks it to fade_in, or, one script tunes the note sharp and another tunes it flat, etc.

However, in the case we're considering for Hans, only one script will be active at any one time. This is much less problematical. However, to do this you can't just throw in five ready-made scripts that were meant to be run individually. You must customize the scripts with some bypass code that can respond to some selecting condition.

For example, if you use keyswitching to select the desired group in K2, then each script can also 'watch' for those keys and only come alive when their specified key is active. Usually, all you have to do is to place a small snippet of code at the head of each callback block. A convenient way to do this would be to use Kotori's NL Editor so you can write a User Function to do the job. Actual bypass code would look something like this:

```
on note
  if ($Bypass = 1)
    exit
  end if
  { The normal NCB code stays here }
end on
```

You would also have to include some code to set the $Bypass variable based on the active keyswitch or whatever else you used for a script-selecting scheme.

God Bless,

Bob


----------



## kotori (Apr 20, 2006)

Justin M @ Thu Apr 20 said:


> Hi all,
> I have just come across this K2 section of the forum and it will be added to my K2 favourites list!!


Hi there Justin, and welcome!
For everyone who don't know Justin he's the guy who's trying to break some kind of record by fitting 8 scripts into 5 script slots. :razz: :wink: 
I hope it's working out ok for you.



Hans Adamson @ Thu Apr 20 said:


> Thonex,
> Where did you find the variable $Keyswitch? I can't find it in my manual. Since it is not all caps I guess it is a user defined variable, but you didn't define the variable?
> Will KSP understand variables that are not defined in the manual?


Hi Hans,
you're right. $Keyswitch would be a user-defined variable and it would have to be declared (although Thonex didn't show this in his example - he probably wanted to concentrate on the core concepts). Btw. his $Keyswitch variable corresponds to my $articulation variable (I left the '$' character out since this is permitted if you use the compiler in the editor).
KSP will only understand the variables declared in the manual (as well as a few secret but not too useful ones).


----------



## Hans Adamson (Apr 20, 2006)

Hans Adamson @ Thu Apr 20 said:


> Thonex,
> Where did you find the variable $Keyswitch? I can't find it in my manual. Since it is not all caps I guess it is a user defined variable, but you didn't define the variable?
> Will KSP understand variables that are not defined in the manual?


Hi Hans,
you're right. $Keyswitch would be a user-defined variable and it would have to be declared (although Thonex didn't show this in his example - he probably wanted to concentrate on the core concepts). Btw. his $Keyswitch variable corresponds to my $articulation variable (I left the '$' character out since this is permitted if you use the compiler in the editor).
KSP will only understand the variables declared in the manual (as well as a few secret but not too useful ones).[/quote]

Thanks Nils,

So how do you explain to KSP what you mean with $Keyswitch? How would you define this variable. I understand you have to declare it, but don't you have to define it as well?


----------

