Old 03-07-2023, 02:49 AM   #1
Viktor_S
Human being with feelings
 
Join Date: Aug 2021
Posts: 12
Default Send MIDI Sysex message from script (actions)

Could you please advise what is the best way to send MIDI Sysex message from script (actions) to external MIDI device?

Sysex MIDI message is
Code:
'F0 21 25 7F 47 50 2D 64 12 11 00 00 02 07 09 00 00 F7'
.

If I send it from MIDI editor everything works fine. But following command doesn't work in a proper way.

Code:
reaper.SendMIDIMessageToHardware(8, 'F0 21 25 7F 47 50 2D 64 12 11 00 00 02 07 09 00 00 F7')
I was trying following as well
Code:
reaper.SendMIDIMessageToHardware(8, '0xF0, 0x21, 0x25, 0x7F, 0x47, 0x50, 0x2D, 0x64, 0x12, 0x11, 0x00, 0x00, 0x02, 0x07, 0x09, 0x00, 0x00, 0xF7')
8 is device number in a MIDI out list.
Viktor_S is offline   Reply With Quote
Old 03-07-2023, 04:47 AM   #2
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 4,012
Default

you have to send binary string, not regular

Last edited by mpl; 03-07-2023 at 05:07 AM.
mpl is offline   Reply With Quote
Old 03-07-2023, 06:07 AM   #3
Viktor_S
Human being with feelings
 
Join Date: Aug 2021
Posts: 12
Default

Quote:
Originally Posted by mpl View Post
you have to send binary string, not regular
Thanks for your replay. Please tell me if I understand correctly that by a binary string you mean something like

Code:
'11110000 00100001 00100101 01111111 01000111 01010000 00101101 01100100 00010010 00010001 00000000 00000000 00000010 00000111 00000110 00000000 00000000 11110111'
Viktor_S is offline   Reply With Quote
Old 03-07-2023, 06:31 AM   #4
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 4,012
Default

Code:
SysEx_msg = 'F0 21 25 7F 47 50 2D 64 12 11 00 00 02 07 09 00 00 F7'
SysEx_msg_bin = '' for hex in SysEx_msg:gmatch('[A-F,0-9]+') do SysEx_msg_bin = SysEx_msg_bin..string.char(tonumber(hex, 16)) end
reaper.SendMIDIMessageToHardware(HW_dev_outID, SysEx_msg_bin)
mpl is offline   Reply With Quote
Old 03-07-2023, 06:39 AM   #5
Viktor_S
Human being with feelings
 
Join Date: Aug 2021
Posts: 12
Default

Quote:
Originally Posted by mpl View Post
Code:
SysEx_msg = 'F0 21 25 7F 47 50 2D 64 12 11 00 00 02 07 09 00 00 F7'
SysEx_msg_bin = '' for hex in SysEx_msg:gmatch('[A-F,0-9]+') do SysEx_msg_bin = SysEx_msg_bin..string.char(tonumber(hex, 16)) end
reaper.SendMIDIMessageToHardware(HW_dev_outID, SysEx_msg_bin)
Thank you very much! You helped me a lot.
Viktor_S is offline   Reply With Quote
Old 03-07-2023, 12:02 PM   #6
JamesX
Human being with feelings
 
Join Date: Feb 2022
Posts: 90
Default

Quote:
Originally Posted by mpl View Post
you have to send binary string, not regular
mpl,

Thanks for the script. Wonderful...
JamesX is offline   Reply With Quote
Old 03-07-2023, 03:06 PM   #7
Viktor_S
Human being with feelings
 
Join Date: Aug 2021
Posts: 12
Default

I believe that this script should be somehow fixed and highlighted in the API description.
Viktor_S is offline   Reply With Quote
Old 02-11-2024, 08:59 AM   #8
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,920
Default

Another way to do it:

Code:
sysex = { 0xF0, 0x41, 0x10, 0x00, 0x00, 0x00, 0x05, 0x12, 0x20, 0x00, 0x40, 0x02, 0x18, 0x06, 0xF7 }
msg=''
for i=1, #sysex do msg = msg .. string.char(sysex[i]) end
deviceid=0
reaper.SendMIDIMessageToHardware(deviceid, msg)

Last edited by schwa; 02-11-2024 at 09:21 AM.
schwa is offline   Reply With Quote
Old 02-13-2024, 09:06 AM   #9
FeedTheCat
Human being with feelings
 
FeedTheCat's Avatar
 
Join Date: May 2019
Location: Berlin
Posts: 2,254
Default

Also useful in this context is that string.char can take multiple arguments. If one can avoid using tables, this is very fast and elegant:
Code:
msg = string.char(0xF0, 0x41, 0x10, 0x00, 0x00, 0x00, 0x05, 0x12, 0x20, 0x00, 0x40, 0x02, 0x18, 0x06, 0xF7)
deviceid = 0
reaper.SendMIDIMessageToHardware(deviceid, msg)
Alternatively it also works when a table is given:
Code:
sysex = {0xF0, 0x41, 0x10, 0x00, 0x00, 0x00, 0x05, 0x12, 0x20, 0x00, 0x40, 0x02, 0x18, 0x06, 0xF7}
deviceid = 0
reaper.SendMIDIMessageToHardware(deviceid, string.char(table.unpack(sysex)))
__________________
Featured scripts: REAPER Update UtilityLil ChordboxGridbox/Adaptive gridMX TunerRS5K LinkMIDI Editor Magic Donate💝: PayPal|ko-fi
FeedTheCat is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 11:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.