Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The old Carbon QuickTime API is becoming obsolete.
- Loading branch information
Showing
7 changed files
with
281 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/**\file | ||
*\section License | ||
* License: GPL | ||
* Online License Link: http://www.gnu.org/licenses/gpl.html | ||
* | ||
*\author Copyright © 2011 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, | ||
* Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#import <Cocoa/Cocoa.h> | ||
#import <QTKit/QTKit.h> | ||
|
||
@interface MusicPlayer : NSObject | ||
{ | ||
QTMovie* currentSong; | ||
float songVolume; | ||
} | ||
|
||
- (id)init; | ||
- (void)shutdown; | ||
- (int)playFile:(const char*)filename looping:(int)loop; | ||
- (void)setVolume:(float)volume; | ||
- (void)play; | ||
- (void)stop; | ||
- (void)rewind; | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
/**\file | ||
*\section License | ||
* License: GPL | ||
* Online License Link: http://www.gnu.org/licenses/gpl.html | ||
* | ||
*\author Copyright © 2005-2011 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, | ||
* Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#import "MusicPlayer.h" | ||
|
||
/** | ||
* QuickTime music player for Mac OS X 10.4 or newer. Uses the Cocoa QTKit. | ||
*/ | ||
|
||
static MusicPlayer* musicPlayer; | ||
|
||
@implementation MusicPlayer | ||
|
||
- (id)init | ||
{ | ||
currentSong = 0; | ||
songVolume = 1.f; | ||
return self; | ||
} | ||
|
||
- (void)shutdown | ||
{ | ||
if(currentSong) | ||
{ | ||
[currentSong stop]; | ||
[currentSong release]; | ||
currentSong = 0; | ||
} | ||
} | ||
|
||
- (int)playFile:(const char*)filename looping:(int)loop | ||
{ | ||
// Get rid of the old song? | ||
if(currentSong) | ||
{ | ||
[currentSong stop]; | ||
[currentSong release]; | ||
currentSong = 0; | ||
} | ||
|
||
NSString* path = [[[NSString alloc] initWithCString:filename encoding:[NSString defaultCStringEncoding]] autorelease]; | ||
currentSong = [[QTMovie alloc] initWithFile:path error:0]; | ||
if(!currentSong) return false; | ||
|
||
[currentSong setVolume:songVolume]; | ||
|
||
// Set the looping attribute. | ||
[currentSong setAttribute:[NSNumber numberWithBool:(loop? YES : NO)] forKey:QTMovieLoopsAttribute]; | ||
|
||
// Start playing. | ||
[currentSong play]; | ||
} | ||
|
||
- (void)setVolume:(float)volume | ||
{ | ||
songVolume = volume; | ||
if(currentSong) | ||
{ | ||
[currentSong setVolume:songVolume]; | ||
} | ||
} | ||
|
||
- (void)play | ||
{ | ||
if(currentSong) | ||
{ | ||
[currentSong play]; | ||
} | ||
} | ||
|
||
- (void)stop | ||
{ | ||
if(currentSong) | ||
{ | ||
[currentSong stop]; | ||
} | ||
} | ||
|
||
- (void)rewind | ||
{ | ||
if(currentSong) | ||
{ | ||
[currentSong gotoBeginning]; | ||
} | ||
} | ||
|
||
@end | ||
|
||
// -------------------------------------------------------------------------- | ||
|
||
#include "sys_audiod.h" | ||
#include "sys_audiod_mus.h" | ||
|
||
static int DM_Ext_Init(void) | ||
{ | ||
// Already initialized? | ||
if(musicPlayer) return true; | ||
|
||
// Create a new QTKit player. | ||
musicPlayer = [[MusicPlayer alloc] init]; | ||
|
||
return true; | ||
} | ||
|
||
static void DM_Ext_Shutdown(void) | ||
{ | ||
if(!musicPlayer) return; | ||
|
||
// Release the player. | ||
[musicPlayer shutdown]; | ||
[musicPlayer release]; | ||
musicPlayer = 0; | ||
} | ||
|
||
static void DM_Ext_Update(void) | ||
{ | ||
if(!musicPlayer) return; | ||
|
||
// Gets called on every frame. | ||
} | ||
|
||
static void DM_Ext_Set(int property, float value) | ||
{ | ||
if(!musicPlayer) | ||
return; | ||
|
||
switch (property) | ||
{ | ||
case MUSIP_VOLUME: | ||
if(value > 1) value = 1; | ||
if(value < 0) value = 0; | ||
[musicPlayer setVolume:value]; | ||
break; | ||
} | ||
} | ||
|
||
static int DM_Ext_Get(int property, void *value) | ||
{ | ||
if(!musicPlayer) | ||
return false; | ||
|
||
switch (property) | ||
{ | ||
case MUSIP_ID: | ||
strcpy(value, "QuickTime(Cocoa)/Ext"); | ||
break; | ||
|
||
default: | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
static void DM_Ext_Pause(int pause) | ||
{ | ||
if(!musicPlayer) return; | ||
|
||
if(pause) | ||
{ | ||
[musicPlayer stop]; | ||
} | ||
else | ||
{ | ||
[musicPlayer play]; | ||
} | ||
} | ||
|
||
static void DM_Ext_Stop(void) | ||
{ | ||
if(!musicPlayer) return; | ||
|
||
[musicPlayer stop]; | ||
[musicPlayer rewind]; | ||
} | ||
|
||
static int DM_Ext_PlayFile(const char *filename, int looped) | ||
{ | ||
if(!musicPlayer) return 0; | ||
|
||
return [musicPlayer playFile:filename looping:looped]; | ||
} | ||
|
||
// The audio driver struct. | ||
audiointerface_music_t audiodQuickTimeMusic = { { | ||
DM_Ext_Init, | ||
DM_Ext_Shutdown, | ||
DM_Ext_Update, | ||
DM_Ext_Set, | ||
DM_Ext_Get, | ||
DM_Ext_Pause, | ||
DM_Ext_Stop }, | ||
NULL, | ||
NULL, | ||
DM_Ext_PlayFile, | ||
}; | ||
|
Oops, something went wrong.