src/cdrom/macosx/CDPlayer.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 29 May 2006 04:04:35 +0000
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
permissions -rw-r--r--
more tweaking indent options
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
    modify it under the terms of the GNU Library General Public
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
    version 2 of the License, or (at your option) any later version.
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
    Library General Public License for more details.
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
    You should have received a copy of the GNU Library General Public
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
    License along with this library; if not, write to the Free
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
    Sam Lantinga
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
    slouken@libsdl.org
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
*/
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1143
diff changeset
    22
#include "SDL_config.h"
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
#include "CDPlayer.h"
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
#include "AudioFilePlayer.h"
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
#include "SDLOSXCAGuard.h"
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    28
/* we're exporting these functions into C land for SDL_syscdrom.c */
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    29
/*extern "C" {*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    31
/*///////////////////////////////////////////////////////////////////////////
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    32
    Constants
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    33
  //////////////////////////////////////////////////////////////////////////*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    35
#define kAudioCDFilesystemID   (UInt16)(('J' << 8) | 'H')       /* 'JH'; this avoids compiler warning */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    37
/* XML PList keys */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
#define kRawTOCDataString           "Format 0x02 TOC Data"
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
#define kSessionsString             "Sessions"
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
#define kSessionTypeString          "Session Type"
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
#define kTrackArrayString           "Track Array"
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
#define kFirstTrackInSessionString      "First Track"
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
#define kLastTrackInSessionString       "Last Track"
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
#define kLeadoutBlockString         "Leadout Block"
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
#define kDataKeyString              "Data"
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
#define kPointKeyString             "Point"
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
#define kSessionNumberKeyString         "Session Number"
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    48
#define kStartBlockKeyString            "Start Block"
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    49
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    50
/*///////////////////////////////////////////////////////////////////////////
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    51
    Globals
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    52
  //////////////////////////////////////////////////////////////////////////*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
#pragma mark -- Globals --
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    56
static int playBackWasInit = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    57
static AudioUnit theUnit;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    58
static AudioFilePlayer *thePlayer = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    59
static CDPlayerCompletionProc completionProc = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    60
static SDL_mutex *apiMutex = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    61
static SDL_sem *callbackSem;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    62
static SDL_CD *theCDROM;
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    64
/*///////////////////////////////////////////////////////////////////////////
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    65
    Prototypes
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    66
  //////////////////////////////////////////////////////////////////////////*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
#pragma mark -- Prototypes --
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
    70
static OSStatus CheckInit();
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
    72
static void FilePlayNotificationHandler(void *inRefCon, OSStatus inStatus);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
    74
static int RunCallBackThread(void *inRefCon);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
#pragma mark -- Public Functions --
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    79
void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
    80
Lock()
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
    if (!apiMutex) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
    83
        apiMutex = SDL_CreateMutex();
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
    }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
    85
    SDL_mutexP(apiMutex);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    88
void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
    89
Unlock()
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
{
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
    91
    SDL_mutexV(apiMutex);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    94
int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
    95
DetectAudioCDVolumes(FSVolumeRefNum * volumes, int numVolumes)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
    int volumeIndex;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
    int cdVolumeCount = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
    OSStatus result = noErr;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   100
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   101
    for (volumeIndex = 1; result == noErr || result != nsvErr; volumeIndex++) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   102
        FSVolumeRefNum actualVolume;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   103
        FSVolumeInfo volumeInfo;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   104
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   105
        memset(&volumeInfo, 0, sizeof(volumeInfo));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   106
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   107
        result = FSGetVolumeInfo(kFSInvalidVolumeRefNum,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   108
                                 volumeIndex,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   109
                                 &actualVolume,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   110
                                 kFSVolInfoFSInfo, &volumeInfo, NULL, NULL);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   111
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   112
        if (result == noErr) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   113
            if (volumeInfo.filesystemID == kAudioCDFilesystemID) {      /* It's an audio CD */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
                if (volumes != NULL && cdVolumeCount < numVolumes)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
                    volumes[cdVolumeCount] = actualVolume;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   116
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
                cdVolumeCount++;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
            }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   119
        } else {
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   120
            /* I'm commenting this out because it seems to be harmless */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   121
            /*SDL_SetError ("DetectAudioCDVolumes: FSGetVolumeInfo returned %d", result); */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
        }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
    }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   124
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
    return cdVolumeCount;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   128
