-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathScriptTarget.h
63 lines (45 loc) · 1.76 KB
/
ScriptTarget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
==============================================================================
ScriptTarget.h
Created: 20 Feb 2017 7:49:11pm
Author: Ben
==============================================================================
*/
#pragma once
const juce::Identifier scriptPtrIdentifier = "_ptr";
const juce::Identifier scriptTargetTypeIdentifier = "_type";
const juce::Identifier ptrCompareIdentifier = "is";
class ScriptTarget
{
public:
ScriptTarget(const juce::String &name, void * ptr, const juce::String &targetType = "");
virtual ~ScriptTarget();
juce::int64 thisPtr;
juce::String scriptTargetName;
juce::var scriptObject;
//var liveScriptObject;
bool scriptObjectIsDirty;
juce::SpinLock scriptObjectLock;
juce::var getScriptObject();
void updateScriptObject(juce::var parent = juce::var());
virtual void updateScriptObjectInternal(juce::var /*parent*/ = juce::var()) {}
static juce::var checkTargetsAreTheSameFromScript(const juce::var::NativeFunctionArgs &args);
virtual juce::String getScriptTargetString();
class ScriptTargetListener
{
public:
virtual ~ScriptTargetListener() {};
virtual void scriptObjectUpdated(ScriptTarget *) {};
};
juce::ListenerList<ScriptTargetListener> scriptTargetListeners;
void addScriptTargetListener(ScriptTargetListener * l) { scriptTargetListeners.add(l); }
void removeScriptTargetListener(ScriptTargetListener * l) { scriptTargetListeners.remove(l); }
template<class T>
static T* getObjectFromJS(const juce::var::NativeFunctionArgs & a);
};
template<class T>
T * ScriptTarget::getObjectFromJS(const juce::var::NativeFunctionArgs & a) {
juce::DynamicObject * d = a.thisObject.getDynamicObject();
if (d == nullptr) return nullptr;
return dynamic_cast<T*>((T*)(juce::int64)d->getProperty(scriptPtrIdentifier));
}