mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
wip: generate song
This commit is contained in:
parent
1ca16043bc
commit
e282843f1f
30
convert.js
30
convert.js
@ -6,12 +6,18 @@ const doc = {
|
|||||||
bpm: groove.BPM,
|
bpm: groove.BPM,
|
||||||
rowsperbeat: 4,
|
rowsperbeat: 4,
|
||||||
score: {
|
score: {
|
||||||
length: groove.patterns[0].length,
|
length: groove.instrumentPatternLists[0].length,
|
||||||
rowsperpattern: groove.patternsize,
|
rowsperpattern: groove.patternsize,
|
||||||
tracks: groove.instrumentPatternLists.map(track => {
|
tracks: groove.instrumentPatternLists.map(track => {
|
||||||
|
const patternMap = {};
|
||||||
const patterns = track.map(patternIndex => groove.patterns[patternIndex]);
|
track.forEach(patternIndex => {
|
||||||
const order = track.map((patternIndex, ndx) => ndx);
|
patternMap[`${patternIndex}`] = groove.patterns[patternIndex];
|
||||||
|
});
|
||||||
|
const patternIndices = Object.keys(patternMap);
|
||||||
|
const patterns = patternIndices.map(patternIndex => patternMap[`${patternIndex}`]);
|
||||||
|
const order = track.map((patternIndex) => {
|
||||||
|
return patternIndices.indexOf(`${patternIndex}`);
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
numvoices: 1,
|
numvoices: 1,
|
||||||
order,
|
order,
|
||||||
@ -25,13 +31,11 @@ const doc = {
|
|||||||
const addInstrument = (name, strdef) => {
|
const addInstrument = (name, strdef) => {
|
||||||
const units = strdef.split('\n')
|
const units = strdef.split('\n')
|
||||||
.map(opline => {
|
.map(opline => {
|
||||||
console.log(opline);
|
|
||||||
const opcode_params = opline.replace(/\s\s+/,'\t').split(/[\t]/);
|
const opcode_params = opline.replace(/\s\s+/,'\t').split(/[\t]/);
|
||||||
const opcode = opcode_params[0];
|
const opcode = opcode_params[0];
|
||||||
const params = opcode_params[1].split(',');
|
const params = opcode_params[1].split(',');
|
||||||
const parameters = {};
|
const parameters = {};
|
||||||
params.forEach(param => {
|
params.forEach(param => {
|
||||||
console.log(param)
|
|
||||||
const paramParts = param.split('(');
|
const paramParts = param.split('(');
|
||||||
const paramName = paramParts[0];
|
const paramName = paramParts[0];
|
||||||
const paramValue = paramParts[1].substr(0, paramParts[1].length - 1);
|
const paramValue = paramParts[1].substr(0, paramParts[1].length - 1);
|
||||||
@ -51,15 +55,25 @@ const addInstrument = (name, strdef) => {
|
|||||||
case 'GAIN':
|
case 'GAIN':
|
||||||
parameters['gain'] = parseInt(paramValue);
|
parameters['gain'] = parseInt(paramValue);
|
||||||
break;
|
break;
|
||||||
|
case 'GAIN':
|
||||||
|
parameters['gain'] = parseInt(paramValue);
|
||||||
|
break;
|
||||||
|
case 'FLAGS':
|
||||||
|
if (opcode == 'GO4K_VCO') {
|
||||||
|
parameters['type'] = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
"type": {
|
"type": {
|
||||||
"GO4K_ENV": "envelope"
|
"GO4K_ENV": "envelope",
|
||||||
|
"GO4K_OUT": "out",
|
||||||
|
//"GO4K_VCO": "oscillator"
|
||||||
}[opcode],
|
}[opcode],
|
||||||
parameters
|
parameters
|
||||||
}
|
}
|
||||||
});
|
}).filter(unit => unit.type ?? false);
|
||||||
doc.patch.push({numvoices: 1, units});
|
doc.patch.push({numvoices: 1, units});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BIN
groove.wasm
Normal file
BIN
groove.wasm
Normal file
Binary file not shown.
69
groove.wat
69
groove.wat
File diff suppressed because one or more lines are too long
@ -1,5 +1,8 @@
|
|||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"test": "node convert.js && ./sointu-compile -o . -arch=wasm tests/groove.yaml && wat2wasm groove.wat && node testwasm.mjs"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"json-to-pretty-yaml": "^1.2.2"
|
"json-to-pretty-yaml": "^1.2.2"
|
||||||
}
|
}
|
||||||
|
14685
tests/groove.yaml
14685
tests/groove.yaml
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
import { readFile, writeFile } from 'fs/promises';
|
import { readFile, writeFile } from 'fs/promises';
|
||||||
|
|
||||||
const wasm = (await readFile('./chords.wasm'));
|
const wasm = (await readFile('./groove.wasm'));
|
||||||
|
|
||||||
const mod = await WebAssembly.instantiate(wasm, {
|
const mod = await WebAssembly.instantiate(wasm, {
|
||||||
m: {
|
m: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user