Methods
(inner) el(duration, data)
Create a score element: an object with duration
It's accepts any data you supply, but duration property has a special meaning: it's a number representing the duration in arbitrary units. It's assumed to be 0 (no duration) if not present or not a valid number
Parameters:
Name | Type | Description |
---|---|---|
duration |
Number | the element duration |
data |
Object | the additional element data |
(inner) map(fn, ctx, score) → {Score}
Map the notes of a musical structure using a function
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | the function used to map the notes |
ctx |
Object | a context object passed to the function |
score |
Score | the score to transform |
Returns:
the transformed score
- Type
- Score
(inner) note(duration, pitch, data) → {Hash}
Create a note from duration and pitch
A note is any object with duration and pitch attributes. The duration must be a number, but the pitch can be any value (although only strings with scientific notation pitches and midi numbers are recogniced by the manipulation or display functions)
If only duration is provided, a partially applied function is returned.
Parameters:
Name | Type | Description |
---|---|---|
duration |
Integer | the note duration |
pitch |
String | Integer | the note pitch |
data |
Hash | (Optional) arbitraty note data |
Returns:
a note
- Type
- Hash
Examples
score.note(1, 'A') // => { duration: 1, pitch: 'A' }
score.note(0.5, 'anything') // => { duration: 0.5, pitch: 'anything' }
score.note(2, 'A', 2, { inst: 'piano' }) // => { duration: 2, pitch: 'A', inst: 'piano' }
// partially applied
['C', 'D', 'E'].map(score.note(1)) // => [{ duration: 1, pitch: 'C'},
{ duration: 1, pitch: 'D'}, { duration: 1, pitch: 'E'}]
(inner) seq(elements) → {Array}
Create a musical structure where elements are sequenetial
Parameters:
Name | Type | Description |
---|---|---|
elements |
Array | an array of elements |
Returns:
the sequential musical structure
- Type
- Array
Example
score.sequential([score.note('A'), score.note('B')])
(inner) sim()
Create a musical structure where elements are simultaneous
Example
score.sim([score.note('A'), score.note('B')])
(inner) transform(elTransform, seqTransform, parTransform, ctx, score) → {*}
Transform a musical structure
This is probably the most important function. It allows complex transformations of musical structures using three functions
Parameters:
Name | Type | Description |
---|---|---|
elTransform |
function | element transform function |
seqTransform |
function | sequential structure transform function |
parTransform |
function | simultaneous structure transform function |
ctx |
* | an additional object passed to transform functions |
score |
Object | the score to transform |
Returns:
the result of the transformation
- Type
- *