addKeySignature method

dynamic addKeySignature({
  1. required int track,
  2. required num time,
  3. required int no_of_accidentals,
  4. required int accidental_type,
  5. required int accidental_mode,
  6. dynamic insertion_order = 0,
})

Add a Key Signature to a track :param track: The track to which this should be added :param time: The time at which the signature should be placed :param accidentals: The number of accidentals in the key signature :param accidental_type: The type of accidental :param mode: The mode of the scale The easiest way to use this function is to make sure that the symbolic constants for accidental_type and mode are imported. By doing this: .. code:: from midiutil.MidiFile import * one gets the following constants defined:

  • SHARPS
  • FLATS
  • MAJOR
  • MINOR So, for example, if one wanted to create a key signature for a minor scale with three sharps: .. code:: MyMIDI.addKeySignature(0, 0, 3, SHARPS, MINOR)

Implementation

/// :param track: The track to which this should be added
/// :param time: The time at which the signature should be placed
/// :param accidentals: The number of accidentals in the key signature
/// :param accidental_type: The type of accidental
/// :param mode: The mode of the scale

/// The easiest way to use this function is to make sure that the symbolic
/// constants for accidental_type and mode are imported. By doing this:

/// .. code::

///     from midiutil.MidiFile import *

/// one gets the following constants defined:

/// * ``SHARPS``
/// * ``FLATS``
/// * ``MAJOR``
/// * ``MINOR``

/// So, for example, if one wanted to create a key signature for a minor
/// scale with three sharps:

/// .. code::

///     MyMIDI.addKeySignature(0, 0, 3, SHARPS, MINOR)

addKeySignature(
    {required int track,
    required num time,
    required int no_of_accidentals,
    required int accidental_type,
    required int accidental_mode,
    insertion_order = 0}) {
  if (this._header.numeric_format == 1) {
    track = 0; // User reported that this is needed.
  }

  this._tracks[track].addKeySignature(this._time_to_ticks(time),
      no_of_accidentals, accidental_type, accidental_mode,
      insertion_order: this._event_counter);
  this._event_counter += 1;
}