fix(document): consolidate rename logic
This commit is contained in:
1 parent
760664a3de
commit
5a93cdc607
1 file changed
+7
-6
@@ -318,15 +318,15 @@ final class DocumentWindowController: NSWindowController, TracksViewControllerDe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func prettifyAudioTrackNames(_ sender: Any) {
|
@IBAction func prettifyAudioTrackNames(_ sender: Any) {
|
||||||
|
// Iterate audio tracks
|
||||||
for track in mp4.tracks {
|
for track in mp4.tracks {
|
||||||
if let audioTrack = track as? MP42AudioTrack {
|
if let audioTrack = track as? MP42AudioTrack {
|
||||||
// Lookup number of channels from Format cell
|
// Parse format summary for channel count
|
||||||
let lowerBound = String.Index.init(encodedOffset: audioTrack.formatSummary.count-4)
|
if let range = audioTrack.formatSummary.range(of: "(\\d+)(?=\\D*$)", options: .regularExpression) {
|
||||||
let upperBound = String.Index.init(encodedOffset: audioTrack.formatSummary.count-3)
|
let channelCount = Int(audioTrack.formatSummary[range])!
|
||||||
let channelCount = Int(String(audioTrack.formatSummary[lowerBound..<upperBound]))
|
|
||||||
|
|
||||||
// Derive track name from number of channels
|
// Use channel count to determine track name
|
||||||
if channelCount! < 2 {
|
if channelCount < 2 {
|
||||||
audioTrack.name = "Mono Audio"
|
audioTrack.name = "Mono Audio"
|
||||||
} else if channelCount == 2 {
|
} else if channelCount == 2 {
|
||||||
audioTrack.name = "Stereo Audio"
|
audioTrack.name = "Stereo Audio"
|
||||||
@@ -335,6 +335,7 @@ final class DocumentWindowController: NSWindowController, TracksViewControllerDe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
doc.updateChangeCount(.changeDone)
|
doc.updateChangeCount(.changeDone)
|
||||||
tracksViewController.reloadData()
|
tracksViewController.reloadData()
|
||||||
|
|||||||
Reference in new issue
Block a user