mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-25 20:48:27 +00:00
fix pattern checks for minified code
This commit is contained in:
parent
ef75590853
commit
9458faf5b0
@ -563,7 +563,7 @@ class Pattern {
|
|||||||
// to avoid object checking for every pattern method, we can remove it here...
|
// to avoid object checking for every pattern method, we can remove it here...
|
||||||
// in the future, patternified args should be marked as well + some better object handling
|
// in the future, patternified args should be marked as well + some better object handling
|
||||||
args = args.map((arg) =>
|
args = args.map((arg) =>
|
||||||
arg.constructor?.name === 'Pattern' ? arg.fmap((value) => value.value || value) : arg
|
isPattern(arg) ? arg.fmap((value) => value.value || value) : arg
|
||||||
);
|
);
|
||||||
const pat_arg = sequence(...args)
|
const pat_arg = sequence(...args)
|
||||||
// arg.locations has to go somewhere..
|
// arg.locations has to go somewhere..
|
||||||
@ -830,14 +830,18 @@ export const tri = fastcat(isaw, saw)
|
|||||||
export const square = signal(t => Math.floor((t*2) % 2))
|
export const square = signal(t => Math.floor((t*2) % 2))
|
||||||
export const square2 = _toBipolar(square)
|
export const square2 = _toBipolar(square)
|
||||||
|
|
||||||
|
export function isPattern(thing) {
|
||||||
|
// thing?.constructor?.name !== 'Pattern' // <- this will fail when code is mangled
|
||||||
|
return thing instanceof Pattern;
|
||||||
|
}
|
||||||
|
|
||||||
function reify(thing) {
|
function reify(thing) {
|
||||||
// Tunrs something into a pattern, unless it's already a pattern
|
// Turns something into a pattern, unless it's already a pattern
|
||||||
if (thing?.constructor?.name == "Pattern") {
|
if (isPattern(thing)) {
|
||||||
return thing
|
return thing;
|
||||||
}
|
}
|
||||||
return pure(thing)
|
return pure(thing)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Basic functions for combining patterns
|
// Basic functions for combining patterns
|
||||||
|
|
||||||
function stack(...pats) {
|
function stack(...pats) {
|
||||||
|
|||||||
@ -49,7 +49,8 @@ export const evaluate = async (code) => {
|
|||||||
drawHelpers.cleanup();
|
drawHelpers.cleanup();
|
||||||
uiHelpers.cleanup();
|
uiHelpers.cleanup();
|
||||||
let evaluated = await eval(shapeshifted);
|
let evaluated = await eval(shapeshifted);
|
||||||
if (evaluated?.constructor?.name !== 'Pattern') {
|
if (!isPattern(evaluated)) {
|
||||||
|
console.log('evaluated', evaluated);
|
||||||
const message = `got "${typeof evaluated}" instead of pattern`;
|
const message = `got "${typeof evaluated}" instead of pattern`;
|
||||||
throw new Error(message + (typeof evaluated === 'function' ? ', did you forget to call a function?' : '.'));
|
throw new Error(message + (typeof evaluated === 'function' ? ', did you forget to call a function?' : '.'));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
import { isNote } from 'tone';
|
import { isNote } from 'tone';
|
||||||
import _WebMidi from 'webmidi';
|
import _WebMidi from 'webmidi';
|
||||||
import { Pattern as _Pattern } from '@strudel/core/strudel.mjs';
|
import { Pattern, isPattern } from '@strudel/core/strudel.mjs';
|
||||||
import { Tone } from '@strudel/tone';
|
import { Tone } from '@strudel/tone';
|
||||||
|
|
||||||
// if you use WebMidi from outside of this package, make sure to import that instance:
|
// if you use WebMidi from outside of this package, make sure to import that instance:
|
||||||
export const WebMidi = _WebMidi;
|
export const WebMidi = _WebMidi;
|
||||||
|
|
||||||
const Pattern = _Pattern;
|
|
||||||
|
|
||||||
export function enableWebMidi() {
|
export function enableWebMidi() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (WebMidi.enabled) {
|
if (WebMidi.enabled) {
|
||||||
@ -28,7 +26,7 @@ const outputByName = (name) => WebMidi.getOutputByName(name);
|
|||||||
|
|
||||||
// Pattern.prototype.midi = function (output: string | number, channel = 1) {
|
// Pattern.prototype.midi = function (output: string | number, channel = 1) {
|
||||||
Pattern.prototype.midi = function (output, channel = 1) {
|
Pattern.prototype.midi = function (output, channel = 1) {
|
||||||
if (output?.constructor?.name === 'Pattern') {
|
if (isPattern(output?.constructor?.name)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`.midi does not accept Pattern input. Make sure to pass device name with single quotes. Example: .midi('${
|
`.midi does not accept Pattern input. Make sure to pass device name with single quotes. Example: .midi('${
|
||||||
WebMidi.outputs?.[0]?.name || 'IAC Driver Bus 1'
|
WebMidi.outputs?.[0]?.name || 'IAC Driver Bus 1'
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import * as krill from './krill-parser.js';
|
|||||||
import * as strudel from '@strudel/core/strudel.mjs';
|
import * as strudel from '@strudel/core/strudel.mjs';
|
||||||
import { addMiniLocations } from '../eval/shapeshifter.mjs';
|
import { addMiniLocations } from '../eval/shapeshifter.mjs';
|
||||||
|
|
||||||
const { pure, Pattern, Fraction, stack, slowcat, sequence, timeCat, silence } = strudel;
|
const { pure, Pattern, Fraction, stack, slowcat, sequence, timeCat, silence, reify } = strudel;
|
||||||
|
|
||||||
const applyOptions = (parent) => (pat, i) => {
|
const applyOptions = (parent) => (pat, i) => {
|
||||||
const ast = parent.source_[i];
|
const ast = parent.source_[i];
|
||||||
@ -159,14 +159,6 @@ Pattern.prototype.define('mini', mini, { composable: true });
|
|||||||
Pattern.prototype.define('m', mini, { composable: true });
|
Pattern.prototype.define('m', mini, { composable: true });
|
||||||
Pattern.prototype.define('h', h, { composable: true });
|
Pattern.prototype.define('h', h, { composable: true });
|
||||||
|
|
||||||
// TODO: move this to strudel?
|
|
||||||
export function reify(thing) {
|
|
||||||
if (thing?.constructor?.name === 'Pattern') {
|
|
||||||
return thing;
|
|
||||||
}
|
|
||||||
return pure(thing);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function minify(thing) {
|
export function minify(thing) {
|
||||||
if (typeof thing === 'string') {
|
if (typeof thing === 'string') {
|
||||||
return mini(thing);
|
return mini(thing);
|
||||||
|
|||||||
@ -50,7 +50,31 @@ Pattern.prototype.tone = function (instrument) {
|
|||||||
const onTrigger = (time, event) => {
|
const onTrigger = (time, event) => {
|
||||||
let note;
|
let note;
|
||||||
let velocity = event.context?.velocity ?? 0.75;
|
let velocity = event.context?.velocity ?? 0.75;
|
||||||
switch (instrument.constructor.name) {
|
if (instrument instanceof PluckSynth) {
|
||||||
|
note = getPlayableNoteValue(event);
|
||||||
|
instrument.triggerAttack(note, time);
|
||||||
|
} else if (instrument instanceof NoiseSynth) {
|
||||||
|
instrument.triggerAttackRelease(event.duration, time); // noise has no value
|
||||||
|
} else if (instrument instanceof Piano) {
|
||||||
|
note = getPlayableNoteValue(event);
|
||||||
|
instrument.keyDown({ note, time, velocity });
|
||||||
|
instrument.keyUp({ note, time: time + event.duration, velocity });
|
||||||
|
} else if (instrument instanceof Sampler) {
|
||||||
|
note = getPlayableNoteValue(event);
|
||||||
|
instrument.triggerAttackRelease(note, event.duration, time, velocity);
|
||||||
|
} else if (instrument instanceof Players) {
|
||||||
|
if (!instrument.has(event.value)) {
|
||||||
|
throw new Error(`name "${event.value}" not defined for players`);
|
||||||
|
}
|
||||||
|
const player = instrument.player(event.value);
|
||||||
|
// velocity ?
|
||||||
|
player.start(time);
|
||||||
|
player.stop(time + event.duration);
|
||||||
|
} else {
|
||||||
|
note = getPlayableNoteValue(event);
|
||||||
|
instrument.triggerAttackRelease(note, event.duration, time, velocity);
|
||||||
|
}
|
||||||
|
/* switch (instrument.constructor.name) {
|
||||||
case 'PluckSynth':
|
case 'PluckSynth':
|
||||||
note = getPlayableNoteValue(event);
|
note = getPlayableNoteValue(event);
|
||||||
instrument.triggerAttack(note, time);
|
instrument.triggerAttack(note, time);
|
||||||
@ -79,7 +103,7 @@ Pattern.prototype.tone = function (instrument) {
|
|||||||
default:
|
default:
|
||||||
note = getPlayableNoteValue(event);
|
note = getPlayableNoteValue(event);
|
||||||
instrument.triggerAttackRelease(note, event.duration, time, velocity);
|
instrument.triggerAttackRelease(note, event.duration, time, velocity);
|
||||||
}
|
} */
|
||||||
};
|
};
|
||||||
return event.setContext({ ...event.context, instrument, onTrigger });
|
return event.setContext({ ...event.context, instrument, onTrigger });
|
||||||
});
|
});
|
||||||
|
|||||||
1313
repl/package-lock.json
generated
1313
repl/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -9,6 +9,7 @@
|
|||||||
"@testing-library/user-event": "^13.5.0",
|
"@testing-library/user-event": "^13.5.0",
|
||||||
"codemirror": "^5.65.2",
|
"codemirror": "^5.65.2",
|
||||||
"events": "^3.3.0",
|
"events": "^3.3.0",
|
||||||
|
"gh-pages": "^3.2.3",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-codemirror2": "^7.2.1",
|
"react-codemirror2": "^7.2.1",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
@ -22,7 +23,10 @@
|
|||||||
"test": "react-scripts test",
|
"test": "react-scripts test",
|
||||||
"eject": "react-scripts eject",
|
"eject": "react-scripts eject",
|
||||||
"tutorial": "parcel src/tutorial/index.html --no-cache",
|
"tutorial": "parcel src/tutorial/index.html --no-cache",
|
||||||
"build-tutorial": "parcel build src/tutorial/index.html --dist-dir ../docs/tutorial --public-url /tutorial --no-optimize --no-scope-hoist --no-cache"
|
"build-tutorial": "parcel build src/tutorial/index.html --dist-dir ../docs/tutorial --public-url /tutorial --no-optimize --no-scope-hoist --no-cache",
|
||||||
|
"predeploy": "npm run build",
|
||||||
|
"deploy": "gh-pages -d build",
|
||||||
|
"static": "npx serve ./build"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": [
|
"extends": [
|
||||||
@ -48,6 +52,7 @@
|
|||||||
"autoprefixer": "^10.4.4",
|
"autoprefixer": "^10.4.4",
|
||||||
"parcel": "^2.3.1",
|
"parcel": "^2.3.1",
|
||||||
"postcss": "^8.4.12",
|
"postcss": "^8.4.12",
|
||||||
|
"serve": "^13.0.2",
|
||||||
"tailwindcss": "^3.0.23"
|
"tailwindcss": "^3.0.23"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user