cabbage-react 1.0.0-beta.27 → 1.0.0-beta.29
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 +101 -100
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,100 +1,101 @@
|
|
|
1
|
-
# Cabbage-React
|
|
2
|
-
|
|
3
|
-
Cabbage-React provides React hooks for synchronizing [Cabbage](https://cabbageaudio.com) with [React](https://github.com/facebook/react), making it easier to build UI
|
|
4
|
-
|
|
5
|
-
## Example Project
|
|
6
|
-
|
|
7
|
-
An example of implementation is available [here](https://github.com/hdale94/cabbage-react-example).
|
|
8
|
-
|
|
9
|
-
## Installation
|
|
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
|
-
import {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const {
|
|
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
|
-
import {
|
|
88
|
-
import "
|
|
89
|
-
import
|
|
90
|
-
import
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
Cabbage
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
1
|
+
# Cabbage-React
|
|
2
|
+
|
|
3
|
+
Cabbage-React provides React hooks for synchronizing [Cabbage](https://cabbageaudio.com) with [React](https://github.com/facebook/react), making it easier to build a custom UI that communicates with the Cabbage host.
|
|
4
|
+
|
|
5
|
+
## Example Project
|
|
6
|
+
|
|
7
|
+
An example of implementation is available [here](https://github.com/hdale94/cabbage-react-example).
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```jsx
|
|
12
|
+
yarn add cabbage-react
|
|
13
|
+
# or
|
|
14
|
+
npm install cabbage-react
|
|
15
|
+
```
|
|
16
|
+
## Hooks
|
|
17
|
+
|
|
18
|
+
### useCabbageState
|
|
19
|
+
|
|
20
|
+
Synchronize a parameter with Cabbage. This hook:
|
|
21
|
+
|
|
22
|
+
- Listens for value updates from Cabbage.
|
|
23
|
+
- Sends local changes (e.g., via sliders, knobs) back to Cabbage.
|
|
24
|
+
|
|
25
|
+
### useCabbageProperties
|
|
26
|
+
|
|
27
|
+
Get properties for a parameter from Cabbage.
|
|
28
|
+
This hook:
|
|
29
|
+
|
|
30
|
+
- Listens for property updates from Cabbage.
|
|
31
|
+
- Updates local state automatically when data changes.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```jsx
|
|
36
|
+
import { InputHTMLAttributes } from "react";
|
|
37
|
+
import { useCabbageProperties, useCabbageState } from "cabbage-react";
|
|
38
|
+
|
|
39
|
+
const HorizontalSlider = ({
|
|
40
|
+
channel,
|
|
41
|
+
paramIdx,
|
|
42
|
+
inputProps,
|
|
43
|
+
}: {
|
|
44
|
+
channel: string;
|
|
45
|
+
paramIdx: number;
|
|
46
|
+
inputProps?: InputHTMLAttributes<HTMLInputElement>;
|
|
47
|
+
}) => {
|
|
48
|
+
const { properties } = useCabbageProperties(channel);
|
|
49
|
+
const { value, setValue } = useCabbageState<number>(channel, paramIdx);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div>
|
|
53
|
+
<input
|
|
54
|
+
type="range"
|
|
55
|
+
min={properties?.range?.min ?? 0}
|
|
56
|
+
max={properties?.range?.max ?? 1}
|
|
57
|
+
step={properties?.range?.increment ?? 0.01}
|
|
58
|
+
value={value}
|
|
59
|
+
onChange={(e) => setValue(e.target.valueAsNumber)}
|
|
60
|
+
{...inputProps}
|
|
61
|
+
style={{
|
|
62
|
+
accentColor: "rgb(147,210,0)",
|
|
63
|
+
...inputProps?.style,
|
|
64
|
+
}}
|
|
65
|
+
/>
|
|
66
|
+
|
|
67
|
+
{/* Displaying the value */}
|
|
68
|
+
<p style={{ margin: 0 }}>{value ?? 0}</p>
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default HorizontalSlider;
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Interact directly with Cabbage
|
|
77
|
+
|
|
78
|
+
You can also import the [Cabbage class](https://github.com/hdale94/cabbage-react/blob/main/src/cabbage/cabbage.js) to send custom messages or interact directly with Cabbage.
|
|
79
|
+
|
|
80
|
+
## Notify Cabbage When UI Is Ready
|
|
81
|
+
|
|
82
|
+
To let Cabbage know your UI is ready to receive data, send a `cabbageIsReadyToLoad` message when your app initializes.
|
|
83
|
+
|
|
84
|
+
Place this call before rendering your app — typically in your main.tsx or index.tsx file:
|
|
85
|
+
|
|
86
|
+
```jsx
|
|
87
|
+
import { StrictMode } from "react";
|
|
88
|
+
import { createRoot } from "react-dom/client";
|
|
89
|
+
import "./index.css";
|
|
90
|
+
import App from "./App.tsx";
|
|
91
|
+
import { Cabbage } from "cabbage-react";
|
|
92
|
+
|
|
93
|
+
// Notify Cabbage that the UI is ready to receive data
|
|
94
|
+
Cabbage.sendCustomCommand("cabbageIsReadyToLoad");
|
|
95
|
+
|
|
96
|
+
createRoot(document.getElementById("root")!).render(
|
|
97
|
+
<StrictMode>
|
|
98
|
+
<App />
|
|
99
|
+
</StrictMode>
|
|
100
|
+
);
|
|
101
|
+
```
|