Skip to content

Commit 58ea6f9

Browse files
committed
Add return to menu button
Resets Drop back to the startup menu and clears all music. Closes #32
1 parent 27f8bc2 commit 58ea6f9

File tree

5 files changed

+99
-4
lines changed

5 files changed

+99
-4
lines changed

audio.lua

+35
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ local song_id = 0
1616
local song_name = nil
1717
local is_paused = false
1818
local current_song = nil
19+
local decoder = nil
1920
local time_count = 0
2021
local music_list = nil
2122
local loop_toggle = false
@@ -27,6 +28,7 @@ function audio.update()
2728
-- plays first song
2829
if current_song == nil then
2930
love.audio.setVolume(0.5)
31+
gui.volume:activate("volume2")
3032
audio.changeSong(1)
3133
end
3234

@@ -172,6 +174,39 @@ function audio.play()
172174
current_song:play()
173175
end
174176

177+
function audio.stop()
178+
current_song:stop()
179+
if microphone_active then
180+
microphone_device:stop()
181+
microphone_active = false
182+
end
183+
end
184+
185+
function audio.reload()
186+
if current_song ~= nil then audio.stop() end
187+
188+
decoder_buffer = 2048
189+
seconds_per_buffer = 0
190+
queue_size = 0
191+
sample_sum = 0
192+
decoder_array = {0,0,0,0,0,0,0}
193+
decoder_array[0] = 0
194+
sample_count = {0,0,0,0,0,0,0}
195+
sample_count[0] = 0
196+
check_old = 0
197+
end_of_song = false
198+
song_id = 0
199+
song_name = nil
200+
is_paused = false
201+
current_song = nil
202+
time_count = 0
203+
music_list = nil
204+
decoder = nil
205+
loop_toggle = false
206+
shuffle_toggle = false
207+
microphone_active = false
208+
end
209+
175210
function audio.toggleLoop()
176211
loop_toggle = not loop_toggle
177212
end

gui.lua

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local gui = {leftPanel = {}, rightPanel = {}, scrubbar = {}, left = {}, playback = {}, right = {}, shuffle = {}, loop = {}, volume = {}, fullscreen = {}, graphics = {}, timestamp_start = {}, timestamp_end = {}, scrubhead = {}}
1+
local gui = {leftPanel = {}, rightPanel = {}, scrubbar = {}, left = {}, playback = {}, right = {}, shuffle = {}, loop = {}, volume = {}, fullscreen = {}, menu = {}, graphics = {}, timestamp_start = {}, timestamp_end = {}, scrubhead = {}}
22
local scrubbar_x1 = 0
33
local scrubbar_y1 = 0
44
local scrubbar_x2 = 0
@@ -17,6 +17,8 @@ local volume_quad = "volume2"
1717
local fullscreen_x = 0
1818
local fullscreen_quad = "fullscreen"
1919
local click_area_y = 0
20+
local menu_x = 0
21+
local menu_y = 0
2022
local scrubhead_radius = 0
2123
local timestamp_start_x = 0
2224
local timestamp_start_y = 0
@@ -76,10 +78,11 @@ function gui.load()
7678
sprite_quads["volume1"] = love.graphics.newQuad(480, 240, 240, 240, mc_image_width, mc_image_height)
7779
sprite_quads["volume2"] = love.graphics.newQuad(720, 240, 240, 240, mc_image_width, mc_image_height)
7880
sprite_quads["volume3"] = love.graphics.newQuad(0, 480, 240, 240, mc_image_width, mc_image_height)
81+
sprite_quads["menu"] = love.graphics.newQuad(240, 480, 240, 240, mc_image_width, mc_image_height)
7982
sprite_quads["loop"] = love.graphics.newQuad(0, 0, 300, 240, loop_image:getWidth(), loop_image:getHeight())
8083
sprite_quads["shuffle"] = love.graphics.newQuad(0, 0, 300, 240, shuffle_image:getWidth(), shuffle_image:getHeight())
8184

82-
sprite_batch = love.graphics.newSpriteBatch(music_control_image, 9)
85+
sprite_batch = love.graphics.newSpriteBatch(music_control_image, 10)
8386
shuffle_sprite = love.graphics.newSpriteBatch(shuffle_image, 1)
8487
loop_sprite = love.graphics.newSpriteBatch(loop_image, 1)
8588
local gui_scaling_multiplier = math.max(graphics_height, 480)
@@ -120,7 +123,9 @@ function gui.load()
120123

121124
offset = graphics_width-sprite_square_side_length-medium_spacing-small_spacing
122125
fullscreen_x = offset-medium_spacing
126+
menu_x = offset-large_spacing
123127
sprites["fullscreen"] = sprite_batch:add(sprite_quads[fullscreen_quad], offset, right_height, 0, scale_x*.93)
128+
sprites["menu"] = sprite_batch:add(sprite_quads["menu"], offset, 10, 0, scale_x)
124129
offset = offset-sprite_square_side_length-large_spacing-small_spacing/2
125130
volume_x = offset-3*small_spacing/2
126131
sprites["volume"] = sprite_batch:add(sprite_quads[volume_quad], offset, right_height, 0, scale_x)
@@ -147,6 +152,7 @@ function gui.load()
147152
scrubbar_y2 = ui_height
148153

