Hi future travelers. I have also got the grid working although it took me a bit. I'm going to leave some notes here in case it might be useful.
This script is a total success for me: https://github.com/giuliomoro/bela-utils/blob/master/bela-setup-monome.sh (thank you @giuliomoro and @padenot !!)
You also need to generate a monome config file. You can generate this config file by following these instructions. Just make sure that you can use those instructions to generate the file in ~/.config/serialosc/
.
Once you have the config file, you need to change one line in the /lib/systemd/system/serialoscd.service
to use it:
ExecStart=/usr/local/bin/serialoscd -c ~/.config/serialosc/
That will make sure that it uses the config you generated and serialoscd doesn't switch ports everytime the Bela turns on.
Then
systemctl daemon-reload
systemctl restart serialoscd
will get it going.
Using monome in code is pretty easy. Here's basically what I did in render.cpp
(full code: https://github.com/schollz/palms/blob/53a85b62d11be26054f162b30342bb01b6c967e4/render.cpp#L12):
...
#include <monome.h>
// monome
monome_t* monome;
unsigned int grid[16][16] = {[0 ... 15][0 ... 15] = 0};
#define MONOME_DEVICE "osc.udp://127.0.0.1:14656/monome"
void handle_press(const monome_event_t* e, void* data) {
unsigned int x, y;
x = e->grid.x;
y = e->grid.y;
/* toggle the button */
grid[x][y] = !grid[x][y];
monome_led_set(e->monome, x, y, grid[x][y]);
}
static void monome_loop(void*) { // monome_event_loop(monome);
while (!Bela_stopRequested()) {
monome_event_handle_next(monome);
}
monome_close(monome);
}
bool setup(BelaContext* context, void* userData) {
/* open the monome device */
if (!(monome = monome_open(MONOME_DEVICE, "8000")))
return -1;
monome_led_all(monome, 0);
/* register our button press callback */
monome_register_handler(monome, MONOME_BUTTON_DOWN, handle_press, NULL);
Bela_runAuxiliaryTask(monome_loop);
...
One important note is that the port you use for #define MONOME_DEVICE "osc.udp://127.0.0.1:14656/monome"
needs to have the port (mine is 14656) match what is in your config file. You can find your port by running cat ~/.config/serialosc/*
, for example it gives me:
server {
port = 14656
}
application {
osc_prefix = "/monome"
host = "127.0.0.1"
port = 8000
}
device {
rotation = 0
}
So you can see that I use port 14656 for everything and define that in my render.cpp