Anklang-0.3.0.dev886+g785567a1 anklang-0.3.0.dev886+g785567a1
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
trkn-utils.cc
Go to the documentation of this file.
1 // This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
2#include "trkn/tracktion.hh" // PCH include must come first
3
4#include "trkn-utils.hh"
5#include "platform.hh"
6#include "main.hh"
7#include "logging.hh"
8#include "internal.hh"
9
10namespace te = tracktion::engine;
11
12namespace Ase {
13
14// == SelectableBaseref ==
15using JuceWeakReference_Selectable = juce::WeakReference<tracktion::Selectable>;
16
17template<size_t N> static JuceWeakReference_Selectable&
18juce_weak_reference_selectable (const char (&mem)[N])
19{
20 static_assert (N == sizeof (JuceWeakReference_Selectable));
21 return *reinterpret_cast<JuceWeakReference_Selectable*> (const_cast<char*> (mem));
22}
23
24SelectableBaseref::SelectableBaseref()
25{
26 static_assert (sizeof (mem_) == sizeof (JuceWeakReference_Selectable));
27 JuceWeakReference_Selectable *const weakref = new (mem_) JuceWeakReference_Selectable (nullptr);
28 assert_return (weakref != nullptr);
29}
30
31SelectableBaseref::~SelectableBaseref()
32{
33 JuceWeakReference_Selectable &weakref = juce_weak_reference_selectable (mem_);
34 weakref.~JuceWeakReference_Selectable();
35}
36
37tracktion::Selectable*
38SelectableBaseref::get () const noexcept
39{
40 JuceWeakReference_Selectable &weakref = juce_weak_reference_selectable (mem_);
41 return weakref.get();
42}
43
44void
45SelectableBaseref::set (tracktion::Selectable *selectable) noexcept
46{
47 JuceWeakReference_Selectable &weakref = juce_weak_reference_selectable (mem_);
48 weakref = selectable;
49}
50
51void
52SelectableBaseref::set (const SelectableBaseref &other) noexcept
53{
54 JuceWeakReference_Selectable &weakref = juce_weak_reference_selectable (mem_);
55 const JuceWeakReference_Selectable &otherref = juce_weak_reference_selectable (other.mem_);
56 weakref = otherref;
57}
58
59// == ase_obj_ helpers ==
60
61void
62register_ase_obj (VirtualBase *ase_impl, tracktion::Selectable &selectable)
63{
64 assert_return (ase_impl != nullptr);
65 return_unless (selectable.ase_obj_ == nullptr);
66 selectable.ase_obj_ = ase_impl;
67}
68
69void
70unregister_ase_obj (VirtualBase *ase_impl, tracktion::Selectable *selectable)
71{
72 if (selectable && selectable->ase_obj_ == ase_impl)
73 selectable->ase_obj_ = nullptr;
74}
75
76VirtualBase*
77find_ase_obj_virtual_base (tracktion::Selectable *selectable)
78{
79 return selectable ? selectable->ase_obj_ : nullptr;
80}
81
82} // Ase
#define assert_return(expr,...)
Return from the current function if expr is unmet and issue an assertion warning.
Definition internal.hh:29
#define return_unless(cond,...)
Return silently if cond does not evaluate to true with return value ...
Definition internal.hh:73
The Anklang C++ API namespace.
Definition api.hh:8
void register_ase_obj(VirtualBase *ase_impl, tracktion::Selectable &selectable)
Helper: register AseImpl with a tracktion Selectable via ase_obj_.
Definition trkn-utils.cc:62
VirtualBase * find_ase_obj_virtual_base(tracktion::Selectable *selectable)
Helper: lookup Ase::VirtualBase from tracktion Selectable via ase_obj_.
Definition trkn-utils.cc:77
void unregister_ase_obj(VirtualBase *ase_impl, tracktion::Selectable *selectable)
Helper: unregister AseImpl from a tracktion Selectable (selectable may be nullptr)
Definition trkn-utils.cc:70
Common base type to allow casting between polymorphic classes.
Definition cxxaux.hh:221