sonnum/zigsonnum/activity.zig

52 lines
No EOL
1.2 KiB
Zig

const std = @import("std");
const math = std.math;
const print = std.debug.print;
const Allocator = std.mem.Allocator;
const SoundNode = @import("soundnode.zig").SoundNode;
const FreqAmpBuffer = @import("freqamp.zig").FreqAmpBuffer;
const utility = @import("utility.zig");
const basicsynths = @import ("activities/basicsynths.zig");
const spatial = @import ("activities/spatial.zig");
pub const Activity = struct {
start_tick: u32,
end_tick: u32,
opcode: u16,
soundnode: *SoundNode,
operands: [6]f64 = std.mem.zeroes([6]f64),
pub fn create(allocator: Allocator, start_tick: u32, end_tick: u32, opcode: u16, soundnode: *SoundNode, operands: [6]f64) !*Activity {
const a = try allocator.create(Activity);
a.* = .{
.start_tick = start_tick,
.end_tick = end_tick,
.opcode = opcode,
.soundnode = soundnode,
.operands = operands,
};
return a;
}
pub fn do(self: *Activity) !void {
switch (self.opcode) {
4 => { self.relay(); },
10 => { spatial.setpos(self); },
50 => { basicsynths.sine(self); },
51 => { basicsynths.triangle(self); },
else => {},
}
}
pub fn relay(self: *Activity) void {
self.soundnode.add_r_amp(self.soundnode.in_wire);
self.soundnode.add_r_amp(self.soundnode.in_air);
}
};