Skip to content

Commit

Permalink
feat: add option to synchronize seek
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhd1701 committed Nov 22, 2021
1 parent a3a7024 commit b85c554
Show file tree
Hide file tree
Showing 14 changed files with 63,797 additions and 63,523 deletions.
1 change: 1 addition & 0 deletions gridplayer/dialogs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(self, parent):
"playlist/save_position": self.playlistSavePosition,
"playlist/save_state": self.playlistSaveState,
"playlist/save_window": self.playlistSaveWindow,
"playlist/seek_synced": self.playlistSeekSync,
"video_defaults/aspect": self.videoAspect,
"video_defaults/random_loop": self.videoRandomLoop,
"video_defaults/muted": self.videoMuted,
Expand Down
8 changes: 7 additions & 1 deletion gridplayer/dialogs/settings_dialog_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Ui_SettingsDialog(object):
def setupUi(self, SettingsDialog):
SettingsDialog.setObjectName("SettingsDialog")
SettingsDialog.resize(440, 409)
SettingsDialog.resize(440, 481)
self.lay_main = QtWidgets.QVBoxLayout(SettingsDialog)
self.lay_main.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
self.lay_main.setObjectName("lay_main")
Expand Down Expand Up @@ -47,6 +47,9 @@ def setupUi(self, SettingsDialog):
self.playlistSaveState = QtWidgets.QCheckBox(SettingsDialog)
self.playlistSaveState.setObjectName("playlistSaveState")
self.lay_left_column.addWidget(self.playlistSaveState)
self.playlistSeekSync = QtWidgets.QCheckBox(SettingsDialog)
self.playlistSeekSync.setObjectName("playlistSeekSync")
self.lay_left_column.addWidget(self.playlistSeekSync)
self.section_grid = QtWidgets.QLabel(SettingsDialog)
font = QtGui.QFont()
font.setBold(True)
Expand Down Expand Up @@ -255,6 +258,9 @@ def retranslateUi(self, SettingsDialog):
self.playlistSaveState.setText(
_translate("SettingsDialog", "Save videos playing / paused status")
)
self.playlistSeekSync.setText(
_translate("SettingsDialog", "Seek in sync by default")
)
self.section_grid.setText(
_translate("SettingsDialog", "Default Grid Parameters")
)
Expand Down
6 changes: 6 additions & 0 deletions gridplayer/player/managers/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@
"func": "close_playlist",
"enabled_if": "is_videos",
},
"Seek Sync": {
"key": "Shift+S",
"icon": "seek-sync",
"func": "switch_seek_synced",
"check": "is_seek_synced",
},
"+1%": {
"key": Qt.Key_Right,
"icon": "seek-plus-1",
Expand Down
2 changes: 2 additions & 0 deletions gridplayer/player/managers/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
"Play / Pause [ALL]",
(
"Jump (to) [ALL]",
"Seek Sync",
"---",
"Random",
"---",
"+1%",
Expand Down
4 changes: 4 additions & 0 deletions gridplayer/player/managers/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PlaylistManager(ManagerBase):
playlist_loaded = pyqtSignal()
window_state_loaded = pyqtSignal(WindowState)
grid_state_loaded = pyqtSignal(GridState)
is_seek_synced_loaded = pyqtSignal(bool)
videos_loaded = pyqtSignal(list)

alert = pyqtSignal()
Expand Down Expand Up @@ -141,6 +142,8 @@ def load_playlist(self, playlist):
if playlist.window_state is not None:
self.window_state_loaded.emit(playlist.window_state)

self.is_seek_synced_loaded.emit(playlist.is_seek_synced)

self.playlist_loaded.emit()

def check_playlist_save(self):
Expand Down Expand Up @@ -182,4 +185,5 @@ def _make_playlist(self):
grid_state=self._ctx.grid_state,
window_state=self._ctx.window_state,
videos=self._ctx.video_blocks.videos,
is_seek_synced=self._ctx.is_seek_synced,
)
18 changes: 18 additions & 0 deletions gridplayer/player/managers/video_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from PyQt5.QtCore import pyqtSignal

from gridplayer.player.managers.base import ManagerBase
from gridplayer.settings import Settings
from gridplayer.utils.misc import qt_connect
from gridplayer.widgets.video_block import VideoBlock

Expand Down Expand Up @@ -61,10 +62,13 @@ class VideoBlocksManager(ManagerBase):
seek_shift = pyqtSignal(int)
seek_shift_ms = pyqtSignal(int)
seek_random = pyqtSignal()
seek_percent = pyqtSignal(float)

def __init__(self, **kwargs):
super().__init__(**kwargs)

self._ctx._is_seek_synced = Settings().get("playlist/seek_synced")

self._ctx.video_blocks = VideoBlocks()

@property
Expand All @@ -77,6 +81,8 @@ def commands(self):
"step_forward": self.cmd_step_forward,
"step_backward": self.cmd_step_backward,
"is_videos": lambda: bool(self._ctx.video_blocks),
"is_seek_synced": lambda: self._ctx.is_seek_synced,
"switch_seek_synced": self.switch_seek_synced,
}

def cmd_play_pause_all(self):
Expand All @@ -101,6 +107,16 @@ def cmd_step_backward(self):
self.pause_all()
self.step_frame.emit(1)

def seek_sync(self, percent):
if self._ctx.is_seek_synced:
self.seek_percent.emit(percent)

def switch_seek_synced(self):
self._ctx.is_seek_synced = not self._ctx.is_seek_synced

def set_seek_synced(self, is_seek_synced):
self._ctx.is_seek_synced = is_seek_synced

def pause_all(self):
self.set_pause.emit(True)

Expand Down Expand Up @@ -143,10 +159,12 @@ def _add_video_block(self, video):
qt_connect(
(vb.exit_request, self.close_video_block),
(vb.is_paused_change, self.playing_count_change),
(vb.percent_changed, self.seek_sync),
(self.set_pause, vb.set_pause),
(self.seek_shift, vb.seek_shift_percent),
(self.seek_shift_ms, vb.seek_shift),
(self.seek_random, vb.seek_random),
(self.seek_percent, vb.seek_percent),
(self.hide_overlay, vb.hide_overlay),
)

Expand Down
1 change: 1 addition & 0 deletions gridplayer/player/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def __init__(self, **kwargs):
("playlist_loaded", "window_state.activate_window"),
("window_state_loaded", "window_state.restore_window_state"),
("grid_state_loaded", "grid.set_grid_state"),
("is_seek_synced_loaded", "video_blocks.set_seek_synced"),
("videos_loaded", "video_blocks.add_videos"),
("alert", "window_state.activate_window"),
("error", "dialogs.error"),
Expand Down
3 changes: 2 additions & 1 deletion gridplayer/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from gridplayer.params import GridState
from gridplayer.params_static import WindowState
from gridplayer.settings import Settings
from gridplayer.settings import Settings, default_field
from gridplayer.video import Video

logger = logging.getLogger(__name__)
Expand All @@ -16,6 +16,7 @@ class Playlist(BaseModel):
grid_state: GridState = GridState()
window_state: Optional[WindowState]
videos: Optional[List[Video]]
is_seek_synced: bool = default_field("playlist/seek_synced")

@classmethod
def read(cls, filename):
Expand Down
Loading

0 comments on commit b85c554

Please sign in to comment.