-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjit-proxy-controller.js
More file actions
143 lines (119 loc) · 3.8 KB
/
jit-proxy-controller.js
File metadata and controls
143 lines (119 loc) · 3.8 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
inlets = 1;
outlets = 1;
const data = {
chooserIdx: 0,
items: [],
};
const options = {
nameContains: "proxyable",
};
declareattribute("name_contains", {
type: "symbol",
default: options.nameContains,
getter: "getNameContains",
setter: "setNameContains",
});
function getNameContains() {
return options.nameContains;
}
function setNameContains(val) {
options.nameContains = val;
}
// trigger when patch saved or notifyclients() called
function getvalueof() {
const dict = new Dict();
dict.parse(JSON.stringify(data));
return dict;
}
// trigger when patch opened or pattrstorage slot called
function setvalueof(dict) {
// restore pattr data from patch
const newData = JSON.parse(dict.stringify());
Object.assign(data, newData);
}
function getParentObjects() {
const parentPatcher = this.patcher.parentpatcher;
const maxObjNames = [];
parentPatcher.applyif(
(obj) => {
const name = obj.getattr("name");
maxObjNames.push(name);
// add new item only
if (!data.items.find((e) => e.name === name)) {
// set default data item
data.items.push({
name,
posMultiplier: 1,
pictslider: [64, 64],
scaleAll: 1,
scaleMax: 1,
});
}
// TODO: bind pattr obj dynamically? or just explicit define in parent patcher
//obj.varname = `proxyed-${name}`;
//const pattr = this.patcher.newdefault(100,100,'pattr', `parent::${obj.varname}::position`)
},
// condition
(obj) => {
const name = obj.getattr("name");
return (
obj.maxclass.startsWith("jit.gl") && name.includes(options.nameContains)
);
}
);
// remove the previous data items if any targeted objs removed in the patcher
data.items = data.items.filter((e) => maxObjNames.includes(e.name));
}
getParentObjects.local = 1;
// listener map
const listenermap = new Map();
function loadbang() {
getParentObjects();
let listener;
listener = new MaxobjListener(this.patcher.getnamed("objChooser"), (obj) => {
data.chooserIdx = obj.value;
const currentItem = data.items.find((_e, i) => i === data.chooserIdx);
// update the internal UIs
this.patcher.getnamed("pictslider").message("set", currentItem.pictslider);
this.patcher.getnamed("posMultiplier").message(currentItem.posMultiplier);
this.patcher.getnamed("scaleAll").message("set", currentItem.scaleAll);
this.patcher.getnamed("scaleMax").message("set", currentItem.scaleMax);
notifyclients();
});
listenermap.set("objChooser", listener);
listener = new MaxobjListener(this.patcher.getnamed("pictslider"), (obj) => {
const currentItem = data.items.find((_e, i) => i === data.chooserIdx);
currentItem.pictslider = obj.value;
notifyclients();
});
listenermap.set("pictslider", listener);
listener = new MaxobjListener(
this.patcher.getnamed("posMultiplier"),
(obj) => {
const currentItem = data.items.find((_e, i) => i === data.chooserIdx);
currentItem.posMultiplier = obj.value;
notifyclients();
}
);
listenermap.set("posMultiplier", listener);
listener = new MaxobjListener(this.patcher.getnamed("scaleAll"), (obj) => {
const currentItem = data.items.find((_e, i) => i === data.chooserIdx);
currentItem.scaleAll = obj.value;
notifyclients();
});
listenermap.set("scaleAll", listener);
listener = new MaxobjListener(this.patcher.getnamed("scaleMax"), (obj) => {
const currentItem = data.items.find((_e, i) => i === data.chooserIdx);
currentItem.scaleMax = obj.value;
notifyclients();
});
listenermap.set("scaleMax", listener);
outlet_dictionary(0, { items: data.items.map((e) => e.name) });
outlet(0, 0);
}
// scan
function bang() {
getParentObjects();
outlet(0, "clear");
outlet_dictionary(0, { items: data.items.map((e) => e.name) });
}