My classes are talking to each other correctly

I have a class (WavPlayer) with a member function fillBuffer().

1
2
3
4
5
BUFFER WavPlayer::fillBuffer(){
	returnedData = wavReader.CreateBuffer();
	
return returnedData;
}

You can see here that fillBuffer() calls CreateBuffer() from an instance of my WavReader class. When CreateBuffer() is called a chain of other functions are called, basically it calls GetOpenFileName() and passes the file name and path to mmioOpen(). Then using the other mmio functions I fill the struct returnedData.

I would like to call this function from another class (WavPlayerEditor), my GUI class. I call it here:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void WavPlayerEditor::valueChanged(CControl* pControl)
{
	float value = pControl->getValue ();		
	switch (pControl->getTag ())
	{
		case kOpen:
			{
				openButton->setValue (value);	
				((WavPlayer*)effect)->fillBuffer();
				break;	
			}	
	}	
	
	effect->setParameterAutomated (pControl->getTag (), pControl->getValue ());
	
}

All this does is check if the "Open" button's value has changed. If so, do something. In this case I want to call the fillBuffer() function from the prior class (WavPlayer).

The problem is CreateBuffer() appears to be getting called twice. Once from the WavPlayerEditor class and then again in the WavPlayer class.

Is there a way around this. I was thinking of creating another function in my WavPlayer class that would simply set the value of a bool variable. Then check if set to true, call fillBuffer().

Hmmmm.... I think I'll try that, but I doubt it will work.

Chris
Nope, same result.

hmmm.... guess I'll keep trying different things til I get it.
You don't need a topic for taliking to yourself!
Is there a way around this.

Not calling it twice sounds like a great idea. If you're not sure where and why it is called twice, set a breakpoint.
If it's valid to call it several times, you can use a flag.
Also, why does a function called "fillBuffer" create a buffer? Shouldn't it be called "createBuffer"?
If you're not sure where and why it is called twice, set a breakpoint.


This.
Topic archived. No new replies allowed.