149154
click_area_y = graphics_height-gui_scaling_multiplier/16
155+
menu_y = scale_x*240+10+medium_spacing
150156
------------------------------------------------------------------------------------
151157
end
152158

@@ -188,7 +194,9 @@ function gui.scale()
188194

189195
offset = graphics_width-sprite_square_side_length-medium_spacing-small_spacing
190196
fullscreen_x = offset-medium_spacing
197+
menu_x = offset-large_spacing
191198
sprite_batch:set(sprites["fullscreen"], sprite_quads[fullscreen_quad], offset, right_height, 0, scale_x*.93)
199+
sprite_batch:set(sprites["menu"], sprite_quads["menu"], offset, 10, 0, scale_x)
192200
offset = offset-sprite_square_side_length-large_spacing-small_spacing/2
193201
volume_x = offset-3*small_spacing/2
194202
sprite_batch:set(sprites["volume"], sprite_quads[volume_quad], offset, right_height, 0, scale_x)
@@ -215,6 +223,7 @@ function gui.scale()
215223
scrubbar_y2 = ui_height
216224

217225
click_area_y = graphics_height-gui_scaling_multiplier/16
226+
menu_y = scale_x*240+10+medium_spacing
218227
------------------------------------------------------------------------------------
219228
end
220229

@@ -481,6 +490,23 @@ function gui.rightPanel:inBoundsX(x)
481490
return x >= volume_x
482491
end
483492

493+
function gui.menu:inBoundsX(x)
494+
return x <= graphics_width and x >= menu_x
495+
end
496+
497+
function gui.menu:inBoundsY(y)
498+
return y >= 0 and y <= menu_y
499+
end
500+
501+
function gui.menu:activate()
502+
audio.reload()
503+
spectrum.reload()
504+
reload()
505+
506+
playback_quad = "pause"
507+
gui.scale()
508+
end
509+
484510
function gui.graphics:setHeight(height)
485511
graphics_height = height
486512
end

images/music_control_sprites.png

269 Bytes
Loading

main.lua

+24-2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,28 @@ function love.load()
152152
------------------------------------------------------------------------------------
153153
end
154154

155+
function reload()
156+
waveform = {}
157+
scrub_head_pause = false
158+
scrub_head_pressed = false
159+
160+
appdata_music = true
161+
162+
fade_interval_counter = 1
163+
fade_bool = false
164+
fade_activated = false
165+
color = "g"
166+
fade_intensity = 1
167+
setColor("g", 1)
168+
sleep_counter = 0
169+
window_visible = true
170+
last_frame_time = 0
171+
cursor_hand_activated = false
172+
previous_volume = 0
173+
microphone_init = false
174+
devices_list = nil
175+
end
176+
155177
function love.update(dt)
156178
if audio.musicExists() or audio.isPlayingMicrophone() then
157179
if audio.isPlayingMicrophone() then audio.updateMicrophone() else audio.update() end
@@ -251,7 +273,7 @@ function love.mousepressed(x, y, key, istouch)
251273
gui.sleep(false)
252274
sleep_counter = 0
253275

254-
local button_table = {"left", "playback", "right", "shuffle", "loop", "volume", "fullscreen"}
276+
local button_table = {"left", "playback", "right", "shuffle", "loop", "volume", "fullscreen", "menu"}
255277

256278
local button
257279
for i,v in ipairs(button_table) do
@@ -292,7 +314,7 @@ function love.mousemoved(x, y, dx, dy, istouch)
292314
gui.sleep(false)
293315
sleep_counter = 0
294316

295-
if gui.left:inBoundsY(y) and ((gui.scrubbar:inBoundsY(y) and gui.scrubbar:inBoundsX(x)) or gui.leftPanel:inBoundsX(x) or gui.rightPanel:inBoundsX(x)) then
317+
if (gui.left:inBoundsY(y) and ((gui.scrubbar:inBoundsY(y) and gui.scrubbar:inBoundsX(x)) or gui.leftPanel:inBoundsX(x) or gui.rightPanel:inBoundsX(x))) or (gui.menu:inBoundsX(x) and gui.menu:inBoundsY(y)) then
296318
if not cursor_hand_activated then love.mouse.setCursor(love.mouse.getSystemCursor("hand")) end
297319
cursor_hand_activated = true
298320
elseif cursor_hand_activated then

spectrum.lua

+12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ local visualizer_type = 3
1616
local tick_amplitude_average = 0
1717
local tick_count = 128
1818

19+
function spectrum.reload()
20+
-- fft gen
21+
spectrum = {}
22+
size = 2048
23+
old_sample = 0
24+
25+
-- spectrum draw
26+
visualizer_type = 3
27+
tick_amplitude_average = 0
28+
tick_count = 128
29+
end
30+
1931
function spectrum.generateWaveform()
2032
local wave = {}
2133
local channels = audio.getChannels()

0 commit comments

Comments
 (0)