|
07-02-2022, 07:53 PM | #1 |
Human being with feelings
Join Date: Jun 2022
Posts: 11
|
String to Hex
Hi.
I'm testing OSC output from TouchOSC and hoping to convert OSC to Midi to send to my DAW. TouchOSC can send Midi directly but I'm just testing using it for now. I'm able to capture an OSC message and multiple parameters. In all my tests, OSCii-bot will only receive OSC parameters that are strings. I can send out an Integer or Float of course but OSCii-bot will not read it. I created a Fader for testing in TouchOSC called "/Note" with 2 string parameters. The 1st parameter outputs "60" to represent the Middle C note. The 2nd parameter outputs the fader level to represent Velocity from 0-127. I'm able to log the OSC message using the following code: Code:
oscmatch("/Note",$'s') ? ( oscparm(idx,type); type=='s' ? ( #note = null; #volume = null; //must use #variables oscparm(0,'s',#note); oscparm(1,'s',#volume); printf(oscstr); printf (" Note: "); printf (#note); printf (" Volume: "); printf(#volume); ); ); Thank you. Last edited by procedure; 07-07-2022 at 09:45 AM. |
07-05-2022, 06:12 PM | #2 |
Human being with feelings
Join Date: Jun 2022
Posts: 11
|
Is my question off-the-wall somehow or the answer so obvious...
In the C language, I do now see people creating their own functions to convert an integer into a Hex value. So I think that can be handled similarly. I see the C language has functions that could help convert a string to a integer but I don't see that in EEL2. Can that be done? Doesn't everyone need to convert a string to Hex in order to send out Midi? |
07-06-2022, 04:30 AM | #3 |
Human being with feelings
Join Date: Apr 2011
Location: Germany
Posts: 228
|
If I understand correctly, you're getting 0-127 in string format but the output format needs to be a number.
In this case try this: Code:
match("%i",#input_value,output_value); #input : input string containing your OSC value output_value : variable that gets to store the value for MIDI output |
07-06-2022, 12:04 PM | #4 |
Human being with feelings
Join Date: Jun 2022
Posts: 11
|
Thanks very much for responding.
Here is the current version of my code with your code added at the end: Code:
oscmatch("/NoteOn/",$'s') ? ( oscparm(idx,type); type=='s' ? ( #note = null; #velocity = null; oscparm(0,'s',#note); oscparm(1,'s',#velocity); printf(oscstr); printf (" Note: "); printf (#note); printf (" Velocity: "); printf(#velocity); printf("\n"); match("%i",#note,intNote); printf("this is intNote: "); printf(intNote); printf("\n"); match("%i",#velocity,intVelocity); printf("this is intVelocity: "); printf(intVelocity); printf("\n"); ); ); /NoteOn/ Note: 60 Velocity: 95.19064 this is intNote: this is intVelocity: /NoteOn/ Note: 60 Velocity: 35.404 this is intNote: this is intVelocity: So I'm not able to get a conversion with either OSC argument. I tried it with #intNote and #intVelocity as well. I don't really understand the use of the types of variables from the programming guide. Any ideas? Thanks. Last edited by procedure; 07-07-2022 at 09:45 AM. |
07-06-2022, 01:27 PM | #5 |
Human being with feelings
Join Date: Apr 2011
Location: Germany
Posts: 228
|
Following the programming manual printf() does what sprintf() does, it's a function used to convert numbers to strings. If you just put a number into it there should be some kind of an error message.
sprintf goes like Code:
sprintf(#string_out,"%i",input_value) For sending MIDI you use this one: midisend(device_index,m1,m2,m3) Sends a simple 3 byte message. device_index is the index number of the midi device, m1 the status byte (type of message + channel), m2 the controller number, m3 the value. So you wanna do something like sending modwheel on channel 1, max position to the first midi device in the list you can do this: Code:
midisend(0,176,1,127); or in hex midisend(0,0xB0,0x01,0x7F); same thing, just different appearance. Comes with all the data formats and whatnot. Maybe I'll come up with a quick solution and leave some code that should allow you to write a simple OSC-MIDI converter. Would be in my interest, too, could use some scripts here and there. OscII Bot just won't output any gfx on my machines, sample scripts ain't working right, don't know why, have to go figure. |
07-06-2022, 04:26 PM | #6 |
Human being with feelings
Join Date: Jun 2022
Posts: 11
|
Thank you very much.
So this is great I now get 2 arguments that are integers from the following code. (This code is completely ridiculous since I'm converting back and forth from floats and strings and integers over and over but I don't know another way...) Now I just need to convert integers to HEX. You are a hero if you can code that. That would be amazing Thank you. --------------------- Code:
oscmatch("/NoteOn/",$'s') ? ( oscparm(idx,type); type=='s' ? ( #note = null; #velocity = null;//must use #variables oscparm(0,'s',#note); //string oscparm(1,'s',#velocity); //string printf(oscstr); printf (" Note: "); printf (#note); printf (" Velocity: "); printf(#velocity); printf("\n"); //OSC Arg 1 - note match("%i",#note,intNote); //convert string to integer sprintf(#string_out1,"%i",intNote); //convert int to string again! printf only prints strings printf("this is intNote: "); printf(#string_out1); printf("\n"); //OSC Arg 2 - velocity match("%f",#velocity,floatVelocity);//convert string to float floatVelocity = floor(floatVelocity);//round float to nearest decimal (will be #.00000) sprintf(#strVelocity,"%i",floatVelocity);//converts float to string (but will look like integer without #.00000) match("%i",#strVelocity,intVelocity);//convert string to integer sprintf(#string_out2,"%i",intVelocity); //convert int to string again! printf only prints strings printf("this is intVelocity: "); printf(#string_out2); printf("\n"); ); ); And the LOG reads: Code:
/NoteOn/ Note: 60 Velocity: 48.527893 this is intNote: 60 this is intVelocity: 48 Last edited by procedure; 07-07-2022 at 09:48 AM. |
Thread Tools | |
Display Modes | |
|
|