padenot

  • Aug 17, 2021
  • Joined Sep 22, 2017
  • 0 discussions
  • 6 posts
  • 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

    • The above setup should work reliably, but I don't have a Monome so I couldn't try it out. @padenot may also be able to say something about how it worked for him. Because of how the BBG + Bela cape are mounted in Salt, you will need to solder some wires to the back of your BeagleBone to break out the UART signals.

    • giuliomoro yes, I removed them as the fields didn't appear to exist anymore in the new BelaInitSettings struct. I assume

      int unused1;
      char unused2[MAX_UNUSED2_LENGTH];

      is where they used to be? Since @andrewcsmith 's bela-sys generates the Rust structs directly from the header, binary compatibility wasn't helpful. It may work with @padenot 's bela-sys since that one doesn't auto-generate the Rust code, in that case I could add them back in (but everything would have to be binary compatible and it could silently break in the future).

      • Nothing breaking has changed in the Bela API since then (it has only been expanded a bit ), so I guess it should just work.

        djensenius Or if there is any chance of official Rust support for Bela?

        There are no hard and fast rules as to how a language becomes "officially supported" by Bela, but we'd need at least a few users who use it routinely, otherwise there is the risk of:
        a) the support breaking, because of API changes, old documentation, etc
        b) spending development time on something that benefits no one

        None of us on the core team of Bela is a Rust developer, which means we wouldn't be in the position of maintaining it and adding features to it without a significant community contribution and/or interest . A possible pathway towards getting "out of the box" support for Rust on Bela, would be for someone (e.g.: you, and/or @padenot / @andrewcsmith if they have kept using it beyond their great contributions above) should make sure the steps above still work, then come up with at least a minimal set of examples to cover the basics (think something like the "Fundamentals" examples we currently provide for C++, or the examples for Supercollider and Csound). In the process, hopefully the functionalities will receive further test and possibly additions.

        I am happy to help every step of the way with integration, but I'd rather not to have to write anything on the Rust side (because I don't know how to!).

        As a side note, a "success story": Supercollider support was added with community contribution where I took part of the integration, and I still maintain it today. We are a few revisions behind the official repo, but now looking at merge upstream in a future not too far away. In the process, I have - to this day - written more lines of Supercollider C++ source code than Supercollider programs.