Skip to content

Latest commit

 

History

History
1105 lines (971 loc) · 39 KB

README.md

File metadata and controls

1105 lines (971 loc) · 39 KB

zazate.js

Zazate.js is music theory and notation package or module for Javascript, can be used by programmers, musicians, composers and researchers to make and investigate music. Zazate.js is integrated with a big numbers of functions related to find notes, chords and intervals.

Features

  • Work with notes, intervals, chords, scales, keys and meters in a simple and theoretically sound way.
  • Generate natural diatonic intervals (seconds, thirds, fourths, etc) and absolute intervals (minors second, perfect fifths, etc.)
  • Generate natural diatonic triads, seventh chords, and absolute chords directly or from shorthand (min7, m/M7, etc). zazate.js also knows about inversions, slashed chords and polychords.
  • Refer to chords by their diatonic function (tonic, subtonic, etc. or I, ii, iii, IV, etc).
  • Work with diatonic scales and their modes (ionian, mixolydian, etc.), generate the minor (natural, harmonic and melodic) and chromatic or whole note scales.
  • Recognize intervals, scales and hundreds of chords from lists of notes.
  • Recognize the harmonic functions of chords.

Installation

via npm:

$ npm install zazate.js

Usage

var zazate = require('zazate.js');
var result = zazate.notes.augment('C');
console.log(result); // print 'C#'

Use this syntax

var zazate = require('zazate.js');
zazate.<library>.<function>(arg1, arg2...);

In zazatz.js, there are the following libraries:

  • notes
  • diatonic
  • intervals
  • chords
  • scales
  • meter
  • values (need documentation)
  • progressions (not full yet)

See functions of each library in documentation below.

Documentation

Index

More documentation is coming soon!!

### notes --------------------------------------- #### fifths Just a list(array): ['F', 'C', 'G', 'D', 'A', 'E', 'B']
#### augment(note) Augments the given note ```js zazate.notes.augment('C'); // return 'C#' zazate.notes.augment('Cb'); // return 'C' ```
#### diminish(note) Diminishes the given note ```js zazate.notes.diminish('C'); // return 'Cb' zazate.notes.diminish('C#'); // return 'C' ```
#### is_enharmonic(note1, note2) Test whether note1 and note2 are enharmonic, ie. they sound the same
#### is_valid_note(note) Returns true if note is in a recognised format. false if not
#### note_to_int(note) Converts notes in the form of C, C#, Cb, C##, etc. to an integer in the range of 0-11. Throws an Error exception if the note format is not recognised.
#### int_to_note(note_int) Converts integers in the range of 0-11 to notes in the form of C or C# (no Cb). You can use int_to_note in diatonic_key to do theoretically correct conversions that bear the key in mind. Throws a Error exception if the note_int is not in range(0,12).
#### remove_redundant_accidentals(note) Removes redundant #'s and b's from the given note. For example: C##b becomes C#, Eb##b becomes E, etc.
#### to_major(note) Returns the major of note. ```js zazate.notes.to_major('A'); // return 'C' ```
#### to_minor(note) Returns the minor of note. ```js zazate.notes.to_minor('C'); // return 'A' ```
### diatonic --------------------------------------- #### basic_keys Just a list(array): ['Gb', 'Db', 'Ab', 'Eb', 'Bb', 'F', 'C', 'G', 'D', 'A', 'E', 'B', 'F#', 'C#', 'G#', 'D#', 'A#']
#### get_notes(key) Returns an ordered list of the notes in this key. For example: if the key is set to 'F', this function will return ['F', 'G', 'A', 'Bb', 'C', 'D', 'E']. Exotic or ridiculous keys like 'C####' or even 'Gbb##bb#b##' will work; Note however that the latter example will also get cleaned up to 'G'. This function will raise an Error if the key isn't recognised
#### int_to_note(note_int, key) A better implementation of int_to_note found in the [notes](#notes) module. This version bears the key in mind and thus creates theoretically correct notes. Will throw an Error if note_int is not in range(0,12)
#### interval(key, start_note, interval) Returns the note found at the interval starting from start_note in the given key. For example interval('C', 'D', 1) will return 'E'. Will raise an Error if the start_note is not a valid note.
### intervals --------------------------------------- #### determine(note1, note2, shorthand) * **Default values**: shorthand = false * Names the interval between note1 and note2.
zazate.intervals.determine("C", "E"); // return 'major third'
zazate.intervals.determine("C", "Eb"); // return 'minor third'
zazate.intervals.determine("C", "E#"); // return 'augmented third'
zazate.intervals.determine("C", "Ebb"); // return 'diminished third'
zazate.intervals.determine("C", "G"); // return 'perfect fifth'
zazate.intervals.determine("C", "F"); // return 'perfect fourth'

