## Classes
GuidedMusicMachine
TreeNode
MusicMachine
## Functions
allowedIntervalQualities(...quality)filter

filter generator that returns a filter which restricts the maximum length of the construction

maxLength(max)filter

filter generator that returns a filter which restricts the maximum length of the construction

maxRange(maxIntervalSize)filter

filter generator that returns a filter which restricts the maximum range of the construction

filter(choices, construction)Array.<string>

a user defined function that choices will be passed through, filtering out certain choices.

plusIntervalInKey(key, sciPitch, intervalSize)String | function

helper function that finds the result of adding a generic interval to a given pitch in the context of a key

Optionally, exclude the intervalSize parameter and get back a curried function with the key and startPitch set as defaults.

sortPitches(pitches)Array.<string>

helper function to sort an array of pitches from lowest to highest

## Typedefs
SymbolChain : string

a string of one or more symbol names seperated by whitespace

MusicGrammar : Object

a user defined context-free grammar formatted as an object consisting of key-value pairs, with each non-terminal symbol pointing to an array of one or more symbol chains choices for this non-terminal. All terminals must be positive or negative numbers, representing musical intervals. Said another way, anything that is not a number must have its own definition.

## GuidedMusicMachine **Kind**: global class * [GuidedMusicMachine](#GuidedMusicMachine) * [new GuidedMusicMachine(guide, [key], [initialScaleDegrees])](#new_GuidedMusicMachine_new) * [.addFilter(filter)](#GuidedMusicMachine+addFilter) * [.construction()](#GuidedMusicMachine+construction) ⇒ Array.<string> * [.tonic()](#GuidedMusicMachine+tonic) * [.isComplete()](#GuidedMusicMachine+isComplete) ⇒ boolean * [.choose(pitchChoice)](#GuidedMusicMachine+choose) * [.pop()](#GuidedMusicMachine+pop) ⇒ string * [.choices([nDeep])](#GuidedMusicMachine+choices) ⇒ Array.<string> * [.constructs()](#GuidedMusicMachine+constructs) ⇒ Array.<string> ### new GuidedMusicMachine(guide, [key], [initialScaleDegrees]) step-by-step construction of music from a predefined Music Machine | Param | Type | Default | Description | | --- | --- | --- | --- | | guide | GuidedDecisionGraph | | a Guided Decision Graph. See: [GuidedDecisionGraph](https://github.com/jrleszcz/grammar-graph/blob/master/api.md#GuidedDecisionGraph) | | [key] | Key | 'C major' | the key in which to apply the generic interval. See [Key](https://github.com/jrleszcz/nmusic/blob/master/api.md#Key) | | [initialScaleDegrees] | Array.<number> | [1] | the scale degree(s) which constructions can start on | ### guidedMusicMachine.addFilter(filter) add a filter to the guide that will filter chioces based on the construction **Kind**: instance method of [GuidedMusicMachine](#GuidedMusicMachine) | Param | Type | Description | | --- | --- | --- | | filter | [filter](#filter) | a callback filter function that returns valid choices | ### guidedMusicMachine.construction() ⇒ Array.<string> the current construction **Kind**: instance method of [GuidedMusicMachine](#GuidedMusicMachine) **Returns**: Array.<string> - a terminal symbol chain ### guidedMusicMachine.tonic() the tonic note of this key @ returns {string} a pitch class string **Kind**: instance method of [GuidedMusicMachine](#GuidedMusicMachine) ### guidedMusicMachine.isComplete() ⇒ boolean is the current construction a valid, complete construction from the starting nonterminal? ie, does the construction end in epsilon? **Kind**: instance method of [GuidedMusicMachine](#GuidedMusicMachine) **Returns**: boolean - is the construction complete ### guidedMusicMachine.choose(pitchChoice) adds the given pitch to the construction **Kind**: instance method of [GuidedMusicMachine](#GuidedMusicMachine) **Throws**: - throws an error if pitchChoice is not in the current set of [choices](#GuidedMusicMachine+choices) | Param | Type | Description | | --- | --- | --- | | pitchChoice | string | Array.<string> | a pitch string in the current set of next choices or an array of choices to be applied sequentially | ### guidedMusicMachine.pop() ⇒ string pop the last choice off the construction **Kind**: instance method of [GuidedMusicMachine](#GuidedMusicMachine) **Returns**: string - the last pitch string of the construction that was submitted through [choose](#GuidedMusicMachine+choose) **Throws**: - throws an error if called when construction is empty ### guidedMusicMachine.choices([nDeep]) ⇒ Array.<string> returns an array of all possible next pitches, or an array of nDeep [TreeNodes](#TreeNode). **Kind**: instance method of [GuidedMusicMachine](#GuidedMusicMachine) **Returns**: Array.<string> - if nDeep=1, an array of pitch strings, else an array of nDeep [TreeNodes](#TreeNode) | Param | Type | Default | Description | | --- | --- | --- | --- | | [nDeep] | number | 1 | will search for nDeep possible choices | ### guidedMusicMachine.constructs() ⇒ Array.<string> Peak inside the machine and get a list of possible constructions at this point. Constructions are returned in the terms of the grammar, not as notes. **Kind**: instance method of [GuidedMusicMachine](#GuidedMusicMachine) **Returns**: Array.<string> - a list of possible constructions **Example** ```js guide.constructs() => ['2 3 -2 JupiterTheme -5 InfinitePhrase'] ``` ## TreeNode **Kind**: global class **See**: TreeNode returned from [GuidedDecisionGraph.choices](GuidedDecisionGraph#choices) **Properties** | Name | Type | Description | | --- | --- | --- | | val | | any value | | next | [Array.<TreeNode>](#TreeNode) | a list of TreeNodes this node links to | ### new TreeNode(dg) Tree nodes to return decision trees from choices | Param | Type | Description | | --- | --- | --- | | dg | DecisionGraph | a Decision Graph that defines a grammar | ## MusicMachine **Kind**: global class * [MusicMachine](#MusicMachine) * [new MusicMachine(grammar, startSymbol, [initialScaleDegrees])](#new_MusicMachine_new) * _instance_ * [.vertices()](#MusicMachine+vertices) ⇒ Array.<string> * [.addFilter(filter)](#MusicMachine+addFilter) * [.createGuide([key])](#MusicMachine+createGuide) ⇒ [GuidedMusicMachine](#GuidedMusicMachine) * _static_ * [.filter](#MusicMachine.filter) * [.maxRange](#MusicMachine.filter.maxRange) ⇒ [filter](#filter) * [.maxLength(max)](#MusicMachine.filter.maxLength) ⇒ [filter](#filter) * [.allowedIntervalQualities(...quality)](#MusicMachine.filter.allowedIntervalQualities) ⇒ [filter](#filter) ### new MusicMachine(grammar, startSymbol, [initialScaleDegrees]) creates a new MusicMachine which can generate Guides for music construction. | Param | Type | Default | Description | | --- | --- | --- | --- | | grammar | [MusicGrammar](#MusicGrammar) | | an object representing a musical grammar. | | startSymbol | string | | the symbol at which to start constructions | | [initialScaleDegrees] | Array.<number> | [1] | the scale degree(s) which constructions can start on | ### musicMachine.vertices() ⇒ Array.<string> get an array of vertex names in the graph **Kind**: instance method of [MusicMachine](#MusicMachine) **Returns**: Array.<string> - the vertex names in this graph ### musicMachine.addFilter(filter) add a filter to the guide that will filter chioces based on the construction **Kind**: instance method of [MusicMachine](#MusicMachine) | Param | Type | Description | | --- | --- | --- | | filter | [filter](#filter) | a callback filter function that returns valid choices | ### musicMachine.createGuide([key]) ⇒ [GuidedMusicMachine](#GuidedMusicMachine) get a new GuidedMusicMachine using this decision graph **Kind**: instance method of [MusicMachine](#MusicMachine) **Returns**: [GuidedMusicMachine](#GuidedMusicMachine) - a new guide from the provided start point **See**: [GuidedMusicMachine](#GuidedMusicMachine) for the methods available on the Guide | Param | Type | Default | Description | | --- | --- | --- | --- | | [key] | string | "'C major'" | the key in which to apply the generic interval. Must be a valid pitch string and mode name seperated by whitespace such as 'Bb minor'. | ### MusicMachine.filter a collection of filter generators that generate filter callback functions intended to be passed to [addFilter](#MusicMachine+addFilter) or [addFilter](#GuidedMusicMachine+addFilter) **Kind**: static property of [MusicMachine](#MusicMachine) * [.filter](#MusicMachine.filter) * [.maxRange](#MusicMachine.filter.maxRange) ⇒ [filter](#filter) * [.maxLength(max)](#MusicMachine.filter.maxLength) ⇒ [filter](#filter) * [.allowedIntervalQualities(...quality)](#MusicMachine.filter.allowedIntervalQualities) ⇒ [filter](#filter) #### filter.maxRange ⇒ [filter](#filter) filter generator that returns a filter which restricts the maximum range of the construction **Kind**: static property of [filter](#MusicMachine.filter) **Returns**: [filter](#filter) - a filter that limits the range of the construction **See**: [maxRange](#maxRange) | Param | Type | Description | | --- | --- | --- | | maxIntervalSize | number | the maximum range (inclusive) of the desired construction | #### filter.maxLength(max) ⇒ [filter](#filter) limit the length of a construction **Kind**: static method of [filter](#MusicMachine.filter) **Returns**: [filter](#filter) - a filter that limits the length of the construction **See**: [maxLength](#maxLength) | Param | Type | Description | | --- | --- | --- | | max | number | the maximum length (inclusive) of the desired construction | #### filter.allowedIntervalQualities(...quality) ⇒ [filter](#filter) only allow certain interval qualities **Kind**: static method of [filter](#MusicMachine.filter) **Returns**: [filter](#filter) - a filter that only allows the specified intervals **See**: [allowedIntervalQualities](#allowedIntervalQualities) | Param | Type | Description | | --- | --- | --- | | ...quality | char | characters representing quality. 'm' = minor, 'M' = Major, 'P' = Perfect, 'd' = diminished, 'A' = augmented | ## allowedIntervalQualities(...quality) ⇒ [filter](#filter) filter generator that returns a filter which restricts the maximum length of the construction **Kind**: global function **Returns**: [filter](#filter) - a filter that limits the length of the construction **Throws**: - Will throw an error if an argument is not a valid quality character | Param | Type | Description | | --- | --- | --- | | ...quality | char | characters representing quality. 'm' = minor, 'M' = Major, 'P' = Perfect, 'd' = diminished, 'A' = augmented | ## maxLength(max) ⇒ [filter](#filter) filter generator that returns a filter which restricts the maximum length of the construction **Kind**: global function **Returns**: [filter](#filter) - a filter that limits the length of the construction | Param | Type | Description | | --- | --- | --- | | max | number | the maximum length (inclusive) of the desired construction | ## maxRange(maxIntervalSize) ⇒ [filter](#filter) filter generator that returns a filter which restricts the maximum range of the construction **Kind**: global function **Returns**: [filter](#filter) - a filter that limits the range of the construction | Param | Type | Description | | --- | --- | --- | | maxIntervalSize | number | the maximum range (inclusive) of the desired construction | ## filter(choices, construction) ⇒ Array.<string> a user defined function that [choices](#GuidedMusicMachine+choices) will be passed through, filtering out certain choices. **Kind**: global function **Returns**: Array.<string> - the choices with notes filtered out | Param | Type | Description | | --- | --- | --- | | choices | Array.<string> | the current choices as returned by [choices](#GuidedMusicMachine+choices) | | construction | Array.<string> | the curent constrution as returned by [construction](#GuidedMusicMachine+construction) | ## plusIntervalInKey(key, sciPitch, intervalSize) ⇒ String | function helper function that finds the result of adding a generic interval to a given pitch in the context of a key Optionally, exclude the intervalSize parameter and get back a curried function with the key and startPitch set as defaults. **Kind**: global function **Returns**: String | function - the resulting pitch string, or if given only one argument, returns a function with the given argument set as a default. | Param | Type | Description | | --- | --- | --- | | key | string | the key in which to apply the generic interval. Must be a valid pitch string and mode name seperated by whitespace such as 'Bb major' or 'Db dorian' | | sciPitch | string | a pitch in scientific pitch notation. | | intervalSize | number | an interval string or number with or without quality. If quality is not provided, accidentals on given pitch will be ignored. | ## sortPitches(pitches) ⇒ Array.<string> helper function to sort an array of pitches from lowest to highest **Kind**: global function **Returns**: Array.<string> - a new clone of the provided pitch string array sorted from low pitch to high pitch | Param | Type | Description | | --- | --- | --- | | pitches | Array.<string> | an array of pitch strings | ## SymbolChain : string a string of one or more symbol names seperated by whitespace **Kind**: global typedef **See**: a SymbolChain is used as definitions in [MusicGrammar](#MusicGrammar) **Example** ```js '4' // just a single symbol, means to go up a fourth '5 -3' // go up a fifth, then down a third 'JupiterTheme 4 -2' // play the JupiterTheme (which will be defined in another definition), // then go up a fourth, then down a second ``` ## MusicGrammar : Object a user defined context-free grammar formatted as an object consisting of key-value pairs, with each [non-terminal symbol](https://github.com/jrleszcz/grammar-graph#non-terminal-symbols) pointing to an array of one or more [symbol chains](https://github.com/jrleszcz/grammar-graph#symbol-chains) choices for this non-terminal. All [terminals](https://github.com/jrleszcz/grammar-graph#terminal-symbols) must be positive or negative numbers, representing musical intervals. Said another way, anything that is not a number must have its own definition. **Kind**: global typedef **Properties** | Name | Type | Description | | --- | --- | --- | | symbol | [Array.<SymbolChain>](#SymbolChain) | each element of the array is a possible definition for this symbol. | **Example** ```js var jupiterGrammar = { InfinitePhrase: [ 'JupiterTheme InfinitePhrase', // InfinitePhrase has two possible definitions 'SecondMotive InfinitePhrase' ], JupiterTheme: [ '2 3 -2' ], // JupiterTheme has only one definition SecondMotive: [ '4 StepDown' ], StepDown: [ '-2', '-2 StepDown'] } // non-terminals: InfinitePhrase, JupiterTheme, SecondMotive, StepDown // terminals: -2, 2, 3, 4 ```