Skip to content

Commit ff29ba8

Browse files
committed
refactoring, refactoring, refactoring
1 parent f727701 commit ff29ba8

19 files changed

Lines changed: 141 additions & 312 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ dist
88
!modules/**/dist
99
**/package-lock.json
1010

11-
native/app/Embedded/*
11+
native/app/Embedded/*
12+
native/app/Sandbox.playground/Resources/track.mp3
Lines changed: 35 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,41 @@
11
import AVFoundation
22
import PlaygroundSupport
3-
import AMCoreAudio
43
import Foundation
5-
import STPrivilegedTask
64

7-
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { timer in
8-
let randomNumber = Int.random(in: 1...20)
9-
print("Number: \(randomNumber)")
10-
}
115

12-
PlaygroundPage.current.needsIndefiniteExecution = true
6+
var engine = AVAudioEngine()
7+
// File
8+
let path = Bundle.main.path(forResource: "track", ofType: "mp3")!
9+
let url = URL(fileURLWithPath: path)
10+
let file = try! AVAudioFile(forReading: url)
11+
let fileFormat = file.processingFormat
12+
let frameCount = UInt32(file.length)
1313

14-
//
15-
//var engine = AVAudioEngine()
16-
//// File
17-
//let path = Bundle.main.path(forResource: "track", ofType: "mp3")!
18-
//let url = URL(fileURLWithPath: path)
19-
//let file = try! AVAudioFile(forReading: url)
20-
//let fileFormat = file.processingFormat
21-
//let frameCount = UInt32(file.length)
22-
//
23-
//let buffer = AVAudioPCMBuffer(pcmFormat: fileFormat, frameCapacity: frameCount)!
24-
//try! file.read(into: buffer, frameCount: frameCount)
25-
//
26-
//let player = AVAudioPlayerNode()
27-
//
28-
//let eq = AVAudioUnitEQ(numberOfBands: 3)
29-
//eq.bypass = false
30-
//eq.globalGain = -16
31-
//let gain = Float32(24)
32-
//let band1 = eq.bands[0]
33-
//band1.filterType = .parametric
34-
//band1.bandwidth = 0.5
35-
//band1.gain = gain
36-
//band1.frequency = 32.0
37-
//band1.bypass = false
38-
//
39-
//let band2 = eq.bands[1]
40-
//band2.filterType = .parametric
41-
//band2.bandwidth = 0.5
42-
//band2.gain = gain
43-
//band2.frequency = 64.0
44-
//band2.bypass = false
45-
//
46-
//let band3 = eq.bands[2]
47-
//band3.filterType = .parametric
48-
//band3.bandwidth = 0.5
49-
//band3.gain = gain
50-
//band3.frequency = 125.0
51-
//band3.bypass = false
52-
//
53-
//var varispeed = AVAudioUnitVarispeed()
54-
//
55-
//engine.attach(varispeed)
56-
//engine.attach(player)
57-
//engine.attach(eq)
58-
//
59-
//
60-
//engine.connect(player, to: varispeed, format: fileFormat)
61-
//engine.connect(varispeed, to: eq, format: fileFormat)
62-
//engine.connect(eq, to: engine.mainMixerNode, format: fileFormat)
63-
//
64-
//try! engine.outputNode.auAudioUnit.setDeviceID(AudioDevice.defaultOutputDevice()!.id)
65-
//engine.prepare()
66-
//try! engine.start()
67-
//print(engine)
68-
//
69-
//player.play()
70-
//player.scheduleBuffer(buffer, at: AVAudioTime(hostTime: 0), options:.loops, completionHandler: nil)
14+
let buffer = AVAudioPCMBuffer(pcmFormat: fileFormat, frameCapacity: frameCount)!
15+
try! file.read(into: buffer, frameCount: frameCount)
16+
17+
let player = AVAudioPlayerNode()
18+
let mixer = AVAudioMixerNode()
19+
let eq = AVAudioUnitEQ()
20+
21+
engine.attach(player)
22+
engine.attach(mixer)
23+
engine.attach(eq)
24+
engine.connect(player, to: mixer, format: fileFormat)
25+
engine.connect(mixer, to: eq, format: fileFormat)
26+
27+
engine.connect(eq, to: engine.mainMixerNode, format: fileFormat)
28+
29+
engine.prepare()
30+
31+
try! engine.start()
32+
print(engine)
33+
engine.mainMixerNode.outputVolume = 0.01
34+
35+
36+
player.play()
37+
player.scheduleBuffer(buffer, at: AVAudioTime(hostTime: 0), options:.loops, completionHandler: nil)
38+
39+
DispatchQueue.main.asyncAfter(deadline: .now() + 5, execute: {
40+
mixer.pan = -1
41+
})

native/app/Sandbox.playground/timeline.xctimeline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
version = "3.0">
44
<TimelineItems>
55
<LoggerValueHistoryTimelineItem
6-
documentLocation = "file:///Users/nodeful/Programming/Bitgapp/eqMac/native/app/Sandbox.playground#CharacterRangeLen=38&amp;CharacterRangeLoc=1314&amp;EndingColumnNumber=2&amp;EndingLineNumber=52&amp;StartingColumnNumber=16&amp;StartingLineNumber=49&amp;Timestamp=615915215.608621"
6+
documentLocation = "file:///Users/nodeful/Programming/Bitgapp/eqMac/native/app/Sandbox.playground#CharacterRangeLen=57&amp;CharacterRangeLoc=494&amp;EndingColumnNumber=0&amp;EndingLineNumber=19&amp;StartingColumnNumber=32&amp;StartingLineNumber=16&amp;Timestamp=645295599.40888"
77
selectedRepresentationIndex = "0"
88
shouldTrackSuperviewWidth = "NO">
99
</LoggerValueHistoryTimelineItem>

native/app/Source/AppDelegate.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, SUUpdaterDelegate {
2121

2222
func applicationDidFinishLaunching(_ aNotification: Notification) {
2323
for window in NSApplication.shared.windows {
24+
window.resignFirstResponder()
2425
window.close()
2526
}
27+
2628
updater.delegate = self
2729
updateProcessed.once { _ in
2830
Application.start()

native/app/Source/Application.swift

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -464,19 +464,9 @@ class Application {
464464
updater.checkForUpdates(nil)
465465
}
466466

467-
static func uninstall (_ completion: @escaping (Bool) -> Void) {
468-
Driver.uninstall(started: {
469-
self.stopSave()
470-
UI.close()
471-
Utilities.delay(100) { UI.showLoadingWindow("Uninstalling eqMac\nIf this process takes too long,\nplease restart your Mac") }
472-
}) { success in
473-
completion(success)
474-
if (success) {
475-
UI.hideLoadingWindow()
476-
try! FileManager.default.removeItem(atPath: Bundle.main.bundlePath)
477-
NSApp.terminate(nil)
478-
}
479-
}
467+
static func uninstall () {
468+
// TODO: Implement uninstaller
469+
Console.log("// TODO: Download Uninstaller")
480470
}
481471

482472
static func stopListeners () {

native/app/Source/ApplicationDataBus.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ApplicationDataBus: DataBus {
2525
"model": Sysctl.model as String,
2626
"version": Bundle.main.infoDictionary?["CFBundleVersion"] as Any,
2727
"isOpenSource": Constants.OPEN_SOURCE,
28-
"driverVersion": Driver.installedVersion
28+
"driverVersion": Driver.installedVersion.description
2929
]
3030
}
3131

@@ -57,10 +57,7 @@ class ApplicationDataBus: DataBus {
5757
}
5858

5959
self.on(.GET, "/uninstall") { _, res in
60-
Application.uninstall() { success in
61-
res.send([ "uninstalled": success ])
62-
}
63-
return nil
60+
return "Downloading Uninstaller"
6461
}
6562

6663
self.on(.GET, "/driver/reinstall/available") { _, res in

native/app/Source/Audio/Engine.swift

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,40 +90,32 @@ class Engine {
9090
}
9191

9292
private func attachVolume () {
93-
// engine.attach(volume.booster.avAudioNode)
94-
engine.attach(volume.leftInput)
95-
engine.attach(volume.rightInput)
96-
engine.attach(volume.mixer)
97-
engine.attach(volume.output)
98-
engine.connect(volume.leftInput, to: volume.mixer, format: format)
99-
engine.connect(volume.rightInput, to: volume.mixer, format: format)
100-
engine.connect(volume.mixer, to: volume.output, format: format)
93+
volume.attachToEngine(engine: engine)
10194
}
10295

10396
private func chain () {
104-
chainSourceToVolume()
105-
chainVolumeToEffects()
97+
chainSourceToEffects()
98+
chainEffectsToVolume()
10699
chainEffects()
107-
chainEffectsToSink()
100+
chainVolumeToSink()
108101
setupRenderCallback()
109102
}
110103

111-
private func chainSourceToVolume () {
104+
private func chainSourceToEffects () {
112105
Console.log("Chaining Source to Volume")
113-
engine.connect(engine.inputNode, to: volume.leftInput, format: format)
114-
engine.connect(engine.inputNode, to: volume.rightInput, format: format)
106+
engine.connect(engine.inputNode, to: effects.equalizers.active.eq, format: format)
115107
}
116108

117-
private func chainVolumeToEffects () {
118-
engine.connect(volume.output, to: effects.equalizers.active.eq, format: format)
109+
private func chainEffectsToVolume () {
110+
engine.connect(effects.equalizers.active.eq, to: volume.mixer, format: format)
119111
}
120112

121113
private func chainEffects () {
122114
Console.log("Chaining Effects")
123115
}
124116

125-
private func chainEffectsToSink () {
126-
engine.connect(effects.equalizers.active.eq, to: engine.mainMixerNode, format: format)
117+
private func chainVolumeToSink () {
118+
engine.connect(volume.output, to: engine.mainMixerNode, format: format)
127119
}
128120

129121
private func setupRenderCallback () {
@@ -174,6 +166,7 @@ class Engine {
174166

175167
private func start () {
176168
engine.prepare()
169+
volume.postSetup()
177170

178171
Console.log("Starting Input Engine")
179172
Console.log(engine)

native/app/Source/Audio/Outputs/Output.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ class Output {
143143

144144
private func start () {
145145
outputEngine.prepare()
146-
147146
Console.log("Starting Output Engine")
148147
Console.log(outputEngine)
149148
try! outputEngine.start()

native/app/Source/Audio/Sources/System/Driver.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ class Driver {
2929
}
3030
}
3131

32-
static var info: Dictionary<String, Any> {
33-
return NSDictionary(contentsOfFile: Bundle.main.path(forResource: "Info", ofType: "plist", inDirectory: "Embedded/eqMac.driver/Contents")!) as! Dictionary<String, Any>
34-
}
35-
3632
static var sampleRates: [Double] {
3733
return [
3834
8_000,
@@ -185,17 +181,5 @@ class Driver {
185181
return AudioDevice.lookup(by: Constants.DRIVER_DEVICE_UID)
186182
}
187183

188-
static func install (started: (() -> Void)? = nil, _ finished: @escaping (Bool) -> Void) {
189-
Script.sudo("install_driver", started: started, { success in
190-
finished(success)
191-
})
192-
}
193-
194-
static func uninstall (started: (() -> Void)? = nil, _ finished: @escaping (Bool) -> Void) {
195-
Script.sudo("uninstall_driver", started: started, { success in
196-
finished(success)
197-
})
198-
}
199-
200184
}
201185

0 commit comments

Comments
 (0)