Skip to content

Commit 3899ad7

Browse files
authored
Merge pull request #2068 from FoamyGuy/winamp_titano
Winamp project updates for PyPortal titano
2 parents f8a82d5 + c0332c5 commit 3899ad7

File tree

4 files changed

+131
-43
lines changed

4 files changed

+131
-43
lines changed
Binary file not shown.

PyPortal_Winamp_Player/PyPortal_Winamp_Skin_Converter/convert_winamp_skin.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@
1414
else:
1515
input_filename = "base.png"
1616

17+
if "-t" in sys.argv or "--titano" in sys.argv:
18+
newsize = (320, 480)
19+
else:
20+
newsize = (240, 320)
21+
1722
# Opens a image in RGB mode
1823
im = Image.open(input_filename)
1924

20-
newsize = (240, 320)
25+
2126

2227
find_text_color_dict = {}
2328

@@ -97,4 +102,4 @@
97102
# convert to indexed color
98103
im = im.convert(mode="P", palette=Image.WEB)
99104
# save output BMP file
100-
im.save(input_filename.replace(".png", "_240x320.bmp"))
105+
im.save(input_filename.replace(".png", "_{}x{}.bmp".format(newsize[0], newsize[1])))

PyPortal_Winamp_Player/code.py

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,54 @@
2929
# display orientation. Must be 90 or 270.
3030
ORIENTATION = 90
3131

32-
if ORIENTATION == 270:
33-
# setup touch screen
34-
ts = adafruit_touchscreen.Touchscreen(
35-
board.TOUCH_YD,
36-
board.TOUCH_YU,
37-
board.TOUCH_XR,
38-
board.TOUCH_XL,
39-
calibration=((5200, 59000), (5800, 57000)),
40-
size=(240, 320),
41-
)
42-
elif ORIENTATION == 90:
43-
# setup touch screen
44-
ts = adafruit_touchscreen.Touchscreen(
45-
board.TOUCH_YU,
46-
board.TOUCH_YD,
47-
board.TOUCH_XL,
48-
board.TOUCH_XR,
49-
calibration=((5200, 59000), (5800, 57000)),
50-
size=(240, 320),
51-
)
52-
else:
53-
raise ValueError("ORIENTATION must be 90 or 270")
32+
PYPORTAL_TITANO = False
33+
34+
if not PYPORTAL_TITANO:
35+
SIZE = (240, 320)
36+
if ORIENTATION == 270:
37+
# setup touch screen
38+
ts = adafruit_touchscreen.Touchscreen(
39+
board.TOUCH_YD,
40+
board.TOUCH_YU,
41+
board.TOUCH_XR,
42+
board.TOUCH_XL,
43+
calibration=((5200, 59000), (5800, 57000)),
44+
size=(240, 320),
45+
)
46+
elif ORIENTATION == 90:
47+
# setup touch screen
48+
ts = adafruit_touchscreen.Touchscreen(
49+
board.TOUCH_YU,
50+
board.TOUCH_YD,
51+
board.TOUCH_XL,
52+
board.TOUCH_XR,
53+
calibration=((5200, 59000), (5800, 57000)),
54+
size=(240, 320),
55+
)
56+
else:
57+
raise ValueError("ORIENTATION must be 90 or 270")
58+
else: # PyPortal Titano
59+
SIZE = (320, 480)
60+
if ORIENTATION == 270:
61+
# setup touch screen
62+
ts = adafruit_touchscreen.Touchscreen(
63+
board.TOUCH_YD,
64+
board.TOUCH_YU,
65+
board.TOUCH_XR,
66+
board.TOUCH_XL,
67+
calibration=((5200, 59000), (5800, 57000)),
68+
size=(320, 480),
69+
)
70+
elif ORIENTATION == 90:
71+
# setup touch screen
72+
ts = adafruit_touchscreen.Touchscreen(
73+
board.TOUCH_YU,
74+
board.TOUCH_YD,
75+
board.TOUCH_XL,
76+
board.TOUCH_XR,
77+
calibration=((5200, 59000), (5800, 57000)),
78+
size=(320, 480),
79+
)
5480

