Skip to content

Commit

Permalink
artwork optimization, file locator bugfixes, audio glitch fix test\n\…
Browse files Browse the repository at this point in the history
…nOccasionally after scrubbing within a track, audio glitches would start to present at the intervals when the decode buffer and the playback buffer swapped. This is a ham-fisted attempt to fix that bug, by eschewing all frame calculations when scheduling buffers, and instead telling the audio player node to schedule the decode buffer when we run out of buffer. Testing seems to show that the bug is fixed, but this is still a bit experimental.
  • Loading branch information
jcm93 committed Sep 5, 2017
1 parent 6bd1aea commit b322377
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion jmc/Backend/Audio/AudioModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ class AudioModule: NSObject {
//print("scheduling buffer \(newBuffer) at frame \(frameToScheduleAt). buffer is \(newBuffer.frameLength) in length")
let time = AVAudioTime(sampleTime: frameToScheduleAt, atRate: currentBuffer.format.sampleRate)
//print(time)
curPlayerNode.scheduleBuffer(newBuffer, at: time, options: .init(rawValue: 0), completionHandler: fileBuffererCompletion)
curPlayerNode.scheduleBuffer(newBuffer, at: nil, options: .init(rawValue: 0), completionHandler: fileBuffererCompletion)
if isFinalBuffer == true {
self.finalBufferQueued = true
self.finalBuffer = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AlbumArtViewController: NSViewController {
var mainWindow: MainWindowController?
var databaseManager = DatabaseManager()
var currentTrack: Track?
var currentURL: URL?


override func viewDidLoad() {
Expand Down Expand Up @@ -47,8 +48,9 @@ class AlbumArtViewController: NSViewController {
DispatchQueue.main.async {
if !found {
self.albumArtView.image = nil
self.currentURL = nil
} else {
guard track.album?.primary_art != nil else { self.albumArtView.image = nil; return }
guard track.album?.primary_art != nil else { self.albumArtView.image = nil; self.currentURL = nil; return }
self.initAlbumArt(track)
}
}
Expand All @@ -58,9 +60,11 @@ class AlbumArtViewController: NSViewController {
self.currentTrack = track
if track.album?.primary_art != nil {
let imageURL = URL(string: track.album!.primary_art!.artwork_location!)!
guard self.currentURL != imageURL else { return }
let image = NSImage(byReferencing: imageURL)
if image.isValid {
self.albumArtView.image = image
self.currentURL = imageURL
}
} else {
if track.library?.finds_artwork == true {
Expand All @@ -69,6 +73,7 @@ class AlbumArtViewController: NSViewController {
}
} else {
self.albumArtView.image = nil
self.currentURL = nil
}
}
}
Expand Down
19 changes: 13 additions & 6 deletions jmc/MissingFilesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,24 @@ class MissingTrackPathTree: NSObject {
}
}

init(with missingTracks: [Track]) {
init(with missingTracks: inout [Track]) {
self.rootNode = MissingTrackPathNode(pathComponent: "/")
let allTrackSet = globalRootLibrary!.tracks as! Set<Track>
self.rootNode.totalTracks = allTrackSet
super.init()
for track in missingTracks {
var indexes = [Int]()
for (index, track) in missingTracks.enumerated() {
if let location = track.location, let url = URL(string: location) {
var path = url.path.components(separatedBy: "/").filter({$0 != ""})
createNode(with: &path, with: track)
} else {
indexes.append(index)
//missingTracks.remove(at: index)
}
}
for index in indexes.sorted().reversed() {
missingTracks.remove(at: index)
}
}
}

Expand All @@ -130,9 +137,10 @@ class MissingFilesViewController: NSViewController, NSOutlineViewDataSource, NSO
var pathTree: MissingTrackPathTree
var fileManager = FileManager.default
var missingTracks = Set<Track>()
var libraryManager: LibraryManagerViewController?

init?(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?, tracks: [Track]) {
self.pathTree = MissingTrackPathTree(with: tracks)
init?(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?, tracks: inout [Track]) {
self.pathTree = MissingTrackPathTree(with: &tracks)
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
self.missingTracks = Set(tracks)
}
Expand Down Expand Up @@ -227,8 +235,7 @@ class MissingFilesViewController: NSViewController, NSOutlineViewDataSource, NSO
outlineView.removeItems(at: IndexSet(integer: rowOfThing), inParent: highestThing.parent, withAnimation: .slideUp)
}
node!.purge()
//outlineView.reloadData()
//outlineView.expandItem(nil, expandChildren: true)
libraryManager?.updateMissingTracks(count: missingTracks.count)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AlbumArtWindowController: NSWindowController {
}

func fadeOutTitleBar() {
//self.window!.standardWindowButton(.closeButton)!.superview!.
self.window!.standardWindowButton(.closeButton)!.superview!.animator().alphaValue = 0
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ class LibraryManagerViewController: NSViewController, NSTableViewDelegate, NSTab
}
}

func displayMissingFilesViewController(for tracks: [Track]) {
self.missingFilesViewController = MissingFilesViewController(nibName: "MissingFilesViewController", bundle: nil, tracks: tracks)
func displayMissingFilesViewController(for tracks: inout [Track]) {
self.missingFilesViewController = MissingFilesViewController(nibName: "MissingFilesViewController", bundle: nil, tracks: &tracks)
self.missingFilesViewController?.libraryManager = self
self.locationManagerView.addSubview(self.missingFilesViewController!.view)
self.missingFilesViewController!.view.topAnchor.constraint(equalTo: self.locationManagerView.topAnchor).isActive = true
self.missingFilesViewController!.view.leftAnchor.constraint(equalTo: self.locationManagerView.leftAnchor).isActive = true
Expand All @@ -289,7 +290,7 @@ class LibraryManagerViewController: NSViewController, NSTableViewDelegate, NSTab
func verifyLocationsModalComplete(response: NSModalResponse) {
guard response != NSModalResponseCancel else {return}
if self.missingTracks!.count > 0 {
displayMissingFilesViewController(for: self.missingTracks!)
displayMissingFilesViewController(for: &self.missingTracks!)
let trackNotFoundArray = self.missingTracks!.map({(track: Track) -> TrackNotFound in
if let location = track.location {
if let url = URL(string: location) {
Expand All @@ -310,6 +311,16 @@ class LibraryManagerViewController: NSViewController, NSTableViewDelegate, NSTab
}
}

func updateMissingTracks(count: Int) {
if count > 0 {
self.libraryLocationStatusImageView.image = NSImage(named: "NSStatusPartiallyAvailable")
self.trackLocationStatusText.stringValue = "\(count) tracks not found."
} else {
self.libraryLocationStatusImageView.image = NSImage(named: "NSStatusAvailable")
self.trackLocationStatusText.stringValue = "All tracks located."
}
}

//dir scanner
@IBOutlet weak var newMediaTableView: NSTableView!
@IBOutlet weak var dirScanStatusTextField: NSTextField!
Expand Down

0 comments on commit b322377

Please sign in to comment.