Creating a MIDI trill effect
This example shows how to create a MIDI “trill” effect, with a randomized rhythm, triggered when a particular incoming MIDI value is detected or when a specified audio amplitude threshold has been reached.
This example shows how to create a MIDI “trill” effect, with a randomized rhythm, triggered when a particular incoming MIDI value is detected or when a specified audio amplitude threshold has been reached.
This example shows three conditions to trigger a bang when incoming values either increase or decrease.
1. A single bang is sent whenever a value goes down below a specific number. In this case, when the value in the slider is below 96.
In this example, the horizontal location of the mouse in the screen is used to determine whether to send a bang or not. The mouse moving from one side of the screen, passing the mid point to the other side of the screen, causes a bang to be sent to the gswitch2 object.
If you know the peak value you’re looking for, you can use sel, >=, peak, or past. If you’re looking at a stream of data coming in in real time and you don’t know what value you’re looking for, then you can only report that a peak has occurred after the peak has been reached, once the input value has started to decrease. This example does just that.
This patch shows an idea for an automated improvising algorithm. At regular intervals of time, which one might think of as the length of a musical phrase (every 1.6 seconds in this example), the metro object chooses a new random number from 0 to 35. That number will be considered a target number toward which the line object should go.
The most direct way to convert one range of numbers into a different range of numbers is a process called linear mapping. For each number in a source (input) range, find the corresponding number in a destination (output) range. The process is to multiply the input value by the size of the destination range (destination maximum minus destination minimum) divided by the source range (source maximum minus source minimum), then add the destination minimum to that.
To translate numbers that occupy a particular range into an equivalent set of numbers in a different range, one common and useful technique is "linear mapping". The term "mapping" refers to making conceptual connections between elements of one domain and elements of another, and "linear" mapping refers to using a mapping function that is a straight line––that is, such that numbers in one domain are mapped to an exactly equivalent position in the new domain. This is a very common and useful operation in media programming.
You can assign input data to have a different function at different times, simply by sending it to different parts of your program. For example, if you have a control device such as a MIDI keyboard or other MIDI controller with a limited number of keys, buttons, knobs, or faders, you can assign one control element to be the mode selector that changes the functionality of all the other elements.
Here are three ways of generating MIDI notes. Admittedly they don't result in very interesting music, but they show ways how numbers can be converted for usage as pitch information.