improvements
This commit is contained in:
parent
58ac740143
commit
9f4fad0707
6 changed files with 120 additions and 70 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
s.setup(100)
|
s.setup(10)
|
||||||
|
|
||||||
;0 s.left.@setgain(0.7)
|
;0 s.left.@setgain(0.7)
|
||||||
;0 s.right.@setgain(0.7)
|
;0 s.right.@setgain(0.7)
|
||||||
|
|
||||||
ns = []
|
ns = []
|
||||||
for k in range(0, 100):
|
for k in range(0, 9):
|
||||||
n = s.node(20)
|
n = s.node(20)
|
||||||
ns.append(n)
|
ns.append(n)
|
||||||
;n->s.left
|
;n->s.left
|
||||||
|
|
@ -15,8 +15,12 @@ for k in range(0, 100):
|
||||||
;0 n.setpos(1,1,1)
|
;0 n.setpos(1,1,1)
|
||||||
;0 n.setpin(52, 0.9)
|
;0 n.setpin(52, 0.9)
|
||||||
|
|
||||||
for i in range(0,20):
|
for i in range(0,40):
|
||||||
;0 n.@setfreq(i, s.note("C3")*(i+1))
|
;0 n.@setfreq(i, s.note("C3")*(i+1))
|
||||||
;0 n.@setfreqgain(i, 1/float(i+1))
|
;0 n.@setfreqgain(i, 1/float(i+1))
|
||||||
|
;n-/>s.left
|
||||||
|
;n-/>s.right
|
||||||
|
|
||||||
;0-9 ns[4].sine()
|
;ns[4]->s.left
|
||||||
|
;ns[4]->s.right
|
||||||
|
;0-90 ns[4].sine()
|
||||||
|
|
@ -5,6 +5,7 @@ OPCODES['create'] = 0
|
||||||
OPCODES['endtick'] = 2
|
OPCODES['endtick'] = 2
|
||||||
OPCODES['link'] = 1
|
OPCODES['link'] = 1
|
||||||
OPCODES['setpin'] = 3
|
OPCODES['setpin'] = 3
|
||||||
|
OPCODES['unlink'] = 8
|
||||||
OPCODES['printstate'] = 9
|
OPCODES['printstate'] = 9
|
||||||
|
|
||||||
with open("zigsonnum/activity.zig", 'r') as zigfl:
|
with open("zigsonnum/activity.zig", 'r') as zigfl:
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,16 @@ class SonnumCompiler:
|
||||||
name_src, name_trg = ln[1:].split('->')
|
name_src, name_trg = ln[1:].split('->')
|
||||||
ln = f'self.add_activity("link", 0, 0, {name_src}, {name_trg}, [0, 2])'
|
ln = f'self.add_activity("link", 0, 0, {name_src}, {name_trg}, [0, 2])'
|
||||||
|
|
||||||
|
elif '=/>' in ln:
|
||||||
|
|
||||||
|
name_src, name_trg = ln[1:].split('=/>')
|
||||||
|
ln = f'self.add_activity("unlink", 0, 0, {name_src}, {name_trg}, [0, 1])'
|
||||||
|
|
||||||
|
elif '-/>' in ln:
|
||||||
|
|
||||||
|
name_src, name_trg = ln[1:].split('-/>')
|
||||||
|
ln = f'self.add_activity("unlink", 0, 0, {name_src}, {name_trg}, [0, 2])'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
ln = ln[1:]
|
ln = ln[1:]
|
||||||
|
|
|
||||||
|
|
@ -156,9 +156,12 @@ pub fn main() !void {
|
||||||
print("{d}-- ", .{tick/44100});
|
print("{d}-- ", .{tick/44100});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (soundnodes.items, 0..) |soundnode, i| {
|
|
||||||
soundnode.nullizeStartTick();
|
for (a_soundnodes.items, 0..) |soundnode, i| {
|
||||||
|
//print("TICK {d} I {d} ", .{tick, i});
|
||||||
|
@memset(soundnode.pins[0..32], 0);
|
||||||
_ = i;
|
_ = i;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tick == nextopcodetick) {
|
if (tick == nextopcodetick) {
|
||||||
|
|
@ -272,6 +275,31 @@ pub fn main() !void {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
8 => {
|
||||||
|
const src = soundnodes.items[src_node];
|
||||||
|
const trg = soundnodes.items[trg_node];
|
||||||
|
//print("Wired nodes at tick {d}\n", .{tick});
|
||||||
|
|
||||||
|
const src_pin: usize = @intFromFloat(op1);
|
||||||
|
const trg_pin: usize = @intFromFloat(op2);
|
||||||
|
|
||||||
|
var found: bool = false;
|
||||||
|
var toremove: u64 = 0;
|
||||||
|
|
||||||
|
for (trg.links.items, 0..) |link, j| {
|
||||||
|
if (link.src_node == src and link.trg_node == trg and link.src_pin == src_pin and link.trg_pin == trg_pin) {
|
||||||
|
toremove = j;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found) {
|
||||||
|
_ = trg.links.orderedRemove(toremove);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
else => {
|
else => {
|
||||||
|
|
||||||
const soundnode = soundnodes.items[src_node];
|
const soundnode = soundnodes.items[src_node];
|
||||||
|
|
@ -281,6 +309,7 @@ pub fn main() !void {
|
||||||
try soundnode.activities.append(a);
|
try soundnode.activities.append(a);
|
||||||
|
|
||||||
if (soundnode.activities.items.len == 1 and soundnode.active == 0) {
|
if (soundnode.activities.items.len == 1 and soundnode.active == 0) {
|
||||||
|
|
||||||
soundnode.active = 1;
|
soundnode.active = 1;
|
||||||
try reactivateSoundNode(&a_soundnodes, &p_soundnodes, soundnode);
|
try reactivateSoundNode(&a_soundnodes, &p_soundnodes, soundnode);
|
||||||
|
|
||||||
|
|
@ -296,56 +325,62 @@ pub fn main() !void {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//All but left and right
|
//All but left and right
|
||||||
|
|
||||||
if (a_soundnodes.items.len > 2) {
|
var iter: usize = 1;
|
||||||
|
//while (iter < 0) {
|
||||||
|
|
||||||
for (a_soundnodes.items[2..], 0..) |soundnode, i| {
|
while (iter < a_soundnodes.items.len - 1) {
|
||||||
|
|
||||||
for (soundnode.links.items, 0..) |link, j| {
|
iter += 1;
|
||||||
|
const soundnode = a_soundnodes.items[iter];
|
||||||
|
|
||||||
|
for (soundnode.links.items, 0..) |link, j| {
|
||||||
|
|
||||||
|
if (link.src_node.active == 1 or link.trg_pin == 1) {
|
||||||
|
link.propagate();
|
||||||
|
|
||||||
if (link.src_node.active == 1 or link.trg_pin == 1) {
|
|
||||||
link.propagate();
|
|
||||||
}
|
|
||||||
_ = j;
|
|
||||||
}
|
}
|
||||||
|
_ = j;
|
||||||
|
}
|
||||||
|
|
||||||
var toremove = ArrayList(usize).init(allocator);
|
var toremove = ArrayList(usize).init(allocator);
|
||||||
defer toremove.deinit();
|
defer toremove.deinit();
|
||||||
|
|
||||||
for (soundnode.activities.items, 0..) |activity, j| {
|
for (soundnode.activities.items, 0..) |activity, j| {
|
||||||
|
|
||||||
if (tick <= activity.end_tick and tick >= activity.start_tick) {
|
if (tick <= activity.end_tick and tick >= activity.start_tick) {
|
||||||
try activity.do();
|
try activity.do();
|
||||||
} else if (tick >= activity.end_tick) {
|
} else if (tick >= activity.end_tick) {
|
||||||
try toremove.append(j);
|
try toremove.append(j);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (soundnode.wantprint == true) {
|
if (soundnode.wantprint == true) {
|
||||||
soundnode.wantprint = false;
|
soundnode.wantprint = false;
|
||||||
soundnode.printState();
|
soundnode.printState();
|
||||||
}
|
}
|
||||||
|
|
||||||
var j: usize = toremove.items.len;
|
var j: usize = toremove.items.len;
|
||||||
|
|
||||||
while (j > 0) {
|
|
||||||
j -= 1;
|
|
||||||
const activity_ind = toremove.items[j];
|
|
||||||
|
|
||||||
_ = soundnode.activities.swapRemove(activity_ind);
|
|
||||||
|
|
||||||
if (soundnode.activities.items.len == 0 and soundnode.active == 1) {
|
|
||||||
|
|
||||||
soundnode.active = 0;
|
|
||||||
try deactivateSoundNode(&a_soundnodes, &p_soundnodes, soundnode);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (j == 0) {
|
||||||
soundnode.fab.increment_tick();
|
soundnode.fab.increment_tick();
|
||||||
_ = i;
|
}
|
||||||
|
|
||||||
|
while (j > 0) {
|
||||||
|
|
||||||
|
j -= 1;
|
||||||
|
const activity_ind = toremove.items[j];
|
||||||
|
|
||||||
|
_ = soundnode.activities.swapRemove(activity_ind);
|
||||||
|
|
||||||
|
if (soundnode.activities.items.len == 0 and soundnode.active == 1) {
|
||||||
|
|
||||||
|
soundnode.active = 0;
|
||||||
|
try deactivateSoundNode(&a_soundnodes, &p_soundnodes, soundnode);
|
||||||
|
|
||||||
|
//print("DEACTIVATING {d} AT TICK {d} ", .{soundnode.uid, tick});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -355,11 +390,18 @@ pub fn main() !void {
|
||||||
for (p_soundnodes.items, 0..) |soundnode, i| {
|
for (p_soundnodes.items, 0..) |soundnode, i| {
|
||||||
soundnode.fab.increment_tick();
|
soundnode.fab.increment_tick();
|
||||||
_ = i;
|
_ = i;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Left and right
|
//Left and right
|
||||||
|
|
||||||
for (soundnodes.items[0..2], 0..) |soundnode, i| {
|
iter = 0;
|
||||||
|
|
||||||
|
//while (iter < 0) {
|
||||||
|
while (iter < 2) {
|
||||||
|
|
||||||
|
const soundnode = soundnodes.items[iter];
|
||||||
|
iter += 1;
|
||||||
|
|
||||||
for (soundnode.links.items, 0..) |link, jz| {
|
for (soundnode.links.items, 0..) |link, jz| {
|
||||||
if (link.src_node.active == 1 or link.trg_pin == 1) {
|
if (link.src_node.active == 1 or link.trg_pin == 1) {
|
||||||
|
|
@ -394,7 +436,6 @@ pub fn main() !void {
|
||||||
_ = soundnode.activities.swapRemove(activity_ind);
|
_ = soundnode.activities.swapRemove(activity_ind);
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Calculating and writing output amps
|
//Calculating and writing output amps
|
||||||
|
|
@ -426,6 +467,8 @@ pub fn main() !void {
|
||||||
|
|
||||||
left.fab.current_tick += 1;
|
left.fab.current_tick += 1;
|
||||||
right.fab.current_tick += 1;
|
right.fab.current_tick += 1;
|
||||||
|
|
||||||
|
|
||||||
tick += 1;
|
tick += 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ pub const SoundNode = struct {
|
||||||
wantprint: bool = false,
|
wantprint: bool = false,
|
||||||
|
|
||||||
fab: FreqAmpBuffer,
|
fab: FreqAmpBuffer,
|
||||||
active: u8 = 1,
|
active: u8 = 0,
|
||||||
|
|
||||||
|
|
||||||
pub fn create(allocator: Allocator, uid: usize, freq_q: u8) !*SoundNode {
|
pub fn create(allocator: Allocator, uid: usize, freq_q: u8) !*SoundNode {
|
||||||
|
|
@ -68,7 +68,6 @@ pub const SoundNode = struct {
|
||||||
|
|
||||||
//Gain and per-freq gains must be initialized as 1
|
//Gain and per-freq gains must be initialized as 1
|
||||||
|
|
||||||
sn.pins[32] = 1;
|
|
||||||
@memset(sn.pins[112..160], 1);
|
@memset(sn.pins[112..160], 1);
|
||||||
|
|
||||||
return sn;
|
return sn;
|
||||||
|
|
@ -84,13 +83,6 @@ pub const SoundNode = struct {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nullizeStartTick(self: *SoundNode) void {
|
|
||||||
|
|
||||||
// Zeroing the first 32 pins (dynamic pins)
|
|
||||||
@memset(self.pins[0..32], 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn corrGain(self: *SoundNode, gainmult: f64) f64 {
|
pub fn corrGain(self: *SoundNode, gainmult: f64) f64 {
|
||||||
|
|
||||||
if (gainmult > 0) {
|
if (gainmult > 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue