Alex McLean 6422047cff
make 0.5hz cps the default (#931)
* 0.5 default cps

* 1 -> 0.5 cps defaults

* start moving examples to 2Hz

* more 2Hz doc edits

* small tweaks

* format

* adapt cycles page

* adapt pitch page

* tonal page

* accumulation

* synth page

* adapt conditional-modifiers

* audio effects page

* adapt signals doc

* fix: errors for signals

* adapt signals page

* start time modifiers

* adapt time modifiers

* adapt factories

* hydra + pattern intro

* adapt mini notation page

* start recipes

* adapt recipes page

* use code_v1 table

* delete old dbdump + add new csv based tool

* fix: tests

* fix: cpm

* shuffle featured patterns

* fix: snapshot

---------

Co-authored-by: Felix Roos <flix91@gmail.com>
2024-01-22 19:02:34 +00:00

32 lines
832 B
JavaScript

import { parse } from 'csv-parse/sync';
import { readFileSync } from 'fs';
import { stringify } from 'csv-stringify/sync';
const hasCpsCall = (code) =>
['setcps', 'setCps', 'setCpm', 'setcpm'].reduce((acc, m) => acc || code.includes(`${m}`), false);
function withCps(code, cps) {
if (hasCpsCall(code)) {
return code;
}
const lines = code.split('\n');
const firstNonLineComment = lines.findIndex((l) => !l.startsWith('//'));
const cpsCall = `setcps(${cps})`;
lines.splice(firstNonLineComment, 0, cpsCall);
return lines.join('\n');
}
const dumpNew = readFileSync('./code_rows.csv', { encoding: 'utf-8' });
const records = parse(dumpNew, {
columns: true,
skip_empty_lines: true,
});
const edited = records.map((entry) => ({
...entry,
code: withCps(entry.code, 1),
}));
console.log(stringify(edited));