Latch and Switch

I created this script because my KeyStep MIDI controller does not have a proper latch/hold function, and I wanted to use various software Arpeggiators in the same way as the one in my Roland SH-01A synthesizer:
This synth allows you to play monophonic melodies without the arpeggiator already turning your first note into a staccato. Only when you press more than one key at the same time, the arpeggiator starts working.
And this is what the AUTO mode in this script is for. With the advantage, that you can even allow for more than one note to be active before notes are sent to the connected arpeggiator.

NEW FEATURE: Velocity based switching and latching. Only hold notes, or send notes to channel B that have a higher velocity than the set thresholds.
And with the version 2.x series comes the option to disable the note display (Monitor) to save loads of CPU / DSP. The default behaviour can be configured with the variable “default_mon”.

Enjoy! Mark Dammer, Scotland, Dec 2023

Features
• Display incoming MIDI notes on the pads.
• Two latch modes, TOGGLE and REPLACE.
• In TOGGLE mode incoming note messages toggle the note on and off.
• REPLACE mode releases already held notes when a new chord is entered. When only one note is active, it can be released by playing it again.
• Release held MIDI notes by tapping on the pads in the user interface.
• Support for two output channels A and B.
• AUTO mode sends any new note to channel B when the number of simultaneously active notes is above the set threshold for number of notes or velocity.
• Manually choose channel A or B while playing. One channel can hold latched notes, while the other can be used to play manually.
• Built-in MIDI panic functionality

The Controls

Knobs
• Top row sets channel numbers for Channels A and B. Turn fully to the right to enable Filter Mode that will not send any messages on A or B.
• Holding SHIFT allows to set the MIDI input channel with the top left knob, or the velocity thresholds for switching (SVel) or latching (LVel).
• AUTO: sets the threshold for AUTO mode. When the number of currently active notes reaches the set threshold level, any additional note will be sent on Channel B.
• Vel: The velocity of the incoming note is used when the knob is turned left, otherwise a fixed velocity can be set.

Pads
• The pads showing “–” are used for displaying notes. Tap on an active pad to silence the note.
• Latch / TOGGLE mode: Incoming note messages will toggle the corresponding note.
Pressing this pad while holding shift will enable latching in REPLACE mode. Double tap SHIFT to switch the default latching mode between TOGGLE and REPLACE.
• Channel A / Channel B: Send notes on the specific channel. This does not affect already latched notes. When both pads are disabled and no specific channel is selected, AUTO mode is active.
• Notes OFF: Turn all notes on Channel A or B off. In AUTO mode both channels will be muted. Pressing this pad while holding SHIFT will trigger a MIDI Panic loop that sends Note OFF messages for all notes on all 16 channels.

Example usage with Arpeggiator

• Route the output of your MIDI controller into the Mozaic input.
• Route the Mozaic output to both the synthesizer and an arpeggiator of your choice.
• Set Channel A to the channel of the synthesizer you are using.
• Set Channel B to a different channel, and make the arpeggiator listen for MIDI notes on Channel B.
• Now you may have to use another plugin to change the MIDI channel of the notes from the arpeggiator back to Channel A. Merge this output with the output from Mozaic and send it to the synth.
• Make sure AUTO mode is enabled, and set the number of notes that should bypass the arpeggiator. Default is 1.
• Play and enjoy!

Changelog:
v1.2 – fixed MIDI panic function.

v1.3 – added REPLACE mode for latching.

v1.4 – allow changing default latch mode. Always toggle when only one note active. Add AU parameters to switch latch mode and trigger MIDI panic button.

v1.5 – “Filter Mode”. Simply turn the A or B channel selector all the way to the right to enable “FLT”. Both Channel A and B can be individually disabled by selecting this mode.
Possible applications:
– Only allow a maximum number of voices in a MIDI stream.
– Ignore an X number of simultaneously pressed notes, then start sending notes to a connected arpeggiator.
– Use it as a workaround in plugin hosts that currently do not route MIDI channel information between plugins. TIP: Use multiple instances of the script in parallel to emulate switching.

v1.6 – velocity based switching and latching.

v2.1 – disable / enable note monitor.