int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   129
ReadTOCData(FSVolumeRefNum theVolume, SDL_CD * theCD)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
{
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   131
    HFSUniStr255 dataForkName;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   132
    OSStatus theErr;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   133
    SInt16 forkRefNum;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   134
    SInt64 forkSize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   135
    Ptr forkData = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   136
    ByteCount actualRead;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   137
    CFDataRef dataRef = 0;
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
    CFPropertyListRef propertyListRef = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   140
    FSRefParam fsRefPB;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   141
    FSRef tocPlistFSRef;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   142
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   143
    const char *error = "Unspecified Error";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   144
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   145
    /* get stuff from .TOC.plist */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
    fsRefPB.ioCompletion = NULL;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
    fsRefPB.ioNamePtr = "\p.TOC.plist";
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
    fsRefPB.ioVRefNum = theVolume;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
    fsRefPB.ioDirID = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
    fsRefPB.newRef = &tocPlistFSRef;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   151
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   152
    theErr = PBMakeFSRefSync(&fsRefPB);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   153
    if (theErr != noErr) {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
        error = "PBMakeFSRefSync";
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
        goto bail;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
    }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   157
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   158
    /* Load and parse the TOC XML data */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   160
    theErr = FSGetDataForkName(&dataForkName);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
    if (theErr != noErr) {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
        error = "FSGetDataForkName";
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
        goto bail;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
    }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   165
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   166
    theErr =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   167
        FSOpenFork(&tocPlistFSRef, dataForkName.length, dataForkName.unicode,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   168
                   fsRdPerm, &forkRefNum);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
    if (theErr != noErr) {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
        error = "FSOpenFork";
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
        goto bail;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
    }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   173
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   174
    theErr = FSGetForkSize(forkRefNum, &forkSize);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
    if (theErr != noErr) {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
        error = "FSGetForkSize";
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
        goto bail;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
    }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   179
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   180
    /* Allocate some memory for the XML data */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   181
    forkData = NewPtr(forkSize);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   182
    if (forkData == NULL) {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
        error = "NewPtr";
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
        goto bail;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
    }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   186
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   187
    theErr = FSReadFork(forkRefNum, fsFromStart, 0 /* offset location */ ,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   188
                        forkSize, forkData, &actualRead);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   189
    if (theErr != noErr) {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
        error = "FSReadFork";
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
        goto bail;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
    }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   193
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   194
    dataRef = CFDataCreate(kCFAllocatorDefault, (UInt8 *) forkData, forkSize);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   195
    if (dataRef == 0) {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
        error = "CFDataCreate";
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
        goto bail;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   200
    propertyListRef = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   201
                                                      dataRef,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   202
                                                      kCFPropertyListImmutable,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   203
                                                      NULL);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
    if (propertyListRef == NULL) {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
        error = "CFPropertyListCreateFromXMLData";
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
        goto bail;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   209
    /* Now we got the Property List in memory. Parse it. */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   210
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   211
    /* First, make sure the root item is a CFDictionary. If not, release and bail. */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   212
    if (CFGetTypeID(propertyListRef) == CFDictionaryGetTypeID()) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   213
        CFDictionaryRef dictRef = (CFDictionaryRef) propertyListRef;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   214
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   215
        CFDataRef theRawTOCDataRef;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   216
        CFArrayRef theSessionArrayRef;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   217
        CFIndex numSessions;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   218
        CFIndex index;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   219
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   220
        /* This is how we get the Raw TOC Data */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   221
        theRawTOCDataRef =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   222
            (CFDataRef) CFDictionaryGetValue(dictRef,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   223
                                             CFSTR(kRawTOCDataString));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   224
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   225
        /* Get the session array info. */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   226
        theSessionArrayRef =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   227
            (CFArrayRef) CFDictionaryGetValue(dictRef,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   228
                                              CFSTR(kSessionsString));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   229
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   230
        /* Find out how many sessions there are. */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   231
        numSessions = CFArrayGetCount(theSessionArrayRef);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   232
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   233
        /* Initialize the total number of tracks to 0 */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
        theCD->numtracks = 0;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   235
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   236
        /* Iterate over all sessions, collecting the track data */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   237
        for (index = 0; index < numSessions; index++) {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
            CFDictionaryRef theSessionDict;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   239
            CFNumberRef leadoutBlock;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   240
            CFArrayRef trackArray;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   241
            CFIndex numTracks;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   242
            CFIndex trackIndex;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   243
            UInt32 value = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   244
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   245
            theSessionDict = (CFDictionaryRef)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   246
                CFArrayGetValueAtIndex(theSessionArrayRef, index);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   247
            leadoutBlock =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   248
                (CFNumberRef) CFDictionaryGetValue(theSessionDict,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   249
                                                   CFSTR
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   250
                                                   (kLeadoutBlockString));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   251
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   252
            trackArray =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   253
                (CFArrayRef) CFDictionaryGetValue(theSessionDict,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   254
                                                  CFSTR(kTrackArrayString));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   255
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   256
            numTracks = CFArrayGetCount(trackArray);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   258
            for (trackIndex = 0; trackIndex < numTracks; trackIndex++) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   259
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
                CFDictionaryRef theTrackDict;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   261
                CFNumberRef trackNumber;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   262
                CFNumberRef sessionNumber;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   263
                CFNumberRef startBlock;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   264
                CFBooleanRef isDataTrack;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   265
                UInt32 value;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   266
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   267
                theTrackDict = (CFDictionaryRef)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   268
                    CFArrayGetValueAtIndex(trackArray, trackIndex);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   269
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   270
                trackNumber =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   271
                    (CFNumberRef) CFDictionaryGetValue(theTrackDict,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   272
                                                       CFSTR
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   273
                                                       (kPointKeyString));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   274
                sessionNumber =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   275
                    (CFNumberRef) CFDictionaryGetValue(theTrackDict,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   276
                                                       CFSTR
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   277
                                                       (kSessionNumberKeyString));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   278
                startBlock =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   279
                    (CFNumberRef) CFDictionaryGetValue(theTrackDict,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   280
                                                       CFSTR
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   281
                                                       (kStartBlockKeyString));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   282
                isDataTrack =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   283
                    (CFBooleanRef) CFDictionaryGetValue(theTrackDict,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   284
                                                        CFSTR
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   285
                                                        (kDataKeyString));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   286
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   287
                /* Fill in the SDL_CD struct */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
                int idx = theCD->numtracks++;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   290
                CFNumberGetValue(trackNumber, kCFNumberSInt32Type, &value);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
                theCD->track[idx].id = value;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   292
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   293
                CFNumberGetValue(startBlock, kCFNumberSInt32Type, &value);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
                theCD->track[idx].offset = value;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   296
                theCD->track[idx].type =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   297
                    (isDataTrack ==
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   298
                     kCFBooleanTrue) ? SDL_DATA_TRACK : SDL_AUDIO_TRACK;
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   300
                /* Since the track lengths are not stored in .TOC.plist we compute them. */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
                if (trackIndex > 0) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   302
                    theCD->track[idx - 1].length =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   303
                        theCD->track[idx].offset - theCD->track[idx -
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   304
                                                                1].offset;
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
                }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
            }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   307
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   308
            /* Compute the length of the last track */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   309
            CFNumberGetValue(leadoutBlock, kCFNumberSInt32Type, &value);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   310
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   311
            theCD->track[theCD->numtracks - 1].length =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   312
                value - theCD->track[theCD->numtracks - 1].offset;
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   314
            /* Set offset to leadout track */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
            theCD->track[theCD->numtracks].offset = value;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
        }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   317
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
    theErr = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
    goto cleanup;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   322
  bail:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   323
    SDL_SetError("ReadTOCData: %s returned %d", error, theErr);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
    theErr = -1;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   325
  cleanup:
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
    if (propertyListRef != NULL)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   328
        CFRelease(propertyListRef);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
    if (dataRef != NULL)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   330
        CFRelease(dataRef);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
    if (forkData != NULL)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   332
        DisposePtr(forkData);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   333
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   334
    FSCloseFork(forkRefNum);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
    return theErr;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   339
