123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- #include "core/strings/stringFunctions.h"
- #include "console/console.h"
- #include "console/simBase.h"
- #include "console/engineAPI.h"
- #include "platform/platformRedBook.h"
- //------------------------------------------------------------------------------
- // Class: RedBookDevice
- //------------------------------------------------------------------------------
- RedBookDevice::RedBookDevice()
- {
- mAcquired = false;
- mDeviceName = 0;
- }
- RedBookDevice::~RedBookDevice()
- {
- delete [] mDeviceName;
- }
- //------------------------------------------------------------------------------
- // Class: RedBook
- //------------------------------------------------------------------------------
- Vector<RedBookDevice *> RedBook::smDeviceList(__FILE__, __LINE__);
- RedBookDevice * RedBook::smCurrentDevice;
- char RedBook::smLastError[1024];
- //------------------------------------------------------------------------------
- void RedBook::init()
- {
- }
- void RedBook::destroy()
- {
- close();
- for( Vector<RedBookDevice*>::iterator i = smDeviceList.begin( ); i != smDeviceList.end( ); i++ ) {
- delete *i;
- }
- smDeviceList.clear( );
- }
- //------------------------------------------------------------------------------
- void RedBook::installDevice(RedBookDevice * device)
- {
- smDeviceList.push_back(device);
- }
- RedBookDevice * RedBook::getCurrentDevice()
- {
- return(smCurrentDevice);
- }
- U32 RedBook::getDeviceCount()
- {
- return(smDeviceList.size());
- }
- const char * RedBook::getDeviceName(U32 idx)
- {
- if(idx >= getDeviceCount())
- {
- setLastError("Invalid device index");
- return("");
- }
- return(smDeviceList[idx]->mDeviceName);
- }
- void RedBook::setLastError(const char * error)
- {
- if(!error || dStrlen(error) >= sizeof(smLastError))
- setLastError("Invalid error string passed");
- else
- dStrcpy(smLastError, error, 1024);
- }
- const char * RedBook::getLastError()
- {
- return(smLastError);
- }
- void RedBook::handleCallback(U32 type)
- {
- switch(type)
- {
- case PlayFinished:
- Con::executef("RedBookCallback", "PlayFinished");
- break;
- }
- }
- //------------------------------------------------------------------------------
- bool RedBook::open(const char * deviceName)
- {
- if(!deviceName)
- {
- setLastError("Invalid device name");
- return(false);
- }
- for(U32 i = 0; i < smDeviceList.size(); i++)
- if(!dStricmp(deviceName, smDeviceList[i]->mDeviceName))
- return(open(smDeviceList[i]));
- setLastError("Failed to find device");
- return(false);
- }
- bool RedBook::open(RedBookDevice * device)
- {
- if(!device)
- {
- setLastError("Invalid device passed");
- return(false);
- }
- close();
- smCurrentDevice = device;
- return(smCurrentDevice->open());
- }
- bool RedBook::close()
- {
- if(smCurrentDevice)
- {
- bool ret = smCurrentDevice->close();
- smCurrentDevice = 0;
- return(ret);
- }
- setLastError("No device is currently open");
- return(false);
- }
- bool RedBook::play(U32 track)
- {
- if(!smCurrentDevice)
- {
- setLastError("No device is currently open");
- return(false);
- }
- return(smCurrentDevice->play(track));
- }
- bool RedBook::stop()
- {
- if(!smCurrentDevice)
- {
- setLastError("No device is currently open");
- return(false);
- }
- return(smCurrentDevice->stop());
- }
- bool RedBook::getTrackCount(U32 * trackCount)
- {
- if(!smCurrentDevice)
- {
- setLastError("No device is currently open");
- return(false);
- }
- return(smCurrentDevice->getTrackCount(trackCount));
- }
- bool RedBook::getVolume(F32 * volume)
- {
- if(!smCurrentDevice)
- {
- setLastError("No device is currently open");
- return(false);
- }
- return(smCurrentDevice->getVolume(volume));
- }
- bool RedBook::setVolume(F32 volume)
- {
- if(!smCurrentDevice)
- {
- setLastError("No device is currently open");
- return(false);
- }
- return(smCurrentDevice->setVolume(volume));
- }
- //------------------------------------------------------------------------------
- // console methods
- //------------------------------------------------------------------------------
- ConsoleFunctionGroupBegin( Redbook, "Control functions for Redbook audio (ie, CD audio).");
- DefineEngineFunction( redbookOpen, bool, (const char * device), (""), "(string device=NULL)"
- "@brief Deprecated\n\n"
- "@internal")
- {
- if(String::compare(device,"")==0)
- return(RedBook::open(RedBook::getDeviceName(0)));
- else
- return(RedBook::open(device));
- }
- DefineEngineFunction( redbookClose, bool, (), , "Close the current Redbook device."
- "@brief Deprecated\n\n"
- "@internal")
- {
- return(RedBook::close());
- }
- DefineEngineFunction( redbookPlay, bool, (S32 track), , "(int track) Play the selected track."
- "@brief Deprecated\n\n"
- "@internal")
- {
- return(RedBook::play(track));
- }
- DefineEngineFunction( redbookStop, bool, (), , "Stop playing."
- "@brief Deprecated\n\n"
- "@internal")
- {
- return(RedBook::stop());
- }
- DefineEngineFunction( redbookGetTrackCount, S32, (), , "Return the number of tracks."
- "@brief Deprecated\n\n"
- "@internal")
- {
- U32 trackCount;
- if(!RedBook::getTrackCount(&trackCount))
- return(0);
- return(trackCount);
- }
- DefineEngineFunction( redbookGetVolume, F32, (), , "Get the volume."
- "@brief Deprecated\n\n"
- "@internal")
- {
- F32 vol;
- if(!RedBook::getVolume(&vol))
- return(0.f);
- else
- return(vol);
- }
- DefineEngineFunction( redbookSetVolume, bool, (F32 volume), , "(float volume) Set playback volume."
- "@brief Deprecated\n\n"
- "@internal")
- {
- return(RedBook::setVolume(volume));
- }
- DefineEngineFunction( redbookGetDeviceCount, S32, (), , "get the number of redbook devices."
- "@brief Deprecated\n\n"
- "@internal")
- {
- return(RedBook::getDeviceCount());
- }
- DefineEngineFunction( redbookGetDeviceName, const char *, (S32 index), , "(int index) Get name of specified Redbook device."
- "@brief Deprecated\n\n"
- "@internal")
- {
- return(RedBook::getDeviceName(index));
- }
- DefineEngineFunction( redbookGetLastError, const char *, (), , "Get a string explaining the last redbook error."
- "@brief Deprecated\n\n"
- "@internal")
- {
- return(RedBook::getLastError());
- }
- ConsoleFunctionGroupEnd( Redbook );
|