Data AcQuisition And Real-Time AnalysisScope - Spectrum - Spectrogram - Signal Generator
Software for Windows
Science with your Sound Card!
Contact us about
MIDI Changes Script Wait
A Wait command pauses the execution of the MIDI Changes script for a specified number of beats. You use this to time the operation of the other script commands. For example, if you want to change the Instrument for Voice 2 to a Trumpet (MIDI instrument number 56) after 32 beats, you could use:
Typically, a script will have multiple Waits such that one pass through the entire script represents some sort of cycle. (Scripts automatically repeat by default.) In the above case you would probably want to change the instrument to something else at another time in the script. Otherwise, the instrument would change to a Trumpet and never change back. As a simple example, you could change it to a Soprano Sax (64) after another 32 beats:
W=32 I2=56 W=32 I2=64
This will alternate between Trumpet and Soprano Sax, changing every 32 beats.
The Wait interval must be an unsigned integer, but it does not need to be a constant; you can use any valid expression, including current MIDI control values, random values, current computer keyboard states or mouse position, input or buffered notes, or oscillators. If the value is zero, there is no Wait and the next command is processed immediately.
For example, to wait for a random interval between 32 and 48 beats, you would use W=?(32,48).
To specify a Wait interval in seconds instead of beats, you can compute beats using the current Tempo in beats/min (TB) or msec per beat (T). For example, if variable US holds the desired number of seconds, you can use:
The above assume integer seconds. For finer resolution you can use fixed-point math. The following assumes Us holds seconds, which may include a fractional part:
By using the intermediate fixed-point variable Uw, the fractional part of Us is preserved during the expression evaluation. It is only converted to an integer when assigned to W in the final statement.
Note: Every Changes script must have at least one Wait command. Otherwise, it would stick in an endless loop on the first beat, furiously executing the same script commands over and over and never getting around to playing any notes.
If there are no Wait commands in the Changes script, the Changes debugger will report "No Waits in Changes script, Voice 2" (or whatever Voice) and will not allow the performance to run.
If a Wait command is present but the specified Wait expression evaluates to zero, the Changes command processor may make an entire pass through the script without a single Wait. In that case, processing of that script stops for one beat, allowing other scripts to run and notes to play.
Similarly, every Loop in a script also requires one or more Waits.
When W is read as a variable, it returns the total elapsed milliseconds since Daqarta was started. You can use this to allow Changes actions at controlled intervals, without using a specific Wait that would block other operations.
For example, supose you want a performance to change Tempo every minute or so. You can set a User Variable to the current time at the start of the performance via UT=W. Then at some convenient place in the script you can see if it is time to take action. The basic idea is to use an IF statement to monitor the difference between the current W value and the UT initial value:
[W-UT>60000 TB=?(100,400) UT=W]
If the current time is 60000 msec (1 minute) more than the initial value, the Tempo is randomly set to a value between 100 and 400 BPM. Then UT is reset to the current time so this will not be activated again until another minute has elapsed.
Because it resets UT after taking action, this script line can be run as often as you like, and can even appear in multiple places in your script, and in the scripts of multiple voices.
And because it deals with absolute time (instead of waiting for a certain nunber of beats like a normal Wait command), it will take action at the same rate regardless of the current Tempo.
Of course, you don't need to use a constant interval; instead of the 60000 msec used here, you could use a random value or a slow oscillator, for instance.
Questions? Comments? Contact us!We respond to ALL inquiries, typically within 24 hrs.
Over 30 Years of Innovative Instrumentation
© Copyright 2007 - 2017 by Interstellar Research
All rights reserved