int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   340
ListTrackFiles(FSVolumeRefNum theVolume, FSRef * trackFiles, int numTracks)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
{
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   342
    OSStatus result = -1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   343
    FSIterator iterator;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   344
    ItemCount actualObjects;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   345
    FSRef rootDirectory;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   346
    FSRef ref;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   347
    HFSUniStr255 nameStr;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   348
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   349
    result = FSGetVolumeInfo(theVolume,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   350
                             0,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   351
                             NULL,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   352
                             kFSVolInfoFSInfo, NULL, NULL, &rootDirectory);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   353
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
    if (result != noErr) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   355
        SDL_SetError("ListTrackFiles: FSGetVolumeInfo returned %d", result);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
        return result;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   359
    result = FSOpenIterator(&rootDirectory, kFSIterateFlat, &iterator);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
    if (result == noErr) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   361
        do {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   362
            result = FSGetCatalogInfoBulk(iterator, 1, &actualObjects,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   363
                                          NULL, kFSCatInfoNone, NULL,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   364
                                          &ref, NULL, &nameStr);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
            if (result == noErr) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   366
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   367
                CFStringRef name;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   368
                name =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   369
                    CFStringCreateWithCharacters(NULL, nameStr.unicode,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   370
                                                 nameStr.length);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   371
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   372
                /* Look for .aiff extension */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   373
                if (CFStringHasSuffix(name, CFSTR(".aiff")) ||
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   374
                    CFStringHasSuffix(name, CFSTR(".cdda"))) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   375
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   376
                    /* Extract the track id from the filename */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
                    int trackID = 0, i = 0;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   378
                    while (i < nameStr.length && !isdigit(nameStr.unicode[i])) {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
                        ++i;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
                    }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   381
                    while (i < nameStr.length && isdigit(nameStr.unicode[i])) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   382
                        trackID = 10 * trackID + (nameStr.unicode[i] - '0');
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
                        ++i;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
                    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   386
#if DEBUG_CDROM
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   387
                    printf("Found AIFF for track %d: '%s'\n",
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   388
                           trackID, CFStringGetCStringPtr(name,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   389
                                                          CFStringGetSystemEncoding
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   390
                                                          ()));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   391
#endif
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   392
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   393
                    /* Track ID's start at 1, but we want to start at 0 */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
                    trackID--;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   395
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   396
                    assert(0 <= trackID && trackID <= SDL_MAX_TRACKS);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   397
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
                    if (trackID < numTracks)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   399
                        memcpy(&trackFiles[trackID], &ref, sizeof(FSRef));
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
                }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   401
                CFRelease(name);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
            }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   403
        }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   404
        while (noErr == result);
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   405
        FSCloseIterator(iterator);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
    }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   407
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
    return 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   411
