Skip to content

Commit

Permalink
Close support subtitle visibility, #4235
Browse files Browse the repository at this point in the history
This commit will:
- Add a Hide Subtitles/Show Subtitles item to the Subtitles menu
- Add a Hide Second Subtitles/Show Second Subtitles item to the
  Subtitles menu
- Add buttons for controlling visibility of subtitles to the SUBTITLES
  tab of the Quick Settings Panel
- Add a key binding mapping v to cycle sub-visibility
- Add a key binding mapping Alt-v to cycle secondary-sub-visibility
- Add a new OSD messages Subtitles Hidden and Subtitles Visible
- Add a new OSD messages Second Subtitles Hidden and Second Subtitles
  Visible
- Add secondary-sub-visibility to watch-later-options
- Add logging of watch-later-options

These changes add a graphical user interface for the mpv features that
control subtitle visibility.
  • Loading branch information
low-batt committed May 17, 2023
1 parent c896187 commit db53072
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 70 deletions.
2 changes: 2 additions & 0 deletions iina/AppData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,6 @@ extension Notification.Name {
static let iinaPlayerStopped = Notification.Name("iinaPlayerStopped")
static let iinaPlayerShutdown = Notification.Name("iinaPlayerShutdown")
static let iinaPlaySliderLoopKnobChanged = Notification.Name("iinaPlaySliderLoopKnobChanged")
static let iinaSecondSubVisibilityChanged = Notification.Name("iinaSecondSubVisibilityChanged")
static let iinaSubVisibilityChanged = Notification.Name("iinaSubVisibilityChanged")
}
1 change: 1 addition & 0 deletions iina/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"quicksetting.hwdec" = "Hardware Decoding";
"quicksetting.deinterlace" = "Deinterlace";
"quicksetting.hdr" = "HDR";
"quicksetting.hide" = "Hide";