#### fifth(note, key) Take the diatonic fifth of note in key. ```js zazate.intervals.fifth("E", "C"); // return 'B' zazate.intervals.fifth("E", "F"); // return 'Bb' ```
#### fourth(note, key) Take the diatonic fourth of note in key. ```js zazate.intervals.fourth("E", "C"); // return 'A' zazate.intervals.fourth("E", "B"); // return 'A#' ```
#### from_shorthand(note, interval, up) * **Default values**: up = true * Returns the note on interval up or down.
zazate.intervals.from_shorthand("A", "b3"); // return 'C'
zazate.intervals.from_shorthand("D", "2"); // return 'A'
zazate.intervals.from_shorthand("E", "2", false); // return 'D'

#### get_interval(note, interval, key) * **Default values**: key = 'C' * Gets the note an interval (in half notes) away from the given note. This will produce mostly theoretical sound results, but you should use the minor and major functions to work around the corner cases.
#### invert(interval) Invert an interval represented as [note1, note2]. ```js zazate.intervals.invert(["C", "E"]); // return ["E", "C"] ```
#### is_consonant(note1, note2, include_fourths) * **Default values**: include_fourths = true * A consonance is a harmony, chord, or interval considered stable, as opposed to a dissonance (see is_dissonant). This function tests whether the given interval is consonant. This basically means that it checks whether the interval is (or sounds like) a unison, third, sixth, perfect fourth or perfect fifth. In classical music the fourth is considered dissonant when used contrapuntal, which is why you can choose to exclude it.
#### is_dissonant(note1, note2, include_fourths) * **Default values**: include_fourths = true * Tests whether an interval is considered unstable, dissonant. In the default case perfect fourths are considered consonant, but this can be changed with the exclude_fourths flag.
#### is_imperfect_consonant(note1, note2) Imperfect consonances are either minor or major thirds or minor or major sixths.
#### is_perfect_consonant(note1, note2, include_fourths) * **Default values**: include_fourths = true * Perfect consonances are either unisons, perfect fourths or fifths, or octaves (which is the same as a unison in this model; see the container.Note class for more). Perfect fourths are usually included as well, but are considered dissonant when used contrapuntal, which is why you can exclude them.
#### measure(note1, note2) Returns an integer in the range of 0-11, determining the half note steps between note1 and note2. ```js zazate.intervals.measure("C", "D"); // return 2 zazate.intervals.measure("D", "C"); // return 10 ```
#### second(note, key) Take the diatonic second of note in key. ```js zazate.intervals.second("E", "C"); // return 'F' zazate.intervals.second("E", "D"); // return 'F#' ```
#### seventh(note, key) Take the diatonic seventh of note in key. ```js zazate.intervals.seventh("E", "C"); // return 'D' zazate.intervals.seventh("E", "B"); // return 'D#' ```
#### sixth(note, key) Take the diatonic sixth of note in key. ```js zazate.intervals.sixth("E", "C"); // return 'C' zazate.intervals.sixth("E", "B"); // return 'C#' ```
#### third(note, key) Take the diatonic third of note in key. ```js zazate.intervals.third("E", "C"); // return 'G' zazate.intervals.third("E", "E"); // return 'G#' ```
#### unison(note, key) * **Default values**: key = null * One of the most useless methods ever written, which returns the unison of note. The key is not at all important, but is here for consistency reasons only.
zazate.intervals.unison("C"); // return 'C'

