|
|
|
04-06-2020, 10:53 AM
|
#1
|
Human being with feelings
Join Date: Apr 2020
Posts: 17
|
Insert SYSEX message
Hi I am trying to write a script that will insert a sysex message where the play head is. All of my code works to get the user message and parse it to what the system uses, but I can't get it to insert.
I am using MIDI_InsertTextSysexEvt in Lua
Lua: boolean reaper.MIDI_InsertTextSysexEvt(MediaItem_Take take, boolean selected, boolean muted, number ppqpos, integer type, string bytestr)
My code for this part is
take = reaper.MIDIEditor_GetTake(reaper.MIDIEditor_GetAct ive())
time = reaper.time_precise()
ppqpos = reaper.MIDI_GetPPQPosFromProjTime(take,time)
reaper.MIDI_InsertTextSysexEvt(take,true,false,ppq pos,1,sysexMessage)
It doesn't throw any errors. But nothing is inserted (the sysexMessage is higher up in the code and works fine, the variable contains the message correctly)
Any ideas?
I'm not a great coder, but I'm not completely without understanding.
Thanks in advance
|
|
|
04-06-2020, 01:34 PM
|
#2
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,749
|
time_precise() gives you the time of day. You want the project timeline time, as given by GetCursorPosition() or similar.
|
|
|
04-06-2020, 01:36 PM
|
#3
|
Human being with feelings
Join Date: Apr 2020
Posts: 17
|
well, now I feel dumb. Thank you.
|
|
|
04-06-2020, 01:40 PM
|
#4
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,749
|
As my grandpa used to say, the only dumb question is... that one you just asked.
(it wasn't a dumb question)
|
|
|
04-06-2020, 01:52 PM
|
#5
|
Human being with feelings
Join Date: Apr 2020
Posts: 17
|
Ha ha ha. I like that. Thanks for your help
|
|
|
04-06-2020, 01:57 PM
|
#6
|
Human being with feelings
Join Date: Apr 2020
Posts: 17
|
All of that works now, but nothing is placed in my midi track. Am I using the correct function to write a sysex message and put it in the take?
|
|
|
04-06-2020, 01:59 PM
|
#7
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,749
|
Yes, that should work. How are you constructing the message?
|
|
|
04-06-2020, 02:15 PM
|
#8
|
Human being with feelings
Join Date: Apr 2020
Posts: 17
|
I take user input for what cue number they want which processes it into a string that reads
7F 01 02 01 01 31 35 2E 35 00 31
the 31, 35, 2E, 35 are the ones that change based on user input
This is the whole message without the F0 and F7 bounding boxes
|
|
|
04-06-2020, 02:30 PM
|
#9
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,749
|
I think you want bytestr to be "\x7F\x01\x02..."
|
|
|
04-06-2020, 02:31 PM
|
#10
|
Human being with feelings
Join Date: Apr 2020
Posts: 17
|
That worked perfect.
Thank you so much. I really appreciate it.
|
|
|
04-06-2020, 02:36 PM
|
#11
|
Human being with feelings
Join Date: Apr 2020
Posts: 17
|
Quote:
Originally Posted by schwa
I think you want bytestr to be "\x7F\x01\x02..."
|
Exactly? with the slash and x?
what about spaces?
|
|
|
04-06-2020, 02:41 PM
|
#12
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,749
|
It's a byte string, not a string of printable characters. "\x7F\x01\x02" is a string of 3 bytes, starting with 7F. "7F 01 02" is a string of 8 bytes, starting with 0x37 which is the ascii code for the character '7'.
|
|
|
04-06-2020, 02:44 PM
|
#13
|
Human being with feelings
Join Date: Apr 2020
Posts: 17
|
Ok, I think I understand.
I'll get on it
|
|
|
04-06-2020, 05:23 PM
|
#14
|
Human being with feelings
Join Date: Apr 2020
Posts: 17
|
Ok, I suck. Do you have time to tell new how to concatenate a byte string.
There first part of my message is correct,
There user input part gets converted to the correct hex, but when i try to put then all together I get the correct information followed by random numbers.
Sorry. Thanks for your time
|
|
|
04-06-2020, 05:32 PM
|
#15
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,749
|
|
|
|
04-06-2020, 05:40 PM
|
#16
|
Human being with feelings
Join Date: Apr 2020
Posts: 17
|
The problem I'm getting is I have a static message of "\x7F\x01\x02..." and then the formatted message which is 31352E35 (15.5) and I can't get it into a "\x31\x35\x2E..." any idea?
|
|
|
04-06-2020, 06:10 PM
|
#17
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,749
|
That's kind of advanced. You'll need to do something like a str:match to get the values out of the text string, then push them onto the bytestring.
|
|
|
04-06-2020, 08:39 PM
|
#18
|
Human being with feelings
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
|
Code:
s_in = '31352E35'
s_out = ''
for char_pair in s_in:gmatch('..') do s_out = s_out..'\\x'..char_pair end
|
|
|
04-07-2020, 06:09 AM
|
#19
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,749
|
Almost, but you can't construct a byte string by piecing together '\x' and values. You need to explicitly push the value on the the bytestring.
Code:
s_out = s_out..string.char(tonumber(char_pair,16))
char_pair is something like "33" or "1F"
tonumber(char_pair,16) interprets the two text characters as a hex value
string.char converts the number to a byte character
Last edited by schwa; 04-07-2020 at 10:31 AM.
|
|
|
04-07-2020, 09:49 AM
|
#20
|
Human being with feelings
Join Date: Apr 2020
Posts: 17
|
Thank you so much for all your help. That worked and will make my programming of messages so much easier.
It comes out in the perfect format.
I still do not completely understand it, but I don't need to.
You guys are great!
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 11:38 AM.
|