Free Wah Auto-Engage Script for Plug’n Script

When controlling a virtual Wah pedal with an expression pedal via MIDI, it is convenient to have a built-in tip switch to activate the Wah effect when pushing the pedal.

However what if all you have is a regular expression pedal without an extra tip switch? Call Plug’n Script to the rescue! Whether you are playing guitar, bass or keyboards (or whatever instrument you want to use a Wah pedal for), you will want to try this script!

Here is an auto-engage script that will automatically send an extra MIDI CC event to enable the effect when the pedal moves above a threshold, and another CC event to disable it when the pedal stays under the threshold for enough time.

/** \file
* auto engage MIDI CC
*/

#include "./library/Midi.hxx"

// metadata
string name="MIDI Auto-Engage";
string description="Create MIDI CC on/off from moving pedal events";

// parameters
array<string> inputParametersNames={"Channel", "Source CC","Dest CC","Threshold","Delay"};
array<double> inputParameters(inputParametersNames.length);

array<double> inputParametersMin={0,1,1,1,0};
array<double> inputParametersMax={16,127,127,127,2000};
array<double> inputParametersDefault={0,1,7,4,500};
array<int> inputParametersSteps={17,128,128,128,128};
array<string> inputParametersFormats={".0", ".0", ".0" , ".0" ,".0"};
array<string> inputParametersUnits = { "", "", "" , "" ,"ms" };


double pauseTimeInSamples = 0;
bool enabled = false;
uint8 lastCCvalue=0;

// local variables
MidiEvent tempEvent; ///< defining temp object in the script to avoid allocations in time-critical processBlock function

/* per-block processing function: called for every block with updated parameters values.
*
*/
void processBlock(BlockData& data)
{
    // reading parameters
    uint8 sourceChannel = int8(inputParameters[0]+.5);
    uint8 sourceCC = int8(inputParameters[1] + .5);
    uint8 destCC = int8(inputParameters[2]+.5);
    uint8 threshold = int8(inputParameters[3] + .5);

    // iterating on MIDI events
    for(uint i=0;i<data.inputMidiEvents.length;i++)
    {
        // check MIDI events from incoming channel
        uint8 eventChannel=MidiEventUtils::getChannel(data.inputMidiEvents[i]);
        if((eventChannel==sourceChannel || sourceChannel==0) 
        && (MidiEventUtils::getType(data.inputMidiEvents[i])==kMidiControlChange) 
        && MidiEventUtils::getCCNumber(data.inputMidiEvents[i])==sourceCC)
        {
            // received MIDI CC => no pause
            pauseTimeInSamples = 0;

            // update last cc value, and create ON event if not enabled yet and value above threshold
            tempEvent = data.inputMidiEvents[i];
            lastCCvalue = MidiEventUtils::getCCValue(tempEvent);
            if (!enabled && lastCCvalue >= threshold)
            {
                enabled = true;
                MidiEventUtils::setCCNumber(tempEvent, destCC);
                MidiEventUtils::setCCValue(tempEvent, 127);
                data.outputMidiEvents.push(tempEvent);
            }
         }
    }

    // below threshold?
    if (lastCCvalue < threshold)
    {
        // send off event if paused since enough time
        if (enabled && (pauseTimeInSamples >= inputParameters[4]*.001 * sampleRate))
        {
            enabled = false;
            tempEvent.timeStamp = 0;
            MidiEventUtils::setCCNumber(tempEvent, destCC);
            MidiEventUtils::setCCValue(tempEvent, 0);
            data.outputMidiEvents.push(tempEvent);
        }

        // update pause time
        pauseTimeInSamples += data.samplesToProcess;
    }
}

Copy and paste this script into a text file, save it with the cxx extension into the Plug’n Script’s user scripts folder, and load it into Plug’n Script. You can also get it here on our GitHub scripts repository.

You can choose the MIDI channel and the source CC number (the one used by the expression pedal), as well as the destination CC number (for the enable/disable event). Threshold and delay time let you choose the time to wait before disabling as well as the position where the pedal should be to disable the effect (usually a small value so that the effect gets disabled when the Wah is down).

Enjoy!

>discuss this topic in the forum

2 thoughts on “Free Wah Auto-Engage Script for Plug’n Script

  1. Hello,
    I copied the script into a text editor, saved it with .cxx extension, placed on my system in
    C:\Users\xxxxxxxxx\Documents\BlueAudio\Blue Cat’s Plug’n Script\Scripts\library.
    Opened Blue cat’s Plug’n Script plugin in Ableton Live.
    Tried to Load the script into the plugin but says its not recognized as a valid script. The plugin appears to be expecting a ‘Preset’ file. Also I noticed that all the other Bluecat factory scripts are with .hxx extension.
    What am I doing wrong (?) as
    Please give me further instructions for where to place and is there some other scripting SW I need to write with.
    Bluecat docs seems to only mention writing scripts for the plugin in Angelscript which look complex as the documentation goes on for many pages…is this type of script the only one that Bluecat Scripts plugin understands?
    -Mike

    1. You should actually place it in the C:\Users\xxxxxxxxx\Documents\BlueAudio\Blue Cat’s Plug’n Script\Scripts\ directory (not inside the library – the include paths will then fail).No need for a preset, simply loading the script from this directory should work.

Leave a Reply

Your email address will not be published. Required fields are marked *