Skip to content

Commit d126ed4

Browse files
committed
small edits
1 parent af76ad6 commit d126ed4

File tree

2 files changed

+106
-74
lines changed

2 files changed

+106
-74
lines changed

CatnipJulia/src/run_catnip.jl

Lines changed: 105 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,148 @@
11
GLMakie.activate!()
22

3+
# set_theme!(theme_black())
4+
35
set_window_config!(;
4-
vsync=false,
5-
framerate=60.0,
6-
float=true,
7-
pause_renderloop=false,
8-
focus_on_show=false,
9-
decorated=true,
10-
title="Catnip"
6+
vsync=false,
7+
framerate=60.0,
8+
float=true,
9+
pause_renderloop=false,
10+
focus_on_show=false,
11+
decorated=true,
12+
title="catnip"
1113
)
1214

1315
function run_catnip(; timeout=false)
14-
numSets = 120
16+
# 5 seconds at 60 samples per second out of catnip
17+
numSets = 300
1518

16-
fig = Figure(resolution=(1200, 800), fontsize=14)
17-
ax1 = Axis3(fig[1, 1]; aspect=(2, 1, 0.25), elevation=pi / 6, perspectiveness=0.5)
19+
fig = Figure(resolution=(1200, 800), fontsize=14)
20+
ax1 = Axis3(fig[1, 1]; aspect=(2, 1, 0.25), elevation=pi / 6, perspectiveness=0.5)
1821

19-
data = CircularBuffer{Vector{Float64}}(numSets)
22+
data = CircularBuffer{Vector{Float64}}(numSets)
2023

21-
push!(data, [0.0, 0.0])
22-
push!(data, [0.0, 0.0])
24+
push!(data, [0.0, 0.0])
25+
push!(data, [0.0, 0.0])
2326

24-
z = Observable(mapreduce(permutedims, vcat, data))
27+
z = Observable(mapreduce(permutedims, vcat, data))
2528

26-
mSize = @lift(Vec3f.(1, 1, $z[:]))
29+
mSize = @lift(Vec3f.(1, 1, $z[:]))
2730

28-
zZ = @lift(0 * $z)
31+
zZ = @lift(0 * $z)
2932

30-
sets = @lift(size($z, 1))
31-
bars = @lift(size($z, 2))
33+
sets = @lift(size($z, 1))
34+
bars = @lift(size($z, 2))
3235

33-
x = @lift(range(1, $sets, $sets))
34-
y = @lift(range(1, $bars, $bars))
36+
x = @lift(range(1, $sets, $sets))
37+
y = @lift(range(1, $bars, $bars))
3538

36-
function makeColorMap(s, b)
37-
mat = zeros(s, b)
39+
idx = Observable(1)
3840

39-
for j = 0:b-1
40-
mat[(j*s)+1] = 0
41-
end
41+
function makeColorMap(s, b, x)
42+
mat = zeros(s, b)
4243

43-
for i = 1:s-1
44-
# v = 1 - min(0.8, i / s)
45-
v = 1 - (i / s)
46-
# v = i / s
44+
for i = 0:s-1
45+
# v = 1 - min(0.8, i / s)
46+
v = 1.0 - (i / s)
47+
# v = i / s
4748

48-
for j = 0:b-1
49-
mat[(j*s)+i+1] = v
50-
end
51-
end
49+
for j = 0:b-1
50+
mat[i+(j*s)+1] = v
51+
end
52+
end
5253

53-
return mat
54+
for j = 0:b-1
55+
mat[x+(j*s)] = 0.0
5456
end
5557

56-
zC = @lift($z[:])
58+
return mat
59+
end
5760

58-
staticColorMap = @lift(makeColorMap($sets, $bars)[:])
61+
function makeColorMap2(z, s, b, x)
62+
d = z[:]
5963

64+
maxValue = reduce(d) do left, right
65+
left > right ? left : right
66+
end
67+
68+
maxValue = max(maxValue, 100.0)
6069

61-
function updateZ()
62-
z[] = mapreduce(permutedims, vcat, data)
70+
for j = 0:b-1
71+
d[x+(j*s)] = maxValue
6372
end
6473

65-
rectMesh = Rect3f(Vec3f(-0.5, -0.5, 0), Vec3f(1, 1, 1))
74+
d[1] = 0.0
75+
76+
return d
77+
end
6678