v2.3 – fixed bug affecting replace mode. Further CPU optimizations. Reduced max number of voices to 8. This can be set with the “max_voices” variable.

Copyright Notice:
Parts of the MIDI panic functionality are based on “_Abolisher_” by Alfred Rademakers. Thanks Alfred!

13 comments on “Latch and Switch
  • pejman on said:

    GREAT with latest version 1,5 it works perfect 🙏❤️.
    Seven years ago I dreamed of making such a patch . Latching and replace 👍.

    THANKS fo sharing this patch .

  • markd on said:

    You might enjoy the latest update to v1.6. This gives you velocity based latching and switching:
    Hit a key harder to make it stick or to send it to the arpeggiator…

  • pejman on said:

    Thats great , The good news is that it can be a very interesting possibility 👍.

    But one question.
    Why does CPU usage increase while using this patch? I test it in AUM only one latch and switch patch Without any other plugins , Sometimes the DSP shows 32% .

    Is this related to the natural structure of your patch or is it due to the timing system you have used in your patch?

    Ipad air 2 , AUM , Latch and switch patch, Buffer size 1024 , sample rate 44,1 , min latency 10 ms.

  • markd on said:

    Thanks for bringing this up. I can see the high DSP usage myself. The patch uses a lot of loops. I will see what can be done to reduce the CPU load.

  • markd on said:

    I have just uploaded a new version that allows you to switch the note monitoring off. This saves lots of DSP power….

  • pejman on said:

    Hi
    I have tested, It is very good . But there is a bug in this version .
    In replace mode i play for example C4 E4 G4 , then i play same C4 E4 G4 again, results: note E4 release unwanted.
    Another example
    I play C4 E4 G4 , and then E4 G4 B4 again, result : E4 release unwanted .

  • markd on said:

    Try v2.3 that I just released. This should fix the bug. As part of further CPU optimizations I have reduced the maximum number of voices to 8. I never even need that many… You can always change this with the “max_voices” variable in the @OnLoad section.

  • pejman on said:

    GREAT .
    it works properly. 🙏👍

    One question: do you use system time for double tap on shift for switching modes ( replace/ toggle ) only ?

  • markd on said:

    Yes, system time is only used for the mode switching.

  • pejman on said:

    I don’t know why you made this decision, but in my opinion, the velocity pad could also be used for switching without the need to write codes related to the system time .
    I mean that by touching the corner of the ( latch on / off pad ) , the switching operation is done.
    Of course, this is my personal opinion, maybe your preferences are different.

  • pejman on said:

    Hi again,
    Can i have a request please ?
    I want to send specific note frome chord taken in replace mode , for example i want only send lowest note or highest note or second note of chord taken to specific channel .

    Because I realized that your patch has the ability to sort notes ( Track the notes that are being held down and sort them lowest note to highest note.)

    So i think it can Recognize the lowest or highest or second or third note of the chord taken. Therefore, it can separate them from the rest of the chord notes and send frome the patch .

  • markd on said:

    What you suggest is problematic: When you play a chord, both the order of the note pitches, and the order of the played notes changes quickly several times before the chord is “stable”. For example if you play an Am chord (ACE), your fingers might actually press the keys in a different order: A, AE, ACE. In this case the order changes twice.

  • pejman on said:

    Thanks for reply 🙏.

    I completely understand what you mean.

    I think in some cases this problem can be ignored ,
    For example This problem exists in many arpeggiators that have programming capabilities ( The ability to put chord note numbers in the specific steps ) . Which is exactly what you mentioned . But we still use it .

    I use BLEASE ARP app . It hasn’t program section. So i need to send only lowest or highest or second or third chord notes to BLEASS arp ,

    The importance of this matter is more than that I want to completely ignore it because of a wrong note that is likely to be in the first step or one of steps of the arpeggiator.

    I will be very grateful if you agree to add this feature to LATCH AND SWITCH. 🙏

  • Leave a Reply

      220 PM
    • Platform:
    • Category: Other Utility
    • Revision: 2.3
    • License: Do What The F*ck You Want To Public License
    • Modified: 3 months ago
    • Views: 584
      Likes: 11
      Downloads: 22
    Download
    Chat