### chords --------------------------------------- #### augmented_major_seventh(note) Builds an augmented major seventh chord on note. ```js zazate.chords.augmented_major_seventh("C") // ["C", "E", "G#", "B"] ```
#### augmented_minor_seventh(note) Builds an augmented minor seventh chord on note. ```js zazate.chords.augmented_minor_seventh("C") // ["C", "E", "G#", "Bb"] ```
#### augmented_triad(note) Builds an augmented triad on note. ```js zazate.chords.augmented_triad("C") // ["C", "E", "G#"] ```
#### determine(chord, shorthand, no_inversions, no_polychords) * **Default values**: shorthand = false, no_inversions = false, no_polychords = false * Names a chord. Can determine almost every chord, from a simple triad to a fourteen note polychord.
#### determine_extended_chord5(chord, shorthand, no_inversions, no_polychords) * **Default values**: shorthand = false, no_inversions = false, no_polychords = false * Determines the names of an extended chord
#### determine_extended_chord6(chord, shorthand, no_inversions, no_polychords) * **Default values**: shorthand = false, no_inversions = false, no_polychords = false * Determines the names of an 6 note chord
#### determine_extended_chord7(chord, shorthand, no_inversions, no_polychords) * **Default values**: shorthand = false, no_inversions = false, no_polychords = false * Determines the names of an 7 note chord
#### determine_polychords(chord, shorthand) * **Default values**: shorthand = false * Determines the polychords in chord. Can handle anything from polychords based on two triads to 6 note extended chords.
#### determine_seventh(seventh, shorthand, no_inversion, no_polychords) * **Default values**: shorthand = false, no_inversion = false, no_polychords = false * Determines the type of seventh chord. Returns the results in a lists, ordered on inversions. Expects seventh to be a list of 4 notes. If shorthand is set to true, results will be returned in chord shorthand ('Cmin7', etc.) - inversions will be dropped in that case. ```js zazate.chords.determine_seventh(['C', 'E', 'G', 'B']) // ['C major seventh'] ```
#### determine_triad(triad, shorthand, no_inversions, placeholder) * **Default values**: shorthand = false, no_inversions = false, placeholder = None * Names the triad. Returns answers in a list. The third argument should not be given. If shorthand is true the answers will be in abbreviated form.

Can determine major, minor, diminished and suspended triads. Also knows about invertions.

zazate.chords.determine_triad(["A", "C", "E"]) // 'A minor triad'
zazate.chords.determine_triad(["C", "E", "A"]) // 'A minor triad, first inversion'
zazate.chordsdetermine_triad(["A", "C", "E"], true) // 'Am'

