Skip to content

Commit 840235e

Browse files
committed
Don't consistently redraw buffers - this helps us not hit the memory error in scsynth-jna so soon (after enough calls to (buffer-data) scsynth-jna runs out of memory as it doesn't free it after use.)
1 parent d51d27a commit 840235e

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/overtone/viz/scope.clj

+18-5
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@
3131
(ref-set scope-group* (group :tail ROOT-GROUP))
3232
(satisfy-deps :scope-group-created)))
3333

34-
(defn- update-scope-data [s]
34+
(defn- update-scope-data
35+
"Updates the scope by reading the current status of the buffer and repainting.
36+
Currently only updates bus scope as there's a bug in scsynth-jna which crashes
37+
the server after too many calls to buffer-data for a large buffer. As buffers
38+
tend to be large, updating the scope frequently will cause the crash to happen
39+
sooner. Need to remove this limitation when scsynth-jna is fixed."
40+
[s]
3541
(let [{:keys [buf size width height panel y-arrays x-array panel]} s
36-
frames (buffer-data buf)
42+
frames (if @(:update? s) (buffer-data buf) @(:frames s))
3743
step (int (/ (buffer-size buf) width))
3844
y-scale (- height (* 2 Y-PADDING))
3945
[y-a y-b] @y-arrays]
@@ -44,10 +50,15 @@
4450
(aget ^floats frames (unchecked-multiply x step)))))))
4551

4652
(reset! y-arrays [y-b y-a])
47-
(.repaint panel)))
53+
(.repaint panel)
54+
55+
(when (and (not (:bus-synth s))
56+
@(:update? s))
57+
(reset! (:frames s) frames)
58+
(reset! (:update? s) false))))
4859

4960
(defn- update-scopes []
50-
(doall (map update-scope-data (vals @scopes*))))
61+
(dorun (map update-scope-data (vals @scopes*))))
5162

5263
(defn- paint-scope [^Graphics g id]
5364
(if-let [scope (get @scopes* id)]
@@ -176,7 +187,9 @@
176187
:width width
177188
:height height
178189
:x-array x-array
179-
:y-arrays (atom [y-a y-b])}
190+
:y-arrays (atom [y-a y-b])
191+
:update? (atom true)
192+
:frames (atom [])}
180193

181194
_ (reset-data-arrays scope)]
182195
(.addWindowListener frame

0 commit comments

Comments
 (0)