5581
# Initializations for SDCard
5682
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
@@ -74,6 +100,7 @@
74100
playlist_file=PLAYLIST_FILE,
75101
skin_image=SKIN_IMAGE,
76102
skin_config_file=SKIN_CONFIG_FILE,
103+
pyportal_titano=PYPORTAL_TITANO,
77104
)
78105

79106
# Add the Group to the Display
@@ -100,16 +127,16 @@
100127
# store the time to compare with next iteration
101128
_previous_touch_time = _now
102129
# if touch is on bottom half
103-
if p[1] > 320 // 2:
130+
if p[1] > SIZE[1] // 2:
104131
# if touch is on right half
105-
if p[0] >= 240 // 2:
132+
if p[0] >= SIZE[0] // 2:
106133
winamp_application.next_track()
107134

108135
# if touch is on left half
109136
else:
110137
winamp_application.previous_track()
111138
# if touch is on top half
112-
elif p[1] <= 240 // 2:
139+
else:
113140
# if currently playing song
114141
if winamp_application.CURRENT_STATE == winamp_application.STATE_PLAYING:
115142
print("pausing")

PyPortal_Winamp_Player/winamp_helpers.py

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ class WinampApplication(displayio.Group):
2323
:param playlist_file: json file containing the playlist of songs
2424
:param skin_image: BMP image file for skin background
2525
:param skin_config_file: json file containing color values
26+
:param pyportal_titano: boolean value. True if using Titano, False otherwise.
2627
"""
2728

2829
STATE_PLAYING = 0
2930
STATE_PAUSED = 1
30-
31+
# pylint: disable=too-many-statements
3132
def __init__(
3233
self,
3334
playlist_file="playlist.json",
3435
skin_image="/base_240x320.bmp",
3536
skin_config_file="base_config.json",
37+
pyportal_titano=False,
3638
):
3739
self.SKIN_IMAGE = skin_image
3840
self.SKIN_CONFIG_FILE = skin_config_file
@@ -50,15 +52,35 @@ def __init__(
5052

5153
# initialize clock display
5254
self.clock_display = ClockDisplay(text_color=self.CONFIG_DATA["time_color"])
53-
self.clock_display.x = 44
54-
self.clock_display.y = 22
55+
if not pyportal_titano:
56+
# standard PyPortal and pynt clock display location
57+
# and playlist display parameters
58+
self.clock_display.x = 44
59+
self.clock_display.y = 22
60+
_max_playlist_display_chars = 30
61+
_rows = 3
62+
else:
63+
# PyPortal Titano clock display location
64+
# and playlist display parameters
65+
self.clock_display.x = 65
66+
self.clock_display.y = 37
67+
_max_playlist_display_chars = 42
68+
_rows = 4
5569

5670
# initialize playlist display
5771
self.playlist_display = PlaylistDisplay(
58-
text_color=self.CONFIG_DATA["text_color"]
72+
text_color=self.CONFIG_DATA["text_color"],
73+
max_chars=_max_playlist_display_chars,
74+
rows=_rows,
5975
)
60-
self.playlist_display.x = 13
61-
self.playlist_display.y = 234
76+
if not pyportal_titano:
77+
# standard PyPortal and pynt playlist display location
78+
self.playlist_display.x = 13
79+
self.playlist_display.y = 234
80+
else:
81+
# PyPortal Titano playlist display location
82+
self.playlist_display.x = 20
83+
self.playlist_display.y = 354
6284

6385
# set playlist into playlist display
6486
self.playlist_display.from_files_list(self.PLAYLIST["playlist"]["files"])
@@ -69,15 +91,26 @@ def __init__(
6991
self.playlist_display.current_track_number - 1
7092
]
7193

94+
if not pyportal_titano:
95+
# standard PyPortal and pynt max characters for track title
96+
_max_chars = 22
97+
else:
98+
# PyPortal Titano max characters for track title
99+
_max_chars = 29
72100
# initialize ScrollingLabel for track name
73101
self.current_song_lbl = scrolling_label.ScrollingLabel(
74102
terminalio.FONT,
75103
text=self.playlist_display.current_track_title,
76104
color=self.CONFIG_DATA["text_color"],
77-
max_characters=22,
105+
max_characters=_max_chars,
78106
)
79107
self.current_song_lbl.anchor_point = (0, 0)
80-
self.current_song_lbl.anchored_position = (98, 19)
108+
if not pyportal_titano:
109+
# standard PyPortal and pynt track title location
110+
self.current_song_lbl.anchored_position = (98, 19)
111+
else:
112+
# PyPortal Titano track title location
113+
self.current_song_lbl.anchored_position = (130, 33)
81114

82115
# Setup the skin image file as the bitmap data source
83116
self.background_bitmap = displayio.OnDiskBitmap(self.SKIN_IMAGE)
@@ -193,8 +226,15 @@ def next_track(self):
193226
# increment current track number
194227
self.playlist_display.current_track_number += 1
195228

196-
# start playing track
197-
self.play_current_track()
229+
try:
230+
# start playing track
231+
self.play_current_track()
232+
except OSError as e:
233+
# file not found
234+
print("Error playing: {}".format(self.current_song_file_name))
235+
print(e)
236+
self.next_track()
237+
return
198238

199239
def previous_track(self):
200240
"""
@@ -209,8 +249,15 @@ def previous_track(self):
209249
# decrement current track number
210250
self.playlist_display.current_track_number -= 1
211251