#### diminished_seventh(note) Builds a diminished seventh chord on note. ```js zazate.chords.diminished_seventh("C") // ["C", "Eb", "Gb", "Bbb"] ```
#### diminished_triad(note) Builds a diminished triad on note. ```js zazate.chords.diminished_triad("C") // ["C", "Eb", "Gb"] ```
#### dominant(key) Returns the dominant chord in key. ```js zazate.chords.dominant("C") // ["G", "B", "D"] ```
#### dominant7(key) Same as [dominant(key)](#chords_dominant), but returns seventh chord
#### dominant_flat_five(note) Builds a dominant flat five chord on note. ```js zazate.chords.dominant_flat_five("C") // ['C', 'E', 'Gb', 'Bb'] ```
#### dominant_flat_ninth(note) Builds a dominant flat ninth chord on note. ```js zazate.chords.dominant_flat_ninth("C") // ['C', 'E', 'G', 'Bb', 'Db'] ```
#### dominant_ninth(note) Builds a dominant ninth chord on note. ```js zazate.chords.dominant_ninth("C") // ['C', 'E', 'G', 'Bb', 'D'] ```
#### dominant_seventh(note) Builds a dominant seventh chord on note. ```js zazate.chords.dominant_seventh("C") // ["C", "E", "G", "Bb"] ```
#### dominant_sharp_ninth(note) Builds a dominant sharp ninth chord on note. ```js zazate.chords.dominant_sharp_ninth("C") // ['C', 'E', 'G', 'Bb', 'D#'] ```
#### dominant_sixth(note) Builds the altered chord 6/7 on note. ```js zazate.chords.dominant_sixth("C") // ['C', 'E', 'G', 'A', 'Bb'] ```
#### dominant_thirteenth(note) Builds a dominant thirteenth chord on note. ```js zazate.chords.dominant_thirteenth('C') // ['C', 'E', 'G', 'Bb', 'D', 'A'] ```
#### eleventh(note) Builds an eleventh chord on note. ```js zazate.chords.eleventh("C") // ['C', 'G', 'Bb', 'F'] ```
#### first_inversion(chord) The first inversion of a chord
#### from_shorthand(shorthand_string, slash) * **Default values**: slash = false * Takes a chord written in shorthand and returns the notes in the chord. The function can recognize triads, sevenths, sixths, ninths, elevenths, thirteenths, slashed chords and a number of altered chords. The second argument should not be given and is only used for a recursive call when a slashed chord or polychord is found. See [Wikibooks](http://en.wikibooks.org/wiki/Music_Theory/Complete_List_of_Chord_Patterns) for a nice overview of chord patterns.
zazate.chords.from_shorthand("Amin") // ["A", "C", "E"]
zazate.chords.from_shorthand("Am/M7") // ["F", "Ab", "C", "E"]
zazate.chords.from_shorthand("A") // ["A", "C#", "E"]
zazate.chords.from_shorthand("A/G") // ["G", "A", "C#", "E"]
zazate.chords.from_shorthand("Dm|G") // ["G", "B", "D", "F", "A"]

Recognised abbreviations: the letters m and M in the following abbreviations can always be substituted by respectively min, mi or - and maj or ma (eg. from_shorthand("Amin7") == from_shorthand("Am7"), etc.).

  • Triads: 'm', 'M' or '', 'dim'.
  • Sevenths: 'm7', 'M7', '7', 'm7b5', 'dim7', 'm/M7' or 'mM7'
  • Augmented chords: 'aug' or '+', '7#5' or 'M7+5', 'M7+', 'm7+', '7+'
  • Suspended chords: 'sus4', 'sus2', 'sus47', 'sus', '11', 'sus4b9' or 'susb9'
  • Sixths: '6', 'm6', 'M6', '6/7' or '67', 6/9 or 69
  • Ninths: '9', 'M9', 'm9', '7b9', '7#9'
  • Elevenths: '11', '7#11', 'm11'
  • Thirteenths: '13', 'M13', 'm13'
  • Altered chords: '7b5', '7b9', '7#9', '67' or '6/7'
  • Special: '5', 'NC', 'hendrix'

