fixed osc server
This commit is contained in:
parent
5d8eea7299
commit
57ad278137
4 changed files with 7 additions and 8 deletions
|
|
@ -62,8 +62,8 @@ export const valueToMidi = (value, fallbackValue) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// used to schedule external event like midi and osc out
|
// used to schedule external event like midi and osc out
|
||||||
export const getEventOffsetMs = (targetTime, currentTime) => {
|
export const getEventOffsetMs = (targetTimeSeconds, currentTimeSeconds) => {
|
||||||
return (targetTime - currentTime) * 1000;
|
return (targetTimeSeconds - currentTimeSeconds) * 1000;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { Invoke } from './utils.mjs';
|
import { Invoke } from './utils.mjs';
|
||||||
import { Pattern, noteToMidi } from '@strudel/core';
|
import { Pattern, getEventOffsetMs, noteToMidi } from '@strudel/core';
|
||||||
|
|
||||||
const ON_MESSAGE = 0x90;
|
const ON_MESSAGE = 0x90;
|
||||||
const OFF_MESSAGE = 0x80;
|
const OFF_MESSAGE = 0x80;
|
||||||
|
|
@ -9,8 +9,8 @@ Pattern.prototype.midi = function (output) {
|
||||||
return this.onTrigger((time_deprecate, hap, currentTime, cps, targetTime) => {
|
return this.onTrigger((time_deprecate, hap, currentTime, cps, targetTime) => {
|
||||||
let { note, nrpnn, nrpv, ccn, ccv, velocity = 0.9, gain = 1 } = hap.value;
|
let { note, nrpnn, nrpv, ccn, ccv, velocity = 0.9, gain = 1 } = hap.value;
|
||||||
//magic number to get audio engine to line up, can probably be calculated somehow
|
//magic number to get audio engine to line up, can probably be calculated somehow
|
||||||
const latency = 0.034;
|
const latencyMs = 34;
|
||||||
const offset = (targetTime - currentTime + latency) * 1000;
|
const offset = getEventOffsetMs(targetTime, currentTime) + latencyMs;
|
||||||
velocity = Math.floor(gain * velocity * 100);
|
velocity = Math.floor(gain * velocity * 100);
|
||||||
const duration = Math.floor((hap.duration.valueOf() / cps) * 1000 - 10);
|
const duration = Math.floor((hap.duration.valueOf() / cps) * 1000 - 10);
|
||||||
const roundedOffset = Math.round(offset);
|
const roundedOffset = Math.round(offset);
|
||||||
|
|
|
||||||
|
|
@ -122,8 +122,7 @@ Pattern.prototype.midi = function (output) {
|
||||||
//magic number to get audio engine to line up, can probably be calculated somehow
|
//magic number to get audio engine to line up, can probably be calculated somehow
|
||||||
const latencyMs = 34;
|
const latencyMs = 34;
|
||||||
// passing a string with a +num into the webmidi api adds an offset to the current time https://webmidijs.org/api/classes/Output
|
// passing a string with a +num into the webmidi api adds an offset to the current time https://webmidijs.org/api/classes/Output
|
||||||
const timeOffsetString = `${getEventOffsetMs(targetTime, currentTime) + latencyMs}`;
|
const timeOffsetString = `+${getEventOffsetMs(targetTime, currentTime) + latencyMs}`;
|
||||||
|
|
||||||
// destructure value
|
// destructure value
|
||||||
let { note, nrpnn, nrpv, ccn, ccv, midichan = 1, midicmd, gain = 1, velocity = 0.9 } = hap.value;
|
let { note, nrpnn, nrpv, ccn, ccv, midichan = 1, midicmd, gain = 1, velocity = 0.9 } = hap.value;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/st
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const OSC = require('osc-js');
|
import OSC from 'osc-js';
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
receiver: 'ws', // @param {string} Where messages sent via 'send' method will be delivered to, 'ws' for Websocket clients, 'udp' for udp client
|
receiver: 'ws', // @param {string} Where messages sent via 'send' method will be delivered to, 'ws' for Websocket clients, 'udp' for udp client
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue