platformRedBook.cpp
Engine/source/platform/platformRedBook.cpp
Public Functions
ConsoleFunctionGroupBegin(Redbook , "Control functions <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> Redbook audio (ie, CD audio)." )
ConsoleFunctionGroupEnd(Redbook )
DefineEngineFunction(redbookClose , bool , () , "Close the current Redbook device." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookGetDeviceCount , S32 , () , "get the number of redbook devices." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookGetDeviceName , const char * , (S32 index) , "(int index) Get name of specified Redbook device." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookGetLastError , const char * , () , "Get <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> string explaining the last redbook error." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookGetTrackCount , S32 , () , "Return the number of tracks." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookGetVolume , F32 , () , "Get the volume." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookOpen , bool , (const char *device) , ("") , "(string device=<a href="/coding/file/typesx86unix_8h/#typesx86unix_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)" "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookPlay , bool , (S32 track) , "(int track) Play the selected track." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookSetVolume , bool , (F32 volume) , "(float volume) Set playback volume." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookStop , bool , () , "Stop playing." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
Detailed Description
Public Functions
ConsoleFunctionGroupBegin(Redbook , "Control functions <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> Redbook audio (ie, CD audio)." )
ConsoleFunctionGroupEnd(Redbook )
DefineEngineFunction(redbookClose , bool , () , "Close the current Redbook device." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookGetDeviceCount , S32 , () , "get the number of redbook devices." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookGetDeviceName , const char * , (S32 index) , "(int index) Get name of specified Redbook device." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookGetLastError , const char * , () , "Get <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> string explaining the last redbook error." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookGetTrackCount , S32 , () , "Return the number of tracks." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookGetVolume , F32 , () , "Get the volume." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookOpen , bool , (const char *device) , ("") , "(string device=<a href="/coding/file/typesx86unix_8h/#typesx86unix_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)" "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookPlay , bool , (S32 track) , "(int track) Play the selected track." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookSetVolume , bool , (F32 volume) , "(float volume) Set playback volume." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
DefineEngineFunction(redbookStop , bool , () , "Stop playing." "@brief <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deprecated\n\n</a>" "@internal" )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "core/strings/stringFunctions.h" 25#include "console/console.h" 26#include "console/simBase.h" 27#include "console/engineAPI.h" 28#include "platform/platformRedBook.h" 29 30//------------------------------------------------------------------------------ 31// Class: RedBookDevice 32//------------------------------------------------------------------------------ 33RedBookDevice::RedBookDevice() 34{ 35 mAcquired = false; 36 mDeviceName = 0; 37} 38 39RedBookDevice::~RedBookDevice() 40{ 41 delete [] mDeviceName; 42} 43 44//------------------------------------------------------------------------------ 45// Class: RedBook 46//------------------------------------------------------------------------------ 47Vector<RedBookDevice*> RedBook::smDeviceList(__FILE__, __LINE__); 48RedBookDevice * RedBook::smCurrentDevice; 49char RedBook::smLastError[1024]; 50 51//------------------------------------------------------------------------------ 52void RedBook::init() 53{ 54} 55 56void RedBook::destroy() 57{ 58 close(); 59 60 for( Vector<RedBookDevice*>::iterator i = smDeviceList.begin( ); i != smDeviceList.end( ); i++ ) { 61 delete *i; 62 } 63 64 smDeviceList.clear( ); 65} 66 67//------------------------------------------------------------------------------ 68void RedBook::installDevice(RedBookDevice * device) 69{ 70 smDeviceList.push_back(device); 71} 72 73RedBookDevice * RedBook::getCurrentDevice() 74{ 75 return(smCurrentDevice); 76} 77 78U32 RedBook::getDeviceCount() 79{ 80 return(smDeviceList.size()); 81} 82 83const char * RedBook::getDeviceName(U32 idx) 84{ 85 if(idx >= getDeviceCount()) 86 { 87 setLastError("Invalid device index"); 88 return(""); 89 } 90 return(smDeviceList[idx]->mDeviceName); 91} 92 93void RedBook::setLastError(const char * error) 94{ 95 if(!error || dStrlen(error) >= sizeof(smLastError)) 96 setLastError("Invalid error string passed"); 97 else 98 dStrcpy(smLastError, error, 1024); 99} 100 101const char * RedBook::getLastError() 102{ 103 return(smLastError); 104} 105 106void RedBook::handleCallback(U32 type) 107{ 108 switch(type) 109 { 110 case PlayFinished: 111 Con::executef("RedBookCallback", "PlayFinished"); 112 break; 113 } 114} 115 116//------------------------------------------------------------------------------ 117bool RedBook::open(const char * deviceName) 118{ 119 if(!deviceName) 120 { 121 setLastError("Invalid device name"); 122 return(false); 123 } 124 125 for(U32 i = 0; i < smDeviceList.size(); i++) 126 if(!dStricmp(deviceName, smDeviceList[i]->mDeviceName)) 127 return(open(smDeviceList[i])); 128 129 setLastError("Failed to find device"); 130 return(false); 131} 132 133bool RedBook::open(RedBookDevice * device) 134{ 135 if(!device) 136 { 137 setLastError("Invalid device passed"); 138 return(false); 139 } 140 141 close(); 142 smCurrentDevice = device; 143 return(smCurrentDevice->open()); 144} 145 146bool RedBook::close() 147{ 148 if(smCurrentDevice) 149 { 150 bool ret = smCurrentDevice->close(); 151 smCurrentDevice = 0; 152 return(ret); 153 } 154 155 setLastError("No device is currently open"); 156 return(false); 157} 158 159bool RedBook::play(U32 track) 160{ 161 if(!smCurrentDevice) 162 { 163 setLastError("No device is currently open"); 164 return(false); 165 } 166 return(smCurrentDevice->play(track)); 167} 168 169bool RedBook::stop() 170{ 171 if(!smCurrentDevice) 172 { 173 setLastError("No device is currently open"); 174 return(false); 175 } 176 return(smCurrentDevice->stop()); 177} 178 179bool RedBook::getTrackCount(U32 * trackCount) 180{ 181 if(!smCurrentDevice) 182 { 183 setLastError("No device is currently open"); 184 return(false); 185 } 186 return(smCurrentDevice->getTrackCount(trackCount)); 187} 188 189bool RedBook::getVolume(F32 * volume) 190{ 191 if(!smCurrentDevice) 192 { 193 setLastError("No device is currently open"); 194 return(false); 195 } 196 return(smCurrentDevice->getVolume(volume)); 197} 198 199bool RedBook::setVolume(F32 volume) 200{ 201 if(!smCurrentDevice) 202 { 203 setLastError("No device is currently open"); 204 return(false); 205 } 206 return(smCurrentDevice->setVolume(volume)); 207} 208 209//------------------------------------------------------------------------------ 210// console methods 211//------------------------------------------------------------------------------ 212 213ConsoleFunctionGroupBegin( Redbook, "Control functions for Redbook audio (ie, CD audio)."); 214 215DefineEngineFunction( redbookOpen, bool, (const char * device), (""), "(string device=NULL)" 216 "@brief Deprecated\n\n" 217 "@internal") 218{ 219 if(String::compare(device,"")==0) 220 return(RedBook::open(RedBook::getDeviceName(0))); 221 else 222 return(RedBook::open(device)); 223} 224 225DefineEngineFunction( redbookClose, bool, (), , "Close the current Redbook device." 226 "@brief Deprecated\n\n" 227 "@internal") 228{ 229 return(RedBook::close()); 230} 231 232DefineEngineFunction( redbookPlay, bool, (S32 track), , "(int track) Play the selected track." 233 "@brief Deprecated\n\n" 234 "@internal") 235{ 236 return(RedBook::play(track)); 237} 238 239DefineEngineFunction( redbookStop, bool, (), , "Stop playing." 240 "@brief Deprecated\n\n" 241 "@internal") 242{ 243 return(RedBook::stop()); 244} 245 246DefineEngineFunction( redbookGetTrackCount, S32, (), , "Return the number of tracks." 247 "@brief Deprecated\n\n" 248 "@internal") 249{ 250 U32 trackCount; 251 if(!RedBook::getTrackCount(&trackCount)) 252 return(0); 253 return(trackCount); 254} 255 256DefineEngineFunction( redbookGetVolume, F32, (), , "Get the volume." 257 "@brief Deprecated\n\n" 258 "@internal") 259{ 260 F32 vol; 261 if(!RedBook::getVolume(&vol)) 262 return(0.f); 263 else 264 return(vol); 265} 266 267DefineEngineFunction( redbookSetVolume, bool, (F32 volume), , "(float volume) Set playback volume." 268 "@brief Deprecated\n\n" 269 "@internal") 270{ 271 return(RedBook::setVolume(volume)); 272} 273 274DefineEngineFunction( redbookGetDeviceCount, S32, (), , "get the number of redbook devices." 275 "@brief Deprecated\n\n" 276 "@internal") 277{ 278 return(RedBook::getDeviceCount()); 279} 280 281DefineEngineFunction( redbookGetDeviceName, const char *, (S32 index), , "(int index) Get name of specified Redbook device." 282 "@brief Deprecated\n\n" 283 "@internal") 284{ 285 return(RedBook::getDeviceName(index)); 286} 287 288DefineEngineFunction( redbookGetLastError, const char *, (), , "Get a string explaining the last redbook error." 289 "@brief Deprecated\n\n" 290 "@internal") 291{ 292 return(RedBook::getLastError()); 293} 294 295ConsoleFunctionGroupEnd( Redbook ); 296