Key:
Filter:
TuningLib/Classes (extension) | Tuning > TuningLib

Key
ExtensionExtension

Handles key changes

Description

Keeps track of key changes and adjusts the tuning of the current scale accordingly. This class works for any tuning system.

Also can quantize a given semitone, cents value or frequency into the currently used scale

Class Methods

.new

create a Key

Arguments:

scale

The current scale

root

The index of the scale root

Instance Methods

.change

Change the current Key. This works correctly with both ET and JI.

Arguments:

degree

The degree of the scale to modulate by. If it and chromatic are nil, revert to previous state.

chromatic

the chromatic interval to modulate by

.mode

changes the mode of the current key

Arguments:

mode

an array of degrees or a key from ScaleInfo. If nil, it revcerts to previous mode

.quantize

Snaps a semitone to the nearest semitone in the current key

Arguments:

semitone

the tone to be quantized, or an array of semitones

round

round: has three modes:

  • \nearest round to the nearest scale semitone
  • \up always round to the semitone above
  • \down always round to the semitone below

gravity

determines how strong the attraction is:

  • 1 = fully quantized
  • 0 = no quantization
  • 0<x<1 interpolate between unquantized and fully quantized values

Returns:

quantised semitone

.quantizeFreq

Snaps the feq value in Hz to the nearest Hz value in the current key

Arguments:

freq

in Hz

base

The base frequency, or root frequency

round

has three modes:

  • \nearest round to the nearest scale frequency
  • \up always round to the scale frequency above
  • \down always round to the nearest scale freq below

gravity

determines how strong the attraction is:

  • 1 = fully quantized
  • 0 = no quantization
  • 0<x<1 interpolate between unquantized and fully quantized values

Returns:

quantised frequency

.quantizeCents

snaps a cents value to the nearest semitone in the current key

Arguments:

cent

the cents value to be quantized, or an array of cents

round

has three modes:

  • \nearest round to the nearest scale degree
  • \up always round to the degree above
  • \down always round to the degree below

gravity

determines how strong the attraction is:

  • 1 = fully quantized
  • 0 = no quantization
  • 0<x<1 interpolate between unquantized and fully quantized values

Returns:

quantised cents

.freqToDegree

rounds a frequency to the neast degree in the current key

Arguments:

freq

in Hz

base

The base frequency, or root frequency

round

has three modes:

  • \nearest round to the nearest scale degree
  • \up always round to the degree above
  • \down always round to the degree below

Returns:

the quantized degree.

NOTE: The return value is the scale step, NOT the semitone.

Examples