All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
Public Types | Static Public Member Functions | List of all members
TaskAfterSuspension Class Reference

A wrapper around a task that is supposed to take a while and is not allowed to be executed simultaneously to the audio rendering. More...

Public Types

enum  ReturnType { ExecutedSynchronously, DeferredToThread }
 The call() method will return one of these to indicate what happened. More...
 

Static Public Member Functions

static ReturnType call (MainController *mc, const ProcessorFunction &f, int TargetThread=IDs::Threads::Loading)
 Executes the function passed as lambda and returns the ReturnType depending on the execution state of the function. More...
 

Detailed Description

A wrapper around a task that is supposed to take a while and is not allowed to be executed simultaneously to the audio rendering.

Some tasks that interfere with the audio rendering (eg. adding / removing modules, swapping samples) have to make sure that the audio thread is not running in parallel. Therefore HISE has a "suspended task" system which kills all voices, waits until the voices have gracefully faded out (including FX tails for reverb effects), then suspends the audio rendering until the task has been completed on a background thread with a minimal amount of locking.

In HISE, this system is used for each one of these events:

You can see this system in action if you do one of these things in HISE while playing notes.

In order to use that system from your own C++ code, just create a lambda that follows the hise::SafeFunctionCall definition and pass it to the call() function:

auto f = [mySampleMap](hise::Processor* p)
{
// You know it's a sampler, so no need for a dynamic_cast
auto sampler = static_cast<hise::ModulatorSampler*>(p);
// Call whatever you need to do.
// (Actually this call makes no sense, since it's already wrapped in a suspended execution)
sampler->loadSampleMap(mySampleMap);
// The lambda definition requires you to return this.
};

This makes sure that the lambda will be executed on the given thread after all voices are killed. However this doesn't necessarily mean asynchronous execution: if you're calling this on the target thread and all voices are already killed, it will be executed synchronously. You can check this with the ReturnType enum passed back from the call() method. This reduces the debugging headaches of asynchronous callbacks wherever possible.

Member Enumeration Documentation

enum ReturnType

The call() method will return one of these to indicate what happened.

Enumerator
ExecutedSynchronously 

If the audio was already suspended and the method was called from the same thread as the desired target thread, this will be returned from the call.

DeferredToThread 

If the audio needs to be suspended and / or the method was called from another thread than the target thread, this will be returned in order to indicate that the function was not yet executed.

Member Function Documentation

static ReturnType call ( MainController mc,
const ProcessorFunction f,
int  TargetThread = IDs::Threads::Loading 
)
inlinestatic

Executes the function passed as lambda and returns the ReturnType depending on the execution state of the function.

©2017 HISE. This documentation is autogenerated from the HISE source code using Doxygen.