Home Page

Functions And Keywords Page

Alphabetical Index

Next Topic

Previous Topic

Sample Programs

Updates And Corrections


Musical Time Functions

There are two ways of keeping time in a sequence recognized by Cakewalk and CAL. The first is in terms of measures, beats and ticks called "M:B:T" time and the other is in the form of a 32-bit number referred to as "raw" time. To put it simply, raw time is a count of the number of clock ticks from the start of a sequence to the end. M:B:T time is that same number divided by the number ticks per beat and that amount further divided by the number of beats in the current song's meter. The result is formatted in standard musical time notation with the remainder number of ticks included for accuracy. At raw time zero, the musical time is 1:1:0 or measure 1, beat 1, tick 0. Note that you cannot have a measure or beat number 0. This is convention as established by hundreds of years of musical tradition and Cakewalk has no intention of flying in the face of it. What Cakewalk adds is the "tick" component. Because events must be precisely located within a musical score, the ticks provide the necessary resolution without having to resort to stuff like 256th notes. Can you imagine how obnoxious such notes would be on paper with all of those little flags on the staff? By using ticks and setting the number of ticks per beat or quarter note, a sequence can record human feel without having to note it in the score, just like the real musicians play. The constant "TIMEBASE" makes the user's setting of the number of ticks per beat available to CAL for calculations and evaluations . The default value is 120 ticks per beat but this can be changed from the front panel. The user can also set the meter from the front panel and thus select 4/4 or 3/4 or 7/8 or whatever meter they want. These settings are then used to calculate the M:B:T time from raw time and vice versa. To facilitate this conversion from human to computer time keeping, CAL has provided us with a set of conversion functions. If you recall our discussion of the "getTime" function, which allows the user to input a time in M:B:T format and let CAL store it as a double word in raw time format (at least in versions other than 7 and 8), we saw an example of a time keeping conversion function. Here are the rest.
 
(meas rawtime)
(beat rawtime)
(tick rawtime)
These functions take the raw time, or a function that resolves to a value of raw time and calculates the proper number of measures, beats or ticks as they would appear in the "Now" window on the front panel. If you wanted to display this information to the user in a dialog box at some point in the program, you could do something like this:
 
(pause "The time is " (meas Event.Time) ":" (beat Event.Time) ":" (tick Event.Time) " at event " (index))
 
Assuming that the "Event.Time" is, say, 22368, the "TIMEBASE" and meter settings are 120 and 4/4 and the current event being scanned by the "forEachEvent" loop is number 2245, the "pause" dialog box would display:
 
The time is 47 :3 :48 at event 2245
 
(makeTime measure beat tick)
This is the reciprocal to the above conversion functions. Like "getTime", this function takes values (or functions resulting in values) for measure, beat and tick and returns a raw time. Like math functions, these functions are meant to be part of a larger function where the resulting calculations can be output or assigned to some variable. Check this out:
 
(insert (makeTime measure beat tick) channel WHEEL value)
Here we have inserted a pitch wheel event at a time calculated from separate measure, beat and tick variables.
 
Next Topic Top Of Page