I am updating a C++ program written twenty years ago to run scientific experiments that involve the precise starting and stopping of sounds. The program also needs to be able to control playback volume, pause sounds or start them at a designated position, loop sounds a specified number of times, and control channel mapping.
The researchers hope to run the program on a modern Mac OS X, but I have never done any development on a Mac before. What is the simplest way to accomplish the above goals in C++ on a Mac?
CoreAudio seems way too complicated. NSSound seems to have all the features I want, but as far as I can tell it is only available in Objective-C? Is it possible to mix Objective-C with C++? Or should I be looking at using the QuickTime SDK?
Thanks for any help.
Yes, you can mix Objective-C and C++. It's a hybrid language called Objective-C++. If NSSound has all of the features you need, go for it; if not, CoreAudio is the way to go. It will be much more challenging to set up and integrate larger libraries such as QuickTime, OpenAL, or FMOD.
Yes, you can mix Objective-C and C++. Objective-C is just C with some stuff added on, and that same stuff can be layered on top of C++ instead to get Objective-C++ (in particular Objective-C++ doesn't have C features that are in Objective-C but not C++).
Using CoreAudio directly may be useful if you need very low latency.
Another option may be OpenAL, which is available as just another built-in framework, OpenAL.framework.
Related
It seems that in Xcode 4 there is no longer a way to create an application that is not limited to the command line using C or C++. I would like to do so, however Glut seems to be one of the only frameworks available for mac that works with C++ and OpenGL, however gluts features are beginning to stop working on modern Operating Systems. Are there other alternatives that will allow me to use C++ or C for software development on a mac? It does not have to be limited to using xcode or opengl.
Yes, it's possible, but it may not be a very good idea. The real question is what problem are you trying to solve?
If you just don't like Obj-C, it should be straightforward to write a very thin shim that wraps the calls you care about in C++.
If you are trying to prove a point, you can actually make calls directly into the Obj-C runtime in plain C code. See this for example: using objc_msgSend to call a Objective C function with named arguments
If it's something else, please enlighten us so we can better answer your question.
QT is your best bet. It comes with a serious IDE and the libraries are written in a very good & intuitive C++.
QT can be found here: http://qt-project.org/downloads
If all you want is a window, an OpenGL context, and user interfacing, then go the SDL way. Completely written in C, cross platform, and almost object-oriented (most data types are structs, anyways). It's also very memory economic (its core DLL is less than 500KB in size and a windowless program uses less than 1MB of RAM on Linux), unlike the monster that is Qt.
I'd also recommend LazyFoo's tutorials to get started, since they indeed cover the learning from the perspective of a C++ programmer, not a C one.
I'm having a devil of a time finding out whether I can make a simple midi output layer using Coremidi without using Objective-C. The app is a QT desktop app in C++, and I want to keep OS specific things to a minimum and localized to just some output modules. Timing and latency is crucial so I'd like the midi output layer to be as close to the metal as possible. I'm getting bad sync latency when using PortMidi, and though I'd find out if it improves with CoreMIDI directly. If someone can tell me whether this is possible, and if so point me at an example, that would be luverly.
CoreMIDI's API is plain old C. You don't need Objective-C or C++.
(It can of course be used directly from Objective-C or C++ code, if you want to, though.)
With few years of experience with Java I decided it's time to take the time and learn C++. I just compiled and run my first C++ with eclipse (of course) and would like to take it one step fw - I wish to build a GUI.
Question: what GUIs are available to C++, something that is an open-source and runs on Mac and eclipse.
Some have mentioned Qt, some wxWidgets.
A quick rundown on crossplatform gui toolkits that you could try:
Qt: Looks appropriately native on whichever platform you use it on. It has its own build system however, which doesn't always like to play nicely with others. If you want the "beginners" experience in making a GUI with Qt, I recommend Qt Creator. It's a standalone IDE built by the developers of Qt.
wxWidgets: While Qt looks native (it tries its best to emulate the look and feel of the OS you are running on). wxWidgets is native. That is, it uses the GUI elements provided by the operating system. Last I looked at wxWidgets the C++ library was falling behind as far as modern development practices go. You are possibly more likely to learn bad programming habits from this library.
gtkmm: This is from the same guys who make the GIMP and Gnome, which as a MacOS user probably doesn't mean a lot to you. They don't try nearly as hard to fit in as wxWidgets and Qt. However, they probably have the most modern C++ library. They have done a lot of work to use modern C++ development practices. This can be helpful for a new programmer, as you are less likely to learn bad habits from them. On the downside, you'll get thrust into the land of templates and function pointers and such.
Those are the big ones with the most momentum behind them. There are countless others to also consider.
Use Qt
http://qt.nokia.com/products/
http://qt.nokia.com/products/eclipse-integration/
I'd recommend Qt which is open source, has an easy-to-use API with GUI designer, and can be used on many operating systems (Windows, Mac, Linux..) and looks native on whatever it's used on.
You might want to take a look at wxWidgets or Qt:
http://www.wxwidgets.org
http://qt.nokia.com/products/
More generally, see here:
http://en.wikipedia.org/wiki/List_of_widget_toolkits#Based_on_C_or_C.2B.2B_.28including_bindings_to_other_languages.29
I've personally used wxWidgets and found it to be quite good, if you're after a recommendation.
I've been coding on C++/Linux for 10+ years.
I am switching to do Mac development.
My development involves GUI components.
Is my only choice to learn Cocoa/Objective-C, or is there a way to wrap Cocoa and use it from C++ land?
Thanks!
Yes, you need to learn Objective-C. Besides, you wouldn't gain much if you didn't need to. It's not the language that's hard to learn but the Cocoa framework (not because it's inherently hard but because it's so huge).
You could use Carbon, but that's deprecated.
As Ole says, Objective-C is not hard to learn if you have a C++ background - and you can mix the languages if you use Objective-C++ (which can be useful, but usually best to partition the code that uses different languages - so use Objective-C/ Cocoa for the GUI layer and C++ for the core logic. I do it this way in my iPhone game, vConqr).
If you've done GUI work in C++ I think you'll appreciate why Objective-C was chosen for Cocoa. It's very nice for event driven designs and has a number of abstractions that are a natural fit. As you get into more abstract areas, though, especially if you use a lot of containers and algorithms, you'll probably start to find the limitations a little annoying. But give it time - there are other useful abstractions that are not immediately obvious (dynamic typing, key/ value coding and other forms of reflection, categories...).
You might also find this stackoverflow question useful.
No, I don't think you need to learn Objective-C. You can use Qt framework to develop applications on Mac using C++.
If you are only going to work on Mac apps, then learn Objective-C and the Cocoa frameworks. Cocoa apps can pick up new features "for free" in newer Mac OS X releases, and will be more future-proof than a cross-platform app framework like Qt.
There are so many aspects to Cocoa frameworks (collectively) that you would be best served by sticking to the native app framework to serve your customers (end users). That is really what matters, not the short term inconvenience of learning a new language or framework (which comes with the job, adapt or die).
Pretty soon you will be as frustrated with Xcode as the rest of us.
I use WxWindows on the Mac for my tool development. Took a little bit of working but I got my Jam based c++ pipeline that I use on windows working perfectly. The only thing you need to remember to get it all correctly working is to create the proper application rules... easy to get working as a jam rule.
As mentioned in a few of the other answers, there are a number of cross platform GUI libraries that support mac. Such as Qt and WxWindows. You can use any of them, I personally have only used Qt and found it quite pleasurable to work with after coming from Java and C toolkits.
In order to use the native GUI libraries, you can use Python as well (PyObjC). Java is also able to make native looking apps in OS X.
I am going to start a game in about 3 weeks and I would really like the game to run at least on another platform (linux, MacOS) but my team thinks that's a lot of work. I am up for it but wanted to know what are the things I should watch out for that won't port to linux (apart from Windows specific APIs like DirectXsound)?
I've been reading online and Windows "_s" functions like sprintf_s appear to exist only on Windows; is this correct or are they implemented on linux also?
No, the _s functions are NOT implemented in the standard gcc library.
(At least, grepping the include files for 'sprintf_s' turns up nothing at all.)
It might be worth looking at cross platform libraries like boost and apr to do some of the heavy lifting work.
A sample of specific things to look for:
Input/Output (DirectX / SDL / OpenGL)
Win32/windows.h functionality (CreateThread, etc)
Using windows controls on the UI
Synchronization primitives (critical sections, events)
Filepaths (directory separators, root names)
Wide char implementations (16 bit on windows, 32bit on linux)
No MFC support on linux (CString, etc)
If I were you I would use some of the available Frameworks out there, that handle Platform independence.
I wrote a 3D-Game as a hobby project with a friend of mine, the server being in Java and the clients running on Windows and Linux. We ended up using Ogre as 3D-Engine and OpenAL as Sound-Engine, both platform independent and available under LGPL.
The only things I really had to write separately were the whole Socket-handling, reading the config from file system and the initialization of the System. Compared to the rest of the Program, that was almost nothing.
The most time consuming will be to set up the entire project to compile under Windows and Linux (or Mac), especially if you're concentrating on one and only occasionally check the other for problems. If you have one in your team who checks regularly for these problems while they're being produced you won't have that much overhead from that as well.
All in all compared to the programming of the game itself, adapting it to different platforms is almost no effort, if all frameworks used are well written, platform independent systems.
Try to encapsulate any non-standard extentions like DirectX, OpenGL, SDL, etc. Then you only have to rewrite those parts based on platform.
I also would make it playable on one OS before even thinking of porting.
For the 'safe' functions: they are non-standard, and almost safe :)
Endianess is something look out for.
Endianess is the order of the bits in a byte. Some platforms are big endian while some are little endian.
This can affect how cross-platform your program is. But the biggest impact this would have would be in network communications. You have to convert from one endian to another before sending or receiving a network message.
If you focus on gameplay, design a game, and them implement that porting should not be especially onerous. If you implement it simultaneous on several platforms it should be straight forward.
But if you focus on effects, design something that you feel is going to "blow the others out of the water," and try to paste a game idea onto them, you are doomed.
So really it is up to you.
Don't know much about windows-apis, but I set up a daily (or on-commit) fully automatic build-system on all platforms you want to support. If you develop something on your windows-box that doesn't work on the others, your build-system should notify you of "failed build on platform x, see logfile/attachment/whatnot for details". It'll catch a lot of cross-paltform issues. Unittests will help as well.
Whether or not to target multiple platforms from the start is a good idea is another question.
Personally I'd start developing on another platform and then see about porting it to windows at a later time ;-)
Just remember that you are creating a model of game that does not depend on the details of any operating system. Your game depends on state management and algorithms which don't depend on the OS. The key is to write your game logic without dependencies to specific libraries which means a lot of encapsulation.
You shouldn't call sprintf_s directly you should write an routine, class, or MACRO that can be changed based on the platform, Don't use DWORD when you can use a class or typedef that can be tailored to different platforms.
For instance if you where making a football game, then algorithms for throwing the ball, running, tackling, positions of the players could be done completely in standard C++ without platform dependencies. If your encapsulation was good you could dump the state of you game to a file and display it separately with a rendering program.
If you truly want to do cross platform development easily I would suggest using one of the already built cross-platform engines like Unity or one of the Garage Games stuff like Torque Game Builder (2D).
I have virtually zero experience in either so can't tell you which is better but the Torque Game builder demo couldn't get through the first tutorial without having problems and they don't answer tech support questions in their forums like they claim to do so I can say avoid them if you are a novice in game design like myself. The big thing about Garage Games was supposed to be their great support, I saw zero support and in fact only saw a bunch of, "Hey, anybody here?" posts with no answers so I guess they are pretty much giving up on supporting their products.
http://unity3d.com/
http://www.garagegames.com/
I'm surprised nobody mentions libSDL and OpenGL because most cross platform games were written using those libraries.
If your game is 2D, you can use libSDL. A good example of game written using it is The Battle of Wesnoth. SDL uses DirectX on Windows, it's just a thin wrapper on it.
If your game is 3D, use OpenGL. For example, Quake 3 uses that library. You can find tons of examples and documentation on it. Of course, there are many libraries that wrap OpenGL, so you don't have to do low-level stuff. Look into OGRE, Crystal Space, etc.
As for the basic C/C++ libraries and functions compatibility, it's best you install some Linux and simply run man page for the function to see if it exists. Of you can look it up on the Internet.