Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern/ route function for multiple addresses #161

Open
ceceba223 opened this issue Jan 13, 2025 · 1 comment
Open

Pattern/ route function for multiple addresses #161

ceceba223 opened this issue Jan 13, 2025 · 1 comment

Comments

@ceceba223
Copy link

ceceba223 commented Jan 13, 2025

Hey,
I'm looking for a way to send multiple key presses via osc. The addresses are supposed to look something like this:

/Key20

/Key21

I can achieve this by writing one address at a time like this:

OSCMessage msg("/Key20");

But I need a function which works for all keys, so I modified it to look like this:

  char address_base = "/Key";
  address_base += key_id;
  OSCMessage msg(address_base);

However that returns an error:

C:\Users\Me\Documents\Arduino\libraries\OSCMessage/OSCMessage.h:112:2: note: candidate: OSCMessage::OSCMessage(const char*) <near match>
  OSCMessage (const char * _address);
  ^~~~~~~~~~
C:\Users\Me\Documents\Arduino\libraries\OSCMessage/OSCMessage.h:112:2: note:   conversion of argument 1 would be ill-formed:

exit status 1

Compilation error: no matching function for call to 'OSCMessage(char&)'

From the documentation I guess the "route" function or the pattern matching could be helpful to me. But I don't quite understand it.
Any help is appreciated.

@njewettlx
Copy link

I had a similar problem, here's how I solved it:

tempOSCmessage is the string in which I built the address I'm trying to send - sensorNum and newReading[sensorNum] are byte and int variables from elsewhere in the program.

msg is the OSC Message object that I am sending.

  String tempOSCmessage = "/location/1/";
  //add sensor number to OSC Address
  tempOSCmessage += sensorNum;
  //add sensor reading to OSC Address
  tempOSCmessage +="/";
  tempOSCmessage += newReading[sensorNum];
  //add "press" command to OSC Address
  tempOSCmessage += "/press";
  //create char* pointer to OSC Address to pass to OSC constructor
  const char* toSend = tempOSCmessage.c_str();
  OSCMessage msg(toSend);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants