-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathHtmlAudioNode.cpp
More file actions
148 lines (128 loc) · 3.84 KB
/
Copy pathHtmlAudioNode.cpp
File metadata and controls
148 lines (128 loc) · 3.84 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "stdafx.h"
#include "HtmlAudioNode.h"
#include "HtmlAudioContext.h"
#include "HtmlAudioParam.h"
IMPLEMENT_CUSTOM_CLASS(HtmlAudioNode, CustomClassBase)
HtmlAudioNode::HtmlAudioNode()
{
}
HtmlAudioNode::~HtmlAudioNode()
{
}
bool HtmlAudioNode::InitClass(const HandleContext&context)
{
return InitClass_s(context, "HTMLAudioNode", HandleObject());
}
bool HtmlAudioNode::OnGetProperty(GetPropertyArgs&args)
{
return CustomClassBase::OnGetProperty(args);
}
bool HtmlAudioNode::OnSetProperty(SetPropertyArgs&args)
{
const char*name = args.GetName();
if (!PROPCMP(name, "context"))
{
m_pContext = dynamic_cast<HtmlAudioContext*>(FindCustomClass(args.GetValue().GetObject()));
}
return CustomClassBase::OnSetProperty(args);
}
bool HtmlAudioNode::connect(IFunctionCallbackArgs&args)//连接到另一个node的输出端,数据会从另一个node推送过来
{
CHECK_ARGS_COUNT_MIN(1, "HtmlAudioNode::connect");
LocalObject objnode(args.getContext(), args[0].GetObject());
HtmlAudioNode*pnode = dynamic_cast<HtmlAudioNode*>(FindCustomClass(objnode));
if (!pnode)
{
assert(0);
return false;
}
LocalObject objthis(args.getContext(), GetJsObject());
LocalObject objOldConnect(args.getContext(),objthis.GetProperty("__connectNode").GetObject());
if (!objOldConnect.IsNull())
{//解除旧的连接
HtmlAudioNode*pnodeOld = dynamic_cast<HtmlAudioNode*>(FindCustomClass(objOldConnect));
assert(pnodeOld);
CustomClassAutoThisObj cc(pnodeOld, objOldConnect);
pnodeOld->RemoveConnectedNode(args.getContext(), objthis);
}
objthis.SetProperty("__connectNode", args[0]);
CustomClassAutoThisObj cc(pnode, objnode);
pnode->AddConnectedNode(args.getContext(), objthis);
return true;
}
bool HtmlAudioNode::disconnect(IFunctionCallbackArgs&args)
{
LocalObject objthis(args.getContext(), GetJsObject());
LocalObject objOldConnect(args.getContext(), objthis.GetProperty("__connectNode").GetObject());
if (!objOldConnect.IsNull())
{//解除旧的连接
HtmlAudioNode*pnodeOld = dynamic_cast<HtmlAudioNode*>(FindCustomClass(objOldConnect));
assert(pnodeOld);
CustomClassAutoThisObj cc(pnodeOld, objOldConnect);
pnodeOld->RemoveConnectedNode(args.getContext(), objthis);
objthis.SetProperty("__connectNode", ValueBase());
}
return true;
}
bool HtmlAudioNode::AddConnectedNode(const HandleContext& context, const HandleObject & objnode)//调用了objnode的connect()后在被连接的node中添加objnode作为输出node
{
LocalObject objthis(context, GetJsObject());
LocalObject objlist(context,objthis.GetProperty("__destNodeList").GetObject());
if (objlist.IsNull())
{
objlist.CreateArrayObject(0);
objthis.SetProperty("__destNodeList", objlist);
}
int nCount = objlist.GetArrayLength();
int iEmpty = -1;
for (int i = 0; i < nCount; i++)
{
LocalObject objitem(context, objlist.GetElement(i).GetObject());
if (objitem == objnode)return true;
if (iEmpty == -1 && objitem.IsNull())
{
iEmpty = i;
}
}
if (iEmpty >= 0)
{
objlist.SetElement(iEmpty, objnode);
}
else
{
objlist.SetElement(nCount, objnode);
}
return true;
}
bool HtmlAudioNode::RemoveConnectedNode(const HandleContext& context, const HandleObject&objnode)
{
LocalObject objthis(context, GetJsObject());
LocalObject objlist(context, objthis.GetProperty("__destNodeList").GetObject());
if (objthis.IsNull())
{
return true;
}
int nCount = objlist.GetArrayLength();
for (int i = 0; i < nCount; i++)
{
LocalObject objitem(context, objlist.GetElement(i).GetObject());
if (objitem == objnode)
{
objlist.SetElement(i, ValueBase());
return true;
}
}
return true;
}
bool HtmlAudioNode::OnConstructor(IFunctionCallbackArgs&args)
{
bool ret = CustomClassBase::OnConstructor(args);
return ret;
}
bool HtmlAudioNode::SetContext(const HandleContext& context, const HandleObject & objctx)
{
return GetJsObject().SetProperty(context, "context", objctx);
}
void HtmlAudioNode::OnValueChanged(HtmlAudioParam* pParam)
{
}