cabbage-react 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/hooks/useCabbageState.d.ts +2 -2
- package/dist/hooks/useCabbageState.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +89 -89
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ npm install cabbage-react
|
|
|
20
20
|
|
|
21
21
|
Synchronize a parameter with Cabbage. This hook:
|
|
22
22
|
|
|
23
|
-
- Identifies and sets the default value defined in Cabbage to
|
|
23
|
+
- Identifies and sets the default value defined in Cabbage to a state.
|
|
24
24
|
- Handles initialization when opening an existing session, or reopening the plugin window.
|
|
25
25
|
- Listens for value updates from the host (DAW), or from Csound.
|
|
26
26
|
- Sends changes back to Cabbage when using the provided value-setter.
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* This hook listens for updates to a parameter value from Cabbage and
|
|
4
4
|
* sends updates to Cabbage when the parameter value changes locally (e.g., through a UI slider).
|
|
5
5
|
*/
|
|
6
|
-
export declare const useCabbageState: <T>(channelId: string
|
|
6
|
+
export declare const useCabbageState: <T>(channelId: string) => {
|
|
7
7
|
value: T | undefined;
|
|
8
|
-
setValue: (newValue: T) => void;
|
|
8
|
+
setValue: (newValue: T, stringData?: string) => void;
|
|
9
9
|
};
|
|
10
10
|
//# sourceMappingURL=useCabbageState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,aAAa,MAAM;;yBAKd,CAAC,eAAe,MAAM;CA4E3D,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react");console.log("Cabbage: loading cabbage.js");class g{static sendChannelUpdate(e,n=null,a=0){if(a===1)g.sendParameterUpdate(e,n);else{const t=e.value!==void 0?e.value:e.stringData||e.floatData;g.sendChannelData(e.channel,t,n)}}static sendParameterUpdate(e,n=null){const a={command:"parameterChange",...e};console.log("Cabbage.sendParameterUpdate:",e,"vscode:",n,"msg:",a),n!==null?(console.log("Sending via vscode.postMessage"),n.postMessage(a)):(console.log("Sending via window.sendMessageFromUI"),window.sendMessageFromUI(a))}static sendCustomCommand(e,n=null){const a={command:e,text:JSON.stringify({})};console.log("Cabbage: sending custom command from UI",a),n!==null?n.postMessage(a):window.sendMessageFromUI(a)}static sendWidgetUpdate(e,n=null){console.log("Cabbage: sending widget update from UI",e.props);const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};n!==null?n.postMessage(a):window.sendMessageFromUI(a)}static sendMidiMessageFromUI(e,n,a,t=null){var s={statusByte:e,dataByte1:n,dataByte2:a};const o={command:"midiMessage",obj:JSON.stringify(s)};console.log("Cabbage: sending midi message from UI",s),t!==null?t.postMessage(o):window.sendMessageFromUI(o)}static sendChannelData(e,n,a=null){var t={channel:e};if(typeof n=="string")t.stringData=n;else if(typeof n=="number")t.floatData=n;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof n);return}const s={command:"channelData",obj:JSON.stringify(t)};console.log("Cabbage: sending channel data from UI",t),a!==null?a.postMessage(s):window.sendMessageFromUI(s)}static MidiMessageFromHost(e,n,a){console.log("Cabbage: Got MIDI Message"+e+":"+n+":"+a)}static triggerFileOpenDialog(e,n,a={}){var t={channel:n,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const s={command:"fileOpen",obj:JSON.stringify(t)};e!==null?e.postMessage(s):window.sendMessageFromUI(s)}static openUrl(e,n,a){var t={url:n,file:a};const s={command:"openUrl",obj:JSON.stringify(t)};e!==null?e.postMessage(s):window.sendMessageFromUI(s)}}const m=r=>{const[e,n]=d.useState();return d.useEffect(()=>{const a=t=>{const{id:s,widgetJson:o,command:l}=t.data;if(s===r&&o&&l==="widgetUpdate"){const i=JSON.parse(o);console.log(`[Cabbage-React] Received properties for channelId ${s}`,i),n(i)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:e}},u=r=>{const{properties:e}=m(r),[n,a]=d.useState(),t=(s,o)=>{a(s);const l={channel:r,value:s,stringData:o};g.sendParameterUpdate(l,null)};return d.useEffect(()=>{var i;const s=e==null?void 0:e.value;if(s!=null){console.log(`[Cabbage-React] Received initial value for channelId "${r}"`,s),a(s);return}const o=e==null?void 0:e.channels.find(c=>c.id===r);if(!o)return;const l=(i=o.range)==null?void 0:i.defaultValue;n===void 0&&l!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${o.id}"`,l),a(l))},[e]),d.useEffect(()=>{const s=o=>{const{command:l}=o.data;if(l==="parameterChange"){const{value:i,paramIdx:c}=o.data;if(i===null)return;console.log(`[Cabbage-React] Received value change for parameterIndex ${c}`,i),a(i)}};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},[]),{value:n,setValue:t}};exports.Cabbage=g;exports.useCabbageProperties=m;exports.useCabbageState=u;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useState as
|
|
1
|
+
import { useState as m, useEffect as c } from "react";
|
|
2
2
|
console.log("Cabbage: loading cabbage.js");
|
|
3
|
-
class
|
|
3
|
+
class d {
|
|
4
4
|
/**
|
|
5
5
|
* Main entry point for sending any data from UI widgets to the Cabbage backend.
|
|
6
6
|
* This function automatically routes messages to the appropriate backend function
|
|
@@ -14,164 +14,164 @@ class c {
|
|
|
14
14
|
* All widget interactions should use this function instead of calling the lower-level
|
|
15
15
|
* sendParameterUpdate or sendChannelData functions directly.
|
|
16
16
|
*/
|
|
17
|
-
static sendChannelUpdate(
|
|
17
|
+
static sendChannelUpdate(e, a = null, n = 0) {
|
|
18
18
|
if (n === 1)
|
|
19
|
-
|
|
19
|
+
d.sendParameterUpdate(e, a);
|
|
20
20
|
else {
|
|
21
|
-
const
|
|
22
|
-
|
|
21
|
+
const t = e.value !== void 0 ? e.value : e.stringData || e.floatData;
|
|
22
|
+
d.sendChannelData(e.channel, t, a);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
static sendParameterUpdate(
|
|
25
|
+
static sendParameterUpdate(e, a = null) {
|
|
26
26
|
const n = {
|
|
27
27
|
command: "parameterChange",
|
|
28
|
-
...
|
|
28
|
+
...e
|
|
29
29
|
};
|
|
30
|
-
console.log("Cabbage.sendParameterUpdate:",
|
|
30
|
+
console.log("Cabbage.sendParameterUpdate:", e, "vscode:", a, "msg:", n), a !== null ? (console.log("Sending via vscode.postMessage"), a.postMessage(n)) : (console.log("Sending via window.sendMessageFromUI"), window.sendMessageFromUI(n));
|
|
31
31
|
}
|
|
32
|
-
static sendCustomCommand(
|
|
32
|
+
static sendCustomCommand(e, a = null) {
|
|
33
33
|
const n = {
|
|
34
|
-
command:
|
|
34
|
+
command: e,
|
|
35
35
|
text: JSON.stringify({})
|
|
36
36
|
};
|
|
37
|
-
console.log("Cabbage: sending custom command from UI", n),
|
|
37
|
+
console.log("Cabbage: sending custom command from UI", n), a !== null ? a.postMessage(n) : window.sendMessageFromUI(n);
|
|
38
38
|
}
|
|
39
|
-
static sendWidgetUpdate(
|
|
40
|
-
console.log("Cabbage: sending widget update from UI",
|
|
39
|
+
static sendWidgetUpdate(e, a = null) {
|
|
40
|
+
console.log("Cabbage: sending widget update from UI", e.props);
|
|
41
41
|
const n = {
|
|
42
42
|
command: "widgetStateUpdate",
|
|
43
|
-
obj: JSON.stringify(CabbageUtils.sanitizeForEditor(
|
|
43
|
+
obj: JSON.stringify(CabbageUtils.sanitizeForEditor(e))
|
|
44
44
|
};
|
|
45
|
-
|
|
45
|
+
a !== null ? a.postMessage(n) : window.sendMessageFromUI(n);
|
|
46
46
|
}
|
|
47
|
-
static sendMidiMessageFromUI(
|
|
48
|
-
var
|
|
49
|
-
statusByte:
|
|
50
|
-
dataByte1:
|
|
47
|
+
static sendMidiMessageFromUI(e, a, n, t = null) {
|
|
48
|
+
var s = {
|
|
49
|
+
statusByte: e,
|
|
50
|
+
dataByte1: a,
|
|
51
51
|
dataByte2: n
|
|
52
52
|
};
|
|
53
53
|
const o = {
|
|
54
54
|
command: "midiMessage",
|
|
55
|
-
obj: JSON.stringify(
|
|
55
|
+
obj: JSON.stringify(s)
|
|
56
56
|
};
|
|
57
|
-
console.log("Cabbage: sending midi message from UI",
|
|
57
|
+
console.log("Cabbage: sending midi message from UI", s), t !== null ? t.postMessage(o) : window.sendMessageFromUI(o);
|
|
58
58
|
}
|
|
59
|
-
static sendChannelData(
|
|
60
|
-
var
|
|
61
|
-
channel:
|
|
59
|
+
static sendChannelData(e, a, n = null) {
|
|
60
|
+
var t = {
|
|
61
|
+
channel: e
|
|
62
62
|
};
|
|
63
|
-
if (typeof
|
|
64
|
-
|
|
65
|
-
else if (typeof
|
|
66
|
-
|
|
63
|
+
if (typeof a == "string")
|
|
64
|
+
t.stringData = a;
|
|
65
|
+
else if (typeof a == "number")
|
|
66
|
+
t.floatData = a;
|
|
67
67
|
else {
|
|
68
|
-
console.warn("Cabbage: sendChannelData received unsupported data type:", typeof
|
|
68
|
+
console.warn("Cabbage: sendChannelData received unsupported data type:", typeof a);
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
|
-
const
|
|
71
|
+
const s = {
|
|
72
72
|
command: "channelData",
|
|
73
|
-
obj: JSON.stringify(
|
|
73
|
+
obj: JSON.stringify(t)
|
|
74
74
|
};
|
|
75
|
-
console.log("Cabbage: sending channel data from UI",
|
|
75
|
+
console.log("Cabbage: sending channel data from UI", t), n !== null ? n.postMessage(s) : window.sendMessageFromUI(s);
|
|
76
76
|
}
|
|
77
|
-
static MidiMessageFromHost(
|
|
78
|
-
console.log("Cabbage: Got MIDI Message" +
|
|
77
|
+
static MidiMessageFromHost(e, a, n) {
|
|
78
|
+
console.log("Cabbage: Got MIDI Message" + e + ":" + a + ":" + n);
|
|
79
79
|
}
|
|
80
|
-
static triggerFileOpenDialog(
|
|
81
|
-
var
|
|
82
|
-
channel:
|
|
80
|
+
static triggerFileOpenDialog(e, a, n = {}) {
|
|
81
|
+
var t = {
|
|
82
|
+
channel: a,
|
|
83
83
|
directory: n.directory || "",
|
|
84
84
|
filters: n.filters || "*",
|
|
85
85
|
openAtLastKnownLocation: n.openAtLastKnownLocation !== void 0 ? n.openAtLastKnownLocation : !0
|
|
86
86
|
};
|
|
87
|
-
const
|
|
87
|
+
const s = {
|
|
88
88
|
command: "fileOpen",
|
|
89
|
-
obj: JSON.stringify(
|
|
89
|
+
obj: JSON.stringify(t)
|
|
90
90
|
};
|
|
91
|
-
|
|
91
|
+
e !== null ? e.postMessage(s) : window.sendMessageFromUI(s);
|
|
92
92
|
}
|
|
93
|
-
static openUrl(
|
|
94
|
-
var
|
|
95
|
-
url:
|
|
93
|
+
static openUrl(e, a, n) {
|
|
94
|
+
var t = {
|
|
95
|
+
url: a,
|
|
96
96
|
file: n
|
|
97
97
|
};
|
|
98
|
-
const
|
|
98
|
+
const s = {
|
|
99
99
|
command: "openUrl",
|
|
100
|
-
obj: JSON.stringify(
|
|
100
|
+
obj: JSON.stringify(t)
|
|
101
101
|
};
|
|
102
|
-
|
|
102
|
+
e !== null ? e.postMessage(s) : window.sendMessageFromUI(s);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
const
|
|
106
|
-
const [
|
|
107
|
-
return
|
|
108
|
-
const n = (
|
|
109
|
-
const { id:
|
|
110
|
-
if (
|
|
105
|
+
const u = (r) => {
|
|
106
|
+
const [e, a] = m();
|
|
107
|
+
return c(() => {
|
|
108
|
+
const n = (t) => {
|
|
109
|
+
const { id: s, widgetJson: o, command: l } = t.data;
|
|
110
|
+
if (s === r && o && l === "widgetUpdate") {
|
|
111
111
|
const i = JSON.parse(o);
|
|
112
112
|
console.log(
|
|
113
|
-
`[Cabbage-React] Received properties for channelId ${
|
|
113
|
+
`[Cabbage-React] Received properties for channelId ${s}`,
|
|
114
114
|
i
|
|
115
|
-
),
|
|
115
|
+
), a(i);
|
|
116
116
|
}
|
|
117
117
|
};
|
|
118
118
|
return window.addEventListener("message", n), () => {
|
|
119
119
|
window.removeEventListener("message", n);
|
|
120
120
|
};
|
|
121
121
|
}, []), {
|
|
122
|
-
properties:
|
|
122
|
+
properties: e
|
|
123
123
|
};
|
|
124
|
-
},
|
|
125
|
-
const { properties: e } =
|
|
126
|
-
s
|
|
124
|
+
}, p = (r) => {
|
|
125
|
+
const { properties: e } = u(r), [a, n] = m(), t = (s, o) => {
|
|
126
|
+
n(s);
|
|
127
127
|
const l = {
|
|
128
|
-
paramIdx: a,
|
|
129
128
|
channel: r,
|
|
130
|
-
value:
|
|
129
|
+
value: s,
|
|
130
|
+
stringData: o
|
|
131
131
|
};
|
|
132
|
-
|
|
132
|
+
d.sendParameterUpdate(l, null);
|
|
133
133
|
};
|
|
134
|
-
return
|
|
135
|
-
var
|
|
136
|
-
const
|
|
137
|
-
if (
|
|
134
|
+
return c(() => {
|
|
135
|
+
var i;
|
|
136
|
+
const s = e == null ? void 0 : e.value;
|
|
137
|
+
if (s != null) {
|
|
138
138
|
console.log(
|
|
139
139
|
`[Cabbage-React] Received initial value for channelId "${r}"`,
|
|
140
|
-
|
|
141
|
-
), s
|
|
140
|
+
s
|
|
141
|
+
), n(s);
|
|
142
142
|
return;
|
|
143
143
|
}
|
|
144
|
-
const
|
|
144
|
+
const o = e == null ? void 0 : e.channels.find(
|
|
145
145
|
(g) => g.id === r
|
|
146
146
|
);
|
|
147
|
-
if (!
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
`[Cabbage-React] Received default value for channelId "${
|
|
151
|
-
|
|
152
|
-
),
|
|
153
|
-
}, [e]),
|
|
154
|
-
const
|
|
155
|
-
const { command:
|
|
156
|
-
if (
|
|
157
|
-
const { value:
|
|
158
|
-
if (
|
|
147
|
+
if (!o) return;
|
|
148
|
+
const l = (i = o.range) == null ? void 0 : i.defaultValue;
|
|
149
|
+
a === void 0 && l !== void 0 && (console.log(
|
|
150
|
+
`[Cabbage-React] Received default value for channelId "${o.id}"`,
|
|
151
|
+
l
|
|
152
|
+
), n(l));
|
|
153
|
+
}, [e]), c(() => {
|
|
154
|
+
const s = (o) => {
|
|
155
|
+
const { command: l } = o.data;
|
|
156
|
+
if (l === "parameterChange") {
|
|
157
|
+
const { value: i, paramIdx: g } = o.data;
|
|
158
|
+
if (i === null) return;
|
|
159
159
|
console.log(
|
|
160
160
|
`[Cabbage-React] Received value change for parameterIndex ${g}`,
|
|
161
|
-
|
|
162
|
-
),
|
|
161
|
+
i
|
|
162
|
+
), n(i);
|
|
163
163
|
}
|
|
164
164
|
};
|
|
165
|
-
return window.addEventListener("message",
|
|
166
|
-
window.removeEventListener("message",
|
|
165
|
+
return window.addEventListener("message", s), () => {
|
|
166
|
+
window.removeEventListener("message", s);
|
|
167
167
|
};
|
|
168
168
|
}, []), {
|
|
169
|
-
value:
|
|
169
|
+
value: a,
|
|
170
170
|
setValue: t
|
|
171
171
|
};
|
|
172
172
|
};
|
|
173
173
|
export {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
d as Cabbage,
|
|
175
|
+
u as useCabbageProperties,
|
|
176
|
+
p as useCabbageState
|
|
177
177
|
};
|