fix: webmidi hints
This commit is contained in:
parent
b4b38f1dc9
commit
9f2bc146c0
3 changed files with 16 additions and 9 deletions
|
|
@ -68,13 +68,13 @@ function App() {
|
||||||
|
|
||||||
useWebMidi({
|
useWebMidi({
|
||||||
ready: useCallback(({ outputs }) => {
|
ready: useCallback(({ outputs }) => {
|
||||||
pushLog(`WebMidi ready! Just add .midi(${outputs.map((o) => `"${o.name}"`).join(' | ')}) to the pattern. `);
|
pushLog(`WebMidi ready! Just add .midi(${outputs.map((o) => `'${o.name}'`).join(' | ')}) to the pattern. `);
|
||||||
}, []),
|
}, []),
|
||||||
connected: useCallback(({ outputs }) => {
|
connected: useCallback(({ outputs }) => {
|
||||||
pushLog(`Midi device connected! Available: ${outputs.map((o) => `"${o.name}"`).join(', ')}`);
|
pushLog(`Midi device connected! Available: ${outputs.map((o) => `'${o.name}'`).join(', ')}`);
|
||||||
}, []),
|
}, []),
|
||||||
disconnected: useCallback(({ outputs }) => {
|
disconnected: useCallback(({ outputs }) => {
|
||||||
pushLog(`Midi device disconnected! Available: ${outputs.map((o) => `"${o.name}"`).join(', ')}`);
|
pushLog(`Midi device disconnected! Available: ${outputs.map((o) => `'${o.name}'`).join(', ')}`);
|
||||||
}, []),
|
}, []),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -123,7 +123,7 @@ function App() {
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{error && (
|
{error && (
|
||||||
<div className={cx('absolute right-2 bottom-2', 'text-red-500')}>{error?.message || 'unknown error'}</div>
|
<div className={cx('absolute right-2 bottom-2 px-2', 'text-red-500')}>{error?.message || 'unknown error'}</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,13 @@ export default function enableWebMidi() {
|
||||||
const outputByName = (name: string) => WebMidi.getOutputByName(name);
|
const outputByName = (name: string) => WebMidi.getOutputByName(name);
|
||||||
|
|
||||||
Pattern.prototype.midi = function (output: string, channel = 1) {
|
Pattern.prototype.midi = function (output: string, channel = 1) {
|
||||||
|
if (output?.constructor?.name === 'Pattern') {
|
||||||
|
throw new Error(
|
||||||
|
`.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'
|
||||||
|
}')`
|
||||||
|
);
|
||||||
|
}
|
||||||
return this.fmap((value: any) => ({
|
return this.fmap((value: any) => ({
|
||||||
...value,
|
...value,
|
||||||
onTrigger: (time: number, event: any) => {
|
onTrigger: (time: number, event: any) => {
|
||||||
|
|
@ -41,8 +48,8 @@ Pattern.prototype.midi = function (output: string, channel = 1) {
|
||||||
const device = output ? outputByName(output) : WebMidi.outputs[0];
|
const device = output ? outputByName(output) : WebMidi.outputs[0];
|
||||||
if (!device) {
|
if (!device) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`🔌 MIDI device ${output ? output : ''} not found. Use one of ${WebMidi.outputs
|
`🔌 MIDI device '${output ? output : ''}' not found. Use one of ${WebMidi.outputs
|
||||||
.map((o: any) => `"${o.name}"`)
|
.map((o: any) => `'${o.name}'`)
|
||||||
.join(' | ')}`
|
.join(' | ')}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,13 +125,13 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent }: any) {
|
||||||
|
|
||||||
/* useWebMidi({
|
/* useWebMidi({
|
||||||
ready: useCallback(({ outputs }) => {
|
ready: useCallback(({ outputs }) => {
|
||||||
pushLog(`WebMidi ready! Just add .midi(${outputs.map((o) => `"${o.name}"`).join(' | ')}) to the pattern. `);
|
pushLog(`WebMidi ready! Just add .midi(${outputs.map((o) => `'${o.name}'`).join(' | ')}) to the pattern. `);
|
||||||
}, []),
|
}, []),
|
||||||
connected: useCallback(({ outputs }) => {
|
connected: useCallback(({ outputs }) => {
|
||||||
pushLog(`Midi device connected! Available: ${outputs.map((o) => `"${o.name}"`).join(', ')}`);
|
pushLog(`Midi device connected! Available: ${outputs.map((o) => `'${o.name}'`).join(', ')}`);
|
||||||
}, []),
|
}, []),
|
||||||
disconnected: useCallback(({ outputs }) => {
|
disconnected: useCallback(({ outputs }) => {
|
||||||
pushLog(`Midi device disconnected! Available: ${outputs.map((o) => `"${o.name}"`).join(', ')}`);
|
pushLog(`Midi device disconnected! Available: ${outputs.map((o) => `'${o.name}'`).join(', ')}`);
|
||||||
}, []),
|
}, []),
|
||||||
}); */
|
}); */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue