daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let gNotePlayer = AKSampler()
  2.  
  3.     do{
  4.         try gNotePlayer.loadWav("Support Objects/Grand Piano")
  5.         print("G Player Ready")
  6.     } catch{
  7.         AKLog("File not found")
  8.         return
  9.     }
  10.  
  11.     let fNotePlayer = AKSampler()
  12.  
  13.     do{
  14.         try fNotePlayer.loadWav("Support Objects/Grand Piano")
  15.         print("F Player Ready")
  16.     } catch{
  17.         AKLog("File not found")
  18.         return
  19.     }
  20.  
  21.     let grandStaffMix = AKMixer(fNotePlayer, gNotePlayer)
  22.  
  23.     AudioKit.output = grandStaffMix
  24.     do{
  25.         try AudioKit.start()
  26.     }catch let error as NSError{
  27.         print(error.debugDescription)
  28.     }
  29.  
  30.     var curBeat = 0
  31.  
  32.     if #available(iOS 10.0, *) {
  33.         timer = Timer.scheduledTimer(withTimeInterval: 60 / tempo * 0.0625, repeats: true) {_ in
  34.  
  35.             if !gNotesMIDI.isEmpty && curBeat < gNotesMIDI.count {
  36.                 if let noteNumber = gNotesMIDI[curBeat] {
  37.                     gNotePlayer.play(noteNumber: MIDINoteNumber(noteNumber))
  38.                 }
  39.             }
  40.  
  41.             if !fNotesMIDI.isEmpty && curBeat < fNotesMIDI.count {
  42.                 if let noteNumber = fNotesMIDI[curBeat] {
  43.                     fNotePlayer.play(noteNumber: MIDINoteNumber(noteNumber))
  44.                 }
  45.             }
  46.  
  47.             curBeat += 1
  48.  
  49.             if curBeat > gNotesMIDI.count + 5 && curBeat > fNotesMIDI.count + 5 {
  50.                 self.stopPlaying()
  51.                 self.isPlaying = false
  52.             }
  53.  
  54.             /*if Double(curBeat) > self.tempo * co {
  55.                 timer.invalidate()
  56.             }*/
  57.         }
  58.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top