On Thursday 17 June 2010 10:48:17 Luis Garrido wrote:
> > At the moment the loaded resources (files, instruments and samples) of
> > the resource managers are not exposed via LSCP or C++ API.
> 
> I've bumped into that one. What would be the orthodox way to unload an
> instrument from a channel using the C++ API (other than the loading a
> dummy instrument trick)? I am trying to add this option to my DSSI
> plugin[*] and still figuring it out, I've tried to force an unload by
> doing:
> 
>         engineChannel->DisconnectAudioOutputDevice();
>         engineChannel->Connect(audioOutputDevice);
> 
> but that is not thread-safe, if you catch it at the wrong time the
> rendering thread will crash.

Yeah, EngineChannelBase::DisconnectAudioOutputDevice() is at the moment not 
safe at all, its currently considered to be called only when the engine or the 
audio output device is suspended. It would be desirable to make this method 
thread safe, but its easy to introduce dead locks at those spots of the code 
(that might even just occur on some OSes), thats why I havent touched it yet.

We should expose AbstractEngine::SuspendAll() and AbstractEngine::ResumeAll() 
to the C++ API, would be just adding 2 lines to src/engines/Engine.h. That way 
you can suspend rendering of the engine, to be able to call not thread safe 
operations and do ResumeAll() afterwards to re-enable rendering of the engine 
again.

For now you could do AudioOutputDevice::Stop() and AudioOutputDevice::Start() 
but that solution is not so good, since you would need to check before whether 
the audio device is actually currently active. Otherwise you would start the 
audio device even though the user might have disabled it intentionally before 
(for some reason).

Instead of DisconnectAudioOutputDevice() and Connect() like you stated above, 
I would try this:

        try {
                // instruct to load nothing
                engineChannel->PrepareLoadInstrument("", 0);
                // will unload the current instrument and then throw an 
exception
                engineChannel->LoadInstrument();
        } catch (...) { // catch all ...
                // ... and ignore all ;-)
        }

CU
Christian

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Linuxsampler-devel mailing list
Linuxsampler-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxsampler-devel

Reply via email to