Old 04-05-2017, 03:51 AM   #1
ceanganb
Human being with feelings
 
Join Date: May 2009
Location: Brazil
Posts: 323
Default Can't get MIDI metadata C++

Hi. I'm using the following code in C++ to get the sysex messages:

Code:
	auto mehwnd = MIDIEditor_GetActive();
	auto mit = MIDIEditor_GetTake(mehwnd);
	int numOfNotes;
	int numOfCCs;
	int numOfSysex;

	MIDI_CountEvts(mit, &numOfNotes, &numOfCCs, &numOfSysex);
	for (int i = 0; i < numOfSysex; ++i)
	{
		bool selectedOutOptional;
		bool mutedOutOptional;
		double ppqposOutOptional;
		int typeOutOptional;
		char msgOptional[1024];
		int msgOptional_sz;

		int retval = MIDI_GetTextSysexEvt(mit, i,
			&selectedOutOptional, &mutedOutOptional, &ppqposOutOptional,
			&typeOutOptional, msgOptional, &msgOptional_sz);
		ShowConsoleMsg(msgOptional);
I tried char* msgOptional, many different array values, nothing works. All the other data are retrived fine. What am I doing wrong, guys?

Thanks.
__________________
Ceanganb

Last edited by ceanganb; 04-05-2017 at 03:52 AM. Reason: improve title
ceanganb is offline   Reply With Quote
Old 04-06-2017, 03:34 AM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Maybe msgOptional_sz needs to initially have the size of your char buffer.
Code:
char msgOptional[1024];
int msgOptional_sz=sizeof(msgOptional);
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 04-06-2017, 08:01 AM   #3
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

I've been stumbling over this _sz also:

http://forum.cockos.com/showthread.php?t=190148
nofish is offline   Reply With Quote
Old 04-06-2017, 09:16 AM   #4
ceanganb
Human being with feelings
 
Join Date: May 2009
Location: Brazil
Posts: 323
Default

@Xenakios: That was it, the * in the msgOptional_sz field led me to thinking I was getting a value instead of setting, like the rest of them. Thanks again for saving me.

@nofish: Yes, I'm also struggling with the older standard C-style idioms, I'm new to C++ and virtually bypassed the char* stuff, back to school again.
__________________
Ceanganb
ceanganb is offline   Reply With Quote
Old 04-06-2017, 09:39 AM   #5
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by ceanganb View Post
@Xenakios: That was it, the * in the msgOptional_sz field led me to thinking I was getting a value instead of setting
In C there isn't really much else to do for "optional" variables than to use a pointer. So you might be able to use a null pointer in this case too...But the pointer to the size variable may also be used to return how much of the buffer Reaper ended up using, so it's probably safer/more useful to give it the address of the integer size variable.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 04-06-2017, 09:58 AM   #6
ceanganb
Human being with feelings
 
Join Date: May 2009
Location: Brazil
Posts: 323
Default

Quote:
Originally Posted by Xenakios View Post
But the pointer to the size variable may also be used to return how much of the buffer Reaper ended up using, so it's probably safer/more useful to give it the address of the integer size variable.
That's what I though, the pointer made me think that it was a value returned from the function, based on other functions' signature, like GetTrackName(MediaTrack* track, char* buf, int buf_sz), where it's clear that the size must be provided. And why "optional", my poor mind can't see what is optional in a sysex message. If it was the case of an empty sysex, but then sizeof would reveal that.

P.S.: In Reaper, an empty sysex can't even exist.
__________________
Ceanganb
ceanganb is offline   Reply With Quote
Old 04-07-2017, 06:09 AM   #7
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by ceanganb View Post
And why "optional", my poor mind can't see what is optional in a sysex message
It's probably optional for the purposes of ReaScript, the C API is just using a similar function signature although the stuff isn't really optional when used from C. (In ReaScript the function can do the needed buffer allocation itself but in C it's typical the allocation and passing in the available size is the responsibility of the calling code.)
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios 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 01:03 PM.


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