int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   412
LoadFile(const FSRef * ref, int startFrame, int stopFrame)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
    int error = -1;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   415
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   416
    if (CheckInit() < 0)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
        goto bail;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   418
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   419
    /* release any currently playing file */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   420
    if (ReleaseFile() < 0)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
        goto bail;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   422
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   423
#if DEBUG_CDROM
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   424
    printf("LoadFile: %d %d\n", startFrame, stopFrame);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   425
#endif
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   426
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   427
    /*try { */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   428
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   429
    /* create a new player, and attach to the audio unit */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   430
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   431
    thePlayer = new_AudioFilePlayer(ref);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   432
    if (thePlayer == NULL) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   433
        SDL_SetError("LoadFile: Could not create player");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   434
        return -3;              /*throw (-3); */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   435
    }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   436
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   437
    if (!thePlayer->SetDestination(thePlayer, &theUnit))
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   438
        goto bail;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   439
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   440
    if (startFrame >= 0)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   441
        thePlayer->SetStartFrame(thePlayer, startFrame);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   442
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   443
    if (stopFrame >= 0 && stopFrame > startFrame)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   444
        thePlayer->SetStopFrame(thePlayer, stopFrame);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   445
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   446
    /* we set the notifier later */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   447
    /*thePlayer->SetNotifier(thePlayer, FilePlayNotificationHandler, NULL); */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   448
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   449
    if (!thePlayer->Connect(thePlayer))
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   450
        goto bail;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   451
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   452
#if DEBUG_CDROM
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   453
    thePlayer->Print(thePlayer);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   454
    fflush(stdout);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   455
