Skip to content

Commit

Permalink
Added playhead
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaid committed Dec 21, 2023
1 parent 8a16809 commit 2d1ac7b
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 18 deletions.
7 changes: 0 additions & 7 deletions binary-waterfall.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import os
import importlib.util

from src import binary_waterfall

if '_PYIBoot_SPLASH' in os.environ and importlib.util.find_spec("pyi_splash"):
import pyi_splash
pyi_splash.close()

if __name__ == "__main__":
binary_waterfall.run()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "binary-waterfall"
version = "3.5.2"
version = "3.6.0"
readme = "README_pypi.md"
description = "A Raw Data Media Player"
license= {file = "LICENSE"}
Expand Down
2 changes: 1 addition & 1 deletion src/binary_waterfall/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .core import run, constants
from .core import run
1 change: 1 addition & 0 deletions src/binary_waterfall/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
from .resources import RESOURCE_PATH, ICON_PATHS
from .links import PROJECT_URL, DONATE_URL, REGISTER_URL
from .colors import COLORS
from .splash import HAS_SPLASH
7 changes: 7 additions & 0 deletions src/binary_waterfall/constants/splash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os
import importlib.util

if '_PYIBoot_SPLASH' in os.environ and importlib.util.find_spec("pyi_splash"):
HAS_SPLASH = True
else:
HAS_SPLASH = False
4 changes: 4 additions & 0 deletions src/binary_waterfall/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def run(self):


def main(args):
if constants.HAS_SPLASH:
import pyi_splash
pyi_splash.close()

main_window = MainWindow(args)
main_window.run()

