update to latest Zig (zig fmt)

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2023-06-25 00:01:55 -07:00
parent 419d82d5fd
commit 29964c99bb
39 changed files with 156 additions and 156 deletions

View file

@ -311,7 +311,7 @@ pub const Context = struct {
var ctl: ?*c.snd_ctl_t = undefined;
_ = switch (-lib.snd_ctl_open(&ctl, card_id.ptr, 0)) {
0 => {},
@enumToInt(std.os.E.NOENT) => break,
@intFromEnum(std.os.E.NOENT) => break,
else => return error.OpeningDevice,
};
defer _ = lib.snd_ctl_close(ctl);
@ -328,7 +328,7 @@ pub const Context = struct {
const snd_stream = modeToStream(mode);
lib.snd_pcm_info_set_stream(pcm_info, snd_stream);
const err = lib.snd_ctl_pcm_info(ctl, pcm_info);
switch (@intToEnum(std.os.E, -err)) {
switch (@enumFromInt(std.os.E, -err)) {
.SUCCESS => {},
.NOENT,
.NXIO,
@ -622,10 +622,10 @@ pub const Player = struct {
if (lib.snd_mixer_selem_get_playback_volume_range(self.mixer_elm, &min_vol, &max_vol) < 0)
return error.CannotSetVolume;
const dist = @intToFloat(f32, max_vol - min_vol);
const dist = @floatFromInt(f32, max_vol - min_vol);
if (lib.snd_mixer_selem_set_playback_volume_all(
self.mixer_elm,
@floatToInt(c_long, dist * vol) + min_vol,
@intFromFloat(c_long, dist * vol) + min_vol,
) < 0)
return error.CannotSetVolume;
}
@ -652,7 +652,7 @@ pub const Player = struct {
if (lib.snd_mixer_selem_get_playback_volume_range(self.mixer_elm, &min_vol, &max_vol) < 0)
return error.CannotGetVolume;
return @intToFloat(f32, vol) / @intToFloat(f32, max_vol - min_vol);
return @floatFromInt(f32, vol) / @floatFromInt(f32, max_vol - min_vol);
}
};

View file

@ -210,8 +210,8 @@ pub const Context = struct {
.channels = channels,
.formats = &.{ .i16, .i32, .f32 },
.sample_rate = .{
.min = @floatToInt(u24, @floor(sample_rate)),
.max = @floatToInt(u24, @floor(sample_rate)),
.min = @intFromFloat(u24, @floor(sample_rate)),
.max = @intFromFloat(u24, @floor(sample_rate)),
},
};
@ -412,7 +412,7 @@ fn freeDevice(allocator: std.mem.Allocator, device: main.Device) void {
fn createStreamDesc(format: main.Format, sample_rate: u24, ch_count: usize) !c.AudioStreamBasicDescription {
var desc = c.AudioStreamBasicDescription{
.mSampleRate = @intToFloat(f64, sample_rate),
.mSampleRate = @floatFromInt(f64, sample_rate),
.mFormatID = c.kAudioFormatLinearPCM,
.mFormatFlags = switch (format) {
.i16 => c.kAudioFormatFlagIsSignedInteger,

View file

@ -142,7 +142,7 @@ pub const Context = struct {
for (self.devices_info.list.items) |*dev| {
if (std.mem.eql(u8, dev.id, id) and mode == dev.mode) {
const new_ch = main.Channel{
.id = @intToEnum(main.Channel.Id, dev.channels.len),
.id = @enumFromInt(main.Channel.Id, dev.channels.len),
};
dev.channels = try self.allocator.realloc(dev.channels, dev.channels.len + 1);
dev.channels[dev.channels.len - 1] = new_ch;
@ -156,7 +156,7 @@ pub const Context = struct {
.mode = mode,
.channels = blk: {
var channels = try self.allocator.alloc(main.Channel, 1);
channels[0] = .{ .id = @intToEnum(main.Channel.Id, 0) };
channels[0] = .{ .id = @enumFromInt(main.Channel.Id, 0) };
break :blk channels;
},
.formats = &.{.f32},

View file

@ -37,7 +37,7 @@ pub const Context = struct {
} else {
inline for (std.meta.fields(Backend), 0..) |b, i| {
if (@typeInfo(
std.meta.fieldInfo(backends.BackendContext, @intToEnum(Backend, b.value)).type,
std.meta.fieldInfo(backends.BackendContext, @enumFromInt(Backend, b.value)).type,
).Pointer.child.init(allocator, options)) |d| {
break :blk d;
} else |err| {
@ -280,7 +280,7 @@ fn unsignedToSigned(comptime T: type, sample: anytype) T {
fn unsignedToFloat(comptime T: type, sample: anytype) T {
const max_int = std.math.maxInt(@TypeOf(sample)) + 1.0;
return (@intToFloat(T, sample) - max_int) * 1.0 / max_int;
return (@floatFromInt(T, sample) - max_int) * 1.0 / max_int;
}
fn signedToSigned(comptime T: type, sample: anytype) T {
@ -296,16 +296,16 @@ fn signedToUnsigned(comptime T: type, sample: anytype) T {
fn signedToFloat(comptime T: type, sample: anytype) T {
const max_int = std.math.maxInt(@TypeOf(sample)) + 1.0;
return @intToFloat(T, sample) * 1.0 / max_int;
return @floatFromInt(T, sample) * 1.0 / max_int;
}
fn floatToSigned(comptime T: type, sample: f64) T {
return @floatToInt(T, sample * std.math.maxInt(T));
return @intFromFloat(T, sample * std.math.maxInt(T));
}
fn floatToUnsigned(comptime T: type, sample: f64) T {
const half = 1 << @bitSizeOf(T) - 1;
return @floatToInt(T, sample * (half - 1) + half);
return @intFromFloat(T, sample * (half - 1) + half);
}
pub const Device = struct {

View file

@ -208,7 +208,7 @@ pub const Context = struct {
c.PW_KEY_AUDIO_RATE,
audio_rate.ptr,
@intToPtr(*allowzero u0, 0),
@ptrFromInt(*allowzero u0, 0),
);
var player = try self.allocator.create(Player);

View file

@ -564,7 +564,7 @@ pub const Player = struct {
return;
}
self.vol = @intToFloat(f32, info.*.volume.values[0]) / @intToFloat(f32, c.PA_VOLUME_NORM);
self.vol = @floatFromInt(f32, info.*.volume.values[0]) / @floatFromInt(f32, c.PA_VOLUME_NORM);
}
};

View file

@ -99,7 +99,7 @@ pub const Context = struct {
fn queryInterfaceCB(self: *const win32.IUnknown, riid: ?*const win32.Guid, ppv: ?*?*anyopaque) callconv(std.os.windows.WINAPI) win32.HRESULT {
if (riid.?.eql(win32.IID_IUnknown.*) or riid.?.eql(win32.IID_IMMNotificationClient.*)) {
ppv.?.* = @intToPtr(?*anyopaque, @ptrToInt(self));
ppv.?.* = @ptrFromInt(?*anyopaque, @intFromPtr(self));
_ = self.AddRef();
return win32.S_OK;
} else {

View file

@ -87,7 +87,7 @@ pub const Context = struct {
errdefer self.allocator.destroy(player);
var captures = try self.allocator.alloc(js.Value, 1);
captures[0] = js.createNumber(@ptrToInt(player));
captures[0] = js.createNumber(@intFromPtr(player));
const document = js.global().get("document").view(.object);
defer document.deinit();
@ -163,7 +163,7 @@ pub const Player = struct {
}
fn resumeOnClick(args: js.Object, _: usize, captures: []js.Value) js.Value {
const self = @intToPtr(*Player, @floatToInt(usize, captures[0].view(.num)));
const self = @ptrFromInt(*Player, @intFromFloat(usize, captures[0].view(.num)));
self.play() catch {};
const document = js.global().get("document").view(.object);
@ -177,7 +177,7 @@ pub const Player = struct {
}
fn audioProcessEvent(args: js.Object, _: usize, captures: []js.Value) js.Value {
const self = @intToPtr(*Player, @floatToInt(usize, captures[0].view(.num)));
const self = @ptrFromInt(*Player, @intFromFloat(usize, captures[0].view(.num)));
const event = args.getIndex(0).view(.object);
defer event.deinit();