C++ newb Q

Miscellaneous Forums/General Discussion/C++ newb Q

#define REVERB_PRESET_SEWERPIPE {21, 1.7f, 0.800f, -1000, -1000}; // truncated example

This works at declaration time:
EAXREVERBPROPERTIES preset = REVERB_PRESET_SEWERPIPE;

But how can I update it with another definition later on?
e.g, preset = REVERB_PRESET_STONEROOM; //not gonna work

#define REVERB_PRESET_SEWERPIPE {21, 1.7f, 0.800f, -1000, -1000}; // truncated example

This works at declaration time:
EAXREVERBPROPERTIES preset = REVERB_PRESET_SEWERPIPE;

First, you should remove the ending semicolon from the #define line, since that's going to be inserted into the line below, causing two semicolons in a row. It shouldn't be a problem here, but it's best to be safe.

But how can I update it with another definition later on?
e.g, preset = REVERB_PRESET_STONEROOM; //not gonna work

It's hard to tell, since your "preset" variable is declared as "EAXREVERBPROPERTIES", which is apparently a preprocessor #define, so I have no idea what it truely is (I hate C code like this - no wonder C has such a bad readability reputation).

It might help if you can find what EAXREVERBPROPERTIES really is defined as. It would seem that it's a float array, but in that case "preset = REVERB_PRESET_STONEROOM;" should work.

Edit: doh! :)

EAXREVERBPROPERTIES preset = REVERB_PRESET_BATHROOM;

Edit: doh! :)

EAXREVERBPROPERTIES preset = REVERB_PRESET_BATHROOM;

?

// Declaration
EAXREVERBPROPERTIES preset;

if(blah)
{
// This works now, it copies all the values from ..GENERIC
// to 'preset'
EAXREVERBPROPERTIES preset = REVERB_PRESET_GENERIC;
}

You are creating a second ( local ) variable named preset. It is valid only within the if block.

After you leave this block the previously defined preset is in effect.

You're right. Any idea how I can copy the values over to the original?

Any idea how I can copy the values over to the original?

"preset = REVERB_PRESET_GENERIC;" should work, but apparently that's not the case. Like I said, it's hard to tell without knowing what EAXREVERBPROPERTIES really is #define'd as. Maybe try searching the library headers for "#define EAXREVERBPROPERTIES" or just "EAXREVERBPROPERTIES".

Ok, this does work fine, there must be a cleaner way but it'll do for now :)

	EAXREVERBPROPERTIES preset;
	EFXEAXREVERBPROPERTIES reverb;

	bool ok = false;

	if(!strcmp(presetName,"REVERB_PRESET_GENERIC") && !ok){
		EAXREVERBPROPERTIES p = REVERB_PRESET_GENERIC;
		preset = p;
		ok = true;}


EAXREVERBPROPERTIES p = EVERB_PRESET_GENERIC;
preset = p;

Ok, now I think I understand. Try this:
namespace ReverbPreset {
    const EAXREVERBPROPERTIES Sewerpipe = {21, 1.7f, 0.800f, -1000, -1000};
    const EAXREVERBPROPERTIES StoneRoom = {...};
}

...

EAXREVERBPROPERTIES preset;
preset = ReverbPreset::Sewerpipe;
preset = ReverbPreset::StoneRoom;


By using const definitions instead of copy-n-paste #define's, you're assigning a EAXREVERBPROPERTIES to an EAXREVERBPROPERTIES variable - a perfectly legal operation. Your original method was trying to assign an array constant to a EAXREVERBPROPERTIES, and it seems that's not legal (though I don't know why).

Always use const or some other proper C++ feature instead of a #define if you can. #define's make it hard for the compiler to understand the context of what you're doing, and they make it harder to debug when something goes wrong.

I'll give that a try, thanks John.