OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4SoundInstance.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Helper classes for individual sounds and effects in sound system. */
19 
20 #include "C4Include.h"
21 
22 #include "platform/C4SoundSystem.h"
23 
24 class C4Object;
25 class C4SoundModifier;
26 
28 {
29  friend class C4SoundInstance;
30 public:
31  C4SoundEffect();
33 public:
35  int32_t Instances;
36  int32_t SampleRate, Length;
40 public:
41  void Clear();
42  bool Load(const char *szFileName, C4Group &hGroup, const char *namespace_prefix);
43  bool Load(BYTE *pData, size_t iDataLen, bool fRaw=false); // load directly from memory
44  void Execute();
45  C4SoundInstance *New(bool fLoop = false, int32_t iVolume = 100, C4Object *pObj = nullptr, int32_t iCustomFalloffDistance = 0, int32_t iPitch = 0, C4SoundModifier *modifier = nullptr);
48  int32_t GetStartedInstanceCount(int32_t iX, int32_t iY, int32_t iRad); // local
49  int32_t GetStartedInstanceCount(); // global
50 
51  const char *GetFullName() const { return Name; }; // return full name including the path prefix
52 protected:
53  void AddInst(C4SoundInstance *pInst);
54  void RemoveInst(C4SoundInstance *pInst);
55 };
56 
58 {
59  friend class C4SoundEffect;
60  friend class C4SoundSystem;
61  friend class C4SoundModifier;
62 protected:
64 public:
66 protected:
72  bool fLooping;
78 
79  // NO_OWNER or a player number signifying which player owns the viewport in which the sound is heard (best)
80  // Note that this does NOT correspond to the player number given in the Sound() script function
81  // (i.e. sounds played only for one player). For example, a global GUI sound would have player==NO_OWNER even if
82  // it is played for a specific player only.
83  int32_t player;
84 public:
85  C4Object *getObj() const { return pObj; }
86  bool isStarted() const { return iChannel != -1; }
87  void Clear();
88  bool Create(C4SoundEffect *pEffect, bool fLoop = false, int32_t iVolume = 100, C4Object *pObj = nullptr, int32_t iNearInstanceMax = 0, int32_t iFalloffDistance = 0, int32_t inPitch = 0, C4SoundModifier *modifier = nullptr);
89  bool CheckStart();
90  bool Start();
91  bool Stop();
92  bool Playing();
93  void Execute();
94  void SetVolume(int32_t inVolume) { iVolume = inVolume; }
95  void SetPan(int32_t inPan) { iPan = inPan; }
96  void SetPitch(int32_t inPitch);
97  void SetVolumeByPos(int32_t x, int32_t y);
98  void SetObj(C4Object *pnObj) { pObj = pnObj; }
99  void ClearPointers(C4Object *pObj);
100  bool Inside(int32_t iX, int32_t iY, int32_t iRad);
101  C4SoundModifier *GetModifier() const { return modifier; }
102  void SetModifier(C4SoundModifier *new_modifier, bool is_global);
103  void SetPlayer(int32_t new_player);
104 };
105 
C4SoundModifier * modifier
bool Create(C4SoundEffect *pEffect, bool fLoop=false, int32_t iVolume=100, C4Object *pObj=nullptr, int32_t iNearInstanceMax=0, int32_t iFalloffDistance=0, int32_t inPitch=0, C4SoundModifier *modifier=nullptr)
C4SoundHandle pSample
void ClearPointers(C4Object *pObj)
void ClearPointers(C4Object *pObj)
void SetPlayer(int32_t new_player)
int32_t SampleRate
uint8_t BYTE
char Name[C4MaxSoundName+1]
void SetPitch(int32_t inPitch)
int32_t iFalloffDistance
C4SoundInstance * GetInstance(C4Object *pObj)
bool isStarted() const
const int32_t C4MaxSoundName
Definition: C4SoundSystem.h:27
C4SoundInstance * pNext
int32_t GetStartedInstanceCount()
C4SoundEffect * Next
struct Mix_Chunk * C4SoundHandle
void AddInst(C4SoundInstance *pInst)
bool Load(const char *szFileName, C4Group &hGroup, const char *namespace_prefix)
void SetObj(C4Object *pnObj)
C4SoundInstance * New(bool fLoop=false, int32_t iVolume=100, C4Object *pObj=nullptr, int32_t iCustomFalloffDistance=0, int32_t iPitch=0, C4SoundModifier *modifier=nullptr)
void SetPan(int32_t inPan)
bool Inside(int32_t iX, int32_t iY, int32_t iRad)
void RemoveInst(C4SoundInstance *pInst)
void SetVolume(int32_t inVolume)
C4SoundInstance * FirstInst
C4SoundEffect * pEffect
C4Object * getObj() const
const char * GetFullName() const
int32_t iNearInstanceMax
C4SoundModifier * GetModifier() const
void SetVolumeByPos(int32_t x, int32_t y)
C4TimeMilliseconds tStarted
void SetModifier(C4SoundModifier *new_modifier, bool is_global)