Skip to content

Commit

Permalink
Add scratch memory
Browse files Browse the repository at this point in the history
  • Loading branch information
abique committed Jan 17, 2025
1 parent 8ec6d4e commit 388d5a8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
9 changes: 9 additions & 0 deletions include/clap/helpers/host-proxy.hh
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ namespace clap { namespace helpers {
void undoRequestRedo() const noexcept;
void undoSetWantsContextUpdates(bool is_subscribed) const noexcept;

//////////////////////////////
// clap_host_scratch_memory //
//////////////////////////////
bool canUseScratchMemory() const noexcept;
bool scratchMemoryReserve(uint32_t scratch_size_bytes,
uint32_t max_concurrency_hint) const noexcept;
void *scratchMemoryAccess() const noexcept;

protected:
void ensureMainThread(const char *method) const noexcept;
void ensureAudioThread(const char *method) const noexcept;
Expand Down Expand Up @@ -226,5 +234,6 @@ namespace clap { namespace helpers {
const clap_host_context_menu *_hostContextMenu = nullptr;
const clap_host_preset_load *_hostPresetLoad = nullptr;
const clap_host_undo *_hostUndo = nullptr;
const clap_host_scratch_memory *_hostScratchMemory = nullptr;
};
}} // namespace clap::helpers
34 changes: 33 additions & 1 deletion include/clap/helpers/host-proxy.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace clap { namespace helpers {
if (!_hostPresetLoad)
getExtension(_hostPresetLoad, CLAP_EXT_PRESET_LOAD);
getExtension(_hostUndo, CLAP_EXT_UNDO);
getExtension(_hostScratchMemory, CLAP_EXT_SCRATCH_MEMORY);
}

template <MisbehaviourHandler h, CheckingLevel l>
Expand Down Expand Up @@ -693,7 +694,8 @@ namespace clap { namespace helpers {
return false;

if (_hostUndo->begin_change && _hostUndo->cancel_change && _hostUndo->change_made &&
_hostUndo->request_undo && _hostUndo->request_redo && _hostUndo->set_wants_context_updates)
_hostUndo->request_undo && _hostUndo->request_redo &&
_hostUndo->set_wants_context_updates)
return true;

return false;
Expand Down Expand Up @@ -744,4 +746,34 @@ namespace clap { namespace helpers {
_hostUndo->set_wants_context_updates(_host, is_subscribed);
}

//////////////////////////////
// clap_host_scratch_memory //
//////////////////////////////
template <MisbehaviourHandler h, CheckingLevel l>
bool HostProxy<h, l>::canUseScratchMemory() const noexcept {
if (!_hostScratchMemory)
return false;

if (_hostScratchMemory->reserve && _hostScratchMemory->access)
return true;

hostMisbehaving("clap_host_scratch_memory is partially implemented!");
return false;
}

template <MisbehaviourHandler h, CheckingLevel l>
bool HostProxy<h, l>::scratchMemoryReserve(uint32_t scratch_size_bytes,
uint32_t max_concurrency_hint) const noexcept {
assert(canUseScratchMemory());
ensureMainThread("scratch_memory.reserve");
return _hostScratchMemory->reserve(_host, scratch_size_bytes, max_concurrency_hint);
}

template <MisbehaviourHandler h, CheckingLevel l>
void *HostProxy<h, l>::scratchMemoryAccess() const noexcept {
assert(canUseScratchMemory());
ensureAudioThread("scratch_memory.access");
return _hostScratchMemory->access(_host);
}

}} // namespace clap::helpers

0 comments on commit 388d5a8

Please sign in to comment.