Jakob Lund wrote: > Earlier versions didn't `delete` Instrument objects at all, because Note > objects that reference them _might_ still live in the sequencer-, midi- or > sampler note queues. I'm trying now to mark each instrument that has a not in > one of these queues, and then postpone deletion of Instrument until it's no > longer marked. I want the `delete` operations to be carried out from a > different thread; in that case it ought to be RT safe I reckon. > That's one possible solution (and a decent one, too). Or you could use reference counting (but that has its problems - you can't delete immediately when refcount=0 because it may happen in audio thread).
One more solution: use instrument numbers instead of instrument pointers in Note objects, and make a translation table in the first part of, say, audioEngine_process. You might even cache that translation table and set a flag every time it needs to be rebuilt (because an instrument has been added or removed). A note with NULL instrument pointer could be ignored by sampler etc. Reading an array (or std::vector) item by its index once per note per nframes is fast enough not to worry about it too much - assuming InstrumentList::get becomes an inline function. The translation table would have to be available in all objects that use Note objects, but that shouldn't be a problem - make it a singleton or just pass a pointer around. Note that audioEngine_process_playNotes needs instrument numbers anyway, it might as well use them directly if they were available in Note object, and not look them up by InstrumentList::get_pos(). [and treat everything above with a huge grain of salt: I'm just browsing/learning Hydrogen source code, everything I said might be completely wrong] Krzysztof ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Hydrogen-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/hydrogen-devel
