Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Background music redux - calling ObjC from within C?

Background music redux - calling ObjC from within C?
Thread Tools
Fresh-Faced Recruit
Join Date: Jul 2003
Location: Belgium
Status: Offline
Reply With Quote
Jul 13, 2003, 02:02 PM
 
All right, I finally managed to get something to work that both is simple and does what it's supposed to do: playing MIDI files in the background and looping them. This was after a dozen Frankenstein constructions which either worked but produced all kinds of menacing warnings in both the compiler and the console, or didn't work at all. I tried callback functions, and apparently these only work if the movie is used inside an NSMovieView object, so there is not really an advantage in using them...

My final solution consists of a dummy window created in IB with a NSMovieView inside it, and a class "SongController" which controls the movie inside the view. Because the game doesn't use any nib files by itself, I had to create a NSWindowController to invoke the window. Now I can make the music loop simply by setting [myNSMovieView setLoopMode:NSQTMovieLoopingPlayback]. However, this is only true if the "Visible at launch time" attribute of the window is set, otherwise it - again - won't loop. Luckily the window is behind the actual game display, so there is no need to hide it.
The upside of all these experiments is that I learned a lot about Cocoa programming

Now there is only one problem left before I can use this system to play songs in the game: how can I reach the ObjectiveC methods of the movie controller class I created, from within the old fashioned C code of the game itself? The movie controller is an object created by the window manager. All I need is some way to send commands to this object, but how?
I will probably need to 'export' a reference to the object when its 'awakeFromNib' method is called, but how can I reach this reference from the outside, and how do I call ObjectiveC methods from within the C code?
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Jul 13, 2003, 02:38 PM
 
Change the extension of the .c file to .m, and just call it.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:10 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2