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 "platform/C4SoundSystem.h"
21 
22 class C4Object;
23 class C4SoundModifier;
24 
26 {
27  friend class C4SoundInstance;
28 public:
29  C4SoundEffect();
31 public:
33  int32_t Instances{0};
34  int32_t SampleRate, Length;
37  C4SoundEffect *Next{nullptr};
38 public:
39  void Clear();
40  bool Load(const char *szFileName, C4Group &hGroup, const char *namespace_prefix);
41  bool Load(BYTE *pData, size_t iDataLen, bool fRaw=false); // load directly from memory
42  void Execute();
43  C4SoundInstance *New(bool fLoop = false, int32_t iVolume = 100, C4Object *pObj = nullptr, int32_t iCustomFalloffDistance = 0, int32_t iPitch = 0, C4SoundModifier *modifier = nullptr);
46  int32_t GetStartedInstanceCount(int32_t iX, int32_t iY, int32_t iRad); // local
47  int32_t GetStartedInstanceCount(); // global
48 
49  const char *GetFullName() const { return Name; }; // return full name including the path prefix
50 protected:
51  void AddInst(C4SoundInstance *pInst);
52  void RemoveInst(C4SoundInstance *pInst);
53 };
54 
56 {
57  friend class C4SoundEffect;
58  friend class C4SoundSystem;
59  friend class C4SoundModifier;
60 protected:
62 public:
64 protected:
66  int32_t iVolume{0}, iPan{0}, iPitch{0}, iChannel{-1};
67  bool pitch_dirty{false};
70  bool fLooping;
74  bool has_local_modifier{false};
76 
77  // NO_OWNER or a player number signifying which player owns the viewport in which the sound is heard (best)
78  // Note that this does NOT correspond to the player number given in the Sound() script function
79  // (i.e. sounds played only for one player). For example, a global GUI sound would have player==NO_OWNER even if
80  // it is played for a specific player only.
81  int32_t player;
82 public:
83  C4Object *getObj() const { return pObj; }
84  bool isStarted() const { return iChannel != -1; }
85  void Clear();
86  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);
87  bool CheckStart();
88  bool Start();
89  bool Stop();
90  bool Playing();
91  void Execute();
92  void SetVolume(int32_t inVolume) { iVolume = inVolume; }
93  void SetPan(int32_t inPan) { iPan = inPan; }
94  void SetPitch(int32_t inPitch);
95  void SetVolumeByPos(int32_t x, int32_t y);
96  void SetObj(C4Object *pnObj) { pObj = pnObj; }
97  void ClearPointers(C4Object *pObj);
98  bool Inside(int32_t iX, int32_t iY, int32_t iRad);
99  C4SoundModifier *GetModifier() const { return modifier; }
100  void SetModifier(C4SoundModifier *new_modifier, bool is_global);
101  void SetPlayer(int32_t new_player);
102 };
103 
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)