Expose scheduler state and don't enqueue/trigger midi keys when repl stopped

This commit is contained in:
Aria
2026-01-14 11:44:48 -06:00
parent b954a25b2b
commit 80875cca95
3 changed files with 23 additions and 3 deletions
+8 -1
View File
@@ -2,7 +2,13 @@ import { NeoCyclist } from './neocyclist.mjs';
import { Cyclist } from './cyclist.mjs';
import { evaluate as _evaluate } from './evaluate.mjs';
import { errorLogger, logger } from './logger.mjs';
import { setCpsFunc, setPattern as exposeSchedulerPattern, setTime, setTriggerFunc } from './schedulerState.mjs';
import {
setCpsFunc,
setIsStarted,
setPattern as exposeSchedulerPattern,
setTime,
setTriggerFunc,
} from './schedulerState.mjs';
import { evalScope } from './evaluate.mjs';
import { register, Pattern, isPattern, silence, stack } from './pattern.mjs';
import { reset_state } from './impure.mjs';
@@ -52,6 +58,7 @@ export function repl({
getTime,
onToggle: (started) => {
updateState({ started });
setIsStarted(started);
onToggle?.(started);
if (!started) {
reset_state();
+9
View File
@@ -8,6 +8,7 @@ let time;
let cpsFunc;
let pattern;
let triggerFunc;
let isStarted;
export function getTime() {
if (!time) {
throw new Error('no time set! use setTime to define a time source');
@@ -42,3 +43,11 @@ export function setTriggerFunc(func) {
export function getTriggerFunc() {
return triggerFunc;
}
export function setIsStarted(val) {
isStarted = !!val;
}
export function getIsStarted() {
return isStarted;
}
+6 -2
View File
@@ -10,6 +10,7 @@ import {
Pattern,
TimeSpan,
getCps,
getIsStarted,
getPattern,
getTime,
getTriggerFunc,
@@ -625,8 +626,11 @@ export async function midikeys(input) {
const { dataBytes, message } = e;
const noteon = message.command === 9;
let noteoff = message.command === 8;
if (!noteon && !noteoff) {
// Ignore non-note messages (e.g. CC, pitchbend, modwheel, etc.)
// Don't enqueue or trigger midi notes if scheduler is not started
const notStarted = !getIsStarted();
// Ignore non-note messages (e.g. CC, pitchbend, modwheel, etc.)
const notANote = !noteon && !noteoff;
if (notStarted || notANote) {
return;
}
const [note, velocity] = dataBytes;