This commit is contained in:
Felix Roos 2022-03-13 11:48:08 +01:00
parent 5d8ccdff25
commit 225f6c7785
6 changed files with 20 additions and 13 deletions

View File

@ -328,7 +328,7 @@ class Pattern {
_opleft(other, func) {
return this.fmap(func).appLeft(reify(other));
}
_asNumber() {
_asNumber(silent = false) {
return this._withEvent((event) => {
const asNumber = Number(event.value);
if (!isNaN(asNumber)) {
@ -344,8 +344,11 @@ class Pattern {
if (isNote(event.value)) {
return new Hap(event.whole, event.part, toMidi(event.value), {...event.context, type: "midi"});
}
throw new Error('cannot parse as number: "' + event.value + '"');
});
if (!silent) {
throw new Error('cannot parse as number: "' + event.value + '"');
}
return event.withValue(() => void 0);
})._removeUndefineds();
}
add(other) {
return this._asNumber()._opleft(other, (a) => (b) => a + b);

2
docs/dist/draw.js vendored
View File

@ -26,7 +26,7 @@ Pattern.prototype.draw = function(callback, cycleSpan, lookaheadCycles = 1) {
cycle = currentCycle;
const begin = currentCycle * cycleSpan;
const end = (currentCycle + lookaheadCycles) * cycleSpan;
events = this.add(0).query(new State(new TimeSpan(begin, end)));
events = this._asNumber(true).query(new State(new TimeSpan(begin, end))).filter((event) => event.part.begin.valueOf() === event.whole.begin.valueOf());
}
}
callback(ctx, events, t, cycleSpan, time);

View File

@ -20,7 +20,7 @@ function useCycle(props) {
events?.filter((event) => event.part.begin.valueOf() === event.whole.begin.valueOf()).forEach((event) => {
Tone.getTransport().schedule((time) => {
const toneEvent = {
time: event.part.begin.valueOf(),
time: event.whole.begin.valueOf(),
duration: event.whole.end.sub(event.whole.begin).valueOf(),
value: event.value,
context: event.context

View File

@ -42450,7 +42450,7 @@ class Pattern {
_opleft(other, func) {
return this.fmap(func).appLeft(reify(other));
}
_asNumber() {
_asNumber(silent = false) {
return this._withEvent((event)=>{
const asNumber = Number(event.value);
if (!isNaN(asNumber)) return event.withValue(()=>asNumber
@ -42466,8 +42466,10 @@ class Pattern {
...event.context,
type: 'midi'
});
throw new Error('cannot parse as number: "' + event.value + '"');
});
if (!silent) throw new Error('cannot parse as number: "' + event.value + '"');
return event.withValue(()=>undefined
); // silent error
})._removeUndefineds();
}
add(other) {
return this._asNumber()._opleft(other, (a)=>(b)=>a + b
@ -136201,7 +136203,9 @@ _strudelMjs.Pattern.prototype.draw = function(callback, cycleSpan, lookaheadCycl
cycle = currentCycle;
const begin = currentCycle * cycleSpan;
const end = (currentCycle + lookaheadCycles) * cycleSpan;
events = this.add(0).query(new State(new TimeSpan(begin, end)));
events = this._asNumber(true) // true = silent error
.query(new State(new TimeSpan(begin, end))).filter((event)=>event.part.begin.valueOf() === event.whole.begin.valueOf()
);
}
}
callback(ctx, events, t, cycleSpan, time);
@ -171654,7 +171658,7 @@ function useCycle(props) {
).forEach((event)=>{
_tone.getTransport().schedule((time)=>{
const toneEvent = {
time: event.part.begin.valueOf(),
time: event.whole.begin.valueOf(),
duration: event.whole.end.sub(event.whole.begin).valueOf(),
value: event.value,
context: event.context
@ -182991,4 +182995,4 @@ exports.default = cx;
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}]},["3uVTb"], "3uVTb", "parcelRequire94c2")
//# sourceMappingURL=index.a8828e57.js.map
//# sourceMappingURL=index.5025d817.js.map

File diff suppressed because one or more lines are too long

View File

@ -11,6 +11,6 @@
<body>
<div id="root"></div>
<noscript>You need to enable JavaScript to run this app.</noscript>
<script src="/tutorial/index.a8828e57.js" defer=""></script>
<script src="/tutorial/index.5025d817.js" defer=""></script>
</body>
</html>