# Newb's First Question (Scripting CC4)



## robindeandotcom (Feb 10, 2008)

Hello.

I'm using 3rd party presets with my Roland V-Drums (TD-20) and Kontakt 3.

One of the sample layers I'm trying to trigger is that of a "splash" high-hat. Namely, I'm trying to trigger the sound that occurs when you push down on the hh pedal and quickly "bounce" the cymbals off of one-another (pedal down and up quickly).

/\~O 

The TD-20 does this automatically but doesn't specify any option to change the generated midi notes for outboard sequencers and software. Hence my dilema.

I'm thinking there might be a way to analyze and compare CC4 data using an "on controller" approach but am not yet experienced enough to try.

My thoughts are that if the CC4 data were to go from 50 to 0 and back to 50 fast enough, this would suggest a cymbal splash action.

Anyone willing to help?


----------



## Thonex (Feb 10, 2008)

Hi robindeandotcom,

Welcome to the forum!! :D 

I'm glad you found your way over here.

I'm not quite following what you're describing. 

If you could give a detailed account of what your Roland is transmitting and what you'd like Kontakt to accomplish... I might be able to help more.

For example, is CC4 responsible for switching between pedal up/down for the hihat?

Cheers,

T


----------



## robindeandotcom (Feb 11, 2008)

Hey Thonex,

My Roland transmits CC4 data that dictates the high hat's being open or closed (and in between). It produces 3 notes total.

They are:

1) bow strike closed/open (and in between)
2) edge strike closed/open (and in between)
3) pedal down (no strike) cymbal being closed sound

The closed/open part is completely ruled by CC4 data.

The problem is that there's a fourth note that I must trigger. My Roland module triggers it automatically within itself but doesn't send a seperate note to outboard gear.

Instead, the note that I'm trying to trigger ends up being sent as note #3 (see above).

Now, I need all three of the notes listed above but I also need to be able to trigger the note which plays the "cymbals splashing together" sound.

Physically, this sound occurs when you bounce your foot off of the high hat pedal and make the cymbals bounce off of eachother one time (quickly) before they reopen ... sort of like a classical cymbal crash.

Based on the limits of my module, to trigger this in outboard gear I'm thinking that perhaps the best way to do this is to detect when a middle number cc4 flows to zero and zero flows back up a little bit but maybe I'm wrong.

I'm open to ideas but remember, I'm a drummer on drums and, in the end, it needs to feel right.

Anyone up for guiding me through the scripting process?


----------



## Thonex (Feb 11, 2008)

I'm still a little confused.... sorry o ... I think maybe the best approach here would be for you to map out what is needed in plain English.

Like:
If I push down on my HH pedal (CC4), I need it to send a value of Zero and play A#1 at the same time.

If I release my HH pedal, I need it to sent CC4 = 127 and play G#1 at the same time

etc...etc..

Thanks,

T


----------



## robindeandotcom (Feb 11, 2008)

Okay.

If I push down on the pedal quickly (all the way) and then release it quickly, I need to play note #20.

The problem is that if I go all the way down to zero and then up even just one, the splash will sound ... which isn't natural.

I need to go from all the way open ... to all the way closed ... to about 15% open for it to trigger that particular note.

Even then I also need for it to be dynamic, so what ever the velocity was at zero needs to be the velocity of the triggered splash.

Just imagine two hi-hat cymbals. If I push down and hold ... "chut" is the quick sound that is presented. Now, if I open them ... there is no sound. Let's do it again, only this time instead of pushing down and holding, I'm quickly pushing down and releasing.

Physically, this would cause the cymbals to "bounce" off of eachother and, thus, a light "crash" is generated. I'm trying to trigger the note which has the "crash" attached to it.

So, if 127 is fully open and 0 is fully closed ... how do we use this as minimally as possible (so that other triggering remains intact) to produce the note?
I can make a short flv demonstrating if you wish.


----------



## Thonex (Feb 11, 2008)

robindeandotcom @ Mon Feb 11 said:


> Okay.
> 
> If I push down on the pedal quickly (all the way) and then release it quickly, I need to play note #20.
> 
> ...



Ok... I'm understanding it better now.

