Skip to content

Commit

Permalink
Merge pull request #138 from NickCulbertson/CodeRefactor
Browse files Browse the repository at this point in the history
Code Refactor
  • Loading branch information
NickCulbertson committed Nov 10, 2023
2 parents 9bea0d4 + c1b9748 commit 8c5cb76
Show file tree
Hide file tree
Showing 24 changed files with 20 additions and 69 deletions.
2 changes: 0 additions & 2 deletions Cookbook/Cookbook/CookbookApp.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright AudioKit. All Rights Reserved.

import AudioKit
import AudioKitEX
import AudioKitUI
import AVFoundation
import CookbookCommon
import SwiftUI
Expand Down
25 changes: 8 additions & 17 deletions Cookbook/CookbookCommon/Sources/CookbookCommon/ContentView.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import AudioKit
import AudioKitEX
import AudioKitUI
import AVFoundation
import SwiftUI

struct ContentView: View {
var body: some View {
NavigationView {
MasterView()
// DetailView()
}.navigationViewStyle(StackNavigationViewStyle())
}
}
Expand All @@ -28,19 +23,15 @@ struct MasterView: View {
NavigationLink("Instrument SFZ", destination: InstrumentSFZView())
}
Group {
NavigationLink("MIDI Monitor", destination: MIDIMonitorView())
NavigationLink("MIDI Track View", destination: MIDITrackDemo())
NavigationLink("Music Toy", destination: MusicToyView())
NavigationLink("Noise Generators", destination: NoiseGeneratorsView())
NavigationLink("Recorder", destination: RecorderView())
NavigationLink("Telephone", destination: Telephone())
NavigationLink("Tuner", destination: TunerView())
NavigationLink("Noise Generators", destination: NoiseGeneratorsView())
NavigationLink("Vocal Tract", destination: VocalTractView())
NavigationLink("MIDI Monitor", destination: MIDIMonitorView())
NavigationLink("MIDI Track View", destination: MIDITrackDemo())
NavigationLink("Recorder", destination: RecorderView())
}
// TODO:
// Text("Level Meter")
// Text("Sequencer")
// Text("MIDI Controller") - MIDI Output Sender
}
}
Group {
Expand Down Expand Up @@ -90,7 +81,7 @@ struct MasterView: View {
Group {
DisclosureGroup("Effects") {
Group {
NavigationLink("Audio3D", destination: AudioKit3DView())
NavigationLink("Audio 3D", destination: AudioKit3DView())
NavigationLink("Auto Panner", destination: AutoPannerView())
NavigationLink("Auto Wah", destination: AutoWahView())
NavigationLink("Balancer", destination: BalancerView())
Expand Down Expand Up @@ -136,12 +127,12 @@ struct MasterView: View {
Group {
DisclosureGroup("Reverb") {
Group {
NavigationLink("Apple Reverb", destination: ReverbView())
NavigationLink("Chowning Reverb", destination: ChowningReverbView())
NavigationLink("Comb Filter Reverb", destination: CombFilterReverbView())
NavigationLink("Costello Reverb", destination: CostelloReverbView())
NavigationLink("Flat Frequency Response Reverb",
destination: FlatFrequencyResponseReverbView())
NavigationLink("Apple Reverb", destination: ReverbView())
NavigationLink("Zita Reverb", destination: ZitaReverbView())
}
}
Expand Down Expand Up @@ -188,10 +179,10 @@ struct MasterView: View {
NavigationLink("Amplitude Envelope", destination: AmplitudeEnvelopeView())
NavigationLink("Dynamic Oscillator", destination: DynamicOscillatorView())
NavigationLink("FM Frequency Modulation", destination: FMOscillatorView())
NavigationLink("Waveform Morphing", destination: MorphingOscillatorView())
NavigationLink("Sine", destination: OscillatorView())
NavigationLink("Phase Distortion", destination: PhaseDistortionOscillatorView())
NavigationLink("Pulse Width Modulation", destination: PWMOscillatorView())
NavigationLink("Sine", destination: OscillatorView())
NavigationLink("Waveform Morphing", destination: MorphingOscillatorView())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ final class AudioKit3DVM: ObservableObject {
init() {
coordinator.updateAudioSourceNodeDelegate = conductor
}

}

protocol UpdateAudioSourceNodeDelegate: AnyObject {
Expand Down Expand Up @@ -57,7 +56,6 @@ class AudioEngine3DConductor: ObservableObject, ProcessesPlayerInput, UpdateAudi
engine.mainMixerNode?.pan = 1.0

print(engine.avEngine)

}

deinit {
Expand All @@ -82,7 +80,6 @@ class AudioEngine3DConductor: ObservableObject, ProcessesPlayerInput, UpdateAudi
func updateSoundSourcePosition(_ position3D: AVAudio3DPoint) {
source1mixer3D.position = position3D
}

}

class SceneCoordinator: NSObject, SCNSceneRendererDelegate, ObservableObject {
Expand Down Expand Up @@ -135,14 +132,11 @@ class SceneCoordinator: NSObject, SCNSceneRendererDelegate, ObservableObject {
y: pointOfView.upVector.y,
z: pointOfView.upVector.z)
))

}

renderer.showsStatistics = self.showsStatistics
renderer.debugOptions = self.debugOptions

}

}

struct AudioKit3DView: View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class AutoWahConductor: ObservableObject, ProcessesPlayerInput {

autowah = AutoWah(player)
dryWetMixer = DryWetMixer(player, autowah)

engine.output = dryWetMixer
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ChorusConductor: ObservableObject, ProcessesPlayerInput {

chorus = Chorus(player)
dryWetMixer = DryWetMixer(player, chorus)
engine.output = chorus
engine.output = dryWetMixer
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class CompressorConductor: ObservableObject, ProcessesPlayerInput {
player.isLooping = true

compressor = Compressor(player)

dryWetMixer = DryWetMixer(player, compressor)
engine.output = dryWetMixer
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class ExpanderConductor: ObservableObject, ProcessesPlayerInput {
player.isLooping = true

expander = Expander(player)

dryWetMixer = DryWetMixer(player, expander)
engine.output = dryWetMixer
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class PeakLimiterConductor: ObservableObject, ProcessesPlayerInput {
player.isLooping = true

peakLimiter = PeakLimiter(player)

dryWetMixer = DryWetMixer(player, peakLimiter)
engine.output = dryWetMixer
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class PhaseLockedVocoderConductor: ObservableObject, HasAudioEngine {
phaseLockedVocoder.amplitude = 1
phaseLockedVocoder.pitchRatio = 1
phaseLockedVocoder.start()

engine.output = phaseLockedVocoder
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ class InstrumentEXSConductor: ObservableObject, HasAudioEngine {
} catch {
Log("Could not load instrument")
}
do {
try engine.start()
} catch {
Log("AudioKit did not start!")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@ class InstrumentSFZConductor: ObservableObject, HasAudioEngine {
Log("Could not find file")
}
instrument.masterVolume = 0.15

engine.output = instrument

do {
try engine.start()
} catch {
Log("AudioKit did not start!")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct NoiseData {
}

class NoiseGeneratorsConductor: ObservableObject, HasAudioEngine {
let engine = AudioEngine()
var brown = BrownianNoise()
var pink = PinkNoise()
var white = WhiteNoise()
Expand All @@ -26,8 +27,6 @@ class NoiseGeneratorsConductor: ObservableObject, HasAudioEngine {
}
}

let engine = AudioEngine()

init() {
mixer.addInput(brown)
mixer.addInput(pink)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import Tonic
//: * Release is the amount of time after a note is let go for the sound to die away to zero.
class AmplitudeEnvelopeConductor: ObservableObject, HasAudioEngine {
let engine = AudioEngine()
var osc: Oscillator
var env: AmplitudeEnvelope
var fader: Fader
var currentNote = 0

func noteOn(pitch: Pitch, point _: CGPoint) {
Expand All @@ -33,10 +36,6 @@ class AmplitudeEnvelopeConductor: ObservableObject, HasAudioEngine {
env.closeGate()
}

var osc: Oscillator
var env: AmplitudeEnvelope
var fader: Fader

init() {
osc = Oscillator()
env = AmplitudeEnvelope(osc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Tonic

class DynamicOscillatorConductor: ObservableObject, HasAudioEngine {
let engine = AudioEngine()
var osc = DynamicOscillator()

func noteOn(pitch: Pitch, point _: CGPoint) {
isPlaying = true
Expand All @@ -23,8 +24,6 @@ class DynamicOscillatorConductor: ObservableObject, HasAudioEngine {
didSet { isPlaying ? osc.start() : osc.stop() }
}

var osc = DynamicOscillator()

init() {
osc.amplitude = 0.2
engine.output = osc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import SwiftUI

class FMOscillatorConductor: ObservableObject, HasAudioEngine {
let engine = AudioEngine()
var osc = FMOscillator()

@Published var isPlaying: Bool = false {
didSet { isPlaying ? osc.start() : osc.stop() }
}

var osc = FMOscillator()

init() {
engine.output = osc
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Tonic

class MorphingOscillatorConductor: ObservableObject, HasAudioEngine {
var engine = AudioEngine()
var osc = MorphingOscillator()

func noteOn(pitch: Pitch, point _: CGPoint) {
isPlaying = true
Expand All @@ -23,8 +24,6 @@ class MorphingOscillatorConductor: ObservableObject, HasAudioEngine {
didSet { isPlaying ? osc.start() : osc.stop() }
}

var osc = MorphingOscillator()

init() {
osc.amplitude = 0.2
engine.output = osc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Tonic

class OscillatorConductor: ObservableObject, HasAudioEngine {
let engine = AudioEngine()
var osc = Oscillator()

func noteOn(pitch: Pitch, point _: CGPoint) {
isPlaying = true
Expand All @@ -23,8 +24,6 @@ class OscillatorConductor: ObservableObject, HasAudioEngine {
didSet { isPlaying ? osc.start() : osc.stop() }
}

var osc = Oscillator()

init() {
osc.amplitude = 0.2
engine.output = osc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Tonic

class PWMOscillatorConductor: ObservableObject, HasAudioEngine {
let engine = AudioEngine()
var osc = PWMOscillator()

func noteOn(pitch: Pitch, point _: CGPoint) {
isPlaying = true
Expand All @@ -23,8 +24,6 @@ class PWMOscillatorConductor: ObservableObject, HasAudioEngine {
didSet { isPlaying ? osc.start() : osc.stop() }
}

var osc = PWMOscillator()

init() {
osc.amplitude = 0.2
engine.output = osc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Tonic

class PhaseDistortionOscillatorConductor: ObservableObject, HasAudioEngine {
let engine = AudioEngine()
var osc = PhaseDistortionOscillator()

func noteOn(pitch: Pitch, point _: CGPoint) {
isPlaying = true
Expand All @@ -23,8 +24,6 @@ class PhaseDistortionOscillatorConductor: ObservableObject, HasAudioEngine {
didSet { isPlaying ? osc.start() : osc.stop() }
}

var osc = PhaseDistortionOscillator()

init() {
osc.amplitude = 0.2
engine.output = osc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class ZitaReverbConductor: ObservableObject, ProcessesPlayerInput {
}
reverb = ZitaReverb(player)
dryWetMixer = DryWetMixer(player, reverb)

engine.output = dryWetMixer
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ struct MIDIPortTestView: View {
VStack {
HStack {
Text("Input Ports Available")
// .font(.title2)
Text("Destination Ports Available")
// .font(.title2)
Text("Virtual Input Ports Available")
// .font(.title2)
Text("Virtual Output Ports Available")
// .font(.title2)
}
HStack {
ForEach(0 ..< conductor.inputNames.count, id: \.self) { index in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ class MIDIPortTestConductor: ObservableObject, MIDIListener {
init() {
midi.createVirtualInputPorts(count: 1, uniqueIDs: [inputUIDDevelop])
midi.createVirtualOutputPorts(count: 1, uniqueIDs: [outputUIDDevelop])
// midi.createVirtualInputPorts(numberOfPort: 1, [inputUIDMain], names: ["MIDI Test Input Port_Main"])
// midi.createVirtualOutputPorts(numberOfPort: 1, [outputUIDMain], names: ["MIDI Test Output Port_Main"])
midi.addListener(self)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright AudioKit. All Rights Reserved. Revision History at http://github.com/AudioKit/AudioKit/
import Foundation

/// Class to handle updating via CADisplayLink
/// Class to handle an updating loop
public class CallbackLoop: NSObject {
private var internalHandler: () -> Void = {}

Expand Down

0 comments on commit 8c5cb76

Please sign in to comment.