mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-22 02:58:32 +00:00
midi cc input poc
This commit is contained in:
parent
0a8874180c
commit
0f72729f0d
@ -2336,3 +2336,9 @@ export const fit = register('fit', (pat) =>
|
|||||||
export const { loopAtCps, loopatcps } = register(['loopAtCps', 'loopatcps'], function (factor, cps, pat) {
|
export const { loopAtCps, loopatcps } = register(['loopAtCps', 'loopatcps'], function (factor, cps, pat) {
|
||||||
return _loopAt(factor, pat, cps);
|
return _loopAt(factor, pat, cps);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** exposes a custom value at query time. basically allows mutating state without evaluation */
|
||||||
|
export const ref = (accessor) =>
|
||||||
|
pure(1)
|
||||||
|
.withValue(() => reify(accessor()))
|
||||||
|
.innerJoin();
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import * as _WebMidi from 'webmidi';
|
|||||||
import { Pattern, isPattern, logger } from '@strudel.cycles/core';
|
import { Pattern, isPattern, logger } from '@strudel.cycles/core';
|
||||||
import { noteToMidi } from '@strudel.cycles/core';
|
import { noteToMidi } from '@strudel.cycles/core';
|
||||||
import { Note } from 'webmidi';
|
import { Note } from 'webmidi';
|
||||||
import EventEmitter from 'events';
|
|
||||||
// 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;
|
||||||
|
|
||||||
@ -137,7 +136,10 @@ Pattern.prototype.midi = function (output) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function midiIn(input) {
|
let listeners = {};
|
||||||
|
const refs = {};
|
||||||
|
|
||||||
|
export async function midin(input) {
|
||||||
console.log('midi in...');
|
console.log('midi in...');
|
||||||
const initial = await enableWebMidi(); // only returns on first init
|
const initial = await enableWebMidi(); // only returns on first init
|
||||||
const device = getDevice(input, WebMidi.inputs);
|
const device = getDevice(input, WebMidi.inputs);
|
||||||
@ -149,12 +151,18 @@ export async function midiIn(input) {
|
|||||||
otherInputs?.length ? `Also available: ${getMidiDeviceNamesString(otherInputs)}` : ''
|
otherInputs?.length ? `Also available: ${getMidiDeviceNamesString(otherInputs)}` : ''
|
||||||
}`,
|
}`,
|
||||||
);
|
);
|
||||||
|
refs[input] = {};
|
||||||
}
|
}
|
||||||
return (fn) => {
|
const cc = (cc) => ref(() => refs[input][cc] || 0);
|
||||||
device.addListener(EventEmitter.ANY_EVENT, (...args) => {
|
|
||||||
console.log('event!', args);
|
listeners[input] && device.removeListener('midimessage', listeners[input]);
|
||||||
fn(args);
|
listeners[input] = (e) => {
|
||||||
});
|
const cc = e.dataBytes[0];
|
||||||
return;
|
const v = e.dataBytes[1];
|
||||||
|
console.log(cc, v);
|
||||||
|
refs[input][cc] = v / 127;
|
||||||
};
|
};
|
||||||
|
device.addListener('midimessage', listeners[input]);
|
||||||
|
//return { cc };
|
||||||
|
return cc;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user