Skip to content

Commit

Permalink
Added more logging of color table changes to debug post-instrumental …
Browse files Browse the repository at this point in the history
…color palette issue
  • Loading branch information
beveradb committed Oct 30, 2024
1 parent f473414 commit 40dc420
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lrc-to-cdg.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Constants for TOML configuration
CLEAR_MODE = "eager"
BACKGROUND_COLOR = "#111427"
BORDER_COLOR = "#ff7acc"
BORDER_COLOR = "#111427"
FONT_SIZE = 18
STROKE_WIDTH = 0
STROKE_STYLE = "octagon"
Expand Down
Binary file removed src/.DS_Store
Binary file not shown.
Binary file removed src/cdgmaker/.DS_Store
Binary file not shown.
44 changes: 35 additions & 9 deletions src/cdgmaker/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class ComposerState:
class KaraokeComposer:
BACKGROUND = 0
BORDER = 1
UNUSED_COLOR = (255, 122, 204)
UNUSED_COLOR = (0, 0, 0)

#region Constructors
# SECTION Constructors
Expand Down Expand Up @@ -198,6 +198,7 @@ def __init__(
self.color_table = list(pad(
self.color_table, 16, padvalue=self.UNUSED_COLOR,
))
logger.debug(f"Color table: {self.color_table}")

self.max_tile_height = 0
self.lyrics: list[LyricInfo] = []
Expand Down Expand Up @@ -781,6 +782,7 @@ def compose(self):
*memory_preset_repeat(self.BACKGROUND),
*load_color_table(self.color_table),
])
logger.debug(f"loaded color table in compose: {self.color_table}")
if self.config.border is not None:
self.writer.queue_packet(border_preset(self.BORDER))
else:
Expand Down Expand Up @@ -1148,6 +1150,7 @@ def _compose_lyric(
*memory_preset_repeat(self.BACKGROUND),
*load_color_table(self.color_table),
])
logger.debug(f"loaded color table in compose_lyrics: {self.color_table}")
if self.config.border is not None:
self.writer.queue_packet(border_preset(self.BORDER))
composer_state.just_cleared = True
Expand Down Expand Up @@ -1428,16 +1431,21 @@ def _compose_instrumental(
load_color_table_lo(color_table),
*text_image_packets,
])
logger.debug(f"loaded color table in compose_instrumental: {color_table}")
else:
# Queue palette packets
palette = list(it.batched(background_image.getpalette(), 3))
if len(palette) < 8:
color_table = list(pad(palette, 8, padvalue=self.UNUSED_COLOR))
logger.debug(f"loaded color table in compose_instrumental: {color_table}")
self.writer.queue_packet(load_color_table_lo(
list(pad(palette, 8, padvalue=self.UNUSED_COLOR))
color_table,
))
else:
color_table = list(pad(palette, 16, padvalue=self.UNUSED_COLOR))
logger.debug(f"loaded color table in compose_instrumental: {color_table}")
self.writer.queue_packets(load_color_table(
list(pad(palette, 16, padvalue=self.UNUSED_COLOR))
color_table,
))

logger.debug("drawing instrumental text")
Expand Down Expand Up @@ -1515,17 +1523,31 @@ def _compose_instrumental(
logger.debug("this instrumental will last \"forever\"")
return

# Wait until the next line should be drawn
# Wait until 3 seconds before the next line should be drawn
current_time = (
self.writer.packets_queued - self.sync_offset
- self.intro_delay
)
end_time = end - 16
logger.debug(f"waiting for {end_time - current_time} frame(s)")
preparation_time = 3 * CDG_FPS # 3 seconds * 300 frames per second = 900 frames
end_time = max(current_time, end - preparation_time)
wait_time = end_time - current_time

logger.debug(f"waiting for {wait_time} frame(s) before showing next lyrics")
self.writer.queue_packets(
[no_instruction()] * (end_time - current_time)
[no_instruction()] * wait_time
)

# Clear the screen for the next lyrics
self.writer.queue_packets([
*memory_preset_repeat(self.BACKGROUND),
*load_color_table(self.color_table),
])
logger.debug(f"loaded color table in compose_instrumental: {self.color_table}")
if self.config.border is not None:
self.writer.queue_packet(border_preset(self.BORDER))

logger.debug("instrumental section ended")

def _compose_intro(self):
# TODO Make it so the intro screen is not hardcoded
logger.debug("composing intro")
Expand Down Expand Up @@ -1609,12 +1631,16 @@ def _compose_intro(self):
# Queue palette packets
palette = list(it.batched(background_image.getpalette(), 3))
if len(palette) < 8:
color_table = list(pad(palette, 8, padvalue=self.UNUSED_COLOR))
logger.debug(f"loaded color table in compose_intro: {color_table}")
self.writer.queue_packet(load_color_table_lo(
list(pad(palette, 8, padvalue=self.UNUSED_COLOR))
color_table,
))
else:
color_table = list(pad(palette, 16, padvalue=self.UNUSED_COLOR))
logger.debug(f"loaded color table in compose_intro: {color_table}")
self.writer.queue_packets(load_color_table(
list(pad(palette, 16, padvalue=self.UNUSED_COLOR))
color_table,
))

# Render background image to packets
Expand Down

0 comments on commit 40dc420

Please sign in to comment.