Thread: String to Hex
View Single Post
Old 07-14-2022, 10:42 AM   #14
procedure
Human being with feelings
 
Join Date: Jun 2022
Posts: 11
Default

Thanks again for you help.
This was my final working script and was tested using the free version of TouchOSC, LoopBe, and FL Studio. It converts OSC from a controller such as TouchOSC and sends Midi through LoopBe to a DAW. It can send NoteOn, NoteOff, and ControlChange. I couldn't get SysEx working:

Code:
@input osc_in OSC "*:7001"     //Set this for your input
@output midi_out MIDI "LoopBe" //Set this for your output device

@init
@timer
@oscmsg

//TouchOSC - Receive 2 Integer OSC parameters to send out as Midi. 
oscmatch("*Note*",$'s') ? (//only works if finds OSC message named Note (or /NoteOn/ or /NoteOff/ etc)
	oscparm(idx,type);
	type=='i' ? (
		
		oscmatch("*NoteOn*",$'s') ? ( msg1 = 0x99 ) : ( msg1 = 0x83 );//noteon 0x99 or noteoff 0x83
		msg2 = oscparm(0); //middle c 0x3C
		msg3 = oscparm(1); //volume 127 0x7F

		midisend(midi_out);
		
	);
);

//TouchOSC - Control Change messages use Channel (1-16) and Ctrl (0-127) and a Value (0-127)
oscmatch("*ControlChange*",$'s') ? (
	oscparm(idx,type);
	type=='i' ? (
		
		msg1 = 0xB0;// 176 = 0xB0 Ch 1, 0xB1 Ch 2, 0xB2 Ch 3,... 0xBF ch 16
		msg2 = oscparm(0); //Ctrl number 0-127
		msg3 = oscparm(1); //value 0-127

		midisend(midi_out);
		
	);
);
	
//SYSEX -- NOT WORKING FOR ME
//if a SysEx (system exclusive) message is received, msg1/msg2/msg3 will all be 0, and oscstr will be set to a string with the SysEx data
//midisend_str(midiout, "\xF0\x00\x01\x02\xF7") example of sending SysEx -- all begin with 0xF0 (status byte that means this is sysex), then manufacturer ID, then 2 pieces of data, and end with 0xF7 to end message
//Universal messages -- There are two universal IDs that can be used by system exclusive messages instead of the specific manufacturer IDs Real time 0x7E (126) or Non-real time 0x7F (127)
//http://www.gweep.net/~prefect/eng/reference/protocol/midispec.html#Pgm
//https://www.recordingblogs.com/wiki/midi-system-exclusive-message
//Midi Song Start 0xFA, Continue 0xFB, Stop 0xFC
oscmatch("*xF0*",$'s') ? (
		midisend_str(midi_out, oscstr);
		
);
procedure is offline   Reply With Quote