Skip to content

Commit

Permalink
properly time the clean up of the audio visualizer
Browse files Browse the repository at this point in the history
this should allow visualizer to persist as long as it is needed
  • Loading branch information
poco0317 committed Feb 19, 2023
1 parent 64d23ef commit 5a71afe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 9 additions & 5 deletions Themes/Rebirth/Scripts/10 AudioVisualizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ function audioVisualizer:new(params)
local screen
local values = frame.values
frame.playbackFunction = function(fft, ss)
-- cleanup
if screen ~= SCREENMAN:GetTopScreen() then
SOUND:ClearPlayBackCallback()
return
end
local samplingRate = ss:GetSampleRate()
local count = #fft

Expand Down Expand Up @@ -245,6 +240,15 @@ function audioVisualizer:new(params)
screen = SCREENMAN:GetTopScreen()
SOUND:SetPlayBackCallback(frame.playbackFunction, frame.sampleCount)
end
frame.EndCommand = function(self)
-- triggers if the screen the visualizer is loaded on gets deleted (a transition or exit)
SOUND:ClearPlayBackCallback()
end
frame.ResetVisualizerMessageCommand = function(self)
screen = SCREENMAN:GetTopScreen()
SOUND:SetPlayBackCallback(frame.playbackFunction, frame.sampleCount)
end

frame[#frame + 1] = frame.sound
return frame
end
14 changes: 9 additions & 5 deletions Themes/_fallback/Scripts/10 AudioVisualizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,6 @@ function audioVisualizer:new(params)
local screen
local values = frame.values
frame.playbackFunction = function(fft, ss)
-- cleanup
if screen ~= SCREENMAN:GetTopScreen() then
SOUND:ClearPlayBackCallback()
return
end
local samplingRate = ss:GetSampleRate()
local count = #fft

Expand Down Expand Up @@ -222,6 +217,15 @@ function audioVisualizer:new(params)
screen = SCREENMAN:GetTopScreen()
SOUND:SetPlayBackCallback(frame.playbackFunction, frame.sampleCount)
end
frame.EndCommand = function(self)
-- triggers if the screen the visualizer is loaded on gets deleted (a transition or exit)
SOUND:ClearPlayBackCallback()
end
frame.ResetVisualizerMessageCommand = function(self)
screen = SCREENMAN:GetTopScreen()
SOUND:SetPlayBackCallback(frame.playbackFunction, frame.sampleCount)
end

frame[#frame + 1] = frame.sound
return frame
end

0 comments on commit 5a71afe

Please sign in to comment.