A very simple example of using Electron in N4M project.
Uses Socket.io to communicate between the main process and the renderer process, and also Max API to bring data back and forth between the main process and the max patch.
Open main.maxpat
and follow the instructions.
This section is for Node.js developers:
If you are familiar with Node.js development, there's not much thing you have to know. Just use your locally installed npm
/ yarn
to manage packages, and test with your local node
.
But remember that your local node
version should match that of runtime, in other words, the one installed inside Max.app
.
I suggest using something like nodenv
, nodebrew
, or any type of version control system.
.
├── README.md
├── electron
│ ├── package.json
│ ├── src
│ ├── webpack.config.js
├── index.js
├── main.maxpat
└── package.json
The flow of the entire process is as follows:
-
A user will open
main.maxpat
and hitnpm run setup
that is connected to'node.script index.js'
. -
This will fire the npm script written in
./package.json
, which has 3 tasks:
2.1 Install the package for the top-level folder. (here)
2.2 Install the package in theelectron
folder.
2.3 Build the electron app with babel and webpack. A bundled js file will be emitted to./electron/dist/
. -
When the user hits
'script start'
in the Max patch, it will evoke./index.js
file, which will boot electron up and also creates a socket server atlocalhost:3000
to enable communication between with the main process and the renderer process of the app. (Socket.io is not always necessary for this task) -
And now let's examine what's going on in the
electron
folder. Suppose you are inelectron
folder,src/main.js
is the file electron first reads. Why? Because by default, electron will read the file specified in themain
property in thepackage.json
of that directory. -
When
src/main.js
is evaluated, it launches a window and readssrc/index.html
. To send/receive data with the Max patch, you'll have to use the Max API. But because Max API is only available in the node process that's evoked bynode.script
in the max patch, you can'trequire('max-api')
in your renderer process. Thus we use socket. So the data will flow fromrenderer process
=>(via socket)main process
=> (via max-api) Max patch.
PRs are welcome!
Small note: If editing the README, please conform to the standard-readme specification.
MIT © 2018 Yuichi Yogo