Key Handles key changes



Keeps track of key changes and adjusts the tuning of the current scale accordingly.

Also can quantize a given semitone, cents value or frequency to the current scale.


Creation / Class Methods


*new (scale )

create a Key

scale - The current scale. 

// Example

a = Scale.choose;

k = Key(a);


Accessing Instance and Class Variables


change (degree)

Change the current Key

degree - The degree of the scale to modulate by. If nil, revert to previous state. Default value is nil.

// Example

k = Key(Scale.choose);

k.scale.degrees;

k.scale.cents;

k.change(4); // modulate to the 5th scale degree (we start counting with 0)

k.scale.degrees;

k.scale.cents;

k.change(4); // modulate to the 5th scale degree (in the new key)

k.scale.degrees;

k.scale.cents;

k.change; // modulate back from the V/V degree

k.scale.degrees;

k.scale.cents;

k.change; // modulate back from the 5th scale degree

k.scale.degrees;

k.scale.cents;


quantizeFreq (freq, base, round , gravity )

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

freq - in Hz. 

base - The base frequency, or root frequency. Default value is 440.

round - has three modes. Default value is 'off'.

\off do not round the answer

\up round the aswer to the nearest scale freq above

\down found the answer to the nearest scale freq below

gravity - determines how strong the attraction is. Default value is 1.

1 = fully quantized

0 = no quantization

0<1 interpolate between unquantized and fully quantized values

// Example

a = Scale.choose;

k = Key(a);

k.quantizeFreq(660, 440);



quantizeCents (cent, round )

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

cents - the cents to be quantized, or an array of cents. 

round - has three modes. Default value is 'off'.

\off do not round the answer

\up round the aswer to the nearest scale freq above

\down found the answer to the nearest scale freq below

// Example

a = Scale.choose;

k = Key(a);

k.quantizeCents(1150);



quantize (semitone, round )

Snaps a semitone to the nearest semitone in the current key

semitone - the tone to be quantized, or an array of semitones. 


round - has three modes. Default value is 'off'.

\off do not round the answer

\up round the aswer to the nearest scale freq above

\down found the answer to the nearest scale freq below

// Example

a = Scale.choose;

k = Key(a);

k.quantize(11.5, \up);

k.quantize([0.1, 3.5, 7.4], \down);