diff options
Diffstat (limited to 'src/al.zig')
-rw-r--r-- | src/al.zig | 73 |
1 files changed, 55 insertions, 18 deletions
diff --git a/src/al.zig b/src/al.zig index bbde02e..a5164d6 100644 --- a/src/al.zig +++ b/src/al.zig @@ -16,7 +16,9 @@ // You should have received a copy of the GNU Lesser General Public License // along with zeal. If not, see <https://www.gnu.org/licenses/>. -const Child = @import("std").meta.Child; +const Child = meta.Child; +const Tag = meta.Tag; +const meta = @import("std").meta; usingnamespace @cImport({ @cInclude("AL/al.h"); @@ -36,21 +38,23 @@ pub const Error = error { OutOfMemory, }; +// FIXME: turn into enum pub const FALSE = AL_FALSE; pub const TRUE = AL_TRUE; pub const AUTO = AL_AUTO_SOFT; -pub const BUFFER = AL_BUFFER; -pub const POSITION = AL_POSITION; -pub const ORIENTATION = AL_ORIENTATION; -pub const PLAYING = AL_PLAYING; -pub const SEC_OFFSET = AL_SEC_OFFSET; -pub const SOURCE_STATE = AL_SOURCE_STATE; -pub const SOURCE_SPATIALIZE = AL_SOURCE_SPATIALIZE_SOFT; - pub const listener = struct { + const Property = enum(ALenum) { + gain = AL_GAIN, + position = AL_POSITION, + velocity = AL_VELOCITY, + orientation = AL_ORIENTATION, + meters_per_unit = AL_METERS_PER_UNIT, + }; + /// Set a property for the listener. - pub fn set(param: ALenum, value: anytype) Error!void { + pub fn set(property: Property, value: anytype) Error!void { + const param = @enumToInt(property); const T = @TypeOf(value); switch (T) { f32 => alListenerf(param, value), @@ -165,17 +169,42 @@ pub const source = struct { } } + const Property = enum(ALenum) { + pitch = AL_PITCH, + gain = AL_GAIN, + position = AL_POSITION, + velocity = AL_VELOCITY, + direction = AL_DIRECTION, + relative = AL_SOURCE_RELATIVE, + looping = AL_LOOPING, + buffer = AL_BUFFER, + state = AL_SOURCE_STATE, + sec_offset = AL_SEC_OFFSET, + spatialize = AL_SOURCE_SPATIALIZE_SOFT, + }; + + pub const State = enum(i32) { + initial = AL_INITIAL, + playing = AL_PLAYING, + paused = AL_PAUSED, + stopped = AL_STOPPED, + }; + /// Set a property for the source. - pub fn set(reference: u32, param: ALenum, value: anytype) Error!void { + pub fn set(reference: u32, property: Property, value: anytype) Error!void { + const param = @enumToInt(property); const T = @TypeOf(value); switch (T) { f32 => alSourcef(reference, param, value), i32 => alSourcei(reference, param, value), - else => switch (Child(T)) { - f32 => alSourcefv(reference, param, value[0..]), - i32 => alSourceiv(reference, param, value[0..]), - else => unreachable, - } + else => switch (@typeInfo(T)) { + .Enum => alSourcei(reference, param, @enumToInt(value)), + else => switch (Child(T)) { + f32 => alSourcefv(reference, param, value[0..]), + i32 => alSourceiv(reference, param, value[0..]), + else => unreachable, + }, + }, } switch (alGetError()) { @@ -189,12 +218,20 @@ pub const source = struct { } /// Get a scalar property from the source. - pub fn get(comptime T: type, reference: u32, param: ALenum) Error!T { + pub fn get(comptime T: type, reference: u32, property: Property) Error!T { + const param = @enumToInt(property); var value: T = undefined; switch (T) { f32 => alGetSourcef(reference, param, &value), i32 => alGetSourcei(reference, param, &value), - else => unreachable, + else => switch (@typeInfo(T)) { + .Enum => { + var raw: i32 = undefined; + alGetSourcei(reference, param, &raw); + value = @intToEnum(T, raw); + }, + else => unreachable, + }, } return switch (alGetError()) { |