Skip to content

Instruments built on two threads at once keep their own synthesizers - #174

Merged
bdbarnett merged 1 commit into
mainfrom
ostinato/pending-per-thread
Oct 15, 2026
Merged

bdbarnett merged 1 commit into
mainfrom
ostinato/pending-per-thread

Conversation

@bdbarnett

Copy link
Copy Markdown
Contributor

Each Instrument adopts the synthesizer Keys its factory made since the last instrument, through a module-wide list. Two factories running on two threads at the same time could take each other's, so one instrument would play through another's voice engine. The list is now per thread. Where there's no threading.local, as on MicroPython and CircuitPython, which build instruments on their one thread, it stays a single shared holder.

  • tests/test_cpython_instrument_threads.py: thread A makes a synthesizer and waits while thread B builds a whole instrument, then A finishes. It fails on main (A's instrument gets B's keyboard) and passes here.
  • tests/test_scheduling_seam.py now reaches the list through _support._pending().
  • The scheduling, live-macro and new tests pass on CPython. On MicroPython and CircuitPython, a minimoog and a dx7 built one after the other each get their own keyboard.

Each Instrument adopts the Keys its factory made through a list that was
module-wide; two factories on two threads could take each other's. The list
is per thread now (one shared holder where there's no threading.local, as on
MicroPython and CircuitPython, which build on one thread).
@bdbarnett
bdbarnett merged commit ff25210 into main Oct 15, 2026
6 checks passed
@bdbarnett
bdbarnett deleted the ostinato/pending-per-thread branch October 15, 2026 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant