Skip to content

Latest commit

 

History

History
131 lines (88 loc) · 8.49 KB

scale.md

File metadata and controls

131 lines (88 loc) · 8.49 KB

Sharp11 Scale Module

require('sharp11').scale

Contains a Scale object, which can be created with scale.create(), and a TraversableScale object, which can be created by calling .traverse() on a Scale object. Methods of these objects do not mutate them, they return a new objects.

Exported Functions

scales .scales

An object mapping scale names to arrays. Each array contains strings representing the intervals in the scale, not including the root.

precedence .precedence

An array of scale names in order of how commonly used they are. This order is used in the .scales() method of the Chord object.

create .create(key, scaleName)

Returns a Scale object. key is a Note object or string representing the key (or root) of the scale. scaleName is a string containing the name of the scale. scaleName is converted to lowercase and spaces are replaced with underscores. Sharp11 supports a wide variety of scales as well as aliases, so Superlocrian, Altered, and Diminished Whole Tone will all work.

isScale .isScale(obj)

Returns true if an object is a Scale or a TraversableScale.

isTraversable .isTraversable(object)

Returns true if a given object is a TraversableScale.

Scale Object

Scale objects consist of a key and a scale name. A Scale may or may not have octave numbers depending on whether or not the key parameter does. Octave numbers behave as expected, so a major scale with a key of G4 will contain the notes G4, A4, B4, C5, D5, E5, F#5. The Scale constructor is accessible directly as .Scale, however new instances should be created using .create() instead.

key .key or .root

A Note object representing key of the scale.

name .name

A string representing the name of the scale (capitalized, spaces between words), e.g., "Harmonic Minor". .name should not be used for comparing scales, because scale.create('minor') and scale.create('natural minor') will produce the same scale but with different .names.

id .id

A string representing the name of the scale (lowercase, underscores between words), e.g., "harmonic_minor" .ids are one-to-one with scales and thus can be used for comparison.

fullName .fullName

A string representing the name of the scale including the key, e.g., "Bb Harmonic Minor".

octave .octave

The (optional) octave number of the scale, i.e., an integer between 0 and 9, or null.

scale .scale

An array of Note objects representing the notes in the scale, e.g., [C, D, E, F, G, A, B]

intervals .intervals

An array of Interval objects representing the intervals in the scale, including the root.

descending .descending()

Returns an array of Note objects representing the notes in the scale descending, starting with the root. .descending() takes into account the abnormal nature of the melodic minor.

clean .clean()

Applies note.clean() to the key and all the notes in the scale.

transpose .transpose(interval, down)

Transposes the scale, applying note.transpose().

transposeDown .transposeDown(interval)

Calls .transpose(interval, true).

nearest .nearest(note)

Returns a Note representing the nearest note on the scale to a given note (Note object or string). Octave numbers are ignored. If there are two nearest notes, the lower will be returned.

contains .contains(note)

Returns true if the given note is in the scale, following the rules of note.containedIn().

inOctave .inOctave(octave)

Returns the scale in a given octave number.

hasInterval .hasInterval(interval)

Returns true if a given interval (Interval object or string) is in the scale.

traverse .traverse(note)

Returns a TraversableScale whose current note is the given note (Note object or string). The given note must have an octave number.

TraversableScale Object

TraversableScale objects contain a scale and a current index and are created by calling .traverse() on a Scale object. TraversableScales can be thought of as a combination of a note and a scale and allow you to easily traverse the scale, as the name implies. They are instrumental (pun intended) in Sharp11's improvisation engine. The TraversableScale constructor is accessible directly as .TraversableScale, however new instances should be created by calling .traverse() on a Scale object instead.

scale .scale

A Scale object representing the scale.

index .index

The index of the scale's current note, starting at 0. .index is mostly used internally, whereas .current() returns the actual note.

octave .octave

Returns the octave number that the scale is currently in. This is the same as the octave number of the scale's root.

length .length

The number of notes in one octave of the scale, equal to .scale.scale.length.

name .name

See .name.

id .id

See .id.

fullName .fullName

See .fullName.

current .current()

Returns a Note object representing the scale's current note.

clean .clean()

See .clean().

transpose .transpose(interval, down)

See .transpose().

transposeDown .transposeDown(interval)

See .transposeDown().

shift .shift(numSteps)

Shifts the current note of the scale by a given number of positions, positive or negative. The resulting scale may have a different octave number depending on how far it has been shifted.

shiftInterval .shiftInterval(interval, down)

Shifts the current note of the scale by a given interval, applying note.transpose(). The resulting scale may have a different octave number depending on how far it has been shifted. Throws an error if the transposed note is not in the scale.

random .random()

Makes the current note of the scale a random note in the scale.

withCurrent .withCurrent(note)

Makes the current note of the scale the given note (Note object or string).

nearest .nearest(note)

See .nearest().

contains .contains(note)

See .contains().

hasInterval .hasInterval(interval)

See .hasInterval().

descending .descending()

See .descending().