thomasfredericks / MicroOsc

MicroOsc is a minimal Open Sound Control (OSC) library for Arduino
MIT License
16 stars 2 forks source link

Handling lists from an OSC message #5

Closed Lytrix closed 5 months ago

Lytrix commented 5 months ago

Hi! I've completed my max4live 5hp eurorack controllers with your great library. Thanks so much for making this!

One question: Is it possible with MicroOsc to also handle lists from an OSC message?

I would like to reduce amount calls to send to my displays by having all data in one OSC message to process and display in one function. Currently every value is send as a separate OSC address and it will take 4 if statement loops in Arduino (name, value, value type, float for slider) to display all required data at to display each value at specific x,y positions, where sometimes the data is not being processed timely enough to get displayed. I saw in OSC CNMAT it is also possible to send values as a list. Would it be also be possible with microOsc? If so, could you provide an example how get the values from a list?

For example:

/controller/1/display/1/row/1 ["FREQ",  0.125, "31.2", "kHz"] 

in CNMAT you could then do:

msg.getString(0), msg.getFloat(1) 

to iterate over the list.

thomasfredericks commented 5 months ago

Hi! You are welcome. Yes MicroOsc supports variable argument lists.

You can can send lists from MicroOsc, but it is really important to cast the values when you do.

You can also receive lists. For example if you send/controller/1/display/1/row/1 ["FREQ", 0.125, "31.2", "kHz"] you can parse the message with:

//  OSC MSG "/controller/1/display/1/row/1" WITH THE LIST "sfss" (string, float, string, string)
if ( receivedOscMessage.checkOscAddress("/controller/1/display/1/row/1", "sfss") ) {

  // GET THE FIRST AS A STRING
  const char * firstAsString = receivedOscMessage.nextAsString();

 // GET THE SECOND AS A FLOAT
  float secondAsFloat  = receivedOscMessage.nextAsFloat();

  // GET THE THIRD AS A STRING
  const char * thirdAsAString = receivedOscMessage.nextAsString();

   // GET THE FORTH AS A STRING
  const char * forthAsAString = receivedOscMessage.nextAsString();
}
Lytrix commented 5 months ago

Thanks for the fast reply and example, it works!

I did not reread the docs to check the advanced section. I only checked the functions in the code, so will do that next time :-)

It updates much faster, but my displays are crashing now after 5 seconds :-), will do some tests to see if it might be due to a wrong type being parsed or maybe it's due to the screen speed/i2c multiplexer switching, so I will close this issue. Have a great weekend!

thomasfredericks commented 5 months ago

Keep me posted if you trace the crashing to MicroOsc!