ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
Macros | Functions
Sound.c File Reference
#include <assert.h>
#include <SDL_rwops.h>
#include "Sound.h"

Go to the source code of this file.

Macros

#define _Class   _Sound
 

Functions

Class * _Sound (void)
 
static void dealloc (Object *self)
 
static void initialize (Class *clazz)
 
static SoundinitWithBytes (Sound *self, const uint8_t *bytes, size_t length)
 
static SoundinitWithChunk (Sound *self, Mix_Chunk *chunk)
 
static SoundinitWithData (Sound *self, const Data *data)
 
static SoundinitWithResource (Sound *self, const Resource *resource)
 
static SoundinitWithResourceName (Sound *self, const char *name)
 
static SoundsoundWithBytes (const uint8_t *bytes, size_t length)
 
static SoundsoundWithChunk (Mix_Chunk *chunk)
 
static SoundsoundWithData (const Data *data)
 
static SoundsoundWithResource (const Resource *resource)
 
static SoundsoundWithResourceName (const char *name)
 

Macro Definition Documentation

◆ _Class

#define _Class   _Sound

Definition at line 30 of file Sound.c.

Function Documentation

◆ _Sound()

Class * _Sound ( void  )

Definition at line 190 of file Sound.c.

190 {
191 static Class *clazz;
192 static Once once;
193
194 do_once(&once, {
195 clazz = _initialize(&(const ClassDef) {
196 .name = "Sound",
197 .superclass = _Object(),
198 .instanceSize = sizeof(Sound),
199 .interfaceOffset = offsetof(Sound, interface),
200 .interfaceSize = sizeof(SoundInterface),
202 });
203 });
204
205 return clazz;
206}
static void initialize(Class *clazz)
Definition: Sound.c:169
Sound loading and playback.
Definition: Sound.h:45

◆ dealloc()

static void dealloc ( Object *  self)
static
See also
Object::dealloc(Object *)

Definition at line 37 of file Sound.c.

37 {
38
39 Sound *this = (Sound *) self;
40
41 Mix_FreeChunk(this->chunk);
42
43 super(Object, self, dealloc);
44}
static void dealloc(Object *self)
Definition: Sound.c:37

◆ initialize()

static void initialize ( Class *  clazz)
static
See also
Class::initialize(Class *)

Definition at line 169 of file Sound.c.

169 {
170
171 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
172
173 ((SoundInterface *) clazz->interface)->initWithBytes = initWithBytes;
174 ((SoundInterface *) clazz->interface)->initWithChunk = initWithChunk;
175 ((SoundInterface *) clazz->interface)->initWithData = initWithData;
176 ((SoundInterface *) clazz->interface)->initWithResource = initWithResource;
177 ((SoundInterface *) clazz->interface)->initWithResourceName = initWithResourceName;
178
179 ((SoundInterface *) clazz->interface)->soundWithBytes = soundWithBytes;
180 ((SoundInterface *) clazz->interface)->soundWithChunk = soundWithChunk;
181 ((SoundInterface *) clazz->interface)->soundWithData = soundWithData;
182 ((SoundInterface *) clazz->interface)->soundWithResource = soundWithResource;
183 ((SoundInterface *) clazz->interface)->soundWithResourceName = soundWithResourceName;
184}
Font * initWithData(Font *self, Data *data, int size, int index)
Image * initWithResourceName(Image *self, const char *name)
Initializes this Image, loading the Resource by the given name.
Definition: Image.c:142
Image * initWithBytes(Image *self, const uint8_t *bytes, size_t length)
Initializes this Image with the specified bytes.
Definition: Image.c:88
Image * initWithResource(Image *self, const Resource *resource)
Initializes this Image with the specified Resource.
Definition: Image.c:126
Sound * soundWithData(const Data *data)
Instantiates an Sound with the specified Data.
Definition: Sound.c:144
Sound * soundWithResourceName(const char *name)
Instantiates an Sound with the specified Resource name.
Definition: Sound.c:160
Sound * soundWithBytes(const uint8_t *bytes, size_t length)
Instantiates an Sound with the specified bytes.
Definition: Sound.c:128
Sound * initWithChunk(Sound *, const Chunk *)
Initializes this Sound with the given audio chunk.
Sound * initWithData(Sound *, Data *)
Sound * soundWithResource(const Resource *resource)
Instantiates an Sound with the specified Resource.
Definition: Sound.c:152
Sound * soundWithChunk(Mix_Chunk *chunk)
Instantiates an Sound with the specified chunk.
Definition: Sound.c:136

◆ initWithBytes()

static Sound * initWithBytes ( Sound self,
const uint8_t *  bytes,
size_t  length 
)
static

Definition at line 52 of file Sound.c.

52 {
53
54 SDL_RWops *src = SDL_RWFromConstMem(bytes, (int) length);
55 if (src) {
56 self = $(self, initWithChunk, Mix_LoadWAV_RW(src, 1));
57 } else {
58 self = release(self);
59 }
60
61 return self;
62}

◆ initWithChunk()

static Sound * initWithChunk ( Sound self,
Mix_Chunk *  chunk 
)
static

Definition at line 83 of file Sound.c.

83 {
84
85 self = (Sound *) super(Object, self, init);
86 if (self) {
87 self->chunk = chunk;
88 assert(self->chunk);
89 }
90
91 return self;
92}
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
Mix_Chunk * chunk
The backing audio chunk.
Definition: Sound.h:61

◆ initWithData()

static Sound * initWithData ( Sound self,
const Data *  data 
)
static

Definition at line 68 of file Sound.c.

68 {
69
70 if (data) {
71 self = $(self, initWithBytes, data->bytes, data->length);
72 } else {
73 self = release(self);
74 }
75
76 return self;
77}

◆ initWithResource()

static Sound * initWithResource ( Sound self,
const Resource *  resource 
)
static

Definition at line 98 of file Sound.c.

98 {
99
100 if (resource) {
101 self = $(self, initWithData, resource->data);
102 } else {
103 self = release(self);
104 }
105
106 return self;
107}
Data * data
The raw font data.
Definition: Font.h:79

◆ initWithResourceName()

static Sound * initWithResourceName ( Sound self,
const char *  name 
)
static

Definition at line 113 of file Sound.c.

113 {
114
115 Resource *resource = $$(Resource, resourceWithName, name);
116
117 self = $(self, initWithResource, resource);
118
119 release(resource);
120
121 return self;
122}

◆ soundWithBytes()

static Sound * soundWithBytes ( const uint8_t *  bytes,
size_t  length 
)
static

Definition at line 128 of file Sound.c.

128 {
129 return $(alloc(Sound), initWithBytes, bytes, length);
130}

◆ soundWithChunk()

static Sound * soundWithChunk ( Mix_Chunk *  chunk)
static

Definition at line 136 of file Sound.c.

136 {
137 return $(alloc(Sound), initWithChunk, chunk);
138}

◆ soundWithData()

static Sound * soundWithData ( const Data *  data)
static

Definition at line 144 of file Sound.c.

144 {
145 return $(alloc(Sound), initWithData, data);
146}

◆ soundWithResource()

static Sound * soundWithResource ( const Resource *  resource)
static

Definition at line 152 of file Sound.c.

152 {
153 return $(alloc(Sound), initWithResource, resource);
154}

◆ soundWithResourceName()

static Sound * soundWithResourceName ( const char *  name)
static

Definition at line 160 of file Sound.c.

160 {
161 return $(alloc(Sound), initWithResourceName, name);
162}