mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 13:48:40 +00:00
fix: web midi
This commit is contained in:
parent
372bdf8be7
commit
eca92cf5b5
@ -12,7 +12,19 @@ export function repl({
|
||||
transpiler,
|
||||
onToggle,
|
||||
}) {
|
||||
const scheduler = new Cyclist({ interval, onTrigger: defaultOutput, onError: onSchedulerError, getTime, onToggle });
|
||||
const scheduler = new Cyclist({
|
||||
interval,
|
||||
onTrigger: (hap, deadline, duration) => {
|
||||
if (!hap.context.onTrigger) {
|
||||
return defaultOutput(hap, deadline, duration);
|
||||
}
|
||||
// call signature of output / onTrigger is different...
|
||||
return hap.context.onTrigger(getTime() + deadline, hap);
|
||||
},
|
||||
onError: onSchedulerError,
|
||||
getTime,
|
||||
onToggle,
|
||||
});
|
||||
const evaluate = async (code, autostart = true) => {
|
||||
if (!code) {
|
||||
throw new Error('no code to evaluate');
|
||||
|
||||
@ -5,7 +5,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
*/
|
||||
|
||||
import * as _WebMidi from 'webmidi';
|
||||
import { Pattern, isPattern, isNote } from '@strudel.cycles/core';
|
||||
import { Pattern, isPattern, isNote, getPlayableNoteValue } from '@strudel.cycles/core';
|
||||
import { getAudioContext } from '@strudel.cycles/webaudio';
|
||||
|
||||
// if you use WebMidi from outside of this package, make sure to import that instance:
|
||||
@ -41,7 +41,7 @@ Pattern.prototype.midi = function (output, channel = 1) {
|
||||
return this._withHap((hap) => {
|
||||
// const onTrigger = (time: number, hap: any) => {
|
||||
const onTrigger = (time, hap) => {
|
||||
let note = hap.value;
|
||||
let note = getPlayableNoteValue(hap);
|
||||
const velocity = hap.context?.velocity ?? 0.9;
|
||||
if (!isNote(note)) {
|
||||
throw new Error('not a note: ' + note);
|
||||
@ -75,7 +75,7 @@ Pattern.prototype.midi = function (output, channel = 1) {
|
||||
device.playNote(note, channel, {
|
||||
time,
|
||||
duration: hap.duration.valueOf() * 1000 - 5,
|
||||
velocity,
|
||||
velocity, // TODO: "OutputChannel.js:942 The 'velocity' option is deprecated. Use 'attack' instead."?
|
||||
});
|
||||
};
|
||||
return hap.setContext({ ...hap.context, onTrigger });
|
||||
|
||||
16
packages/react/dist/index.cjs.js
vendored
16
packages/react/dist/index.cjs.js
vendored
File diff suppressed because one or more lines are too long
436
packages/react/dist/index.es.js
vendored
436
packages/react/dist/index.es.js
vendored
File diff suppressed because it is too large
Load Diff
@ -33,8 +33,9 @@ currently broken / buggy:
|
||||
- [ ] repl log section => remove?
|
||||
- [ ] hideHeader flag
|
||||
- [ ] pending flag
|
||||
- [ ] web midi
|
||||
- [x] web midi, TODO: test
|
||||
- [ ] draw / pianoroll
|
||||
- [ ] repl url hash does not work
|
||||
- [x] pause does stop
|
||||
- [ ] pause then play logs "TOO LATE" and drops some events
|
||||
- [x] random button triggers start
|
||||
|
||||
@ -150,7 +150,7 @@ function App() {
|
||||
// getTime: () => Tone.getTransport().seconds,
|
||||
});
|
||||
|
||||
/* useWebMidi({
|
||||
useWebMidi({
|
||||
ready: useCallback(
|
||||
({ outputs }) => {
|
||||
pushLog(`WebMidi ready! Just add .midi(${outputs.map((o) => `'${o.name}'`).join(' | ')}) to the pattern. `);
|
||||
@ -169,7 +169,7 @@ function App() {
|
||||
},
|
||||
[pushLog],
|
||||
),
|
||||
}); */
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user