Old 12-30-2021, 01:26 PM   #1
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 7,431
Default gmem cannot be used for midisend_buf...?

Playing around with MIDI stuff, it seems that gmem does not behave as an ordinary buffer when it comes to midisend_buf.

I can do this just fine:
Code:
@init
searchDeviceRequest = "\xF0\x42\x50\x00\x44\xF7"; // Minilogue stuff
buf = 1000;
offset = 0;
loop(strlen(searchDeviceRequest),
	buf[offset+4] = str_getchar(searchDeviceRequest, offset);
	offset += 1;
);

@block
midisend_buf(0, buf+4, strlen(searchDeviceRequest));
And I do get the expected result; the correct sysex is sent out and the Minilogue replies with the expected message.

However, if I use gmem as buffer instead:
Code:
options:gmem=MF_TestSysExMsg

@init
searchDeviceRequest = "\xF0\x42\x50\x00\x44\xF7"; // Minilogue stuff
offset = 0;
loop(strlen(searchDeviceRequest),
	gmem[offset+4] = str_getchar(searchDeviceRequest, offset);
	offset += 1;
);

@block
midisend_buf(0, gmem+4, strlen(searchDeviceRequest));
this sends the string F0 00 00 00 00 00 00 F7, which (not unexpectedly) the Minilogue does not reply to at all.

Does anyone know what's up with this?
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   Reply With Quote
Old 12-31-2021, 01:54 AM   #2
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,652
Default

It would seem that you can use gmem[] only with square brackets, but not as a "pointer", i.e. gmem[i] = x is OK, but (gmem+i)[0] = x doesn't work as expected. That is, the latter uses a variable that happens to be named gmem, so it accesses local memory at addres gmem+i, but it doesn't access global memory. And I guess the same goes for midisend_buf(), and basically anywhere where you use a pointer.
Tale is offline   Reply With Quote
Old 12-31-2021, 07:55 AM   #3
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 7,431
Default

Quote:
Originally Posted by Tale View Post
It would seem that you can use gmem[] only with square brackets, but not as a "pointer", i.e. gmem[i] = x is OK, but (gmem+i)[0] = x doesn't work as expected. That is, the latter uses a variable that happens to be named gmem, so it accesses local memory at addres gmem+i, but it doesn't access global memory. And I guess the same goes for midisend_buf(), and basically anywhere where you use a pointer.
Aha. Yeah I guess that would explain the behavior I see.

So I would have to copy the elements from gmem into a local buffer to use for midisend_buf. It is a pity, but would work.

Thanks
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian 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 08:44 AM.


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