addTimeSignature method
Add a time signature event.
:param track: The track to which the signature is assigned. Note that
in a format 1 file this parameter is ignored and the event is
written to the tempo track
:param time: The time (in beats) at which the event is placed.
In general this should probably be time 0 (the beginning of the
track).
:param numerator: The numerator of the time signature. Int
:param denominator: The denominator of the time signature, expressed as
a power of two (see below). Int
:param clocks_per_tick: The number of MIDI clock ticks per metronome
click (see below).
:param notes_per_quarter: The number of annotated 32nd notes in a MIDI
quarter note. This is almost always 8 (the default), but some
sequencers allow this value to be changed. Unless you know that
your sequencing software supports it, this should be left at its
default value.
The data format for this event is a little obscure.
The denominator
should be specified as a power of 2, with
a half note being one, a quarter note being two, and eight note
being three, etc. Thus, for example, a 4/4 time signature would
have a numerator
of 4 and a denominator
of 2. A 7/8 time
signature would be a numerator
of 7 and a denominator
of 3.
The clocks_per_tick
argument specifies the number of clock
ticks per metronome click. By definition there are 24 ticks in
a quarter note, so a metronome click per quarter note would be
24. A click every third eighth note would be 3 * 12 = 36.
The notes_per_quarter
value is also a little confusing. It
specifies the number of 32nd notes in a MIDI quarter note. Usually
there are 8 32nd notes in a quarter note (8/32 = 1/4), so
the default value is 8. However, one can change this value if
needed. Setting it to 16, for example, would cause the music to
play at double speed, as there would be 16/32 (or what could be
considered two quarter notes for every one MIDI quarter note.
Note that both the clocks_per_tick
and the
notes_per_quarter
are specified in terms of quarter notes,
even is the score is not a quarter-note based score (i.e.,
even if the denominator is not 4
). So if you're working with a
time signature of, say, 6/8, one still needs to specify the clocks
per quarter note.
Implementation
/// :param track: The track to which the signature is assigned. Note that
/// in a format 1 file this parameter is ignored and the event is
/// written to the tempo track
/// :param time: The time (in beats) at which the event is placed.
/// In general this should probably be time 0 (the beginning of the
/// track).
/// :param numerator: The numerator of the time signature. [Int]
/// :param denominator: The denominator of the time signature, expressed as
/// a power of two (see below). [Int]
/// :param clocks_per_tick: The number of MIDI clock ticks per metronome
/// click (see below).
/// :param notes_per_quarter: The number of annotated 32nd notes in a MIDI
/// quarter note. This is almost always 8 (the default), but some
/// sequencers allow this value to be changed. Unless you know that
/// your sequencing software supports it, this should be left at its
/// default value.
/// The data format for this event is a little obscure.
/// The ``denominator`` should be specified as a power of 2, with
/// a half note being one, a quarter note being two, and eight note
/// being three, etc. Thus, for example, a 4/4 time signature would
/// have a ``numerator`` of 4 and a ``denominator`` of 2. A 7/8 time
/// signature would be a ``numerator`` of 7 and a ``denominator``
/// of 3.
/// The ``clocks_per_tick`` argument specifies the number of clock
/// ticks per metronome click. By definition there are 24 ticks in
/// a quarter note, so a metronome click per quarter note would be
/// 24. A click every third eighth note would be 3 * 12 = 36.
/// The ``notes_per_quarter`` value is also a little confusing. It
/// specifies the number of 32nd notes in a MIDI quarter note. Usually
/// there are 8 32nd notes in a quarter note (8/32 = 1/4), so
/// the default value is 8. However, one can change this value if
/// needed. Setting it to 16, for example, would cause the music to
/// play at double speed, as there would be 16/32 (or what could be
/// considered *two* quarter notes for every one MIDI quarter note.
/// Note that both the ``clocks_per_tick`` and the
/// ``notes_per_quarter`` are specified in terms of quarter notes,
/// even is the score is not a quarter-note based score (i.e.,
/// even if the denominator is not ``4``). So if you're working with a
/// time signature of, say, 6/8, one still needs to specify the clocks
/// per quarter note.
addTimeSignature(
{required int track,
required num time,
required int numerator,
required int denominator,
required clocks_per_tick,
notes_per_quarter = 8}) {
if (this._header.numeric_format == 1) {
track = 0;
}
this._tracks[track].addTimeSignature(this._time_to_ticks(time), numerator,
denominator, clocks_per_tick, notes_per_quarter,
insertion_order: this._event_counter);
this._event_counter += 1;
}