Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7671511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:04:35+00:00 2026-05-31T16:04:35+00:00

I am working with the MusicPlayer API and I am trying to solve a

  • 0

I am working with the MusicPlayer API and I am trying to solve a problem I am having with user callback.

I have user events that are placed at every note event of a MIDI. When the notes are played, these user events pass the integer value of the note to a user callback function as *inEventData:

void noteUserCallback (void *inClientData, MusicSequence inSequence, MusicTrack inTrack, MusicTimeStamp inEventTime, const MusicEventUserData *inEventData, MusicTimeStamp inStartSliceBeat, MusicTimeStamp inEndSliceBeat)
{
    UserEvent* event = (UserEvent *)inEventData;
    UInt32 size = event->length;
    UInt32 note = event->playedNote;
    UInt32 timestamp = event->tStamp;
    NSLog(@"Size: %lu Note: %lu, Timestamp: %lu", size, note, timestamp);

    switch (note) {
        case 60:
            [whiteKey60 setImage:highlightA];
            break;

        default:
            break;
    }
}

Based upon these notes, I would like to makes changes to the UI. Namely, I have a number of UIImageViews that I would like to be able to update with different images based upon the value of the note (see above in switch statement).

The user callback function is associated with the sequence like this:

MusicSequenceSetUserCallback(sequence, noteUserCallback, NULL);

The third parameter of the above function connected with the void *inClientData parameter of the user callback function.

My problem is, that when I try to access the IBOutlets of my view from within the user callback function, I cannot. To fix this, I tried to pass the view controller into the MusicSequenceSetUserCallback function like this:

MusicSequenceSetUserCallback(sequence, noteUserCallback, self);

The problem I am having is that this inClientData parameter is of type void and I cannot pass in a ViewController* object. I tried simply creating a bridge when I set the callback function and then bridging back again within the user callback function but it didn’t seem to work.

If anyone has any thoughts on how I could accomplish this. Even if it’s a completely different methods, I would really appreciate it.

Thanks.

EDIT

I tried the following:

MusicSequenceSetUserCallback(sequence, noteUserCallback, (__bridge_retained void *)self);

and

void noteUserCallback (void *inClientData, MusicSequence inSequence, MusicTrack inTrack, MusicTimeStamp inEventTime, const MusicEventUserData *inEventData, MusicTimeStamp inStartSliceBeat, MusicTimeStamp inEndSliceBeat)
{   
    PracticeViewController* pvc = (__bridge_transfer PracticeViewController *)inClientData;

    [pvc.whiteKey21 setImage:pvc.highlightA];

    UserEvent* event = (UserEvent *)inEventData;
    UInt32 size = event->length;
    UInt32 note = event->playedNote;
    UInt32 timestamp = event->tStamp;
    NSLog(@"Size: %lu Note: %lu, Timestamp: %lu", size, note, timestamp);

    switch (note) {
        case 60:
            break;

        default:
            break;
    }
}

Unfortunately, it gives me this error: Thread 13 AURemoteIO::IOThread: EXC_BAD_ACCESS (code=2, address=0x10)

EDIT

Changing both bridges to __bridge silences the error but it is still not working properly; the call to change in the image in whiteKey60 does not work. It isn’t a problem with the UIImageView connection because doing the same in viewDidLoad works fine.

What seems to be going on, to me anyways, is that self isn’t making it to the function or perhaps its breaking the connection when it’s passed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:04:36+00:00Added an answer on May 31, 2026 at 4:04 pm

    Take a look at the declaration for MusicSequenceSetUserCallback again:

    OSStatus MusicSequenceSetUserCallback (
        MusicSequence              inSequence,
        MusicSequenceUserCallback  inCallback,
        void                       *inClientData
    );
    

    inClientData‘s type isn’t void — that wouldn’t make sense, variables in C can never have a type of void. Rather, it’s void * — roughly, a pointer to something unspecified.

    You need to cast the variable to a void * on the way in, and from a void * on the way out. Assuming that self is a MyClass *, then:

    MusicSequenceSetUserCallback(sequence, noteUserCallback, (void *)self);
    

    and in the callback:

    void noteUserCallback (void *inClientData, MusicSequence inSequence, MusicTrack inTrack, MusicTimeStamp inEventTime, const MusicEventUserData *inEventData, MusicTimeStamp inStartSliceBeat, MusicTimeStamp inEndSliceBeat)
    {
        MyClass* self = (MyClass *)inClientData;
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on a project that parses a log of events, and then updates a
I have an Android application that makes use of TTS (Text to speech) API.
Working with a Lucene index, I have a standard document format that looks something
I'm trying to embed this player to a web page: http://musicplayer.sourceforge.net/ It's working fine,
Working with an API that can handle multiple connections (i.e. sessions), each of these
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch
Working with a SqlCommand in C# I've created a query that contains a IN
Working on a project at the moment and we have to implement soft deletion
Working on a project where a sequential set of methods must be run every
Working on calling a C function from my asm project. I'm trying to push

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.