4 Replies
      Latest reply: Sep 17, 2016 9:49 AM by jbmaxwell RSS
      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 8 Level 8 (8,660 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 (70 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.

                   

                  -DS

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

                      Hi DS,

                       

                      Thanks for your reply. This part of the code has changed a couple of times since my original posting—partly in updating to Swift 3.0—and I'm not working in this part of the app right now. If I have the problem again, and it seems reproducible, I'll file a radar.

                       

                      thanks,

                       

                      J.