What is the best method of using FMOD on the iPhone when using multiple View Controllers?
Currently, I create a new system object as each ViewController loads, without releasing the previously created. I would guess that this is less than ideal? However, I cant see a way to create one master system object in my app delegate and then simply access it from each loaded view. (bare in mind I am a new ObjC/C++ programmer)
- tdc asked 8 years ago
In your view controller header file, are you doing anything like:
and I think you still need:
In your view controller.
Hope this helps.
I found some of the the problems:
Firstly, you were right Mathew, I had to rename all .m files to .mm.
Secondly, ‘template’ appears to be a reserved word in Objective-C++, but not in Objective-C, hence that compilation error.
Thirdly, I had to write a get’er method in MyAppDelegate.mm as FMOD objects can’t be synthesized by Xcode.
So now it all compiles, but stops at the linker, saying that a global I’ve declared in my appDelegate.h file is a ‘duplicate symbol’.
I don’t think it has anything to do with FMOD, but if anyone knows if Objective C++ treats global variables differently to Objective C, please let me know, because this is my last stumbling block on my crusade for nirvana: FMOD players in several viewcontrollers! ….I hope…
Thanks for your response CuriousG.
Yes, I have the necessary references back to the appDelegate in my viewController’s header file. I know this because I access other appDelegate properties using the same singleton method.
I think the main issue is that I get the following compiler error in the appDelegate.h property declaration part:
[quote:2ssluu6y]"…expected specifier-qualifier-list before ‘FMOD"[/quote:2ssluu6y]
for this declaration:
Exactly the same declaration works fine when in the viewController’s header file. What gives?
Got it to work. Eventually!
So now FMOD’s playing in several viewcontrollers. That was the easy part.
Cos I had to change all global variables into AppDelegate ivars and make get’er and set’er methods for them all so that I can access them from other viewcontrollers.
It was a bitch of a job that had nothing to do with FMOD except it had to be done to make it work. The alternative would have been to convert all FMOD calls to C function calls (to avoid having to compile and link everything as .mm), but that seemed even less appealing.
Anyways, thanks for all the support!
thx & brgds.
Firstly it’s worth mentioning that on iPhone you cannot have multiple FMOD system objects that use CoreAudio, older versions permitted this with unforeseen consequences, newer versions will return an error.
To handle sharing the system between multiple view controllers perhaps you should move the FMOD code out into its own code file, possibly use a singleton to get access to the one FMOD instance.
Hmm. I’ll take a look and see if I’ve gotten that same error and how I could reproduce it.
Another quick thought. Sometimes when you rename a file from a .m extension to .mm, it only renames it in XCode, and not in the file system. I found this out recently when I created a class with a .m extension and remembered afterwords. I noticed that when it didn’t compile that on the left it said .mm, but on the title bar when I was in the file it still said .m!
Hi and thanks for the tip.
My appDelegate.mm file is definitely .mm so that’s hardly the issue.
In search of the problem, I’ve reduced the whole thing to ONLY doing the following in my appDelegate.h file:
and this in the interface section:
…and I still get the following compiler error message at above FMOD::System *system declaration:
[quote:24h82jh7]Expected specifier-qualifier-list before ‘FMOD’
If I comment out those 4 lines (and return to appDelegate.m), everything compiles and runs smoothly, playing away in the one viewController that I’ve been using FMOD up until now.
Hmm.. What about Foundation.h? Occasionally I will get crazy C-Like bug and it gets fixed if I import Foundation.h (even if it’s been imported elsewhere if you believe that).
I presume the FMOD example files work? Are you compiling for the latest Base SDK?
If you even comment out:
Do you still get the error?
Basically in my appDelegate, I have lines that look like this:
[code:1b9ovbcv]controller = [[myViewController alloc] initWithSystem:&system];[/code:1b9ovbcv]
and then in my myViewController code I have:
@interface myViewController : UIViewController
– (id)initWithSystem:(FMOD::System **)_system
Hope that makes sense. And feel free to let me know if there is a better way.
Thanks, this may lead us somewhere.
When commenting out even the "FMOD::System *system declaration it still throws a number of compiler errors in all viewController’s in which .h file I have the following #import:
…that I need to access other singleton appDelegate properties.
Do I need to make all viewController’s .m files into .mm if I use above #import statement in their .h (which is pretty much all of them)?
And yes, I’ve tried with and without foundation.h. Makes no difference.
You can access your AppDelegate though the singleton application class (sharedApplication)
[code:3a94ghcp]UIApplication *app = [UIApplication sharedApplication];
MyAppDelegate *myAppDel = app.delegate;
MyAppDelegate would have an FMOD::System* and you would access it through a getter.
this way each controller view is not strongly coupled to the system. ie no need to pass a reference
- sohla answered 8 years ago
Yes, by indirection if anything imports the singleton header they will also get the headers included by that singleton (hence FMOD).
To make things simple you could just make all your code files .mm I don’t see any disadvantage to this. Or if it is critical your files remain as .m you can use the FMOD C interface.
Please login first to submit.