And you say that the pedal does not send out a midi note at all.... correct?

If it does send out midi notes.... I'm guessing it sends out the Velcity info with it... which make this kind of script fairly simple.

Let us know what (if any) midi *note* info the pedal transmits to the outside world.


----------



## robindeandotcom (Feb 11, 2008)

The pedal sends out CC4 data and ONE midi note (when fully closed). The midi note that fires when fully closed must remain for that particular playing technique (press pedal and hold). That's sort of the trick, I suppose.

Press pedal and release - all in short time - is the note that needs to be experimented with.

THE NOTE GENERATED BY PEDAL DOWN ACTION: #44

I'm starting to get and idea here and am hoping you can put it into action LOL.

If note = 44 and is followed by cc4 of particular value shortly after ... do NOT play #44. Instead play #20.

Ya?


----------



## Thonex (Feb 11, 2008)

robindeandotcom @ Mon Feb 11 said:


> The pedal sends out CC4 data and ONE midi note (when fully closed). The midi note that fires when fully closed must remain for that particular playing technique (press pedal and hold). That's sort of the trick, I suppose.
> 
> Press pedal and release - all in short time - is the note that needs to be experimented with.
> 
> ...



Ok... one other question... does midi note #44 send different velocities depending on how hard you step on the pedal?


----------



## robindeandotcom (Feb 11, 2008)

It does


----------



## robindeandotcom (Feb 12, 2008)

How does something like (full of hacks) this sound?

on note
if ($EVENT_NOTE = 44)

// something like "wait 1 millisecond"
// then "check to see if CC4 is greater than 3"
// if it is greater than three, change note
// otherwise never mind, play note

end if
end on


----------



## Thonex (Feb 12, 2008)

robindeandotcom @ Tue Feb 12 said:


> How does something like (full of hacks) this sound?
> 
> on note
> if ($EVENT_NOTE = 44)
> ...



well... something along those lines... but probably more like this:

on note

if ($EVENT_NOTE = 44 )

play closed hi hat sample 

end if

on release

if the time it was held down > 50 ms then don't play anything.

If the time is was held down is < 50 ms then play splashy sample sound.

end on

read about "on release" call backs in the KSP pdf.

I'm a little busy these next few days... so I'll only be popping in briefly.

Cheers,

T


----------



## robindeandotcom (Feb 12, 2008)

Your architecture probably won't work. My own is likely the best bet. Here's why ...

1) if it's the "splash" technique, the closed hi-hat sample should NOT sound.
2) for my electronic drums, on release won't do the job because all note lengths are identical (shrug).

All I need now is some code to experiment with.


----------



## robindeandotcom (Feb 12, 2008)

Can someone tell me, how do I say "if %CC[4] = something"?


----------



## Thonex (Feb 12, 2008)

robindeandotcom @ Tue Feb 12 said:


> Can someone tell me, how do I say "if %CC[4] = something"?



if (%CC[4] = 0)

{do something here}

end if


Read from page 34 of the KSP manual:



> Control Statements
> A lot of times, we (or, better said, KSP) need to make decisions based on certain conditions.
> KSP knows three types of control statements: if, select and while.
> if…else…end
> ...


----------



## robindeandotcom (Feb 12, 2008)

Thanks for everything Thonex.

I almost have this script working to perfection! 

It currently reads (in FULL) as follows:


```
on init
declare $alternate
end on
on controller
set_controller (4, 127 - %CC[4])
end on
on note
if ($EVENT_NOTE = 22)
change_note($EVENT_ID, $EVENT_NOTE + 19)
end if
if (($EVENT_NOTE = 41 or $EVENT_NOTE = 42) and $alternate = 0)
$alternate := 1
else if (($EVENT_NOTE = 41 or $EVENT_NOTE = 42) and $alternate = 1)
change_note($EVENT_ID, $EVENT_NOTE - 24)
$alternate := 0

// Hi-Hat Splash Script

else if ($EVENT_NOTE = 44)
ignore_event($EVENT_ID)
wait(11111)
if (%CC[4] < 18)
play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, 1)
else play_note($EVENT_NOTE - 24, $EVENT_VELOCITY, 0, 1)
end if
end if
end if
end if
end on
```

