# Hi Hat Script?



## MaraschinoMusic (Sep 8, 2009)

Before I have a crack at it myself, I was wondering if anyone has written a script to intelligently mute open or partially open HiHats when the key assigned to the HiHat pedal samples is played.
/\~O 
Using voice groups & setting polyphony to 1 voice is not an option, otherwise the open samples will mute each other which is not what happens in reality!

Only the pedal key must mute the open hats, not the closed hats or subsequent hits on any of the keys assigned to open hats. This is the way 'real' drums work - a closed hit does not actually mute an open hit, closing the hats with the pedal does (which of course you have to do before you can actually play them closed up!)

I guess the script must take into account any notes that are assigned to open or partially open samples, and if any of those samples are still playing (if this can be detected) when the note assigned to the pedal hat is played, then mute them.

Any pointers in the right direction would be appreciated


----------



## gregjazz (Sep 9, 2009)

Here's a rough hihat muting script I made for you. Let me know if you have any questions. 

As you can see, you can remove the "case 42" part if you don't want the hihat closed hit to mute anything.

*on init*
``*family* temp
````*declare* polyphonic a
````*declare* polyphonic b
````*declare* polyphonic c
````*declare* polyphonic d
``*end* *family*
``*family* engine
````*declare* *const* polyphony := 16
``*end* *family*
``*family* mute_id
````*declare* hh_open[engine.polyphony]
````*declare* hh_close[engine.polyphony]
````*declare* hh_closed[engine.polyphony] 
``*end* *family*
``message("")
``make_perfview
*end on*

*on note*
``*select*(EVENT_NOTE)
````_{HIHAT}_
````*case* 46 _{HIHAT OPEN}_
``````*sort*(mute_id.hh_open, 0)
``````mute_id.hh_open[0] := EVENT_ID
````*case* 44 _{HIHAT CLOSE}_
``````*sort*(mute_id.hh_close, 0)
``````mute_id.hh_close[0] := EVENT_ID
``````*for* temp.a := 0 *to* engine.polyphony - 1
````````fade_out(mute_id.hh_open[temp.a], 150000, 0)
````````mute_id.hh_open[temp.a] := 0
``````*end for*
````*case* 42 _{HIHAT CLOSED (OPTIONAL)}_
``````*sort*(mute_id.hh_closed, 0)
``````mute_id.hh_closed[0] := EVENT_ID
``````*for* temp.a := 0 *to* engine.polyphony - 1
````````fade_out(mute_id.hh_open[temp.a], 100000, 0)
````````mute_id.hh_open[temp.a] := 0
``````*end for*
``*end select*
*end on*


----------



## MaraschinoMusic (Sep 9, 2009)

Thanks Greg, that's exactly the help I needed 

I will need to change the values in the case statements as my drum maps are not GM, and also add a few more options for the 1/4 open, 1/2 open, 3/4 open samples... but that's given me a great start to work from - thanks again.


----------



## keelerstein (Sep 14, 2009)

Hi, I've been trying to figure out something along these lines myself these last couple of days. I set up the various degrees of open hats on one key controlled by a cc and thought it would be cool if when playing a closed hat while the open is in progress it would automatically trigger the close hat simultaneously thus choking the open hat.
Anyway, thought the above script would be a good starting point, however I haven't got off to a good start, when I try copying and pasting it into Nils' script editor I get the message " Syntax error at line 22". Am I missing something obvious? 
Many thanks, Keelerstein


----------



## gregjazz (Sep 14, 2009)

Did you make sure to take out the ` symbols? Maybe KScript didn't automatically do that. I tried compiling it right now and there were no problems.


----------



## keelerstein (Sep 15, 2009)

Hi Greg, thanks for the reply. Well I'm baffled! tried copying and pasting into script editor and the same error message. Have also removed the ` symbols and tried with the same result. Here's what I did:
1.Copy and paste script to notepad.
2. Remove all ` Symbols
3. Copy from notepad to nils' editor v. 1.3.2
4. Press F5 to compile.

Just for reference the code that I pasted minus ` symbols

on init
family temp
declare polyphonic a
declare polyphonic b
declare polyphonic c
declare polyphonic d
end family
family engine
declare const polyphony := 16
end family
family mute_id
declare hh_open[engine.polyphony]
declare hh_close[engine.polyphony]
declare hh_closed[engine.polyphony]
end family
message("")
make_perfview
end on

on note
select(EVENT_NOTE)
{HIHAT}
case 46 {HIHAT OPEN}
sort(mute_id.hh_open, 0)
mute_id.hh_open[0] := EVENT_ID
case 44 {HIHAT CLOSE}
sort(mute_id.hh_close, 0)
mute_id.hh_close[0] := EVENT_ID
for temp.a := 0 to engine.polyphony - 1
fade_out(mute_id.hh_open[temp.a], 150000, 0)
mute_id.hh_open[temp.a] := 0
end for
case 42 {HIHAT CLOSED (OPTIONAL)}
sort(mute_id.hh_closed, 0)
mute_id.hh_closed[0] := EVENT_ID
for temp.a := 0 to engine.polyphony - 1
fade_out(mute_id.hh_open[temp.a], 100000, 0)
mute_id.hh_open[temp.a] := 0
end for
end select
end on


----------



## Nickie Fønshauge (Sep 15, 2009)

Try putting the {HIHAT} comment at the end of the previous line instead.

``*select*(EVENT_NOTE) _{HIHAT}_ 

Apparently the lone comment gives the editor hickups (which it shouldn't, of course, but hey, it's just a computer program :D ).


----------



## keelerstein (Sep 15, 2009)

Many thanks Nickie, that did the trick. :D


----------



## gregjazz (Sep 15, 2009)

It still compiles fine for me, but then I just realized I'm on KScript version 1.3.1. I'm outdated!


----------



## Nickie Fønshauge (Sep 15, 2009)

gregjazz @ 15th September 2009 said:


> It still compiles fine for me, but then I just realized I'm on KScript version 1.3.1. I'm outdated!


So am I and it didn't work until I made the small adaptation mentioned earlier :?


----------



## gregjazz (Sep 16, 2009)

Nickie Fønshauge @ Tue Sep 15 said:


> gregjazz @ 15th September 2009 said:
> 
> 
> > It still compiles fine for me, but then I just realized I'm on KScript version 1.3.1. I'm outdated!
> ...



Ah, you know what it probably is, is that I have all the script optimizing and compacting options enabled, which would obviously automatically remove the comments.


----------



## Nickie Fønshauge (Sep 17, 2009)

Yep, "Compact output" does it


----------

