OpenClonk
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 #ifndef INC_C4SoundInstance
21 #define INC_C4SoundInstance
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{0};
36  int32_t SampleRate, Length;
39  C4SoundEffect *Next{nullptr};
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:
68  int32_t iVolume{0}, iPan{0}, iPitch{0}, iChannel{-1};
69  bool pitch_dirty{false};
72  bool fLooping;
76  bool has_local_modifier{false};
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, int32_t relative_volume = 100);
98  void SetObj(C4Object *pnObj) { pObj = pnObj; }
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 
106 #endif
struct Mix_Chunk * C4SoundHandle
const int32_t C4MaxSoundName
Definition: C4SoundSystem.h:27
uint8_t BYTE
void RemoveInst(C4SoundInstance *pInst)
int32_t SampleRate
bool Load(const char *szFileName, C4Group &hGroup, const char *namespace_prefix)
const char * GetFullName() const
int32_t GetStartedInstanceCount()
C4SoundInstance * New(bool fLoop=false, int32_t iVolume=100, C4Object *pObj=nullptr, int32_t iCustomFalloffDistance=0, int32_t iPitch=0, C4SoundModifier *modifier=nullptr)
void ClearPointers(C4Object *pObj)
C4SoundInstance * GetInstance(C4Object *pObj)
char Name[C4MaxSoundName+1]
C4SoundHandle pSample
void AddInst(C4SoundInstance *pInst)
C4SoundInstance * FirstInst
C4SoundEffect * Next
void SetVolume(int32_t inVolume)
void SetVolumeByPos(int32_t x, int32_t y, int32_t relative_volume=100)
C4Object * getObj() const
void SetPitch(int32_t inPitch)
C4SoundModifier * GetModifier() const
void SetObj(C4Object *pnObj)
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)
C4SoundInstance * pNext
int32_t iNearInstanceMax
void SetPan(int32_t inPan)
C4SoundModifier * modifier
C4TimeMilliseconds tStarted
C4SoundEffect * pEffect
void SetModifier(C4SoundModifier *new_modifier, bool is_global)
void ClearPointers(C4Object *pObj)
int32_t iFalloffDistance
void SetPlayer(int32_t new_player)
bool isStarted() const
bool Inside(int32_t iX, int32_t iY, int32_t iRad)