Skip to content

Commit

Permalink
shared sswift package setup achieved
Browse files Browse the repository at this point in the history
  • Loading branch information
nodeful committed Nov 23, 2021
1 parent 87a6d76 commit 1015635
Show file tree
Hide file tree
Showing 64 changed files with 617 additions and 513 deletions.
Binary file removed native/app/Embedded
Binary file not shown.
5 changes: 3 additions & 2 deletions native/app/Source/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ServiceManagement
import Sparkle
import EmitterKit
import AMCoreAudio
import Shared

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, SUUpdaterDelegate {
Expand Down Expand Up @@ -42,7 +43,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, SUUpdaterDelegate {
}
}

delay(2000) {
Async.delay(2000) {
if (stillCheckingConnection) {
self.updateProcessed.emit()
}
Expand Down Expand Up @@ -102,7 +103,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, SUUpdaterDelegate {
}

func updater(_ updater: SUUpdater, didDismissUpdateAlertPermanently permanently: Bool, for item: SUAppcastItem) {
delay(500, completion: {
Async.delay(500, completion: {
if !self.willBeDownloadingUpdate {
self.updateProcessed.emit()
}
Expand Down
28 changes: 14 additions & 14 deletions native/app/Source/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import SwiftyJSON
import ServiceManagement
import ReSwift
import Sparkle
import Shared

enum VolumeChangeDirection: String {
case UP = "UP"
Expand Down Expand Up @@ -117,7 +118,7 @@ class Application {
equalizersTypeChangedListener = Equalizers.typeChanged.on { _ in
if (enabled) {
stopSave {}
delay(100) {
Async.delay(100) {
setupAudio()
}
}
Expand Down Expand Up @@ -190,7 +191,7 @@ class Application {
removeEngines()
try! AudioDeviceEvents.recreateEventEmitters([.isAliveChanged, .volumeChanged, .nominalSampleRateChanged])
self.setupDriverDeviceEvents()
delay(500) {
Async.delay(500) {
selectOutput(device: getLastKnowDeviceFromStack())
}
}
Expand All @@ -207,7 +208,7 @@ class Application {
}
} else {
stopRemoveEngines {
delay(1000) {
Async.delay(1000) {
// need a delay, because emitter should finish it's work at first
try! AudioDeviceEvents.recreateEventEmitters([.isAliveChanged, .volumeChanged, .nominalSampleRateChanged])
setupDriverDeviceEvents()
Expand Down Expand Up @@ -258,7 +259,7 @@ class Application {
static func selectOutput (device: AudioDevice) {
ignoreEvents = true
stopRemoveEngines {
delay(500) {
Async.delay(500) {
ignoreEvents = false
AudioDevice.currentOutputDevice = device
}
Expand Down Expand Up @@ -292,8 +293,7 @@ class Application {
}

if (selectedDevice!.outputBalanceSupported) {
balance = mapValue(
value: Double(selectedDevice!.virtualMasterBalance(direction: .playback)!),
balance = Double(selectedDevice!.virtualMasterBalance(direction: .playback)!).remap(
inMin: 0,
inMax: 1,
outMin: -1,
Expand All @@ -318,7 +318,7 @@ class Application {
AudioDevice.currentSystemDevice = Driver.device!

// TODO: Figure out a better way
delay(1000) {
Async.delay(1000) {
ignoreEvents = false
createAudioPipeline()
startingPassthrough = false
Expand Down Expand Up @@ -369,7 +369,7 @@ class Application {
if ignoreEvents { return }
ignoreEvents = true
stopRemoveEngines {
delay(1000) {
Async.delay(1000) {
// need a delay, because emitter should finish it's work at first
try! AudioDeviceEvents.recreateEventEmitters([.isAliveChanged, .volumeChanged, .nominalSampleRateChanged])
setupDriverDeviceEvents()
Expand Down Expand Up @@ -398,7 +398,7 @@ class Application {
ignoreVolumeEvents = true
Driver.device!.setVirtualMasterVolume(deviceVolume, direction: .playback)
Volume.gainChanged.emit(Double(deviceVolume))
delay (50) {
Async.delay (50) {
ignoreVolumeEvents = false
}
}
Expand Down Expand Up @@ -426,7 +426,7 @@ class Application {
}
if direction == .UP {
ignoreNextDriverMuteEvent = true
delay(100) {
Async.delay(100) {
ignoreNextDriverMuteEvent = false
}
}
Expand All @@ -453,7 +453,7 @@ class Application {
var newGain = steps[stepIndex]

if (newGain <= 1) {
delay(100) {
Async.delay(100) {
Driver.device!.setVirtualMasterVolume(Float(newGain), direction: .playback)
}
} else {
Expand Down Expand Up @@ -521,7 +521,7 @@ class Application {
static func stopEngines (_ completion: @escaping () -> Void) {
DispatchQueue.main.async {
var returned = false
delay(2000) {
Async.delay(2000) {
if (!returned) {
completion()
}
Expand Down Expand Up @@ -563,7 +563,7 @@ class Application {

static func handleWakeUp () {
// Wait for devices to initialize, not sure what delay is appropriate
delay(1000) {
Async.delay(1000) {
if !enabled { return }
if lastKnownDeviceStack.count == 0 { return setupAudio() }
let lastDevice = lastKnownDeviceStack.last
Expand All @@ -577,7 +577,7 @@ class Application {
if newDevice != nil && newDevice!.isAlive() && newDevice!.nominalSampleRate() != nil {
setupAudio()
} else {
delay(1000) {
Async.delay(1000) {
checkLastKnownDeviceActive()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import ReSwift
import EmitterKit
import SwiftyUserDefaults
import Shared

class AdvancedEqualizer: Equalizer, StoreSubscriber {
static let frequencies: [Double] = [32, 64, 125, 250, 500, 1_000, 2_000, 4_000, 8_000, 16_000]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation
import ReSwift
import SwiftyUserDefaults
import Shared

struct AdvancedEqualizerState: State {
var selectedPresetId: String = "flat"
Expand All @@ -30,7 +31,7 @@ func AdvancedEqualizerStateReducer(action: Action, state: AdvancedEqualizerState
state.transition = transition
case .setShowDefaultPresets(let show)?:
state.showDefaultPresets = show
delay(100) {
Async.delay(100) {
AdvancedEqualizer.presetsChanged.emit(AdvancedEqualizer.presets)
}
case .none:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ReSwift
import EmitterKit
import AVFoundation
import AMCoreAudio
import Shared

let BasicEqualizerDefaultPresets: [BasicEqualizerPreset] = []
class BasicEqualizer: Equalizer, StoreSubscriber {
Expand Down
1 change: 1 addition & 0 deletions native/app/Source/Audio/Engine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import AVFoundation
import Foundation
import AudioToolbox
import EmitterKit
import Shared

class Engine {

Expand Down
3 changes: 2 additions & 1 deletion native/app/Source/Audio/Outputs/Output.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SwiftyUserDefaults
import EmitterKit
import AVFoundation
import AudioToolbox
import Shared

class Output {
var device: AudioDevice
Expand Down Expand Up @@ -61,7 +62,7 @@ class Output {

self.setupCallback()

delay(200) { [weak self] in
Async.delay(200) { [weak self] in
self?.start()
self?.startComputeVarispeedRate()
}
Expand Down
3 changes: 2 additions & 1 deletion native/app/Source/Audio/Sources/Sources.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation
import ReSwift
import EmitterKit
import Shared

public enum SourceType : String {
// case File = "File"
Expand Down Expand Up @@ -51,7 +52,7 @@ class Sources {
InputSource.requestPermission() { allowed in
if !InputSource.hasPermission {
NSWorkspace.shared.open(URL(string:"x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone")!)
delay(1000) {
Async.delay(1000) {

Alert.confirm(
title: "Microphone Usage Permission",
Expand Down
5 changes: 3 additions & 2 deletions native/app/Source/Audio/Sources/System/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import AMCoreAudio
import CoreFoundation
import Version
import EmitterKit
import Shared

class Driver {
static func check (_ completion: @escaping() -> Void) {
Expand Down Expand Up @@ -96,7 +97,7 @@ class Driver {
return device!.name
}
set {
let size = sizeof(CFString.self)
let size = Memory.sizeof(CFString.self)
var name = newValue as CFString
checkErr(AudioObjectSetPropertyData(Driver.device!.id, &EQMDeviceCustom.addresses.name, 0, nil, size, &name))
}
Expand All @@ -107,7 +108,7 @@ class Driver {
return Driver.device!.latency(direction: .playback)!
}
set {
let size = sizeof(CFNumber.self)
let size = Memory.sizeof(CFNumber.self)

var newLatency = newValue
var latency: CFNumber = CFNumberCreate(kCFAllocatorDefault, CFNumberType.sInt32Type, &newLatency)
Expand Down
6 changes: 3 additions & 3 deletions native/app/Source/Audio/Volume/Volume.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Volume: StoreSubscriber {
}

if (balanceSupported) {
device.setVirtualMasterBalance(Float32(mapValue(value: balance, inMin: -1, inMax: 1, outMin: 0, outMax: 1)), direction: .playback)
device.setVirtualMasterBalance(Float32(balance.remap(inMin: -1, inMax: 1, outMin: 0, outMax: 1)), direction: .playback)
mixer.pan = 0
} else {
mixer.pan = Float(balance)
Expand All @@ -57,10 +57,10 @@ class Volume: StoreSubscriber {
Application.ignoreNextVolumeEvent = true
device.setVirtualMasterVolume(1.0, direction: .playback)
}
virtualVolume = mapValue(value: gain, inMin: 1, inMax: 2, outMin: 1, outMax: 6)
virtualVolume = gain.remap(inMin: 1, inMax: 2, outMin: 1, outMax: 6)

if (balanceSupported) {
device.setVirtualMasterBalance(Float32(mapValue(value: balance, inMin: -1, inMax: 1, outMin: 0, outMax: 1)), direction: .playback)
device.setVirtualMasterBalance(Float32(balance.remap(inMin: -1, inMax: 1, outMin: 0, outMax: 1)), direction: .playback)
mixer.pan = 0
} else {
mixer.pan = Float(balance)
Expand Down
3 changes: 2 additions & 1 deletion native/app/Source/Helpers/eqMac2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation
import AVFoundation
import Shared

class eqMac2 {

Expand All @@ -27,7 +28,7 @@ class eqMac2 {
isDefault: false,
gains: AdvancedEqualizerPresetGains(
global: 0,
bands: gains.map { mapValue(value: $0, inMin: -1, inMax: 1, outMin: -24, outMax: 24) }
bands: gains.map { $0.remap(inMin: -1, inMax: 1, outMin: -24, outMax: 24) }
)
))
}
Expand Down
4 changes: 3 additions & 1 deletion native/app/Source/Networking/Networking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import Foundation
import Connectivity
import EmitterKit
import Shared

class Networking {
static let connectivity = Connectivity()

Expand Down Expand Up @@ -47,7 +49,7 @@ class Networking {
}
}

delay(1000) {
Async.delay(1000) {
if (!returned) {
returned = true
completion(false)
Expand Down
7 changes: 4 additions & 3 deletions native/app/Source/UI/UI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import SwiftyUserDefaults
import WebKit
import Zip
import SwiftHTTP
import Shared

enum UIMode: String, Codable {
case window = "window"
Expand Down Expand Up @@ -288,12 +289,12 @@ class UI: StoreSubscriber {
UI.cachedIsShown = shown
UI.isShownChanged.emit(shown)
}
delay(1000) { checkIfVisible() }
Async.delay(1000) { checkIfVisible() }
}

checkIfVisible()
completion()
delay(1000) {
Async.delay(1000) {
UI.duringInit = false
}
}
Expand Down Expand Up @@ -457,7 +458,7 @@ class UI: StoreSubscriber {
}
}

delay(1000) {
Async.delay(1000) {
if (!returned) {
returned = true
completion(false)
Expand Down
3 changes: 2 additions & 1 deletion native/app/Source/UI/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Cocoa
import WebKit
import EmitterKit
import Shared

class ViewController: NSViewController, WKNavigationDelegate {
// MARK: - Properties
Expand Down Expand Up @@ -56,7 +57,7 @@ class ViewController: NSViewController, WKNavigationDelegate {
self.webView.load(request)


delay(1000) {
Async.delay(1000) {
self.loadingView.isHidden = true
self.loadingSpinner.stopAnimation(nil)
}
Expand Down
3 changes: 2 additions & 1 deletion native/app/Source/UI/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation
import Cocoa
import Shared

class Window: NSWindow, NSWindowDelegate {

Expand All @@ -20,7 +21,7 @@ class Window: NSWindow, NSWindowDelegate {
self.titlebarAppearsTransparent = true
self.isMovableByWindowBackground = true

delay(1000, completion: {
Async.delay(1000, completion: {
for subview in self.contentView!.superview!.subviews {
if subview.isKind(of: NSClassFromString("NSTitlebarContainerView")!) {
let titleBarView = subview.subviews[0]
Expand Down
File renamed without changes.
Loading

0 comments on commit 1015635

Please sign in to comment.