Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="24127" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="24506" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="24127"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="24506"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand Down Expand Up @@ -265,6 +265,12 @@ CA
<action selector="showTrackOffsetSheet:" target="-1" id="570"/>
</connections>
</menuItem>
<menuItem title="Clear tracks offsets" keyEquivalent="t" id="cTo-Cl-rOf">
<modifierMask key="keyEquivalentModifierMask" option="YES"/>
<connections>
<action selector="clearTrackOffsets:" target="-1" id="cTo-Ac-rOf"/>
</connections>
</menuItem>
<menuItem title="Insert a Chapter" id="573">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Insert a Chapter" id="574">
Expand Down Expand Up @@ -465,7 +471,8 @@ CA
<action selector="performMiniaturize:" target="-1" id="37"/>
</connections>
</menuItem>
<menuItem title="Zoom" id="239">
<menuItem title="Zoom" keyEquivalent="z" id="239">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<connections>
<action selector="performZoom:" target="-1" id="240"/>
</connections>
Expand Down
23 changes: 20 additions & 3 deletions Base.lproj/QueueOptions.xib
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="UlG-O3-eNc" userLabel="OptionsView">
<rect key="frame" x="0.0" y="0.0" width="382" height="642"/>
<rect key="frame" x="0.0" y="0.0" width="382" height="664"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="zEH-aV-Tl7">
Expand Down Expand Up @@ -527,8 +527,22 @@
</binding>
</connections>
</button>
<button toolTip="Remove start offsets from all tracks" verticalHuggingPriority="752" translatesAutoresizingMaskIntoConstraints="NO" id="cTo-Of-Btn">
<rect key="frame" x="111" y="360" width="124" height="16"/>
<buttonCell key="cell" type="check" title="Clear tracks offsets" bezelStyle="regularSquare" imagePosition="left" alignment="left" controlSize="small" inset="2" id="cTo-Of-Cel">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="label" size="11"/>
</buttonCell>
<connections>
<binding destination="-2" name="value" keyPath="self.options.clearTrackOffset" id="cTo-Of-Bnd">
<dictionary key="options">
<bool key="NSValidatesImmediately" value="YES"/>
</dictionary>
</binding>
</connections>
</button>
<button toolTip="Rename audio tracks according to channel count (Mono, Stereo, Surround)" verticalHuggingPriority="753" translatesAutoresizingMaskIntoConstraints="NO" id="81E-pQ-vyQ">
<rect key="frame" x="111" y="360" width="159" height="16"/>
<rect key="frame" x="111" y="340" width="159" height="16"/>
<buttonCell key="cell" type="check" title="Prettify audio track names" bezelStyle="regularSquare" imagePosition="left" alignment="left" controlSize="small" state="on" inset="2" id="akF-dR-OPB" userLabel="Prettify audio track names">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="label" size="11"/>
Expand Down Expand Up @@ -847,10 +861,13 @@
<constraint firstItem="etc-K7-Atw" firstAttribute="leading" secondItem="S7L-mA-j3Y" secondAttribute="trailing" constant="7" id="lRh-Vo-1XH"/>
<constraint firstItem="KWg-Ak-bB6" firstAttribute="firstBaseline" secondItem="muY-E0-hVI" secondAttribute="firstBaseline" id="lu4-VE-F0x"/>
<constraint firstItem="22k-mA-HyA" firstAttribute="top" secondItem="etc-K7-Atw" secondAttribute="bottom" constant="6" symbolic="YES" id="mRD-fX-qMt"/>
<constraint firstItem="cTo-Of-Btn" firstAttribute="top" secondItem="22k-mA-HyA" secondAttribute="bottom" constant="6" symbolic="YES" id="cTo-Of-Top"/>
<constraint firstItem="cTo-Of-Btn" firstAttribute="leading" secondItem="S7L-mA-j3Y" secondAttribute="trailing" constant="7" id="cTo-Of-Ld"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="cTo-Of-Btn" secondAttribute="trailing" constant="20" symbolic="YES" id="cTo-Of-Tr"/>
<constraint firstItem="86l-GG-SpO" firstAttribute="top" secondItem="DVM-Js-DwK" secondAttribute="bottom" constant="4" id="mYq-MI-cyr"/>
<constraint firstItem="ZZk-4j-Ji7" firstAttribute="top" secondItem="slL-2h-MPl" secondAttribute="bottom" constant="4" id="n9b-Ub-usn"/>
<constraint firstItem="08Q-2k-0Gb" firstAttribute="baseline" secondItem="k33-Yf-DbF" secondAttribute="baseline" id="nPl-tv-zwn"/>
<constraint firstItem="81E-pQ-vyQ" firstAttribute="top" secondItem="22k-mA-HyA" secondAttribute="bottom" constant="6" symbolic="YES" id="ntR-jS-xXX"/>
<constraint firstItem="81E-pQ-vyQ" firstAttribute="top" secondItem="cTo-Of-Btn" secondAttribute="bottom" constant="6" symbolic="YES" id="ntR-jS-xXX"/>
<constraint firstItem="5rh-cM-iOg" firstAttribute="top" secondItem="ZVm-yi-3cE" secondAttribute="bottom" constant="4" id="o3T-cH-W5B"/>
<constraint firstItem="5rh-cM-iOg" firstAttribute="leading" secondItem="73q-gi-fe2" secondAttribute="trailing" constant="9" id="oAW-Hc-PIL"/>
<constraint firstItem="s8r-Cf-VfB" firstAttribute="leading" secondItem="9GN-f6-r2j" secondAttribute="leading" id="oUh-bK-O8z"/>
Expand Down
3 changes: 3 additions & 0 deletions Classes/DocumentToolbarDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class DocumentToolbarDelegate: NSObject, NSToolbarDelegate {
action: #selector(DocumentWindowController.fixAudioFallbacks(_:)),
keyEquivalent: "")
menu.addItem(NSMenuItem.separator())
menu.addItem(withTitle: NSLocalizedString("Clear tracks offsets", comment: "Toolbar"),
action: #selector(DocumentWindowController.clearTrackOffsets(_:)),
keyEquivalent: "")
menu.addItem(withTitle: NSLocalizedString("Offset…", comment: "Toolbar"),
action: #selector(DocumentWindowController.showTrackOffsetSheet(_:)),
keyEquivalent: "")
Expand Down
8 changes: 8 additions & 0 deletions Classes/DocumentWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ final class DocumentWindowController: NSWindowController, TracksViewControllerDe
#selector(addChaptersEvery(_:)),
#selector(iTunesFriendlyTrackGroups(_:)),
#selector(clearTrackNames(_:)),
#selector(clearTrackOffsets(_:)),
#selector(prettifyAudioTrackNames(_:)),
#selector(fixAudioFallbacks(_:)),
#selector(sendToQueue(_:)):
Expand Down Expand Up @@ -342,6 +343,13 @@ final class DocumentWindowController: NSWindowController, TracksViewControllerDe
tracksViewController.reloadData()
}

