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.maxpatand hitnpm run setupthat 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 theelectronfolder.
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.jsfile, which will boot electron up and also creates a socket server atlocalhost:3000to 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
electronfolder. Suppose you are inelectronfolder,src/main.jsis the file electron first reads. Why? Because by default, electron will read the file specified in themainproperty in thepackage.jsonof that directory. -
When
src/main.jsis 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.scriptin 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