212-
# start playing track
213-
self.play_current_track()
252+
try:
253+
# start playing track
254+
self.play_current_track()
255+
except OSError as e:
256+
# file not found
257+
print("Error playing: {}".format(self.current_song_file_name))
258+
print(e)
259+
self.previous_track()
260+
return
214261

215262
def pause(self):
216263
"""
@@ -244,17 +291,24 @@ class PlaylistDisplay(displayio.Group):
244291
245292
:param text_color: Hex color code for the text in the list
246293
:param song_list: Song names in the list
247-
:param current_track_number: initial track number shown at the top of the list.
294+
:param current_track_number: initial track number shown at the top of the list.l
295+
:param max_chars: int max number of characters to show in a row. Excess characters are cut.
296+
:param rows: how many rows to show. One track per row. Default 3 rows
248297
"""
249298

250-
def __init__(self, text_color, song_list=None, current_track_number=0):
299+
def __init__(
300+
self, text_color, song_list=None, current_track_number=0, max_chars=30, rows=3
301+
):
251302
super().__init__()
252303

304+
self._rows = rows
253305
if song_list is None:
254306
song_list = []
255307
self._song_list = song_list
256308
self._current_track_number = current_track_number
257309

310+
self._max_chars = max_chars
311+
258312
# the label to show track titles inside of
259313
self._label = bitmap_label.Label(terminalio.FONT, color=text_color)
260314

@@ -275,13 +329,15 @@ def update_display(self):
275329

276330
# get the current track plus the following 2
277331
_showing_songs = self.song_list[
278-
self.current_track_number - 1 : self.current_track_number + 3 - 1
332+
self.current_track_number - 1 : self.current_track_number + self._rows - 1
279333
]
280334

281335
# format the track titles into a single string with newlines
282336
_showing_string = ""
283337
for index, song in enumerate(_showing_songs):
284-
_cur_line = "{}. {}".format(self.current_track_number + index, song[:30])
338+
_cur_line = "{}. {}".format(
339+
self.current_track_number + index, song[: self._max_chars]
340+
)
285341
_showing_string = "{}{}\n".format(_showing_string, _cur_line)
286342

287343
# put it into the label

0 commit comments

Comments
 (0)