mirror of
https://codeberg.org/uzu/strudel
synced 2026-09-05 22:58:09 -04:00
cyclist bridge
This commit is contained in:
@@ -6,8 +6,6 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
|
||||
import createClock from './zyklus.mjs';
|
||||
import { logger } from './logger.mjs';
|
||||
import { Invoke } from '../../website/src/tauri.mjs';
|
||||
import { listen } from '@tauri-apps/api/event';
|
||||
|
||||
export class Cyclist {
|
||||
constructor({ interval, onTrigger, onToggle, onError, getTime, latency = 0.1 }) {
|
||||
@@ -18,30 +16,6 @@ export class Cyclist {
|
||||
this.lastEnd = 0; // query end of last tick
|
||||
this.getTime = getTime; // get absolute time
|
||||
this.onToggle = onToggle;
|
||||
this.start_timer;
|
||||
this.abeLinkListener = listen('abelink-event', async (e) => {
|
||||
const payload = e?.payload;
|
||||
if (payload == null) {
|
||||
return;
|
||||
}
|
||||
const { play, bpm, timestamp } = payload;
|
||||
// (if bpm !== prev_bpm) {
|
||||
//update the clock
|
||||
// }
|
||||
if (this.started !== play && play != null) {
|
||||
if (play) {
|
||||
this.start_timer = window.setTimeout(() => {
|
||||
logger('[cyclist] start');
|
||||
this.clock.start();
|
||||
this.setStarted(true);
|
||||
}, timestamp - Date.now());
|
||||
} else {
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
|
||||
const { message, message_type } = e.payload;
|
||||
});
|
||||
this.latency = latency; // fixed trigger time offset
|
||||
const round = (x) => Math.round(x * 1000) / 1000;
|
||||
this.clock = createClock(
|
||||
@@ -84,18 +58,13 @@ export class Cyclist {
|
||||
this.started = v;
|
||||
this.onToggle?.(v);
|
||||
}
|
||||
startClock() {}
|
||||
start() {
|
||||
if (!this.pattern) {
|
||||
throw new Error('Scheduler: no pattern set! call .setPattern first.');
|
||||
}
|
||||
|
||||
const linkmsg = {
|
||||
bpm: 110,
|
||||
play: true,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
Invoke('sendabelinkmsg', { linkmsg });
|
||||
logger('[cyclist] start');
|
||||
this.clock.start();
|
||||
this.setStarted(true);
|
||||
}
|
||||
pause() {
|
||||
logger('[cyclist] pause');
|
||||
@@ -107,12 +76,6 @@ export class Cyclist {
|
||||
this.clock.stop();
|
||||
this.lastEnd = 0;
|
||||
this.setStarted(false);
|
||||
const linkmsg = {
|
||||
bpm: 110,
|
||||
play: false,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
Invoke('sendabelinkmsg', { linkmsg });
|
||||
}
|
||||
setPattern(pat, autostart = false) {
|
||||
this.pattern = pat;
|
||||
|
||||
@@ -4,6 +4,8 @@ import { logger } from './logger.mjs';
|
||||
import { setTime } from './time.mjs';
|
||||
import { evalScope } from './evaluate.mjs';
|
||||
import { register } from './pattern.mjs';
|
||||
import { isTauri } from '../../website/src/tauri.mjs';
|
||||
import { CyclistBridge } from '../desktopbridge/cyclistbridge.mjs';
|
||||
|
||||
export function repl({
|
||||
interval,
|
||||
@@ -17,13 +19,16 @@ export function repl({
|
||||
onToggle,
|
||||
editPattern,
|
||||
}) {
|
||||
const scheduler = new Cyclist({
|
||||
const abelinkEnabled = isTauri();
|
||||
const cyclistParams = {
|
||||
interval,
|
||||
onTrigger: getTrigger({ defaultOutput, getTime }),
|
||||
onError: onSchedulerError,
|
||||
getTime,
|
||||
onToggle,
|
||||
});
|
||||
};
|
||||
const scheduler = abelinkEnabled ? new CyclistBridge(cyclistParams) : new Cyclist(cyclistParams);
|
||||
|
||||
const setPattern = (pattern, autostart = true) => {
|
||||
pattern = editPattern?.(pattern) || pattern;
|
||||
scheduler.setPattern(pattern, autostart);
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { Cyclist } from '@strudel.cycles/core';
|
||||
import { logger } from '../core/logger.mjs';
|
||||
import { Invoke } from '../../website/src/tauri.mjs';
|
||||
import { listen } from '@tauri-apps/api/event';
|
||||
|
||||
export class CyclistBridge extends Cyclist {
|
||||
constructor(params) {
|
||||
super(params);
|
||||
|
||||
this.start_timer;
|
||||
this.abeLinkListener = listen('abelink-event', async (e) => {
|
||||
const payload = e?.payload;
|
||||
if (payload == null) {
|
||||
return;
|
||||
}
|
||||
const { play, bpm, timestamp } = payload;
|
||||
// (if bpm !== prev_bpm) {
|
||||
//update the clock
|
||||
// }
|
||||
if (this.started !== play && play != null) {
|
||||
if (play) {
|
||||
this.start_timer = window.setTimeout(() => {
|
||||
logger('[cyclist] start');
|
||||
this.clock.start();
|
||||
this.setStarted(true);
|
||||
}, timestamp - Date.now());
|
||||
} else {
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
|
||||
const { message, message_type } = e.payload;
|
||||
});
|
||||
}
|
||||
|
||||
start() {
|
||||
if (!this.pattern) {
|
||||
throw new Error('Scheduler: no pattern set! call .setPattern first.');
|
||||
}
|
||||
|
||||
const linkmsg = {
|
||||
bpm: 110,
|
||||
play: true,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
Invoke('sendabelinkmsg', { linkmsg });
|
||||
}
|
||||
|
||||
stop() {
|
||||
logger('[cyclist] stop');
|
||||
this.clock.stop();
|
||||
this.lastEnd = 0;
|
||||
this.setStarted(false);
|
||||
const linkmsg = {
|
||||
bpm: 110,
|
||||
play: false,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
Invoke('sendabelinkmsg', { linkmsg });
|
||||
}
|
||||
}
|
||||
@@ -7,3 +7,4 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
export * from './midibridge.mjs';
|
||||
export * from './utils.mjs';
|
||||
export * from './oscbridge.mjs';
|
||||
export * from './cyclistbridge.mjs';
|
||||
|
||||
@@ -49,6 +49,7 @@ if (isTauri()) {
|
||||
import('@strudel/desktopbridge/loggerbridge.mjs'),
|
||||
import('@strudel/desktopbridge/midibridge.mjs'),
|
||||
import('@strudel/desktopbridge/oscbridge.mjs'),
|
||||
import('@strudel/desktopbridge/cyclistbridge.mjs'),
|
||||
]);
|
||||
} else {
|
||||
modules.concat([import('@strudel.cycles/midi'), import('@strudel.cycles/osc')]);
|
||||
|
||||
Reference in New Issue
Block a user