Choke groups



  • Hello,

    I'd like to make a very basic drums vst with the ability to stop the open Hi-Hat sound when the the closed Hi-Hat is triggered. Is there a built-in solution or a script is needed?


  • administrators

    Hi Ludo,

    this sounds like a perfect task for a little script. Just save the event ids of every MIDI message that triggers a open hi hat and call Synth.noteOffByEventId() whenever a closed Hi Hat is played. If you only allow one open hi hat sound to ring, it gets even easier (then you don't have to keep a list of event IDs around).



  • Thanks for your answer and for your app by the way, it's great!
    Do you think something like that could work?

    var closeHiHatKey = 66;
    var openHiHatKey = 70;
    var evtList = [];
    var evtListLength = 0;
    var groupList = [];
    groupList[0] = closeHiHatKey;
    groupList[1] = openHiHatKey;
    
    function onNoteOn()
    {
    	for (var i = 0; i < groupList.length; i++) {
    		if (Message.getNoteNumber()==groupList[i]) {
    			evtListLength = evtList.length;
    			for (var j = evtListLength; j < 0; j--) {
    				Synth.noteOffByEventId(evtList[j]);	
    				evtList.pop();
      			}
    			evtList.push(Message.getEventId());
    		}
    	}
    }
    function onNoteOff()
    {
    	
    }
    function onController()
    {
    	
    }
    function onTimer()
    {
    	
    }
    function onControl(number, value)
    {
    	
    }

  • administrators

    The onNoteOn callback is a bit too complicated (you don't need to use nested for loops).

    Also, you need to call Message.makeArtificial() for the note on you want to kill later using Synth.noteOffByEventId(). The reason for this is rather complicated but there's an explanation here.

    This script should do what you need. I've added comments where possible:

    // Use const var for constants for improved performance.
    const var closeHiHatKey = 66;
    const var openHiHatKey = 70;
    
    //  An Array is also a constant, even if it will be populated later on
    const var evtList = [];
    
    // make sure it has enough storage to avoid allocation during the noteOn callback
    evtList.reserve(64);
    
    function onNoteOn()
    {
        if(Message.getNoteNumber() == closeHiHatKey)
        {
            // Always use the for ... in loop if you don't need the index
            for(eventId in evtList)
            {
                // Send the note off command for the given event id
                Synth.noteOffByEventId(eventId);
            }
            
            // Clear all notes
            evtList.clear();
        }
        else if (Message.getNoteNumber() == openHiHatKey)
        {
            // This is necessary because you will kill the note artificially and HISE
            // can only kill artifical notes for stability reasons
            Message.makeArtificial();
            
            // Add this ID to the list (it'll add the artificial event ID)
            evtList.push(Message.getEventId());
        }
    }
    function onNoteOff()
    {
        if(Message.getNoteNumber() == openHiHatKey)
        {
            // We need to ignore the note-off message
            // for the open hi-hat so it will keep ringing...
            Message.ignoreEvent(true);
        }
    }
    function onController()
    {
        
    }
    function onTimer()
    {
        
    }
    function onControl(number, value)
    {
        
    }
    


  • Thank you very much, I learned a lot!



  • Hi,
    I'm back with another but related question. I would like to use the one shot option for my instrument but your script doesn't work anymore. Is there a way to make it work?

    Thanks

    Ludovic


  • administrators

    Are you sure? I've just checked and it works here exactly like back in the days.



  • Yes I think. I tried a lot of time. When « playback settings / playback » is « normal », it works great but when I switch to « one shot », it looks like the function noteOffByEventId doesn’t cut the sound.


  • administrators

    Yes this is intentional. One shot means „ignore the note off and play the whole sample“.



  • Ok, I understand that. This HH things is a very particular case. But as far as I know, several sampler work this way for drums instruments, one shot and choke group. Do you think it would be possible to implement that in Hise? It’s certainly not a high priority but it could be a good feature…


  • administrators

    The script above already ignores the note off for the open hihat so it should behave like oneshot + choke group.



  • Ah Ok! Sorry for my dumb's questions... So I could use Message.ignoreEvent(true) in the onNoteOff() function for the all drum set to emulate the one shot option, that's it?

    Thanks again for your time


  • administrators

    Yep that should work.


Log in to reply

Looks like your connection to Choke groups was lost, please wait while we try to reconnect.