4 Replies
      Latest reply on Sep 17, 2016 9:49 AM by jbmaxwell
      jbmaxwell Level 1 Level 1 (0 points)

        I'm writing a MIDI sequencing tool using MusicPlayer and I need to write my events on-the-fly. I find that I can write MIDI events to a running track/sequence but User events don't seem to get written. They only seem to get written if the sequence is stopped.


        The basic function I'm using to actually write the events is:

        func addUserEventToSequence(event: Event, sequence: MusicSequence, track: MusicTrack) {
                var tempEvent = event
                withUnsafePointer(&tempEvent) { eventPtr in
                    let dataPtr: UnsafePointer<MusicEventUserData> = UnsafePointer(eventPtr)
                    if(MusicTrackNewUserEvent(track, event.timestamp, dataPtr) != noErr)
                        print("Couldn't add feedback event!")


        The "Event" struct is very close to MusicEventUserData but adds a few properties. This definitely works when the sequencer is stopped, but it seems to fail when the sequencer's running. Am I missing something?

        • Re: Write User events to running sequence
          KMT Level 9 Level 9 (15,755 points)

               > but it seems to fail when the sequencer's running.


          What are/aren't you seeing that makes you unsure? Any errors? Is the print being hit?

            • Re: Write User events to running sequence
              jbmaxwell Level 1 Level 1 (0 points)

              That function "seems" to fail, in that I'm not totally certain this function is to blame for the events not being added while playing back... No errors, though. Everything appears to work (i.e., log) the same way as when the sequencer is stopped, except that I'm not seeing my User events coming back through the callback.


              To expand a little: my basic routine is: 1) add MIDI events to the sequence, time-stamped just beyond the play time, 2) copy those events to user events. (I add the MIDI events first to enable either MIDI or host-based audio playback, and also to make MIDI export straightforward.)

                • Re: Write User events to running sequence
                  SoundOfMind Apple Staff Apple Staff (80 points)

                  When Sequence tracks are modified by adding or removing events, they are supposed to swap in a copy of the track while the editing is happening, and then swap back in the now-edited track when the edit is complete.  If this is not working correctly, it would be great to be able to track this with a radar from you, plus if possible a little app which reproduces the problem.  In addition, if you reply to this thread with the radar ID once you have it, that will really speed things up.