forked from soundio/soundstage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
274 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
import get from '../../../fn/modules/get.js'; | ||
import id from '../../../fn/modules/id.js'; | ||
import capture from '../../../fn/modules/capture.js'; | ||
import overload from '../../../fn/modules/overload.js'; | ||
import Event from '../event.js'; | ||
import parseFrequency from '../parse/parse-frequency.js'; | ||
import parseGain from '../parse/parse-gain.js'; | ||
|
||
const tuning = 440; | ||
|
||
/** | ||
parseEvent(array, string) | ||
Takes a sequence string and outputs an array of events. | ||
**/ | ||
|
||
export default overload(get(1), { | ||
// name gain duration | ||
'note': capture(/^(\w+)\s+([^\s]+)\s+(\w+)\s*/, { | ||
1: (event, captures) => { | ||
event[2] = parseFrequency(tuning, captures[1]); | ||
event[3] = parseGain(captures[2]); | ||
event[4] = parseFloat(captures[3]); | ||
return event; | ||
} | ||
}), | ||
|
||
// name target duration | ||
'sequence': capture(/^(\w+)\s+(\w+)\s+(\w+)\s*/, { | ||
1: (event, captures) => { | ||
event[2] = captures[1]; | ||
event[3] = captures[2]; | ||
event[4] = parseFloat(captures[3]); | ||
return event; | ||
} | ||
}), | ||
|
||
// name value [curve] | ||
'param': capture(/^(\w+)\s+([-\d\.]+)(?:\s+(step|linear|exponential|target|curve))?\s*/, { | ||
1: (event, captures) => { | ||
event[2] = captures[1]; | ||
event[3] = parseFloat(captures[2]); | ||
event[4] = 'step'; | ||
return event; | ||
}, | ||
|
||
// curve | ||
3: overload((event, captures) => captures[3], { | ||
// duration | ||
'target': capture(/^(\w+)\s*/, { | ||
1: (event, captures) => { | ||
event[4] = 'target'; | ||
event[5] = parseFloat(captures[1]); | ||
return event; | ||
} | ||
}), | ||
|
||
// Set curve | ||
default: (event, captures) => { | ||
event[4] = captures[3]; | ||
return event; | ||
} | ||
}) | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
import get from '../../../fn/modules/get.js'; | ||
import id from '../../../fn/modules/id.js'; | ||
import capture from '../../../fn/modules/capture.js'; | ||
import overload from '../../../fn/modules/overload.js'; | ||
import Event from '../event.js'; | ||
import parseEvent from './parse-event.js'; | ||
import parseFrequency from './parse-frequency.js'; | ||
import parseGain from './parse-gain.js'; | ||
|
||
const types = { | ||
1: 'note', | ||
4: 'param', | ||
5: 'sequence' | ||
}; | ||
|
||
function parseType(value) { | ||
// Crude but sort of effective | ||
return types[value] || value; | ||
} | ||
|
||
|
||
/** | ||
parseEvents(string) | ||
Takes a sequence string and outputs an array of events. | ||
**/ | ||
|
||
const event = []; | ||
const parseEvents = capture(/^\s*([-\d\.e]+)\s+(\w+)\s+/, { | ||
2: (data, captures) => { | ||
// time | ||
event[0] = parseFloat(captures[1]); | ||
// type | ||
event[1] = captures[2]; | ||
// parameters | ||
parseEvent(event, captures); | ||
// Convert to event object | ||
data.push(Event.from(event)); | ||
return data; | ||
}, | ||
|
||
close: (data, captures) => { | ||
const consumed = (captures.consumed || 0) | ||
+ captures.index | ||
+ captures[0].length ; | ||
|
||
return consumed < captures.input.length ? | ||
parseEvents(data, captures) : | ||
data ; | ||
} | ||
}); | ||
|
||
export default function(string) { | ||
const data = []; | ||
return parseEvents(data, string); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
import id from '../../../fn/modules/id.js'; | ||
import overload from '../../../fn/modules/overload.js'; | ||
import toType from '../../../fn/modules/to-type.js'; | ||
import { toNoteNumber, floatToFrequency } from '../../../midi/modules/data.js'; | ||
|
||
const rdigit = /^\d/; | ||
|
||
export default overload(toType, { | ||
'number': id, | ||
'string': (value, tuning) => ( | ||
rdigit.test(value) ? | ||
value.slice(-2) === 'Hz' ? parseFloat(value) : | ||
floatToFrequency(tuning, value) : | ||
floatToFrequency(tuning, toNoteNumber(value)) | ||
) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
import toGain from '../../../fn/modules/to-gain.js'; | ||
import parseValue from '../../../fn/modules/parse-value.js'; | ||
|
||
export default parseValue({ | ||
'': parseFloat, | ||
'dB': toGain | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
import run from '../../../fn/modules/test.js'; | ||
import context from '../context.js'; | ||
import parseEvents from '../parse/parse-events.js'; | ||
|
||
run('Event.of()', [ | ||
[[0, 'note', 440, 1, 1]], | ||
[[0, 'note', 440, 1, 1]], | ||
[[0, 'note', 440, 1, 1]], | ||
[[0, 'note', 440, 0.001, 1]], | ||
[[1, 'sequence', 'name', 'target', 8]], | ||
[[1.1, 'param', 'gain', 0, 'step']], | ||
[[8.012, 'param', 'gain', 0.5, 'target', 3]], | ||
[ | ||
[0, 'note', 440, 1, 1], | ||
[0, 'note', 440, 1, 1], | ||
[1, 'sequence', 'name', 'target', 8], | ||
[1.1, 'param', 'gain', 0, 'step'], | ||
[8.012, 'param', 'gain', 0.5, 'target', 3], | ||
] | ||
], function(test, done) { | ||
test(parseEvents('0 note A4 1 1')); | ||
test(parseEvents(' 0 note A4 1 1 ')); | ||
test(parseEvents(' 0 note A4 0dB 1 ')); | ||
test(parseEvents(' 0 note A4 -60dB 1 ')); | ||
test(parseEvents('1 sequence name target 8')); | ||
test(parseEvents('1.1 param gain 0')); | ||
test(parseEvents('8.012 param gain 0.5 target 3')); | ||
test(parseEvents(` | ||
0 note A4 1 1 | ||
0 note A4 0dB 1 | ||
1 sequence name target 8 | ||
1.1 param gain 0 | ||
8.012 param gain 0.5 target 3 | ||
`)); | ||
|
||
done(); | ||
}, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.