#endif
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   456
    /*}
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   457
       catch (...)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   458
       {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   459
       goto bail;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   460
       } */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   461
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   462
    error = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   463
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   464
  bail:
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
    return error;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   466
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   468
int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   469
ReleaseFile()
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
    int error = -1;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   472
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   473
    /* (Don't see any way that the original C++ code could throw here.) --ryan. */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   474
    /*try { */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   475
    if (thePlayer != NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   476
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   477
        thePlayer->Disconnect(thePlayer);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   478
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   479
        delete_AudioFilePlayer(thePlayer);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   480
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   481
        thePlayer = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   482
    }
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   483
    /*}
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   484
       catch (...)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   485
       {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   486
       goto bail;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   487
       } */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   488
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   489
    error = 0;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   490
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   491
/*  bail: */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   492
    return error;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   494
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   495
int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   496
PlayFile()
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   497
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   498
    OSStatus result = -1;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   499
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   500
    if (CheckInit() < 0)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
        goto bail;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   502
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   503
    /*try { */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   504
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   505
    // start processing of the audio unit
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   506
    result = AudioOutputUnitStart(theUnit);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   507
    if (result)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   508
        goto bail;              //THROW_RESULT("PlayFile: AudioOutputUnitStart")
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   509
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   510
    /*}
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   511
       catch (...)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   512
       {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   513
       goto bail;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   514
       } */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   515
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516
    result = 0;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   517
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   518
  bail:
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   519
    return result;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   520
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   521
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   522
int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   523
PauseFile()
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   524
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   525
    OSStatus result = -1;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   526
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   527
    if (CheckInit() < 0)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   528
        goto bail;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   529
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   530
    /*try { */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   531
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   532
    /* stop processing the audio unit */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   533
    result = AudioOutputUnitStop(theUnit);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   534
    if (result)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   535
        goto bail;              /*THROW_RESULT("PauseFile: AudioOutputUnitStop") */
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   536
    /*}
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   537
       catch (...)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   538
       {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   539
       goto bail;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   540
       } */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   541
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   542
    result = 0;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   543
  bail:
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   544
    return result;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   545
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   547
void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   548
SetCompletionProc(CDPlayerCompletionProc proc, SDL_CD * cdrom)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   549
{
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   550
    assert(thePlayer != NULL);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   551
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   552
    theCDROM = cdrom;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   553
    completionProc = proc;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   554
    thePlayer->SetNotifier(thePlayer, FilePlayNotificationHandler, cdrom);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   555
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   556
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   557
int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   558
GetCurrentFrame()
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   559
{
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   560
    int frame;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   561
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   562
    if (thePlayer == NULL)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   563
        frame = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   564
    else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   565
        frame = thePlayer->GetCurrentFrame(thePlayer);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   566
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   567
    return frame;
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   568
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   569
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   570
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   571
#pragma mark -- Private Functions --
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   572
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   573
static OSStatus
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   574
CheckInit()
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   575
{
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   576
    if (playBackWasInit)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   577
        return 0;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   578
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   579
    OSStatus result = noErr;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   580
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   581
    /* Create the callback semaphore */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   582
    callbackSem = SDL_CreateSemaphore(0);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   583
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   584
    /* Start callback thread */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   585
    SDL_CreateThread(RunCallBackThread, NULL);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   586
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   587
    {                           /*try { */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   588
        ComponentDescription desc;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   589
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   590
        desc.componentType = kAudioUnitComponentType;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   591
        desc.componentSubType = kAudioUnitSubType_Output;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   592
        desc.componentManufacturer = kAudioUnitID_DefaultOutput;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   593
        desc.componentFlags = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   594
        desc.componentFlagsMask = 0;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   595
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   596
        Component comp = FindNextComponent(NULL, &desc);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   597
        if (comp == NULL) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   598
            SDL_SetError("CheckInit: FindNextComponent returned NULL");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   599
            if (result)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   600
                return -1;      //throw(internalComponentErr);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   601
        }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   602
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   603
        result = OpenAComponent(comp, &theUnit);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   604
        if (result)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   605
            return -1;          //THROW_RESULT("CheckInit: OpenAComponent")
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   606
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   607
        // you need to initialize the output unit before you set it as a destination
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   608
        result = AudioUnitInitialize(theUnit);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   609
        if (result)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   610
            return -1;          //THROW_RESULT("CheckInit: AudioUnitInitialize")
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   611
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   612
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   613
        playBackWasInit = true;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   614
    }
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   615
    /*catch (...)
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   616
       {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   617
       return -1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   618
       } */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   619
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   620
    return 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   621
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   622
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   623
static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   624
FilePlayNotificationHandler(void *inRefCon, OSStatus inStatus)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   625
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   626
    if (inStatus == kAudioFilePlay_FileIsFinished) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   627
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   628
        /* notify non-CA thread to perform the callback */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   629
        SDL_SemPost(callbackSem);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   630
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   631
    } else if (inStatus == kAudioFilePlayErr_FilePlayUnderrun) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   632
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   633
        SDL_SetError("CDPlayer Notification: buffer underrun");
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   634
    } else if (inStatus == kAudioFilePlay_PlayerIsUninitialized) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   635
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   636
        SDL_SetError("CDPlayer Notification: player is uninitialized");
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   637
    } else {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   638
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   639
        SDL_SetError("CDPlayer Notification: unknown error %ld", inStatus);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   640
    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   641
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   642
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   643
static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   644
RunCallBackThread(void *param)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   645
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   646
    for (;;) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   647
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   648
        SDL_SemWait(callbackSem);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   649
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   650
        if (completionProc && theCDROM) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   651
#if DEBUG_CDROM
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   652
            printf("callback!\n");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   653
#endif
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   654
            (*completionProc) (theCDROM);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   655
        } else {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   656
#if DEBUG_CDROM
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   657
            printf("callback?\n");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   658
#endif
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   659
        }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   660
    }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   661
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   662
#if DEBUG_CDROM
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
   663
    printf("thread dying now...\n");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   664
#endif
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   665
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   666
    return 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   667
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   668
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   669
/*}; // extern "C" */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   670
/* vi: set ts=4 sw=4 expandtab: */