use performance clock for osc mode
This commit is contained in:
parent
8da1d9fbf3
commit
796f741a92
5 changed files with 19 additions and 8 deletions
|
|
@ -412,6 +412,11 @@ export class ClockCollator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function getPerformanceTimeSeconds() {
|
||||||
|
return performance.now() / 1000
|
||||||
|
}
|
||||||
|
|
||||||
// Floating point versions, see Fraction for rational versions
|
// Floating point versions, see Fraction for rational versions
|
||||||
// // greatest common divisor
|
// // greatest common divisor
|
||||||
// export const gcd = function (x, y, ...z) {
|
// export const gcd = function (x, y, ...z) {
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ function connect() {
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// const collator = new ClockCollator({getTargetClockTime: () => (performance.now() + performance.timeOrigin) / 1000});
|
||||||
const collator = new ClockCollator({});
|
const collator = new ClockCollator({});
|
||||||
|
|
||||||
export async function oscTrigger(t_deprecate, hap, currentTime, cps = 1, targetTime) {
|
export async function oscTrigger(t_deprecate, hap, currentTime, cps = 1, targetTime) {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
import { oscTriggerTauri } from '../desktopbridge/oscbridge.mjs';
|
import { oscTriggerTauri } from '../desktopbridge/oscbridge.mjs';
|
||||||
import { isTauri } from '../desktopbridge/utils.mjs';
|
import { isTauri } from '../desktopbridge/utils.mjs';
|
||||||
import { getAudioContext } from '../superdough/superdough.mjs';
|
|
||||||
import { oscTrigger } from './osc.mjs';
|
import { oscTrigger } from './osc.mjs';
|
||||||
|
|
||||||
|
|
||||||
const trigger = isTauri() ? oscTriggerTauri : oscTrigger;
|
const trigger = isTauri() ? oscTriggerTauri : oscTrigger;
|
||||||
|
|
||||||
export const superdirtOutput = (hap, deadline, hapDuration, cps, targetTime) => {
|
export const superdirtOutput = (hap, deadline, hapDuration, cps, targetTime) => {
|
||||||
const ctx = getAudioContext();
|
const currentTime = performance.now() / 1000
|
||||||
const currentTime = ctx.currentTime;
|
|
||||||
return trigger(null, hap, currentTime, cps, targetTime);
|
return trigger(null, hap, currentTime, cps, targetTime);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,10 @@ export const getAudioContext = () => {
|
||||||
return audioContext;
|
return audioContext;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function getAudioContextCurrentTime() {
|
||||||
|
return getAudioContext().currentTime
|
||||||
|
}
|
||||||
|
|
||||||
let workletsLoading;
|
let workletsLoading;
|
||||||
function loadWorklets() {
|
function loadWorklets() {
|
||||||
if (!workletsLoading) {
|
if (!workletsLoading) {
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ 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/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { code2hash, logger, silence } from '@strudel/core';
|
import { code2hash, getPerformanceTimeSeconds, logger, silence } from '@strudel/core';
|
||||||
import { getDrawContext } from '@strudel/draw';
|
import { getDrawContext } from '@strudel/draw';
|
||||||
import { transpiler } from '@strudel/transpiler';
|
import { transpiler } from '@strudel/transpiler';
|
||||||
import {
|
import {
|
||||||
getAudioContext,
|
getAudioContextCurrentTime,
|
||||||
webaudioOutput,
|
webaudioOutput,
|
||||||
resetGlobalEffects,
|
resetGlobalEffects,
|
||||||
resetLoadedSounds,
|
resetLoadedSounds,
|
||||||
|
|
@ -56,8 +56,10 @@ async function getModule(name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useReplContext() {
|
export function useReplContext() {
|
||||||
const { panelPosition, isZen, isSyncEnabled, audioEngineTarget } = useSettings();
|
const { isSyncEnabled, audioEngineTarget } = useSettings();
|
||||||
const defaultOutput = audioEngineTarget === audioEngineTargets.superdirt ? superdirtOutput : webaudioOutput;
|
const shouldUseWebaudio = audioEngineTarget !== audioEngineTargets.superdirt;
|
||||||
|
const defaultOutput = shouldUseWebaudio ? webaudioOutput : superdirtOutput;
|
||||||
|
const getTime = shouldUseWebaudio ? getAudioContextCurrentTime : getPerformanceTimeSeconds;
|
||||||
|
|
||||||
const init = useCallback(() => {
|
const init = useCallback(() => {
|
||||||
const drawTime = [-2, 2];
|
const drawTime = [-2, 2];
|
||||||
|
|
@ -65,7 +67,7 @@ export function useReplContext() {
|
||||||
const editor = new StrudelMirror({
|
const editor = new StrudelMirror({
|
||||||
sync: isSyncEnabled,
|
sync: isSyncEnabled,
|
||||||
defaultOutput,
|
defaultOutput,
|
||||||
getTime: () => getAudioContext().currentTime,
|
getTime,
|
||||||
setInterval,
|
setInterval,
|
||||||
clearInterval,
|
clearInterval,
|
||||||
transpiler,
|
transpiler,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue