Skip to content

Commit

Permalink
fixed osc server
Browse files Browse the repository at this point in the history
  • Loading branch information
daslyfe committed Apr 21, 2024
1 parent 5d8eea7 commit 57ad278
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/core/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export const valueToMidi = (value, fallbackValue) => {
};

// used to schedule external event like midi and osc out
export const getEventOffsetMs = (targetTime, currentTime) => {
return (targetTime - currentTime) * 1000;
export const getEventOffsetMs = (targetTimeSeconds, currentTimeSeconds) => {
return (targetTimeSeconds - currentTimeSeconds) * 1000;
};

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/desktopbridge/midibridge.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Invoke } from './utils.mjs';
import { Pattern, noteToMidi } from '@strudel/core';
import { Pattern, getEventOffsetMs, noteToMidi } from '@strudel/core';

const ON_MESSAGE = 0x90;
const OFF_MESSAGE = 0x80;
Expand All @@ -9,8 +9,8 @@ Pattern.prototype.midi = function (output) {
return this.onTrigger((time_deprecate, hap, currentTime, cps, targetTime) => {
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
const latency = 0.034;
const offset = (targetTime - currentTime + latency) * 1000;
const latencyMs = 34;
const offset = getEventOffsetMs(targetTime, currentTime) + latencyMs;
velocity = Math.floor(gain * velocity * 100);
const duration = Math.floor((hap.duration.valueOf() / cps) * 1000 - 10);
const roundedOffset = Math.round(offset);
Expand Down
3 changes: 1 addition & 2 deletions packages/midi/midi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ Pattern.prototype.midi = function (output) {
//magic number to get audio engine to line up, can probably be calculated somehow
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
const timeOffsetString = `${getEventOffsetMs(targetTime, currentTime) + latencyMs}`;

const timeOffsetString = `+${getEventOffsetMs(targetTime, currentTime) + latencyMs}`;
// destructure value
let { note, nrpnn, nrpv, ccn, ccv, midichan = 1, midicmd, gain = 1, velocity = 0.9 } = hap.value;

Expand Down
2 changes: 1 addition & 1 deletion packages/osc/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/>.
*/

const OSC = require('osc-js');
import OSC from 'osc-js';

const config = {
receiver: 'ws', // @param {string} Where messages sent via 'send' method will be delivered to, 'ws' for Websocket clients, 'udp' for udp client
Expand Down

0 comments on commit 57ad278

Please sign in to comment.