The problem that remains is a bit of cross talk which can't be easily addressed from within my external drum brain, as the cross talk is coming from a dual trigger which is triggering another one of it's own triggers (lol).

This brings up more of the same questioning but applies to the same issue I'm working on, so here goes:

1) I need a way to say "if these notes are played too closely together, note # blah gets priority ... ignore and don't play the other note".

2) The samples in this preset are designed to be cut off by other notes (plural). The ONLY note that I wish to cut off other notes is #44.

How do I do this?

I realize that much of this is in the manual and I will research it. However, posting the question never hurts, right?


----------



## Tod (Feb 12, 2008)

robindeandotcom @ Tue Feb 12 said:


> 1) I need a way to say "if these notes are played too closely together, note # blah gets priority ... ignore and don't play the other note".



Hi robindeandotcom,

Lookup (do a search for) *$ENGINE_UPTIME*, That might help you.

Tod


----------



## Thonex (Feb 12, 2008)

Be careful with your code below:


```
on controller
set_controller (4, 127 - %CC[4])
end on
```

The problem with this is... any time your patch receives any CC control info... you'll trigger the "set_controller (4, 127 - %CC[4])".

A good practice is to use this:


```
on controller

select ($CC_NUM)

case 4

set_controller (4, 127 - %CC[4])

end select

end on
```


taken from p. 34 of pdf 



> select()
> select is an elaborated version of if..else..end:
> on note
> select($EVENT_VELOCITY)
> ...



Another solution is to use the %CC_TOUCHED[] command



> on controller
> if (%CC_TOUCHED[1] = 1)
> message ("You've changed the mod wheel!")
> wait (1000000)
> ...


----------



## Thonex (Feb 12, 2008)

robindeandotcom @ Tue Feb 12 said:


> What pdf file are you talkin' about? Is there an online codec resource for all of this? Either way, I'm starting to have some fun here.[/code]



We're talking about the Kontakt Script Language Manual.pdf.

It should be in your documentation folder inside your K2 application folder.

I use it so much that I have an alias of it on my task bar :lol:


----------



## robindeandotcom (Feb 13, 2008)

Yeah, I followed your lead and added it to mine as well.

Here's my entire hh script in it's current form.

How am I doing?

Do you see any problem areas?


```
{declare variables}

on init
declare $hh_pedal := 0
declare $threshold := 0
declare $alternate := 0
end on

{reverse hh polarity}

on controller
if (%CC_TOUCHED[4] = 1) 
set_controller (4, 127 - %CC[4])
end if
end on

{fix for the hh bell while pedal fully down glitch}

on note
if ($EVENT_NOTE = 22)
change_note($EVENT_ID, $EVENT_NOTE + 19)
end if

{detect bow or edge}

if (in_range($EVENT_NOTE, 41, 42))

{avoid pedal based double triggering}

if (($ENGINE_UPTIME - $hh_pedal) < $threshold)
ignore_event($EVENT_ID)
exit
end if

{alternate right and left hands}

if ($alternate = 0)
$alternate := 1
else
change_note($EVENT_ID, $EVENT_NOTE - 24)
$alternate := 0
end if

{hh pedal scripts}

else if ($EVENT_NOTE = 44)
$hh_pedal := $ENGINE_UPTIME

{detect clamp or splash}

wait(11111)
if (%CC[4] >= 18)
$threshold := 300
play_note($EVENT_NOTE - 24, $EVENT_VELOCITY, 0, 1)
else $threshold := 15
end if

end if
end if
end on
```


----------



## Thonex (Feb 13, 2008)

Is it working? :D 

T


----------



## robindeandotcom (Feb 13, 2008)

It is indeed. I wanted to be sure I didn't do anything that should be avoided like before.

It works well and feels pretty good.


----------



## Thonex (Feb 13, 2008)

robindeandotcom @ Wed Feb 13 said:


> It is indeed. I wanted to be sure I didn't do anything that should be avoided like before.
> 
> It works well and feels pretty good.



=o =o =o 

There's the proof right there.

Just quickly looking over the code all looks in order. But there are other's here who could better "proofread" your script.

I'm glad it works... and congratulations!!

T


----------