@IBAction func clearTrackOffsets(_ sender: Any) {
mp4.clearTrackOffsets()

doc.updateChangeCount(.changeDone)
tracksViewController.reloadData()
}

@IBAction func prettifyAudioTrackNames(_ sender: Any) {

for track in mp4.tracks.compactMap({ $0 as? MP42AudioTrack }) {
Expand Down
8 changes: 8 additions & 0 deletions Classes/MP42FileAdditions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ extension MP42File {

return name.isEmpty ? nil : name
}

func clearTrackOffsets() {
for track in tracks {
if track.startOffset != 0 {
track.startOffset = 0
}
}
}
}

extension MP42AudioTrack {
Expand Down
20 changes: 20 additions & 0 deletions Classes/QueueAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,26 @@ class QueueClearTrackNameAction : NSObject, QueueActionProtocol {

}

/// An action that removes track start offsets.
class QueueClearTrackOffsetAction : NSObject, QueueActionProtocol {

var type: QueueActionType { return .pre }
var localizedDescription: String { return NSLocalizedString("Clearing tracks offsets", comment: "Action localized description") }
override var description: String { return NSLocalizedString("Clear tracks offsets", comment: "Action description") }

override init() {}

func runAction(_ item: QueueItem) -> Bool {
item.mp4File?.clearTrackOffsets()
return true
}

func encode(with aCoder: NSCoder) {}
required init?(coder aDecoder: NSCoder) {}
static var supportsSecureCoding: Bool { return true }

}

/// An action that renames audio tracks.
class QueuePrettifyAudioTrackNameAction : NSObject, QueueActionProtocol {

Expand Down
3 changes: 3 additions & 0 deletions Classes/QueueController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
if prefs.clearTrackName {
item.addAction(QueueClearTrackNameAction())
}
if prefs.clearTrackOffset {
item.addAction(QueueClearTrackOffsetAction())
}
if prefs.prettifyAudioTrackName {
item.addAction(QueuePrettifyAudioTrackNameAction())
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/QueueItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ import MP42Foundation
actionsInternal = aDecoder.decodeObject(of: [NSArray.classForCoder(), QueueSetAction.classForCoder(),
QueueMetadataAction.classForCoder(), QueueSubtitlesAction.classForCoder(),
QueueSetLanguageAction.classForCoder(), QueueFixFallbacksAction.classForCoder(),
QueueClearTrackNameAction.classForCoder(), QueuePrettifyAudioTrackNameAction.classForCoder(),
QueueClearTrackNameAction.classForCoder(), QueueClearTrackOffsetAction.classForCoder(), QueuePrettifyAudioTrackNameAction.classForCoder(),
QueueRenameChaptersAction.classForCoder(),
QueueOrganizeGroupsAction.classForCoder(), QueueColorSpaceAction.classForCoder(),
QueueSetOutputFilenameAction.classForCoder(), QueueClearExistingMetadataAction.classForCoder(),
Expand Down
5 changes: 5 additions & 0 deletions Classes/QueuePreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final class QueuePreferences: NSObject {
static private let SBQueueOrganize: String = "SBQueueOrganize"
static private let SBQueueFixFallbacks: String = "SBQueueFixFallbacks"
static private let SBQueueClearTrackName: String = "SBQueueClearTrackName"
static private let SBQueueClearTrackOffset: String = "SBQueueClearTrackOffset"
static private let SBQueuePrettifyAudioTrackName: String = "SBQueuePrettifyAudioTrackName"
static private let SBQueueRenameChapters: String = "SBQueueRenameChapters"
static private let SBQueueMetadata: String = "SBQueueMetadata"
Expand Down Expand Up @@ -60,6 +61,7 @@ final class QueuePreferences: NSObject {
@objc dynamic var organize: Bool
@objc dynamic var fixFallbacks: Bool
@objc dynamic var clearTrackName: Bool
@objc dynamic var clearTrackOffset: Bool
@objc dynamic var prettifyAudioTrackName: Bool
@objc dynamic var renameChapters: Bool
@objc dynamic var subtitles: Bool
Expand Down Expand Up @@ -104,6 +106,7 @@ final class QueuePreferences: NSObject {
self.organize = ud.bool(forKey: QueuePreferences.SBQueueOrganize)
self.fixFallbacks = ud.bool(forKey: QueuePreferences.SBQueueFixFallbacks)
self.clearTrackName = ud.bool(forKey: QueuePreferences.SBQueueClearTrackName)
self.clearTrackOffset = ud.bool(forKey: QueuePreferences.SBQueueClearTrackOffset)
self.prettifyAudioTrackName = ud.bool(forKey: QueuePreferences.SBQueuePrettifyAudioTrackName)
self.renameChapters = ud.bool(forKey: QueuePreferences.SBQueueRenameChapters)
self.subtitles = ud.bool(forKey: QueuePreferences.SBQueueSubtitles)
Expand Down Expand Up @@ -146,6 +149,7 @@ final class QueuePreferences: NSObject {
QueuePreferences.SBQueueFixTrackLanguageValue: "en",
QueuePreferences.SBQueueFixFallbacks: false,
QueuePreferences.SBQueueClearTrackName: false,
QueuePreferences.SBQueueClearTrackOffset: false,
QueuePreferences.SBQueuePrettifyAudioTrackName: false,
QueuePreferences.SBQueueRenameChapters: false,
QueuePreferences.SBQueueMetadata: false,
Expand Down Expand Up @@ -186,6 +190,7 @@ final class QueuePreferences: NSObject {
ud.set(organize, forKey: QueuePreferences.SBQueueOrganize)
ud.set(fixFallbacks, forKey: QueuePreferences.SBQueueFixFallbacks)
ud.set(clearTrackName, forKey: QueuePreferences.SBQueueClearTrackName)
ud.set(clearTrackOffset, forKey: QueuePreferences.SBQueueClearTrackOffset)
ud.set(prettifyAudioTrackName, forKey: QueuePreferences.SBQueuePrettifyAudioTrackName)
ud.set(renameChapters, forKey: QueuePreferences.SBQueueRenameChapters)
ud.set(subtitles, forKey: QueuePreferences.SBQueueSubtitles)
Expand Down
22 changes: 22 additions & 0 deletions Classes/ScriptCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,28 @@ class SBClearTrackNamesScriptCommand: NSScriptCommand, ScriptCommandDocumentTarg
}
}

@objc(SBClearTrackOffsetsScriptCommand)
class SBClearTrackOffsetsScriptCommand: NSScriptCommand, ScriptCommandDocumentTargeting {

override func performDefaultImplementation() -> Any? {
let logger = Logger.shared
guard let sublerDoc = targetedDocument() else {
logger.write(toLog: "No document available for clearing track offsets")
return nil
}

// Use the existing IBAction instead of duplicating logic
if let windowController = sublerDoc.windowControllers.first as? DocumentWindowController {
windowController.clearTrackOffsets(self)
logger.write(toLog: "Script successfully cleared all track offsets")
} else {
logger.write(toLog: "No window controller found for clearing track offsets")
}

return nil
}
}

@objc(SBPrettifyAudioTrackNamesScriptCommand)
class SBPrettifyAudioTrackNamesScriptCommand: NSScriptCommand, ScriptCommandDocumentTargeting {

Expand Down
5 changes: 5 additions & 0 deletions Subler.sdef
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
<parameter name="into" code="into" type="document" optional="yes" description="The target document to clear track names for." />
</command>

<command name="clear track offsets" code="SublClOf" description="Clear all track offsets.">
<cocoa class="SBClearTrackOffsetsScriptCommand" />
<parameter name="into" code="into" type="document" optional="yes" description="The target document to clear track offsets for." />
</command>

<command name="prettify audio track names" code="SublPret" description="Prettify audio track names.">
<cocoa class="SBPrettifyAudioTrackNamesScriptCommand" />
<parameter name="into" code="into" type="document" optional="yes" description="The target document to prettify audio track names for." />
Expand Down