mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-24 03:58:53 +00:00
fix: highlighting sync
This commit is contained in:
parent
c7c90b0647
commit
372bdf8be7
@ -16,6 +16,7 @@ export class Cyclist {
|
|||||||
constructor({ interval, onTrigger, onToggle, onError, getTime, latency = 0.1 }) {
|
constructor({ interval, onTrigger, onToggle, onError, getTime, latency = 0.1 }) {
|
||||||
this.getTime = getTime;
|
this.getTime = getTime;
|
||||||
this.onToggle = onToggle;
|
this.onToggle = onToggle;
|
||||||
|
this.latency = latency;
|
||||||
const round = (x) => Math.round(x * 1000) / 1000;
|
const round = (x) => Math.round(x * 1000) / 1000;
|
||||||
this.clock = createClock(
|
this.clock = createClock(
|
||||||
getTime,
|
getTime,
|
||||||
@ -44,8 +45,8 @@ export class Cyclist {
|
|||||||
interval, // duration of each cycle
|
interval, // duration of each cycle
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
getPhase() {
|
getPhase(latencyCompensation = true) {
|
||||||
return this.phase;
|
return this.phase - (latencyCompensation ? this.latency : 0);
|
||||||
}
|
}
|
||||||
setStarted(v) {
|
setStarted(v) {
|
||||||
this.started = v;
|
this.started = v;
|
||||||
@ -59,12 +60,10 @@ export class Cyclist {
|
|||||||
this.setStarted(true);
|
this.setStarted(true);
|
||||||
}
|
}
|
||||||
pause() {
|
pause() {
|
||||||
this.clock.stop();
|
this.clock.pause();
|
||||||
// delete this.origin;
|
|
||||||
this.setStarted(false);
|
this.setStarted(false);
|
||||||
}
|
}
|
||||||
stop() {
|
stop() {
|
||||||
delete this.origin;
|
|
||||||
this.clock.stop();
|
this.clock.stop();
|
||||||
this.setStarted(false);
|
this.setStarted(false);
|
||||||
}
|
}
|
||||||
|
|||||||
30
packages/react/dist/index.cjs.js
vendored
30
packages/react/dist/index.cjs.js
vendored
File diff suppressed because one or more lines are too long
617
packages/react/dist/index.es.js
vendored
617
packages/react/dist/index.es.js
vendored
File diff suppressed because one or more lines are too long
@ -82,7 +82,7 @@ function App() {
|
|||||||
view,
|
view,
|
||||||
pattern,
|
pattern,
|
||||||
active: !activeCode?.includes('strudel disable-highlighting'),
|
active: !activeCode?.includes('strudel disable-highlighting'),
|
||||||
getTime: () => scheduler.phase,
|
getTime: () => scheduler.getPhase(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const error = evalError || schedulerError;
|
const error = evalError || schedulerError;
|
||||||
|
|||||||
@ -49,7 +49,7 @@ export function MiniRepl({ tune, hideOutsideView = false, init, enableKeyboard }
|
|||||||
view,
|
view,
|
||||||
pattern,
|
pattern,
|
||||||
active: started && !activeCode?.includes('strudel disable-highlighting'),
|
active: started && !activeCode?.includes('strudel disable-highlighting'),
|
||||||
getTime: () => scheduler.phase,
|
getTime: () => scheduler.getPhase(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// set active pattern on ctrl+enter
|
// set active pattern on ctrl+enter
|
||||||
|
|||||||
@ -14,9 +14,9 @@ function useHighlighting({ view, pattern, active, getTime }) {
|
|||||||
const audioTime = getTime();
|
const audioTime = getTime();
|
||||||
// force min framerate of 10 fps => fixes crash on tab refocus, where lastEnd could be far away
|
// force min framerate of 10 fps => fixes crash on tab refocus, where lastEnd could be far away
|
||||||
// see https://github.com/tidalcycles/strudel/issues/108
|
// see https://github.com/tidalcycles/strudel/issues/108
|
||||||
const begin = Math.max(lastEnd.current || audioTime, audioTime - 1 / 10);
|
const begin = Math.max(lastEnd.current || audioTime, audioTime - 1 / 10, 0); // negative time seems buggy
|
||||||
const span = [begin, audioTime + 1 / 60];
|
const span = [begin, audioTime + 1 / 60];
|
||||||
lastEnd.current = audioTime + 1 / 60;
|
lastEnd.current = span[1];
|
||||||
highlights.current = highlights.current.filter((hap) => hap.whole.end > audioTime); // keep only highlights that are still active
|
highlights.current = highlights.current.filter((hap) => hap.whole.end > audioTime); // keep only highlights that are still active
|
||||||
const haps = pattern.queryArc(...span).filter((hap) => hap.hasOnset());
|
const haps = pattern.queryArc(...span).filter((hap) => hap.hasOnset());
|
||||||
highlights.current = highlights.current.concat(haps); // add potential new onsets
|
highlights.current = highlights.current.concat(haps); // add potential new onsets
|
||||||
|
|||||||
@ -48,7 +48,6 @@ function useStrudel({ defaultOutput, interval, getTime, evalOnMount = false, ini
|
|||||||
const togglePlay = async () => {
|
const togglePlay = async () => {
|
||||||
if (started) {
|
if (started) {
|
||||||
scheduler.pause();
|
scheduler.pause();
|
||||||
// scheduler.stop();
|
|
||||||
} else {
|
} else {
|
||||||
await activateCode();
|
await activateCode();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,8 +35,10 @@ currently broken / buggy:
|
|||||||
- [ ] pending flag
|
- [ ] pending flag
|
||||||
- [ ] web midi
|
- [ ] web midi
|
||||||
- [ ] draw / pianoroll
|
- [ ] draw / pianoroll
|
||||||
- [ ] pause does stop
|
- [x] pause does stop
|
||||||
|
- [ ] pause then play logs "TOO LATE" and drops some events
|
||||||
- [x] random button triggers start
|
- [x] random button triggers start
|
||||||
- [?] highlighting seems too late (off by latency ?)
|
|
||||||
- [ ] unexpected ast format without body expression (kalimba)
|
- [ ] unexpected ast format without body expression (kalimba)
|
||||||
- [ ] highlighting sometimes drops highlights (zeldasRescue first note)
|
- [x] highlighting seems too late (off by latency ?)
|
||||||
|
- [x] highlighting sometimes drops highlights (zeldasRescue first note)
|
||||||
|
- [ ] highlighting still sometimes drops highlights (zeldasRescue somtimes)
|
||||||
|
|||||||
@ -146,7 +146,7 @@ function App() {
|
|||||||
view,
|
view,
|
||||||
pattern,
|
pattern,
|
||||||
active: started && !activeCode?.includes('strudel disable-highlighting'),
|
active: started && !activeCode?.includes('strudel disable-highlighting'),
|
||||||
getTime: () => scheduler.phase,
|
getTime: () => scheduler.getPhase(),
|
||||||
// getTime: () => Tone.getTransport().seconds,
|
// getTime: () => Tone.getTransport().seconds,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -312,7 +312,11 @@ function App() {
|
|||||||
{/* onCursor={markParens} */}
|
{/* onCursor={markParens} */}
|
||||||
<CodeMirror value={code} onChange={setCode} onViewChanged={setView} />
|
<CodeMirror value={code} onChange={setCode} onViewChanged={setView} />
|
||||||
<span className="z-[20] bg-black rounded-t-md py-1 px-2 fixed bottom-0 right-1 text-xs whitespace-pre text-right pointer-events-none">
|
<span className="z-[20] bg-black rounded-t-md py-1 px-2 fixed bottom-0 right-1 text-xs whitespace-pre text-right pointer-events-none">
|
||||||
{!started ? `press ctrl+enter to play\n` : isDirty ? `press ctrl+enter to update\n` : 'press ctrl+dot do stop\n'}
|
{!started
|
||||||
|
? `press ctrl+enter to play\n`
|
||||||
|
: isDirty
|
||||||
|
? `press ctrl+enter to update\n`
|
||||||
|
: 'press ctrl+dot do stop\n'}
|
||||||
</span>
|
</span>
|
||||||
{error && (
|
{error && (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@ -308,7 +308,6 @@ export const blippyRhodes = `samples({
|
|||||||
}
|
}
|
||||||
}, 'https://loophole-letters.vercel.app/')
|
}, 'https://loophole-letters.vercel.app/')
|
||||||
|
|
||||||
const bass = synth(osc('sawtooth8')).chain(vol(.5),out())
|
|
||||||
const scales = cat('C major', 'C mixolydian', 'F lydian', ['F minor', cat('Db major','Db mixolydian')])
|
const scales = cat('C major', 'C mixolydian', 'F lydian', ['F minor', cat('Db major','Db mixolydian')])
|
||||||
|
|
||||||
stack(
|
stack(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user