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

Reply
 
Thread Tools Display Modes
Old 06-22-2017, 02:09 AM   #1
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default Someone who knows C++ could have a look at this very simple code? Newbie here!

Hello!

I get the messages that "identifier (...) is undefined)
Code:
{	
Main_OnCommand(NamedCommandLookup("_S&M_HIDEFXCHAIN"), 0); // Hide FX chain
Main_OnCommand(NamedCommandLookup("_S&M_WNONLY2"), 0); // Float next FX
GetFocusedFX(trackNr, itemNr, fxNr);
int index = *fxNr;
HWND fxwindow = TrackFX_GetFloatingWindow(track, index);
RECT rc;
GetWindowRect(fxwindow, &rc);
int xPos = (GetSystemMetrics(SM_CXSCREEN) - rc.right) / 2;
int yPos = (GetSystemMetrics(SM_CYSCREEN) - rc.bottom) / 2;
SetWindowPos(fxwindow, 0, xPos, yPos, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
I have no idea about C++. What does this mean and how to define them?
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 06-22-2017, 02:20 AM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

What is the full error message? On which line is it?

I see no declarations for track, trackNr, itemNr or fxNr in the short snippet you posted. If the error is related to one of those variables, you need to create them before using them (unlike Lua which just assumes nil whenever it encounters an unknown variable).

Code:
int trackNumber, itemNumber, fxNumber;
switch(GetFocusedFX(&trackNumber, &itemNumber, &fxNumber)) {
case 1:
  printf("fx %d on track %d\n", fxNumber, trackNumber);
  break;
case 2:
  printf("fx %d on item %d of track %d\n", fxNumber, itemNumber, trackNumber);
  break;
default:
  // no fx has focus. abort mission!
  return;
}

Last edited by cfillion; 06-22-2017 at 03:34 AM.
cfillion is offline   Reply With Quote
Old 06-22-2017, 03:31 AM   #3
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

The error relates to the identifiers I have underlined. (trackNr, etc) Track is already defined...

The Reascript API says: int GetFocusedFX(int* tracknumberOut, int* itemnumberOut, int* fxnumberOut )

I'll try it the way you posted and report back. Thanks!
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 06-22-2017, 03:38 AM   #4
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

I changed the code to this:
Code:
{	
	Main_OnCommand(NamedCommandLookup("_S&M_HIDEFXCHAIN"), 0); // Hide FX chain
	Main_OnCommand(NamedCommandLookup("_S&M_WNONLY2"), 0); // Float next FX
	int trackNumber, itemNumber, fxNumber;
	GetFocusedFX(&trackNumber, &itemNumber, &fxNumber);
	HWND fxwindow = TrackFX_GetFloatingWindow(track, fxNumber);
	RECT rc;
	GetWindowRect(fxwindow, &rc);
	int xPos = (GetSystemMetrics(SM_CXSCREEN) - rc.right) / 2;
	int yPos = (GetSystemMetrics(SM_CYSCREEN) - rc.bottom) / 2;
	SetWindowPos(fxwindow, 0, xPos, yPos, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
But it doesn't center the window. Any ideas why?
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 06-22-2017 at 03:51 AM.
amagalma is offline   Reply With Quote
Old 06-22-2017, 04:00 AM   #5
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

I tried
Code:
MoveWindow(fxwindow, xPos, yPos, rc.right - rc.left, rc.bottom - rc.top, true);
But same result.. Window does not move..
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 06-22-2017, 05:03 AM   #6
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

I managed to move it, but it does not go to where it is supposed to go.. Wonder why...

Code:
{
Main_OnCommand(NamedCommandLookup("_S&M_HIDEFXCHAIN"), 0); // Hide FX chain
Main_OnCommand(NamedCommandLookup("_S&M_WNONLY1"), 0); // Float next FX
int trackNumber, itemNumber, fxNumber;
GetFocusedFX(&trackNumber, &itemNumber, &fxNumber);
HWND mainwindow = GetMainHwnd();
HWND fxwindow = GetLastActivePopup(mainwindow);
RECT rc;
GetWindowRect(fxwindow, &rc);
int xPos = (GetSystemMetrics(SM_CXSCREEN) - rc.right) / 2;
int yPos = (GetSystemMetrics(SM_CYSCREEN) - rc.bottom) / 2;
SetWindowPos(fxwindow, 0, xPos, yPos, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 06-22-2017 at 05:10 AM.
amagalma is offline   Reply With Quote
Old 06-22-2017, 07:43 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 amagalma View Post
I managed to move it, but it does not go to where it is supposed to go.. Wonder why...
Error in your calculations for the new position?
__________________
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 06-22-2017, 08:11 AM   #8
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

The way I calculate is correct.. I think it may be due to wrong data for the calculations.. Maybe GetLastActivePopup is not the best way to do it.. But in the previous way, when using GetFocusedFX it didn't work at all...
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 06-22-2017, 09:04 AM   #9
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Another C++ question...

Why this does not work? (makes Reaper crash)
Code:
MediaTrack* track = GetSelectedTrack(0, 0);
int fxcount = TrackFX_GetCount(track);
int nextfx = 0;
for (int i = 0; i = (fxcount - 1); i = i + 1)
{
	bool open = TrackFX_GetOpen(track, i);
	if (open == true)
	{
		nextfx = i + 1;
	}
}
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 06-22-2017, 09:28 AM   #10
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

I would write it like something like this :
Code:
MediaTrack* track = GetSelectedTrack(0, 0);
if (track!=nullptr)
{
  int fxcount = TrackFX_GetCount(track);
  int nextfx = 0;
  for (int i = 0; i < fxcount; ++i)
  {
	bool open = TrackFX_GetOpen(track, i);
	if (open == true)
	{
		nextfx = i + 1;
	}
  }
}
__________________
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 06-22-2017, 10:14 AM   #11
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Thank you very much Xenakios! It works!
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 06-22-2017, 11:26 AM   #12
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

More questions!

Code:
MediaTrack* track = GetSelectedTrack(0, 0);
int tracknumber = GetMediaTrackInfo_Value(track, "IP_TRACKNUMBER");
int fxcount = TrackFX_GetCount(track);
for (int i = 0; i < fxcount; ++i)
{
char trackFXName[128];
TrackFX_GetFXName(track, i, trackFXName, sizeof(trackFXName));

-- I want to make now a string that would be:
char windowName = trackFXName + " - Track " + tracknumber + " [" + i + "/" + fxcount + "]"

HWND killwindow = FindWindowEx(mainwindow, NULL, NULL, windowName);
DestroyWindow(killwindow);
}
The idea is to destroy (close) all fx windows one by one.

Any help please? Thanks!
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 06-22-2017 at 11:36 AM.
amagalma is offline   Reply With Quote
Old 06-22-2017, 12:34 PM   #13
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

How can I concatenate "FX: Track " and an integer and form a LPCTSTR in order to use it with the FindWindow?
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 06-22-2017, 01:22 PM   #14
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by amagalma View Post
How can I concatenate "FX: Track " and an integer and form a LPCTSTR in order to use it with the FindWindow?
I would use the sprintf function to deal with that in this case.
__________________
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 06-22-2017, 02:01 PM   #15
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Or snprintf to prevent buffer overflows (VS2015+ if using Microsoft's tools).
http://en.cppreference.com/w/c/io/snprintf

Last edited by cfillion; 06-22-2017 at 02:59 PM.
cfillion is offline   Reply With Quote
Old 06-22-2017, 03:42 PM   #16
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Thank you guys! A small example, if it is possible?

Let's say I have
"Track number is " and
int tracknumber = 2

What do I write to produce "Track number is 2" and be in LPCTSTR format?
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 06-22-2017 at 04:01 PM.
amagalma is offline   Reply With Quote
Old 06-22-2017, 03:58 PM   #17
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Code:
const int tracknumber = 2;

char output[24];
snprintf(output, sizeof(output), "Track number is %d", tracknumber);
It's similar to Lua's string.format function. LPCTSTR is just const char * (when UNICODE is not defined).
cfillion is offline   Reply With Quote
Old 06-22-2017, 03:59 PM   #18
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Code:
std::string startchain = "FX: Track ";
std::string result;
char numstr[21];
sprintf(numstr, "%d", tracknumber);
result = startchain + numstr;
wstring path_wstr(result.begin(), result.end());
HWND windowName = FindWindow("#32770", result.c_str());
This seems to work.. Do you think it is ok?
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 06-22-2017, 04:10 PM   #19
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Thank you cfillion! This worked!

Regarding my question in post #12

What should I change to make this correct?:

snprintf(output, sizeof(output), trackFXName + " - Track %d [%d/%d]", tracknumber, i, fxcount);

trackFXName is char
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 06-22-2017 at 04:23 PM.
amagalma is offline   Reply With Quote
Old 06-22-2017, 04:24 PM   #20
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Quote:
Originally Posted by amagalma View Post
This seems to work.. Do you think it is ok?
It's not very efficient: there's a lot of copying going on. It can be simplified to this: http://sprunge.us/cCXI?cpp (and then to just a C string and s(n)printf for even less copying/resize).

Quote:
Originally Posted by amagalma View Post
What should I change to make this correct?:
The format specifier for strings is %s (like %d is for ints). See the documentation I've linked above in #15 for the full list: (s)(n)printf is very powerful!

Code:
snprintf(output, sizeof(output), "%s - Track %d [%d/%d]",
  trackFXName, tracknumber, i, fxcount);

Last edited by cfillion; 06-22-2017 at 05:33 PM. Reason: fixed typo
cfillion is offline   Reply With Quote
Old 06-22-2017, 05:03 PM   #21
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Thank you very much cfillion!

My whole working code now is:
Code:
if(m_pan_dir == PD_RIGHT)
{
	MediaTrack* track = CSurf_TrackFromID(m_bank_offset, g_csurf_mcpmode);
	if (track != nullptr)
	{	
		int tracknumber = GetMediaTrackInfo_Value(track, "IP_TRACKNUMBER");
		int fxcount = TrackFX_GetCount(track);
		int nextfx = 0;
		if (fxcount == 0) // No FX in track
		{
			Main_OnCommand(40291, 0); //add FX
		}
		else // FX in track
		{
			for (int i = 0; i < fxcount; ++i)
			{	//find last open
				bool open = TrackFX_GetOpen(track, i);
				if (open == true)
				{
					nextfx = i + 1;
				}
			}
			if (nextfx == fxcount) nextfx = 0; // cycle
			TrackFX_Show(track, nextfx, 3);
			// Close FX Chain window
			char output[14];
			snprintf(output, sizeof(output), "FX: Track %d", tracknumber);
			HWND windowName = FindWindow("#32770", output);
			DestroyWindow(windowName);
			// Close all other floating windows and center the open one
			char trackFXName[128];
			char output2[150];
			for (int i = 0; i < fxcount; ++i)
			{
				TrackFX_GetFXName(track, i, trackFXName, sizeof(trackFXName));
				snprintf(output2, sizeof(output2), "%s - Track %d [%d/%d]", trackFXName, tracknumber, i+1, fxcount);
				HWND windowName = FindWindow("#32770", output2);
				if (i != nextfx) DestroyWindow(windowName); 
				else
				{
					RECT rc;
					GetWindowRect(windowName, &rc);
					int xPos = (GetSystemMetrics(SM_CXSCREEN) - rc.right) / 2;
					int yPos = (GetSystemMetrics(SM_CYSCREEN) - rc.bottom) / 2;
					SetWindowPos(windowName, 0, xPos, yPos, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
				}
			}
		}
	}
}
It's something I am adding to the Faderport XT driver...

But as Xenakios noted, there seems to be something wrong with the way I am calculating how to place the floating FX in the middle of screen...
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 06-22-2017 at 05:11 PM.
amagalma is offline   Reply With Quote
Old 06-22-2017, 05:43 PM   #22
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

This is the correct:
Code:
int xPos = GetSystemMetrics(SM_CXSCREEN)/2 - (rc.right - rc.left)/2;
int yPos = GetSystemMetrics(SM_CYSCREEN)/2 - (rc.bottom - rc.top)/2;
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 06-22-2017, 06:16 PM   #23
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

And here is the final result! Thanks to both of you!
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma 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:21 AM.


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