Old 11-27-2019, 02:49 PM   #1
LuCsa
Human being with feelings
 
Join Date: Aug 2016
Posts: 51
Default Basic Questions about JSFX MIDI functions

Hello!

Working on my first JSFX MIDI "effect" (which was covered in another thread), some questions concerning the MIDI functions of JSFX arose.

I'm refering to the documentation on this link: https://www.reaper.fm/sdk/js/midi.php#js_midi

Code:
midisend(offset,msg1,msg2,msg3)
1) What is offset? What unit with respect to what? The last incoming event? If so, how can I simply filter out certain events from a MIDI receive and not send them without destroying the order of events?

2) According to the code examples and what I tried, msg2 is the note/CC number (which is a 7bit number), the MSB always being 0, since it's a data byte. Same is true for msg3, encoding velocity/value of CC. Correct?

Code:
midisend(0, $x90, 69+(127*256))
3) In this old syntax, the "second lowest byte of the third parameter will be used as third byte in the MIDI message". --> So, I guess that the lowest byte will be interpreted as msg2? Higher bytes will be ignored? Why is the order reversed?

Code:
midisend_buf(offset,buf, len) -- REAPER 4.60+    

buf = 100000;
buf[0] = 0x90;
buf[1] = 69;
buf[2] = 127;
midisend_buf(10,buf,3); // send (at sample offset 10) note-on channel 0, note 69, velocity 127
4) Why is buf initialized the way it is? What type is it?

5) Does buf[i] access the bytes of the variable buf?

6) What is the len parameter and in what units? Message length in bytes?

7) Apart from SysEx: When would I use midisend_str or midisend_buf instead of midisend?


Thanks a lot!
Lukas
LuCsa is offline   Reply With Quote
Old 11-27-2019, 08:00 PM   #2
ashcat_lt
Human being with feelings
 
Join Date: Dec 2012
Posts: 4,363
Default

Can't answer all of these, but I'll try to cover what I can. Mostly just to subscribe to the thread and see answers from people who understand it better.


Quote:
Originally Posted by LuCsa View Post
1) What is offset? What unit with respect to what?
Pretty sure it's a number of samples into the current block. The midi send/receives happen on every block (interface sample buffer period), which can be a pretty coarse measurement, and this parameter tells it when exactly in that block the event should happen.

Quote:
4) Why is buf initialized the way it is? What type is it?
Looks like buf is an index into the one unique variable array available to the effect. The value set there is actually the first slot in the array to which this variable will refer. Basically, it's the position of buf[0] in the greater array. If you set foo = x, and bar = x, then foo[y] will reference exactly the same slot as bar[y]. IDK why you'd want to start this buffer 100,000 slots into the array in this particular case. Maybe just to keep it out of the way in case you want to do other things?

Quote:
5) Does buf[i] access the bytes of the variable buf?
I think I just answered that, but it's confusing, so I'll put it another way. buf[i] references the (buf+i)th slot in the array.

Hope some of this helps, and looking forward to answers to some of the others.
ashcat_lt is online now   Reply With Quote
Old 11-28-2019, 12:56 AM   #3
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,007
Default

Quote:
Originally Posted by LuCsa View Post
2) According to the code examples and what I tried, msg2 is the note/CC number (which is a 7bit number), the MSB always being 0, since it's a data byte. Same is true for msg3, encoding velocity/value of CC. Correct?
Correct (although I believe a faulty plug-in could send you a data byte with bit 7 on).

Quote:
Originally Posted by LuCsa View Post
Code:
midisend(0, $x90, 69+(127*256))
3) In this old syntax, the "second lowest byte of the third parameter will be used as third byte in the MIDI message". --> So, I guess that the lowest byte will be interpreted as msg2? Higher bytes will be ignored? Why is the order reversed?
Because some MIDI message types (Program Change, Channel Aftertouch) have only 2 bytes (i.e. msg1 and msg2).
Tale is offline   Reply With Quote
Old 11-29-2019, 07:55 AM   #4
Time Waster
Human being with feelings
 
Time Waster's Avatar
 
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 869
Default

1) Assuming you are receiving a MIDI message and then processing it in some way, you will generally want to send out a MIDI message at the same offset it was received on, unless you have a good reason not to.

5) In JSFX you can have up to 32,000,000 indexed memory slots (default is about 8,000,000). Each slot can store a numerical value or a text string. The syntax used to access a memory slot is number1[number2] and the index number for the slot is the sum of those two numbers. In your example the variable 'buf' has been set to 100000, so slot 100000 has been set to 0x90, slot 100001 has been set to 69 and 100002 has been set to 127.

6) 'len' is the length of the buffer, in this case three slots. In this example, the argument 'len' is telling midisend_buf() to read the values from three consecutive slots, starting from slot buf[0], and send those out as a three byte MIDI message.

7) midisend_buf() might save a bit of code if you already have the data you want to send stored in a buffer. I can't say I've ever used it, although maybe I should
__________________
ReaRack JSFX Modular Synth - Mostly harmless: https://stash.reaper.fm/v/28403/ReaR...dularSynth.zip
The Wasters of Time: https://soundcloud.com/thewastersoftime
Time Waster is offline   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 02:59 PM.


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