forked from Neon-MT/NisWave
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentry-ui.py
More file actions
534 lines (418 loc) · 24.5 KB
/
Copy pathentry-ui.py
File metadata and controls
534 lines (418 loc) · 24.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
# =============================================================================
# NisWave Music Player UI
# A music player interface built with Pygame featuring folder navigation,
# track selection, and album cover display
# =============================================================================
import pygame
from pygame.font import Font
import os
import threading
import sys
from pathlib import Path
from pynput.keyboard import Key, KeyCode, Listener
from wave_renderer import WaveVisualizer
from enum import Enum
from screeninfo import get_monitors
from platformdirs import user_music_dir
from get_files import get_music_files_and_directories
from update_image import get_cover_art
from queue_handler import shuffler, generated_unshuffled_queue
# =============================================================================
# Screen Initialization
# =============================================================================
# Get monitor information and extract screen dimensions
primary_monitor = [mon for mon in get_monitors() if mon.is_primary][0]
SCREEN_WIDTH = primary_monitor.width
SCREEN_HEIGHT = primary_monitor.height
# Set up media inputs
global media_input
media_input = ""
data_lock = threading.Lock()
def on_press(key: Key | KeyCode | None) -> None:
global media_input
with data_lock:
media_input = key
return
def on_release(key: Key | KeyCode | None) -> None:
global media_input
with data_lock:
media_input = ""
return
def listening() -> None:
with Listener(on_press = on_press, on_release = on_release) as listener:
listener.join()
return
threading.Thread(target=listening).start()
def init_pygame() -> tuple[Font, pygame.Surface]:
# Initialize Pygame and font
pygame.init()
pygame.mixer.init() # Initialize mixer for audio playback
#pygame.font.init()
nix_font = pygame.font.SysFont('Arial', 30)
surface = pygame.display.set_mode(
(SCREEN_WIDTH, SCREEN_HEIGHT),
pygame.RESIZABLE)
pygame.display.set_caption("pregus101's NisWave app")
return nix_font, surface
nix_font, screen = init_pygame()
folder_path = Path(user_music_dir())
currently_playing_folder_path = folder_path
# =============================================================================
# Application State Variables
# =============================================================================
OLD_SIZE = 640 # Previous album cover size (for resize detection)
STARTED = False # Track whether playback has begun
PLAYING_SONG = "" # Currently playing song filename
current_time_ms = 0
current_time_sec = current_time_ms / 1000.0
retry = False
# Wave visualizer state
visualizer = None # Will hold the WaveVisualizer instance
visualizer_running = False
# Create surface objects for directory and file windows
directory_buttons_window = pygame.Surface((SCREEN_WIDTH/5, SCREEN_HEIGHT/2))
file_buttons_window = pygame.Surface((SCREEN_WIDTH/5, SCREEN_HEIGHT/2))
# Set inital button states
play_pause = "play" # Can be "play" or "pause"
shuffle = False # Shuffle mode state
# Initialize the played songs
played_songs = []
# Scroll state variables
dir_scroll_offset = 0.0 # Vertical offset for directories
file_scroll_offset = 0.0 # Vertical offset for files
# Default cover art path (used if no cover art is found in the MP3 file)
cover_art_path = os.path.join(os.path.dirname(__file__), "assets/default_cover.jpg") # Default cover art path
class Color(Enum):
GRAY = (64, 64, 64)
LIGHT_GRAY = (128, 128, 128)
DARK_GREEN = (32, 64, 32)
LIGHT_GREEN = (64, 128, 64)
skip_button_color = Color.GRAY.value
play_pause_button_color = Color.GRAY.value
back_button_color = Color.GRAY.value
shuffle_button_color = Color.GRAY.value
previous_button_color = Color.GRAY.value
old_input = ""
# # Create the queue for auto-playing songs (will be populated with files from the current directory)
# DIRECTORY_ONLY, FILES_ONLY, directory_buttons, file_buttons = get_music_files_and_directories(folder_path, SCREEN_HEIGHT)
# queue = FILES_ONLY.copy() # Initialize queue with available songs in the current directory
# ============================================================================
# MAIN APPLICATION LOOP
# ============================================================================
while True:
cover_art_size = int(640 * ((SCREEN_WIDTH/1920 + SCREEN_HEIGHT/1147) / 2))
mouse_pos = pygame.mouse.get_pos()
# ========================================================================
# EVENT HANDLING
# ========================================================================
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEMOTION:
if shuffle:
shuffle_button_color = Color.LIGHT_GREEN.value if (SCREEN_WIDTH-SCREEN_WIDTH/5)/2-135+SCREEN_WIDTH/5 <= mouse_pos[0] <= (SCREEN_WIDTH-SCREEN_WIDTH/5)/2-85+SCREEN_WIDTH/5 and SCREEN_HEIGHT-50 <= mouse_pos[1] <= SCREEN_HEIGHT-30 else Color.DARK_GREEN.value # Change shuffle button color on hover
else:
shuffle_button_color = Color.LIGHT_GRAY.value if (SCREEN_WIDTH-SCREEN_WIDTH/5)/2-135+SCREEN_WIDTH/5 <= mouse_pos[0] <= (SCREEN_WIDTH-SCREEN_WIDTH/5)/2-85+SCREEN_WIDTH/5 and SCREEN_HEIGHT-50 <= mouse_pos[1] <= SCREEN_HEIGHT-30 else Color.GRAY.value # Change shuffle button color on hover
if (SCREEN_WIDTH-SCREEN_WIDTH/5)/2-25+SCREEN_WIDTH/5 <= mouse_pos[0] <= (SCREEN_WIDTH-SCREEN_WIDTH/5)/2+25+SCREEN_WIDTH/5 and SCREEN_HEIGHT-50 <= mouse_pos[1] <= SCREEN_HEIGHT-30:
play_pause_button_color = Color.LIGHT_GRAY.value # Lighter gray on hover
else:
play_pause_button_color = Color.GRAY.value # Default gray
# Change back button color on hover
if SCREEN_WIDTH/5-40 <= mouse_pos[0] <= SCREEN_WIDTH/5-20 and 5 <= mouse_pos[1] <= 25:
back_button_color = Color.LIGHT_GRAY.value # Lighter gray on hover
else:
back_button_color = Color.GRAY.value # Default gray
# Change skip button color on hover
if (SCREEN_WIDTH-SCREEN_WIDTH/5)/2+30+SCREEN_WIDTH/5 <= mouse_pos[0] <= (SCREEN_WIDTH-SCREEN_WIDTH/5)/2+80+SCREEN_WIDTH/5 and SCREEN_HEIGHT-50 <= mouse_pos[1] <= SCREEN_HEIGHT-30:
skip_button_color = Color.LIGHT_GRAY.value # Lighter gray on hover
else:
skip_button_color = Color.GRAY.value # Default gray
# prevoius button color on hover
if (SCREEN_WIDTH-SCREEN_WIDTH/5)/2-80+SCREEN_WIDTH/5 <= mouse_pos[0] <= (SCREEN_WIDTH-SCREEN_WIDTH/5)/2-30+SCREEN_WIDTH/5 and SCREEN_HEIGHT-50 <= mouse_pos[1] <= SCREEN_HEIGHT-30:
previous_button_color = Color.LIGHT_GRAY.value # Lighter gray on hover
else:
previous_button_color = Color.GRAY.value # Default gray
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
DIRECTORY_ONLY, FILES_ONLY, directory_buttons, file_buttons = get_music_files_and_directories(folder_path, SCREEN_HEIGHT, dir_scroll_offset, file_scroll_offset)
print(SCREEN_WIDTH/5-25 <= mouse_pos[0] <= SCREEN_WIDTH/5-5 and 5 <= mouse_pos[1] <= 25)
print(SCREEN_WIDTH/5-25, mouse_pos[0], SCREEN_WIDTH/5-5, mouse_pos[1])
if SCREEN_WIDTH/5-40 <= mouse_pos[0] <= SCREEN_WIDTH/5-20 and 5 <= mouse_pos[1] <= 25:
folder_path = os.path.dirname(folder_path)
print("Back button clicked, new folder path:", folder_path)
if (SCREEN_WIDTH-SCREEN_WIDTH/5)/2+30+SCREEN_WIDTH/5 <= mouse_pos[0] <= (SCREEN_WIDTH-SCREEN_WIDTH/5)/2+80+SCREEN_WIDTH/5 and SCREEN_HEIGHT-50 <= mouse_pos[1] <= SCREEN_HEIGHT-30 and STARTED:
pygame.mixer.music.stop()
if (SCREEN_WIDTH-SCREEN_WIDTH/5)/2-80+SCREEN_WIDTH/5 <= mouse_pos[0] <= (SCREEN_WIDTH-SCREEN_WIDTH/5)/2-30+SCREEN_WIDTH/5 and SCREEN_HEIGHT-50 <= mouse_pos[1] <= SCREEN_HEIGHT-30 and STARTED:
if current_time_sec <= 10:
try:
file_path = os.path.join(currently_playing_folder_path, played_songs[-1])
skip = False
except:
skip = True
print(skip)
if not skip:
STARTED = True
PLAYING_SONG = os.path.basename(file_path)
played_songs.remove(PLAYING_SONG)
queue_raw.insert(0, PLAYING_SONG) # Add current song back to the front of the queue_raw
queue.insert(0, PLAYING_SONG)
# Get album cover art for the selected track
render_size, cover_art_path = get_cover_art(file_path, cover_art_size)
# CREATE AND START WAVE VISUALIZER
visualizer = WaveVisualizer(file_path,
render_size[0],
render_size[1])
# Set wave color to contrast with album cover
cover_art_path = os.path.join(os.path.dirname(__file__), "temp_cover_art/temp_cover.png")
visualizer.set_color_from_image(cover_art_path)
visualizer.load_audio()
visualizer.play()
visualizer_running = True
else:
# CREATE AND START WAVE VISUALIZER
visualizer = WaveVisualizer(file_path,
render_size[0],
render_size[1])
visualizer.load_audio()
visualizer.play()
visualizer_running = True
if (SCREEN_WIDTH-SCREEN_WIDTH/5)/2-25+SCREEN_WIDTH/5 <= mouse_pos[0] <= (SCREEN_WIDTH-SCREEN_WIDTH/5)/2+25+SCREEN_WIDTH/5 and SCREEN_HEIGHT-75 <= mouse_pos[1] <= SCREEN_HEIGHT-25:
if play_pause == "play" and STARTED:
STARTED = False
play_pause = "pause"
try:
WaveVisualizer.set_pause_state(visualizer, True) # Pause the visualizer
except:
pass # Visualizer may not be initialized yet, ignore if error occurs
else:
STARTED = True
play_pause = "play"
try:
WaveVisualizer.set_pause_state(visualizer, False) # Unpause the visualizer
except:
pass # Visualizer may not be initialized yet, ignore if error occurs
STARTED = False
if (SCREEN_WIDTH-SCREEN_WIDTH/5)/2-135+SCREEN_WIDTH/5 <= mouse_pos[0] <= (SCREEN_WIDTH-SCREEN_WIDTH/5)/2-85+SCREEN_WIDTH/5 and SCREEN_HEIGHT-50 <= mouse_pos[1] <= SCREEN_HEIGHT-30:
if not PLAYING_SONG == '':
if shuffle:
queue = generated_unshuffled_queue(PLAYING_SONG, queue_raw)
else:
queue = shuffler(queue_raw, PLAYING_SONG)
print(queue)
shuffle = not shuffle # Toggle shuffle state
for button in directory_buttons:
if button[0] <= mouse_pos[1] <= button[0] + 30 and mouse_pos[1] <= SCREEN_HEIGHT/2 and mouse_pos[0] <= song_select_window:
folder_path = os.path.join(folder_path, button[1])
for button in file_buttons:
if button[0] <= mouse_pos[1] <= button[0] + 30 and mouse_pos[0] <= song_select_window:
# refresh variables for new song
queue_raw = generated_unshuffled_queue(button[1], FILES_ONLY.copy())
if shuffle:
queue = shuffler(queue_raw, button[1], True)
else:
queue = queue_raw.copy()
play_pause = "play" # Reset play/pause state to "play" when a new song is selected
played_songs = [] # Clear the list of played songs when a new song is selected
# Load and play the selected file
file_path = os.path.join(folder_path, button[1])
currently_playing_folder_path = folder_path # Update the currently playing folder path
STARTED = True
# queue_raw.remove(button[1])
# queue.remove(button[1])
PLAYING_SONG = button[1]
# Get album cover art for the selected track
render_size, cover_art_path = get_cover_art(file_path, cover_art_size)
# CREATE AND START WAVE VISUALIZER
visualizer = WaveVisualizer(file_path,
render_size[0],
render_size[1])
# Set wave color to contrast with album cover
visualizer.set_color_from_image(cover_art_path)
visualizer.load_audio()
visualizer.play()
visualizer_running = True
if event.type == pygame.MOUSEWHEEL and mouse_pos[0] <= song_select_window:
if mouse_pos[1] < SCREEN_HEIGHT/2: # Directory section
dir_scroll_offset -= event.y * 40 # Scroll by item height
dir_scroll_offset = max(0, min(dir_scroll_offset,
max(0, len(DIRECTORY_ONLY) * 40 - (SCREEN_HEIGHT/2 - 60))))
else: # File section
file_scroll_offset -= event.y * 40
file_scroll_offset = max(0, min(file_scroll_offset,
max(0, len(FILES_ONLY) * 40 - (SCREEN_HEIGHT/2 - 60))))
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE and visualizer:
if play_pause == "play" and STARTED:
pygame.mixer.music.pause()
STARTED = False
play_pause = "pause"
try:
WaveVisualizer.set_pause_state(visualizer, True) # Pause the visualizer
except:
pass # Visualizer may not be initialized yet, ignore if error occurs
else:
pygame.mixer.music.unpause()
STARTED = True
play_pause = "play"
try:
WaveVisualizer.set_pause_state(visualizer, False) # Unpause the visualizer
except:
pass # Visualizer may not be initialized yet, ignore if error occurs
STARTED = False
with data_lock:
if not old_input == media_input:
old_input = media_input
if media_input == Key.media_play_pause and visualizer:
if play_pause == "play" and STARTED:
pygame.mixer.music.pause()
STARTED = False
play_pause = "pause"
try:
WaveVisualizer.set_pause_state(visualizer, True) # Pause the visualizer
except:
pass # Visualizer may not be initialized yet, ignore if error occurs
else:
pygame.mixer.music.unpause()
STARTED = True
play_pause = "play"
try:
WaveVisualizer.set_pause_state(visualizer, False) # Unpause the visualizer
except:
pass # Visualizer may not be initialized yet, ignore if error occurs
STARTED = False
# ========================================================================
# AUTO-PLAY & QUEUE MANAGEMENT
# ========================================================================
# Auto-play next song when current song finishes
if STARTED and not len(queue_raw) <= 0:
if not pygame.mixer.music.get_busy():
try:
queue_raw.remove(PLAYING_SONG)
queue.remove(PLAYING_SONG)
except:
retry = True
newsong = queue[0] if queue else ""
file_path = os.path.join(currently_playing_folder_path, newsong)
if os.path.isfile(file_path):
played_songs.append(PLAYING_SONG) # Add the previous song to the list of played songs
PLAYING_SONG = newsong
# queue_raw.remove(newsong)
# queue.remove(newsong)
# Get cover art and update visualizer for the new song
render_size, cover_art_path = get_cover_art(file_path, cover_art_size)
# UPDATE VISUALIZER FOR NEW SONG
visualizer = WaveVisualizer(file_path,
render_size[0],
render_size[1])
# Set wave color to contrast with album cover
visualizer.set_color_from_image(cover_art_path)
visualizer.load_audio()
visualizer.play()
visualizer_running = True
else:
print("No more songs in the queue to play.")
STARTED = False # Stop playback if there are no more songs to play
visualizer_running = False # Stop the visualizer as well
cover_art_path = os.path.join(os.path.dirname(__file__), "assets/default_cover.jpg") # Reset to default cover art path
if retry:
pygame.mixer.music.stop()
retry = False
# ========================================================================
# RENDERING & DISPLAY
# ========================================================================
current_time_ms = pygame.mixer.music.get_pos()
current_time_sec = current_time_ms / 1000.0
# Update screen dimensions in case window was resized
SCREEN_WIDTH, SCREEN_HEIGHT = screen.get_size()
song_select_window = SCREEN_WIDTH / 5
# ---- LEFT SIDEBAR: Directory and File Selection ----
# Draw left sidebar background (light gray for directory/file selection area)
pygame.draw.rect(screen, (40, 40, 40), (0, 0, song_select_window, SCREEN_HEIGHT))
# Get directories and files in current folder
DIRECTORY_ONLY, FILES_ONLY, directory_buttons, file_buttons = get_music_files_and_directories(folder_path, SCREEN_HEIGHT, dir_scroll_offset, file_scroll_offset)
# Create subsurface for folder section (top half of sidebar)
folder_surf = screen.subsurface(0, 0, song_select_window, SCREEN_HEIGHT)
# Create subsurface for file list section (bottom half of sidebar)
file_surf = screen.subsurface(0, SCREEN_HEIGHT/2, song_select_window, SCREEN_HEIGHT/2)
# Draw folder list with header
for directory in DIRECTORY_ONLY:
text_surface = nix_font.render(directory, True, (255, 255, 255))
folder_surf.blit(text_surface, (10, (DIRECTORY_ONLY.index(directory)+1)*40 + 10 - dir_scroll_offset))
pygame.draw.rect(screen, (40, 40, 40), (0, 0, song_select_window, 40))
text_surface = nix_font.render("Folders:", True, (255, 255, 255))
folder_surf.blit(text_surface, (10, 10))
# Draw file list background
pygame.draw.rect(screen, (40, 40, 40), (0, SCREEN_HEIGHT/2, song_select_window, SCREEN_HEIGHT/2))
# Draw file list with header
for file in FILES_ONLY:
text_surface = nix_font.render(file, True, (255, 255, 255))
file_surf.blit(text_surface, (10, (FILES_ONLY.index(file)+1)*40 + 10 - file_scroll_offset))
pygame.draw.rect(screen, (40, 40, 40), (0, SCREEN_HEIGHT/2, song_select_window, 40))
text_surface = nix_font.render("Files:", True, (255, 255, 255))
file_surf.blit(text_surface, (10, 10))
try:
# Draw scrollbars
dir_max_scroll = max(0, len(DIRECTORY_ONLY) * 40 - (SCREEN_HEIGHT/2 - 60))
if dir_max_scroll > 0:
scrollbar_h = (SCREEN_HEIGHT/2 - 60) * (SCREEN_HEIGHT/2 - 60) / (len(DIRECTORY_ONLY) * 40)
scrollbar_y = dir_scroll_offset * (SCREEN_HEIGHT/2 - 60) / (len(DIRECTORY_ONLY) * 40)
pygame.draw.rect(screen, (100, 100, 100),
(song_select_window - 10, scrollbar_y, 8, scrollbar_h))
file_max_scroll = max(0, len(FILES_ONLY) * 40 - (SCREEN_HEIGHT/2 - 60))
if file_max_scroll > 0:
scrollbar_h = (SCREEN_HEIGHT/2 - 60) * (SCREEN_HEIGHT/2 - 60) / (len(FILES_ONLY) * 40)
scrollbar_y = file_scroll_offset * (SCREEN_HEIGHT/2 - 60) / (len(FILES_ONLY) * 40)
pygame.draw.rect(screen, (100, 100, 100),
(song_select_window - 10, SCREEN_HEIGHT/2 + scrollbar_y, 8, scrollbar_h))
except:
print("Not enough space to draw scrollbars")
# ---- RIGHT SIDE: Album Cover and Visualizer ----
# Draw right side background (dark gray for album cover area)
pygame.draw.rect(screen, (20, 20, 20), (song_select_window, 0, SCREEN_WIDTH - song_select_window, SCREEN_HEIGHT))
# Draw back button (small gray square)
pygame.draw.rect(screen, back_button_color, (SCREEN_WIDTH/5-40, 5, 20, 20))
#draw media control buttons (small gray rectangles)
# pygame.draw.rect(screen, play_pause_button_color, ((SCREEN_WIDTH-SCREEN_WIDTH/5)/2-25+SCREEN_WIDTH/5, SCREEN_HEIGHT-30, 50, 20))
if play_pause == "pause":
play_button = pygame.image.load(os.path.join(os.path.dirname(__file__), "assets/Play_play.jpg"))
else:
play_button = pygame.image.load(os.path.join(os.path.dirname(__file__), "assets/Play_pause.jpg"))
play_button_rect = play_button.get_rect()
play_button_rect.center = ((SCREEN_WIDTH-SCREEN_WIDTH/5)/2+SCREEN_WIDTH/5, SCREEN_HEIGHT-50)
screen.blit(play_button, play_button_rect)
pygame.draw.rect(screen, skip_button_color, ((SCREEN_WIDTH-SCREEN_WIDTH/5)/2+30+SCREEN_WIDTH/5, SCREEN_HEIGHT-50, 50, 20))
pygame.draw.rect(screen, previous_button_color, ((SCREEN_WIDTH-SCREEN_WIDTH/5)/2-80+SCREEN_WIDTH/5, SCREEN_HEIGHT-50, 50, 20))
pygame.draw.rect(screen, shuffle_button_color, ((SCREEN_WIDTH-SCREEN_WIDTH/5)/2-135+SCREEN_WIDTH/5, SCREEN_HEIGHT-50, 50, 20))
# Load and display album cover art, centered on right side
album_cover = pygame.image.load(cover_art_path)
image_rect = album_cover.get_rect()
# Center the cover image on the right side of the screen
image_rect.center = ((SCREEN_WIDTH-(SCREEN_WIDTH/5))/2+SCREEN_WIDTH/5, SCREEN_HEIGHT/2)
screen.blit(album_cover, image_rect)
# ---- NOW PLAYING INFO ----
# Display currently playing song name
if STARTED:
text_surface = nix_font.render("Now Playing: " + PLAYING_SONG, True, (255, 255, 255))
screen.blit(text_surface, ((SCREEN_WIDTH-song_select_window)/2+SCREEN_WIDTH/5-(13+len(PLAYING_SONG))*7, SCREEN_HEIGHT/2 + render_size[1]/2 + 10))
# Update album cover if screen size changed
if cover_art_size != OLD_SIZE:
render_size, cover_art_path = get_cover_art(os.path.join(currently_playing_folder_path, PLAYING_SONG), cover_art_size)
OLD_SIZE = cover_art_size
# ---- WAVE VISUALIZATION RENDERING ----
try:
# Render wave visualization on the right side
if visualizer and visualizer_running:
# Create a subsurface for the visualizer (right side of screen)
vis_surface = screen.subsurface(song_select_window+(((SCREEN_WIDTH-song_select_window)/2-render_size[0]/2)), 0,
render_size[0], SCREEN_HEIGHT/2+render_size[1]/2)
# Render one frame of the wave visualization
if not visualizer.render_frame(vis_surface, mouse_pos):
visualizer_running = False # Song finished, stop rendering
# Update visualizer render position if window was resized
if visualizer:
visualizer.update_render_size(int(render_size[0]),
int((SCREEN_HEIGHT/2)+(render_size[1]/2)))
except:
pass # give the visualizer some time to initialize before trying to create the subsurface for it, ignore errors if it fails at first
# ---- UPDATE DISPLAY ----
# Refresh the display with all rendered elements
pygame.display.flip()