Expand Down
28 changes: 23 additions & 5 deletions src/binary_waterfall/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def __init__(self,
flip_v,
flip_h,
alignment,
playhead_visible,
parent=None
):
super().__init__(parent=parent)
Expand All @@ -163,6 +164,7 @@ def __init__(self,
self.flip_v = flip_v
self.flip_h = flip_h
self.alignment = alignment
self.playhead_visible = playhead_visible

self.width_label = QLabel("Width:")
self.width_label.setAlignment(Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignRight)
Expand Down Expand Up @@ -207,6 +209,13 @@ def __init__(self,
self.alignment_entry.setCurrentIndex(2)
self.alignment_entry.currentIndexChanged.connect(self.alignment_entry_changed)

self.playhead_entry_label = QLabel("Playhead:")
self.playhead_entry_label.setAlignment(Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignRight)

self.playhead_entry = QCheckBox("Visible")
self.playhead_entry.setChecked(self.playhead_visible)
self.playhead_entry.stateChanged.connect(self.playhead_entry_changed)

self.flip_v_entry_label = QLabel("Vertical:")
self.flip_v_entry_label.setAlignment(Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignRight)

Expand Down Expand Up @@ -235,11 +244,13 @@ def __init__(self,
self.main_layout.addWidget(self.color_format_entry, 2, 1)
self.main_layout.addWidget(self.alignment_label, 3, 0)
self.main_layout.addWidget(self.alignment_entry, 3, 1)
self.main_layout.addWidget(self.flip_v_entry_label, 4, 0)
self.main_layout.addWidget(self.flip_v_entry, 4, 1)
self.main_layout.addWidget(self.flip_h_entry_label, 5, 0)
self.main_layout.addWidget(self.flip_h_entry, 5, 1)
self.main_layout.addWidget(self.confirm_buttons, 6, 0, 1, 2)
self.main_layout.addWidget(self.playhead_entry_label, 4, 0)
self.main_layout.addWidget(self.playhead_entry, 4, 1)
self.main_layout.addWidget(self.flip_v_entry_label, 5, 0)
self.main_layout.addWidget(self.flip_v_entry, 5, 1)
self.main_layout.addWidget(self.flip_h_entry_label, 6, 0)
self.main_layout.addWidget(self.flip_h_entry, 6, 1)
self.main_layout.addWidget(self.confirm_buttons, 7, 0, 1, 2)

self.setLayout(self.main_layout)

Expand All @@ -253,6 +264,7 @@ def get_video_settings(self):
result["flip_v"] = self.flip_v
result["flip_h"] = self.flip_h
result["alignment"] = self.alignment
result["playhead_visible"] = self.playhead_visible

return result

Expand All @@ -278,6 +290,12 @@ def color_format_entry_changed(self):
error_popup.setWindowTitle("Error")
error_popup.exec()

def playhead_entry_changed(self, value):
if value == 0:
self.playhead_visible = False
else:
self.playhead_visible = True

def flip_v_entry_changed(self, value):
if value == 0:
self.flip_v = False
Expand Down
32 changes: 29 additions & 3 deletions src/binary_waterfall/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def __init__(self,
volume=100,
flip_v=True,
flip_h=False,
alignment=constants.AlignmentCode.MIDDLE
alignment=constants.AlignmentCode.MIDDLE,
playhead_visible=True
):
# Initialize class variables
self.audio_length_ms = None
Expand All @@ -48,7 +49,8 @@ def __init__(self,
self.audio_filename = None
self.flip_v = None
self.flip_h = None
self.alignment = alignment
self.alignment = None
self.playhead_visible = None

# Make the temp dir for the class instance
self.temp_dir = tempfile.mkdtemp()
Expand All @@ -71,6 +73,8 @@ def __init__(self,

self.set_alignment(alignment=alignment)

self.set_playhead_visible(playhead_visible=playhead_visible)

self.set_audio_settings(
num_channels=num_channels,
sample_bytes=sample_bytes,
Expand Down Expand Up @@ -278,6 +282,9 @@ def set_flip(self, flip_v, flip_h):
def set_alignment(self, alignment):
self.alignment = alignment

def set_playhead_visible(self, playhead_visible):
self.playhead_visible = playhead_visible

def set_audio_settings(self,
num_channels,
sample_bytes,
Expand Down Expand Up @@ -379,6 +386,14 @@ def get_address(self, ms):

return address

def get_playhead_row(self):
if self.alignment == constants.AlignmentCode.END:
return 0
elif self.alignment == constants.AlignmentCode.START:
return self.height - 1
else:
return round((self.height - 1) / 2)

# A 1D Python byte string
def get_frame_bytestring(self, ms):
picture_bytes = bytes()
Expand All @@ -404,7 +419,7 @@ def get_frame_bytestring(self, ms):
if len(picture_bytes) >= full_length:
break

# Fill one BGR byte value
# Fill one RGB byte value
this_byte = [b'\x00', b'\x00', b'\x00']
for c in self.color_format:
if c == constants.ColorFmtCode.RED:
Expand Down Expand Up @@ -441,6 +456,17 @@ def get_frame_bytestring(self, ms):
pad_length = full_length - picture_bytes_length
picture_bytes += b"\x00" * pad_length

# Invert playhead row if needed
if self.playhead_visible:
playhead_row = self.get_playhead_row()
row_size = self.width * 3
playhead_start = playhead_row * row_size
playhead_end = playhead_start + row_size

playhead = helpers.invert_bytes(picture_bytes[playhead_start:playhead_end])

picture_bytes = picture_bytes[:playhead_start] + playhead + picture_bytes[playhead_end:]

return picture_bytes

# A PIL Image (RGB)
Expand Down
2 changes: 1 addition & 1 deletion src/binary_waterfall/version.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Version: 3.5.2
Version: 3.6.0
CompanyName: Ella Jameson (nimaid)
FileDescription: A Raw Data Media Player
InternalName: Binary Waterfall
Expand Down
4 changes: 4 additions & 0 deletions src/binary_waterfall/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def video_settings_clicked(self):
flip_v=self.bw.flip_v,
flip_h=self.bw.flip_h,
alignment=self.bw.alignment,
playhead_visible=self.bw.playhead_visible,
parent=self
)

Expand All @@ -478,6 +479,9 @@ def video_settings_clicked(self):
self.bw.set_alignment(
alignment=video_settings["alignment"]
)
self.bw.set_playhead_visible(
playhead_visible=video_settings["playhead_visible"]
)
self.player.refresh_dims()
self.player.update_image()
# We need to wait a moment for the size hint to be computed
Expand Down

0 comments on commit 2d1ac7b

Please sign in to comment.