67-
display(fig)
79+
zC = @lift($z[:])
6880

69-
command = `$(ENV["GOBIN"])/catnip -d alsa_output.pci-0000_0e_00.4.iec958-stereo.monitor -r 122880 -n 2048 -sas 5 -sf 45 -i -nw -nwb 50`
70-
#command = `go run ./cmd/catnip -d spotify -r 122880 -n 2048 -sas 5 -sf 45 -i -nw -nwb 50`
81+
staticColorMap = @lift(makeColorMap2($z, $sets, $bars, $idx)[:])
7182

7283

73-
try
74-
open(command, "r", stdout) do io
75-
count = 0
76-
while count < numSets + 2
77-
count += 1
84+
function updateZ()
85+
z[] = mapreduce(permutedims, vcat, data)
86+
end
7887

79-
line = readline(io)
80-
line = rstrip(lstrip(line))
81-
elms = split(line, " ")
82-
nums = map(x -> parse(Float64, x), elms)
83-
#println(nums)
84-
pushfirst!(data, reverse(nums))
85-
end
88+
rectMesh = Rect3f(Vec3f(-0.5, -0.5, 0), Vec3f(1, 1, 1))
8689

87-
updateZ()
90+
display(fig)
8891

89-
limits!(ax1, 0, sets[], 0, bars[], 0, 100)
92+
command = `catnip -d spotify -r 122880 -n 2048 -sas 6 -sf 45 -i -nw -nwb 60`
93+
#command = `go run ./cmd/catnip -d spotify -r 122880 -n 2048 -sas 5 -sf 45 -i -nw -nwb 50`
9094

91-
meshscatter!(ax1, x, y, zZ; marker=rectMesh, color=staticColorMap,
92-
markersize=mSize, colormap=:summer,
93-
shading=true)
9495

96+
try
97+
open(command, "r", stdout) do io
98+
count = 0
99+
while count < numSets + 2
100+
count += 1
95101

102+
line = readline(io)
103+
line = strip(line)
104+
elms = split(line, " ")
105+
elms = [elm for elm in elms if !isempty(elm)]
106+
nums = map(x -> parse(Float64, strip(x)), elms)
107+
#println(nums)
108+
pushfirst!(data, reverse(nums))
109+
end
96110

97-
#while !eof(io) && (count < numSets + 4 || !timeout)
98-
while !eof(io) && !timeout
99-
count += 1
100-
line = readline(io)
101-
line = rstrip(lstrip(line))
102-
elms = split(line, " ")
103-
nums = map(x -> parse(Float64, x), elms)
104-
nums = reverse(nums)
111+
updateZ()
105112

106-
#println(nums)
113+
limits!(ax1, 0, sets[], 0, bars[], 0, 100)
107114

108-
pushfirst!(data, nums)
115+
meshscatter!(ax1, x, y, zZ; marker=rectMesh, color=staticColorMap,
116+
markersize=mSize, colormap=:plasma,
117+
shading=true)
109118

110-
updateZ()
111-
end
119+
120+
121+
#while !eof(io) && (count < numSets + 4 || !timeout)
122+
while !eof(io) && !timeout
123+
count += 1
124+
if count >= numSets
125+
count = 0
112126
end
113-
catch e
114-
@show e
127+
128+
line = readline(io)
129+
line = strip(line)
130+
elms = split(line, " ")
131+
elms = [elm for elm in elms if !isempty(elm)]
132+
nums = map(x -> parse(Float64, strip(x)), elms)
133+
nums = reverse(nums)
134+
135+
idx[] = numSets - count
136+
#println(nums)
137+
138+
data[idx[]] = nums
139+
140+
# pushfirst!(data, nums)
141+
142+
updateZ()
143+
end
115144
end
145+
catch e
146+
@show e
147+
end
116148
end

cmd/catnip/number_writer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (d *Writer) Write(buffers [][]float64, channels int) error {
111111
xBin = d.binCount - 1 - xBin
112112
}
113113

114-
fmt.Printf("%4.2f ", chBins[xBin]*scale)
114+
fmt.Printf("%6.3f ", chBins[xBin]*scale)
115115
}
116116
}
117117

0 commit comments

Comments
 (0)