Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 04-27-2016, 03:20 PM   #1
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default TrackFX_GetInstrument(MediaTrack* track) C version working ? (solved)

edit:
Solved, see below

=== original post ===

I got this code for testing

Code:
void TestAction(COMMAND_T* ct)
{
	MediaTrack* track = GetTrack(0, 0); // get track 1 (index 0)
	int numParams = 0; int instrIdx = 0;
	if (track) {
		numParams = TrackFX_GetNumParams(track, 0); // works
		instrIdx = TrackFX_GetInstrument(track); // does nothing or throws exception
	}
}
I somehow cannot get 'TrackFX_GetInstrument(Track*)' working, it either does nothing or throws an exception.

https://i.imgur.com/gWv38ao.jpg

I know the EEL version is working, because I use it in a script.

Could someone confirm / deny if the C version is working correctly or if I'm doing something wrong ?

Last edited by nofish; 04-28-2016 at 05:00 AM.
nofish is offline   Reply With Quote
Old 04-27-2016, 03:32 PM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Have you correctly initialized the function pointer for TrackFX_GetInstrument in your C or C++ 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
Old 04-27-2016, 03:48 PM   #3
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Thanks Xen.

But sorry, uh what ?
That's a Reaper API function I'm calling, what do I have to init ?

I'm asking because for TrackFX_GetNumParams(Track*, idx), also an API function, I haven't init anything either and it works.

edit:
I think that's already handled by the SWS codebase I'm using ?

(sorry for the noob question, taking my first steps with SWS extensions)
nofish is offline   Reply With Quote
Old 04-27-2016, 03:52 PM   #4
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by nofish View Post
Thanks Xen.

But sorry, uh what ?
That's a Reaper API function I'm calling, what do I have to init ?

I'm asking because for TrackFX_GetNumParams(Track*, idx), also an API function, I haven't init anything either and it works.

(sorry for the noob question, taking my first steps with SWS extensions)
The Reaper API functions must be "loaded" from Reaper in C and C++ code before they can be correctly used. I don't know how the SWS extension does the API function initing these days, but it used to be a manual thing with the horrible IMPAPI macro. There may be the IMPAPI calls for TrackFX_GetNumParams and various other API functions, but not for the one you are now trying to use.
__________________
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-27-2016, 04:01 PM   #5
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Aha, now that makes more sense to me.

I think I now remember you mentioning IMPAPI macro when I had a look at your extension plugin example.
I can investigate further now, thanks.
nofish is offline   Reply With Quote
Old 04-27-2016, 04:12 PM   #6
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Just checked the source code. It's still using the manual import of the API functions and TrackFX_GetInstrument is missing in sws_extension.cpp. So you should add IMPAPI(TrackFX_GetInstrument); among the other IMPAPI invokations.

There's a way to remove the use of IMPAPI and load all the declared functions in one go, but that might need some changes in the source code I can't myself test right now.
__________________
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-28-2016, 04:11 AM   #7
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

That helped a lot, I was totally unaware of that 'API functions loading' requirement.
Coming from ReaScript I thought I can instantly use them also in C / SWS extensions and scratched my head why it didn't work.

Will try the IMPAPI thing and report back how it went.

Thanks again.
nofish is offline   Reply With Quote
Old 04-28-2016, 04:58 AM   #8
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

It works !

I found it was only a one-liner to add (as you said) as SWS did already the had work.
So, easy once you know what to do.
nofish is offline   Reply With Quote
Old 04-28-2016, 05:11 AM   #9
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by nofish View Post
It works !

I found it was only a one-liner to add (as you said) as SWS did already the had work.
So, easy once you know what to do.
The missing IMPAPI calls are a classic mine to step into. The code should really be changed to use the newer API loading mechanism instead.
__________________
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-28-2016, 06:56 AM   #10
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Quote:
Originally Posted by Xenakios View Post
The missing IMPAPI calls are a classic mine to step into. The code should really be changed to use the newer API loading mechanism instead.
Agreed. Though changing the base code is nothing I could / wanted to do at this point.
But I'll ping Jeffos to at least update the SWS Wiki about it for now, because yeah, it's a stepping stone for beginners, as I've found the hard way.
nofish 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 12:01 PM.


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