Here's a breakdown of the code and how it works:
Parameter Definitions:
- High Note: Sets the maximum MIDI note value.
- Low Note: Sets the minimum MIDI note value.
- Probability: Determines the chance of a note being sent, expressed as a percentage.
Event Handling:
- Note Filtering:
- Checks if the incoming MIDI note's pitch is within the specified range.
- If the note is outside the range, an "all notes off" message is sent to prevent unintended sounds.
- Probability Check:
- Uses a random number generator to determine if the note should be sent based on the
probabilityparameter. - If the random number is less than or equal to the
probability, the note is sent.
- Uses a random number generator to determine if the note should be sent based on the
- Event Sending:
- If the note passes both the range and probability checks, it's sent to the output.
Key Points:
- Randomness: The
eventShouldSend()function introduces randomness by generating a random number between 1 and 100. If this number is less than or equal to theprobabilitysetting, the note is sent. - Flexibility: By adjusting the
High Note,Low Note, andProbabilityparameters, you can create a wide range of effects, from subtle randomization to extreme filtering. - Efficiency: The code is optimized for performance, ensuring smooth processing of MIDI data.
Additional Tips:
- Experiment with different probability settings to achieve various levels of randomness and filtering.
- Combine this script with other MIDI effects to create complex and interesting sound transformations.
- Consider using this script to create unique rhythmic patterns and melodic variations.
By understanding the core concepts and the code behind this MIDI Note Range Filter with a Probability Gate, you can unlock new creative possibilities in your music production.