Hello,
I am trying to create a music app in Xcode using MIDI in swift language.
I have encountered a problem that when i activate the code the code is giving me this error:"EXC_BAD-INSTRUCTION(code = EXC_I386_INVOP,subcode=0x0)" (the error is in the bolded line below).
the odd thing is that the same code is running fine in the Xcode's playground.
here is the code:
import UIKit
import AVFoundation
// Creating the sequence
var sequence:MusicSequence? = nil
var musicSequence = NewMusicSequence(&sequence)
// Creating a track
var track:MusicTrack? = nil
var musicTrack = MusicSequenceNewTrack(sequence!, &track) --> the error is given in this line
var musicPlayer:MusicPlayer? = nil
var player = NewMusicPlayer(&musicPlayer)
// Adding notes
var time = MusicTimeStamp(1.0)
var note = MIDINoteMessage(channel: 0,
note: 60,
velocity: 250,
releaseVelocity: 0,
duration: 2 )
var note1 = MIDINoteMessage(channel: 0,
note: 63,
velocity: 250,
releaseVelocity: 0,
duration: 2 )
var note2 = MIDINoteMessage(channel: 0,
note: 67,
velocity: 250,
releaseVelocity: 0,
duration: 2 )
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func chord(_ sender: UIButton) {
musicTrack = MusicTrackNewMIDINoteEvent(track!, time, ¬e)
musicTrack = MusicTrackNewMIDINoteEvent(track!, time, ¬e2)
musicTrack = MusicTrackNewMIDINoteEvent(track!, time, ¬e1)
player = MusicPlayerSetSequence(musicPlayer!, sequence)
player = MusicPlayerStart(musicPlayer!)
}
}