Online music jam/Global Metronome/Mathematical Aspects

Workflow to create an Global Metronome edit

The following steps are based on basic mathematical principles and show the underlying arithmetic. Basically a global metronom refers to a global zero of time (not the Big Bang - it is January 1st 1970, 0:00am). We assume that all metronoms start with the first beat on the January 1st 1970 and dependent on the beats per minute and the beats per measure a global metronom has the same reference point in time (see https://niebert.github.io/globalmetronome for testing).

Miliseconds, Seconds, Minutes and Beats Per Minute edit

At first we define global time stamps for the beats with a global zero as time stamp:

  • (Global Zero Time Stamp) Define a initial joined time stamp   is in general a number, representing the number of milliseconds since midnight January 1, 1970. This is the global reference point.
  • (Beats Per Minute - BPM) The bpm beats per minutes define the beat. First of all we calculate the milliseconds between to beats. It is important to keep the duration in milliseconds as integer values, so we round all calculations from float to integer values. Lets do the basic calculations.
  • (Second) 1000 milliseconds   1 second
  • (Minute) 60 seconds   1 minute   60000 milliseconds
  • (Beats Per Minute - BPM) if the tempo is defined by 120bpm then a single beat has the duration of   milliseconds. Let us perform another calculation with 111bpm an then the duration of a single beat is  . We will round the value always to an integer value, i.e. with 111bpm we use as beat duration 541 milliseconds.
  • (Global Beat Time) we want to have a global time stamp of beat, so we start the metronome theoretically at all location at   and the first beat (independent from the defined bpm value) will alway be at  . The next beats for 120bpm will be at  ,  ,  , .... The next beats for 111bpm will be at  ,  ,  , ....

Current Time in Milliseconds edit

Even in a browser you can determine the current time in milliseconds e.g. with Javascript

  var n = Date.now();

On the 3rd of June 2021 the value of   was  . For 120bpm you could add 500 milliseconds is the duration of the beat and we could add 500 until we exceed the current timestamp. So the next global beat would be at  ,  , ...

For the beat duration of 500 milliseconds we could easily determine the next beat by looking at the last 3 digits in the number   (i.e. "...012" and the next beat will be at "...500", "...000", "...500", ...

For other beat durations in milliseconds we cannot use the last 3 digits approach. We need an efficient iteration.

Efficient Iteration edit

Of course the iteration with the basic beat duration provides mathematically the correct time stamp for the next beat. Nevertheless looking at the correct mathematical approach from the computer science angle then the iteration is time consuming. As a consequence we would like to perform the iteration with larger time steps to calculate the next beat and also determine the next "1" in a measure/bar. We will calculate the timesteps in milliseconds in integer values. The following calculations are performed for "111bpm" and a beat duration of 541 milliseconds per beat.

Meter of the Measure/Bar edit

We also have to consider the meter in which the online Jam is performed because a metronome could have an accent on the 1 and 2,3,4 in a measure does not have an accent in the measure. The meter is e.g. 3 for a waltz and e.g. 5 for the Jazz standard "Take Five". Now we calculate in meter steps to identify also the next "1" in the measure/bar,

  • The next 1 in measure/bar   milliseconds for 4 beats, measure duration is   milliseconds.

Now we add to   an integer value of the type   until we exceed the current time stamp  .

  • we can add   without exceeding  
  • we can add   without exceeding  
  • we can add   without exceeding  
  • we can add   without exceeding  
  • we can add   without exceeding  
  • we can add   without exceeding  
  • we can add   without exceeding  
  • we can add   without exceeding  
  • we can add   without exceeding  

Now we add 2164 to 1622727305704 and we get with 1622727307868 the next global "1" in the next measure/bar after  .