// OSDMessage.swift
"osd.pause" = "Pause";
Expand Down
178 changes: 122 additions & 56 deletions iina/Base.lproj/QuickSettingViewController.xib

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions iina/MPVController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,13 @@ class MPVController: NSObject {
// sub-visibility, but the option secondary-sub-visibility is missing. This inconsistency is
// likely to confuse users, so insure the visibility setting for secondary subtitles is also
// saved in watch later files.
if let watchLaterOptions = getString(MPVOption.ProgramBehavior.watchLaterOptions),
if let watchLaterOptions = getString(MPVOption.WatchLater.watchLaterOptions),
watchLaterOptions.contains(MPVOption.Subtitles.subVisibility),
!watchLaterOptions.contains(MPVOption.Subtitles.secondarySubVisibility) {
setString(MPVOption.ProgramBehavior.watchLaterOptions, watchLaterOptions + "," +
setString(MPVOption.WatchLater.watchLaterOptions, watchLaterOptions + "," +
MPVOption.Subtitles.secondarySubVisibility)
}
if let watchLaterOptions = getString(MPVOption.ProgramBehavior.watchLaterOptions) {
if let watchLaterOptions = getString(MPVOption.WatchLater.watchLaterOptions) {
Logger.log("Options mpv is configured to save in watch later files: \(watchLaterOptions)")
}

Expand Down Expand Up @@ -1132,17 +1132,15 @@ class MPVController: NSObject {

case MPVOption.Subtitles.subVisibility:
if let visible = UnsafePointer<Bool>(OpaquePointer(property.data))?.pointee {
if player.info.isSubVisible != visible {
player.info.isSubVisible = visible
player.sendOSD(visible ? .subVisible : .subHidden)
DispatchQueue.main.async {
self.player.subVisibilityChanged(visible)
}
}

case MPVOption.Subtitles.secondarySubVisibility:
if let visible = UnsafePointer<Bool>(OpaquePointer(property.data))?.pointee {
if player.info.isSecondSubVisible != visible {
player.info.isSecondSubVisible = visible
player.sendOSD(visible ? .secondSubVisible : .secondSubHidden)
DispatchQueue.main.async {
self.player.secondSubVisibilityChanged(visible)
}
}

Expand Down
24 changes: 20 additions & 4 deletions iina/PlayerCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -975,12 +975,14 @@ class PlayerCore: NSObject {
}
}

func toggleSubVisibility() {
mpv.setFlag(MPVOption.Subtitles.subVisibility, !info.isSubVisible)
func toggleSubVisibility(_ set: Bool? = nil) {
let newState = set ?? !info.isSubVisible
mpv.setFlag(MPVOption.Subtitles.subVisibility, newState)
}

func toggleSecondSubVisibility() {
mpv.setFlag(MPVOption.Subtitles.secondarySubVisibility, !info.isSecondSubVisible)
func toggleSecondSubVisibility(_ set: Bool? = nil) {
let newState = set ?? !info.isSecondSubVisible
mpv.setFlag(MPVOption.Subtitles.secondarySubVisibility, newState)
}

func loadExternalSubFile(_ url: URL, delay: Bool = false) {
Expand Down Expand Up @@ -1608,13 +1610,27 @@ class PlayerCore: NSObject {
postNotification(.iinaSIDChanged)
}

func secondSubVisibilityChanged(_ visible: Bool) {
guard info.isSecondSubVisible != visible else { return }
info.isSecondSubVisible = visible
sendOSD(visible ? .secondSubVisible : .secondSubHidden)
postNotification(.iinaSecondSubVisibilityChanged)
}

func sidChanged() {
guard !isShuttingDown, !isShutdown else { return }
info.sid = Int(mpv.getInt(MPVOption.TrackSelection.sid))
postNotification(.iinaSIDChanged)
sendOSD(.track(info.currentTrack(.sub) ?? .noneSubTrack))
}

func subVisibilityChanged(_ visible: Bool) {
guard info.isSubVisible != visible else { return }
info.isSubVisible = visible
sendOSD(visible ? .subVisible : .subHidden)
postNotification(.iinaSubVisibilityChanged)
}

func trackListChanged() {
// No need to process track list changes if playback is being stopped. Must not process track
// list changes if mpv is terminating as accessing mpv once shutdown has been initiated can
Expand Down
14 changes: 13 additions & 1 deletion iina/QuickSettingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ class QuickSettingViewController: NSViewController, NSTableViewDataSource, NSTab
@IBOutlet weak var audioDelaySliderConstraint: NSLayoutConstraint!
@IBOutlet weak var customAudioDelayTextField: NSTextField!


@IBOutlet weak var hideSwitch: Switch!
@IBOutlet weak var secHideSwitch: Switch!
@IBOutlet weak var subLoadSementedControl: NSSegmentedControl!
@IBOutlet weak var subDelaySlider: NSSlider!
@IBOutlet weak var subDelaySliderIndicator: NSTextField!
Expand Down Expand Up @@ -211,6 +212,8 @@ class QuickSettingViewController: NSViewController, NSTableViewDataSource, NSTab
self.subTableView.reloadData()
self.secSubTableView.reloadData()
}
observe(.iinaSecondSubVisibilityChanged) { [unowned self] _ in secHideSwitch.checked = !player.info.isSecondSubVisible }
observe(.iinaSubVisibilityChanged) { [unowned self] _ in hideSwitch.checked = !player.info.isSubVisible }
}

// MARK: - Validate UI
Expand Down Expand Up @@ -282,6 +285,15 @@ class QuickSettingViewController: NSViewController, NSTableViewDataSource, NSTab
}

private func updateSubTabControl() {
hideSwitch.checked = !player.info.isSubVisible
hideSwitch.action = {
self.player.toggleSubVisibility(!$0)
}
secHideSwitch.checked = !player.info.isSecondSubVisible
secHideSwitch.action = {
self.player.toggleSecondSubVisibility(!$0)
}

if let currSub = player.info.currentTrack(.sub) {
// FIXME: CollorWells cannot be disable?
let enableTextSettings = !(currSub.isAssSub || currSub.isImageSub)
Expand Down
1 change: 1 addition & 0 deletions iina/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"quicksetting.hwdec" = "Hardware Decoding";
"quicksetting.deinterlace" = "Deinterlace";
"quicksetting.hdr" = "HDR";
"quicksetting.hide" = "Hide";

// OSDMessage.swift
"osd.pause" = "Pause";
Expand Down

0 comments on commit db53072

Please sign in to comment.