haiku/src/kits/game/GameSound.cpp

632 lines
9.5 KiB
C++
Raw Normal View History

//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS
//
// 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.
//
// File Name: GameSound.cpp
// Author: Christopher ML Zumwalt May (zummy@users.sf.net)
// Description: Provides much of interfaces with BGameSoundDevice on behalf
// of the rest of it's childern.
//------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
#include <stdio.h>
#include <string.h>
// System Includes -------------------------------------------------------------
// Project Includes ------------------------------------------------------------
#include <GameSoundBuffer.h>
#include <GameSoundDevice.h>
// Local Includes --------------------------------------------------------------
#include <GameSound.h>
using std::nothrow;
// Local Defines ---------------------------------------------------------------
// BGameSound class ------------------------------------------------------------
BGameSound::BGameSound(BGameSoundDevice *device)
: fSound(-1)
{
fDevice = GetDefaultDevice();
fInitError = fDevice->InitCheck();
}
BGameSound::BGameSound(const BGameSound &other)
: fSound(-1)
{
memcpy(&fFormat, &other.fFormat, sizeof(gs_audio_format));
fDevice = GetDefaultDevice();
fInitError = fDevice->InitCheck();
}
BGameSound::~BGameSound()
{
if (fSound >= 0)
fDevice->ReleaseBuffer(fSound);
ReleaseDevice();
}
status_t
BGameSound::InitCheck() const
{
return fInitError;
}
BGameSoundDevice *
BGameSound::Device() const
{
return fDevice;
}
gs_id
BGameSound::ID() const
{
return fSound;
}
const gs_audio_format &
BGameSound::Format() const
{
return fDevice->Format(fSound);
}
status_t
BGameSound::StartPlaying()
{
fDevice->StartPlaying(fSound);
return B_OK;
}
bool
BGameSound::IsPlaying()
{
return fDevice->IsPlaying(fSound);
}
status_t
BGameSound::StopPlaying()
{
fDevice->StopPlaying(fSound);
return B_OK;
}
status_t
BGameSound::SetGain(float gain,
bigtime_t duration)
{
gs_attribute attribute;
attribute.attribute = B_GS_GAIN;
attribute.value = gain;
attribute.duration = duration;
attribute.flags = 0;
return fDevice->SetAttributes(fSound, &attribute, 1);
}
status_t
BGameSound::SetPan(float pan,
bigtime_t duration)
{
gs_attribute attribute;
attribute.attribute = B_GS_PAN;
attribute.value = pan;
attribute.duration = duration;
attribute.flags = 0;
return fDevice->SetAttributes(fSound, &attribute, 1);
}
float
BGameSound::Gain()
{
gs_attribute attribute;
attribute.attribute = B_GS_GAIN;
attribute.flags = 0;
if (fDevice->GetAttributes(fSound, &attribute, 1) != B_OK)
return 0.0;
return attribute.value;
}
float
BGameSound::Pan()
{
gs_attribute attribute;
attribute.attribute = B_GS_PAN;
attribute.flags = 0;
if (fDevice->GetAttributes(fSound, &attribute, 1) != B_OK)
return 0.0;
return attribute.value;
}
status_t
BGameSound::SetAttributes(gs_attribute *inAttributes,
size_t inAttributeCount)
{
return fDevice->SetAttributes(fSound, inAttributes, inAttributeCount);
}
status_t
BGameSound::GetAttributes(gs_attribute *outAttributes,
size_t inAttributeCount)
{
return fDevice->GetAttributes(fSound, outAttributes, inAttributeCount);
}
status_t
BGameSound::Perform(int32 selector,
void *data)
{
return B_ERROR;
}
void *
BGameSound::operator new(size_t size)
{
return ::operator new(size);
}
void *
BGameSound::operator new(size_t size, const std::nothrow_t &nt) throw()
{
return ::operator new(size, nt);
}
void
BGameSound::operator delete(void *ptr)
{
::operator delete(ptr);
}
#if !__MWERKS__
// there's a bug in MWCC under R4.1 and earlier
void
BGameSound::operator delete(void *ptr, const std::nothrow_t &nt) throw()
{
::operator delete(ptr, nt);
}
#endif
status_t
BGameSound::SetMemoryPoolSize(size_t in_poolSize)
{
return B_ERROR;
}
status_t
BGameSound::LockMemoryPool(bool in_lockInCore)
{
return B_ERROR;
}
int32
BGameSound::SetMaxSoundCount(int32 in_maxCount)
{
return in_maxCount;
}
status_t
BGameSound::SetInitError(status_t in_initError)
{
fInitError = in_initError;
return B_OK;
}
status_t
BGameSound::Init(gs_id handle)
{
if (fSound < 0) fSound = handle;
return B_OK;
}
/*
BGameSound &
BGameSound::operator=(const BGameSound &other)
{
if (fSound)
fDevice->ReleaseBuffer(fSound);
fSound = other.fSound;
fInitError = other.fInitError;
return this;
}
*/
/* unimplemented for protection of the user:
*
* BGameSound::BGameSound()
*/
status_t
BGameSound::_Reserved_BGameSound_0(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_1(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_2(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_3(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_4(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_5(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_6(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_7(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_8(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_9(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_10(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_11(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_12(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_13(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_14(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_15(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_16(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_17(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_18(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_19(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_20(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_21(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_22(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_23(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_24(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_25(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_26(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_27(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_28(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_29(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_30(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_31(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_32(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_33(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_34(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_35(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_36(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_37(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_38(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_39(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_40(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_41(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_42(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_43(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_44(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_45(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_46(int32 arg, ...)
{
return B_ERROR;
}
status_t
BGameSound::_Reserved_BGameSound_47(int32 arg, ...)
{
return B_ERROR;
}