#### half_diminished_seventh(note) Builds a half diminished seventh (=minor seventh flat five) chord on note. ```js zazate.chords.half_diminished_seventh("C") // ["C", "Eb", "Gb", "Bb"] ```
#### hendrix_chord(note) Builds the famous Hendrix chord (7b12). ```js zazate.chords.hendrix_chord('C') // ['C', 'E', 'G', 'Bb', 'Eb'] ```
#### int_desc(tries) Helper function that returns the inversion of the triad in a string.
#### invert(chord) Inverts a given chord one time.
#### lydian_dominant_seventh(note) Builds the lydian dominant seventh (7#11) on note. ```js zazate.chords.lydian_dominant_seventh('C') // ['C', 'E', 'G', 'Bb', 'F#'] ```
#### major_ninth(note) Builds a major ninth chord on note. ```js zazate.chords.major_ninth("C") // ['C', 'E', 'G', 'B', 'D'] ```
#### major_seventh(note) Builds a major seventh chord on note. ```js zazate.chords.major_seventh("C") // ["C", "E", "G", "B"] ```
#### major_sixth(note) Builds a major sixth chord on note. ```js zazate.chords.major_sixth("C") // ['C', 'E', 'G', 'A'] ```
#### major_thirteenth(note) Builds a major thirteenth chord on note. ```js zazate.chords.major_thirteenth("C") // ['C', 'E', 'G', 'B', 'D', 'A'] ```
#### major_triad(note) Builds a major triad chord on note. ```js zazate.chords.major_triad("C") // ["C", "E", "G"] ```
#### mediant(key) Returns the mediant chord in key. ```js zazate.chords.mediant("C") // ["E", "G", "B"] ```
#### mediant7(key) Same as mediant(key), but returns seventh chord
#### minor_major_seventh(note) Builds a minor major seventh chord on note. ```js zazate.chords.minor_major_seventh("C") // ["C", "Eb", "G", "B"] ```
#### minor_ninth(note) Builds a minor ninth chord on note. ```js zazate.chords.minor_ninth("C") // ['C', 'Eb', 'G', 'Bb', 'D'] ```
#### minor_seventh(note) Builds a minor seventh chord on note. ```js zazate.chords.minor_seventh("C") // ["C", "Eb", "G", "Bb"] ```
#### minor_seventh_flat_five(note) See half_diminished_seventh(note) for docs
#### minor_sixth(note) Builds a minor sixth chord on note. ```js zazate.chords.minor_sixth("C") // ['C', 'Eb', 'G', 'A'] ```
#### minor_thirteenth(note) Builds a minor thirteenth chord on note. ```js zazate.chords.minor_thirteenth("C") // ['C', 'Eb', 'G', 'Bb', 'D', 'A'] ```
#### minor_triad(note) Builds a minor triad chord on note. ```js zazate.chords.minor_triad("C") // ["C", "Eb", "G"] ```
#### second_inversion(chord) Returns the second inversion of chord.
#### seventh(note, key) Returns the seventh chord on note in key. ```js zazate.chords.seventh("C", "C") // ["C", "E", "G", "B"] ```
#### sevenths(key) Returns all the sevenths chords in key in a list.
#### sixth_ninth(note) Returns the sixth/ninth chord on note in key. ```js zazate.chords.sixth_ninth('C') // ['C', 'E', 'G', 'A', 'D'] ```
#### subdominant(key) Returns the subdominant chord in key. ```js zazate.chords.subdominant('C') // ["F", "A", "C"] ```
#### subdominant7(key) Same as subdominant(key), but returns seventh chord.
#### submediant(key) Returns the submediant chord in key. ```js zazate.chords.submediant('C') // ["A", "C", "E"] ```
#### submediant7(key) Same as submediant(key), but returns seventh chord.
#### subtonic(key) Returns the subtonic chord in key. ```js zazate.chords.subtonic('C') // ['B', 'D', 'F'] ```
#### subtonic7(key) Same as subtonic(key), but returns seventh chord
#### supertonic(key) Returns the supertonic chord in key. ```js zazate.chords.supertonic('C') // ["D", "F", "A"] ```
#### supertonic7(key) Same as supertonic(key), but returns seventh chord.
#### suspended_fourth_ninth(note) Builds a suspended fourth flat ninth chord on note. ```js zazate.chords.suspended_fourth_ninth('C') // ['C', 'F', 'G', 'Db'] ```
#### suspended_fourth_triad(note) Builds a suspended fourth triad on note. ```js zazate.chords.suspended_fourth_triad('C') // ["C", "F", "G"] ```
#### suspended_second_triad(note) Builds a suspended second triad on note. ```js zazate.chords.suspended_second_triad('C') // ["C", "D", "G"] ```
#### suspended_seventh(note) Builds a suspended (flat) seventh chord on note. ```js zazate.chords.suspended_seventh('C') // ["C", "F", "G", "Bb"] ```
#### suspended_triad(note) An alias for suspended_fourth_triad
#### third_inversion(chord) Returns the third inversion of chord.
#### tonic(key) Returns the tonic chord in key. ```js zazate.chords.tonic('C') // ["C", "E", "G"] ```
#### tonic7(key) Same as tonic(key), but returns seventh chord instead
#### triad(note, key) Returns the triad on note in key as an array. ```js zazate.chords.triad("E", "C") // ["E", "G", "B"] zazate.chords.triad("E", "B") // ["E", "G#", "B"] ```
#### triads(key) Returns all the triads in key. Implemented using a cache.
### scales --------------------------------------- #### aeolian(note) Returns the aeolian mode scale starting on note. ```js zazate.scales.aeolian("A") // ["A", "B", "C", "D", "E", "F", "G"] ```
#### determine(scale) Determines the kind of scale. Can recognize all the diatonic modes and the minor scales. ```js zazate.scales.determine(["C", "D", "E", "F", "G", "A", "B"]) // 'C ionian' ```
#### diatonic(note) Returns the diatonic mode scale starting on note. ```js zazate.scales.diatonic("C") // ["C", "D", "E", "F", "G", "A", "B"] ```
#### diminished(note) Returns the diminished mode scale starting on note. ```js zazate.scales.diminished("C") // ['C', 'D', 'Eb', 'F', 'Gb', 'Ab', 'A', 'B'] ```
#### dorian(note) Returns the dorian mode scale starting on note. ```js zazate.scales.dorian("D") // ["D", "E", "F", "G", "A", "B", "C"] ```
#### get_notes(key) Returns an ordered array of the notes in this key. For example: if the key is set to 'F', this function will return ['F', 'G', 'A', 'Bb', 'C', 'D', 'E']. Exotic or ridiculous keys like 'C####' or even 'Gbb##bb#b##' will work; Note however that the latter example will also get cleaned up to 'G'. This function will raise an NoteFormatError if the key isn't recognised
#### harmonic_minor(note) Returns the harmonic minor mode scale starting on note. ```js zazate.scales.harmonic_minor("A") // ["A", "B", "C", "D", "E", "F", "G#"] ```
#### ionian(note) Returns the ionian mode scale starting on note. ```js zazate.scales.ionian("C") // ["C", "D", "E", "F", "G", "A", "B"] ```
#### locrian(note) Returns the locrian mode scale starting on note. ```js zazate.scales.locrian("B") // ["B", "C", "D", "E", "F", "G", "A"] ```
#### lydian(note) Returns the lydian mode scale starting on note. ```js zazate.scales.lydian("F") // ["F", "G", "A", "B", "C", "D", "E"] ```
#### lydian(note) Returns the melodic minor mode scale starting on note. ```js zazate.scales.melodic_minor("A") // ["A", "B", "C", "D", "E", "F#", "G#"] ```
#### mixolydian(note) Returns the mixolydian mode scale starting on note. ```js zazate.scales.mixolydian("G") // ["G", "A", "B", "C", "D", "E", "F"] ```
#### natural_minor(note) Returns the natural minor mode scale starting on note. ```js zazate.scales.natural_minor("A") // ["A", "B", "C", "D", "E", "F", "G"] ```
#### phrygian(note) Returns the phrygian mode scale starting on note. ```js zazate.scales.phrygian("E") // ["E", "F", "G", "A", "B", "C", "D"] ```
#### whole_note(note) Returns the whole note mode scale starting on note. ```js zazate.scales.whole_note("E") // ["C", "D", "E", "F#", "G#", "A#"] ```
### meter A meter is represented by a array. 4/4 time would look like [4,4], 3/4 like [3,4], etc.
#### common_time A meter (array) with value: [4,4]
#### cut_time A meter (array) with value: [2,2]
#### is_asymmetrical(meter)

Returns true if meter is an asymmetrical meter, false otherwise.

zazate.meter.is_asymmetrical([3,4]) // true
zazate.meter.is_asymmetrical([3,4]) // false

#### is_compound(meter) Returns true if meter is a compund meter, false otherwise. ```js zazate.meter.is_compound([3,4]) // true zazate.meter.is_compound([3,4]) // false ```
#### is_simple(meter) Returns true if meter is a simple meter, false otherwise. ```js zazate.meter.is_simple([3,4]) // true zazate.meter.is_simple([3,4]) // true ```
#### is_valid(meter) Returns true if meter is a valid tuple representation of a meter. Examples for meters are [3,4] for 3/4, [4,4] for 4/4, etc.
#### valid_beat_duration(duration) Returns true when log2(duration) is an integer.