Class within Class problem | General C++ Topics | Forum


Please consider registering

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —

— Match —

— Forum Options —

Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Class within Class problem
September 20, 2013 - 3:38 pm
Member Since: September 12, 2013
Forum Posts: 43
sp_UserOfflineSmall Offline

Hi Will

I constructed a simple class SinOscillator to calculate one sinewave. After that I constructed a class MultiSin containing 4 x SinOscillator with f, f*2, f*3, f*4 (a kind of simple Hammond). This works fine.

After that I constructed within the main plugin 2 x MultiSin to have more than one note, lets say you play a C and an G. But now it seems that the 2 MultiSin use the same SinOscillator set. (The played notes are not C and G but one single note 2.5 times higher than C ).

What is necessary to have a correct MultiSin[index1]SinOscillator[index2] adressing ?? And by the way, is it possible to have indexed user control variables for the faders (e.g. m_fMyVariable[index] ) ??

Many thanks for your help.


September 21, 2013 - 9:23 pm
Member Since: January 29, 2017
Forum Posts: 689
sp_UserOfflineSmall Offline

I have created a simple plug-in that replicates what you are trying to do (link is at the end of this reply). I use forwarding functions to set the parameters but it looks like you want to access each sine component individually. I put both ways of doing this so check the code carefully.

// in MultiSine.h
// array of four
CSine sineArray[4];

// in the plug_in.h
CMultiSine multiSineArray[2];

// in userInterfaceChange() as an example:

As for your question on indexing variables; you can do this indirectly by using the RackAFX linked list of GUI control objects. Each GUI control (slider, button) on the UI is indexed from 0->39 for the sliders and 41-44 for the button banks). This ID value is also shown at the top of the table when you setup a slider.

Each control is encapsulated in a CUICtrl object. These are then stored in a linked list in the plugin object. The CUICtrl object has a pointer to your member variable and uses this to change the value as the user moves the slider. You can access this pointer and de-reference it to use it. For example in userInterfaceChange again, and using my method of calling one function that internally sets the 4 frequencies:

// accessing the m_fOsc2Fo with an index from the UIControl array
// get the pointer; I know it is slider #1
CUICtrl* pUICtrl = getUICtrlByControlID(1);

// check to make sure its valid before using, just to make sure...
// use it by de-referencing the Cooked data

You can get the whole plug-in project here:


September 21, 2013 - 9:33 pm
Member Since: January 29, 2017
Forum Posts: 689
sp_UserOfflineSmall Offline

BTW: the UI Control object and list are explained on pp 504-505 in my book.

- Will

September 22, 2013 - 9:23 pm
Member Since: September 12, 2013
Forum Posts: 43
sp_UserOfflineSmall Offline

Hi Will,

thanks - now my project works. (I used the Gordon-Smith Oscillator as a simple solution). All I had to do is to move my function definitions from the .cpp to the correspondent .h file and declare them as inline. Likewise I moved the multiple sine object declaration from the .cpp to the .h file. I do not understand this completely but I am very happy with this solution. The inline declaration generates much lesser CPU load now.


September 22, 2013 - 10:32 pm
Member Since: January 29, 2017
Forum Posts: 689
sp_UserOfflineSmall Offline

Hi Peter:

It should not make a difference whether the functions are inline in the .h file or in the .cpp file as far as functionality goes.

However, the member object declarations (multi-sine object) *must* be in the .h file. That is the original source of your problem.

Also, remember to compile in Release mode (after you debug) as this will greatly reduce CPU load.

- Will

Forum Timezone: America/New_York

Most Users Ever Online: 152

Currently Online:
10 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Chaes: 56

Skyler: 48

StevieD: 46

Derek: 46

Frodson: 45

Peter: 43

TheSmile: 43

Nickolai: 43

clau_ste: 39

jeanlecode: 37

Member Stats:

Guest Posters: 1

Members: 768

Moderators: 1

Admins: 6

Forum Stats:

Groups: 13

Forums: 42

Topics: 842

Posts: 3347

Moderators: W Pirkle: 689