Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD setFinishCallback to SamplePlayer #64

Closed
wants to merge 9 commits into from

Conversation

ninovanhooff
Copy link
Collaborator

@ninovanhooff ninovanhooff commented Mar 29, 2024

Please check whether I handled the userdata pointer right.

Tested with a proc and with nil (to-unset) from the game's perspective. Did not test whether it was properly cleaned up in the files changed in this repo.

Sorry for the messy git history. Removing those .idea files from all branches trips me up

@ninovanhooff ninovanhooff changed the title Add setFinishCallback to SamplePlayer ADD setFinishCallback to SamplePlayer Mar 29, 2024
@ninovanhooff
Copy link
Collaborator Author

Hmm, I get this warning when compiling

CC: ../../playdate-nim/src/playdate/sound.nim
/Users/ninovanhooff/.cache/nim/wheelsprung_r/device/@m..@s..@splaydate-nim@ssrc@[email protected]: In function 'setFinishCallback__OOZOOZplaydate45nimZsrcZplaydateZsound_1589':
/Users/ninovanhooff/.cache/nim/wheelsprung_r/device/@m..@s..@splaydate-nim@ssrc@[email protected]:837:132: warning: passing argument 2 of 'playdate__OOZOOZplaydate45nimZsrcZplaydateZbindingsZapi_30->sound->sampleplayer->setFinishCallback' from incompatible pointer type [-Wincompatible-pointer-types]
  837 |   (*(*(*playdate__OOZOOZplaydate45nimZsrcZplaydateZbindingsZapi_30).sound).sampleplayer).setFinishCallback((*this_0).Sup.resource, privateFinishCallback__OOZOOZplaydate45nimZsrcZplaydateZsound_1427, NIM_NIL);
      |                                                                                                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                                                                    |
      |                                                                                                                                    void (*)(void *, void *)
/Users/ninovanhooff/.cache/nim/wheelsprung_r/device/@m..@s..@splaydate-nim@ssrc@[email protected]:837:132: note: expected 'void (*)(SoundSource *, void *)' {aka 'void (*)(struct SoundSource *, void *)'} but argument is of type 'void (*)(void *, void *)'
CC: ../../../.choosenim/toolchains/nim-1.6.16/lib/pure/parsejson.nim
CC: ../../../.choosenim/to

@samdze
Copy link
Owner

samdze commented Apr 3, 2024

Going to check this, from the first tests I get a compiler error:

/Users/sam/.nimble/pkgs/playdate-0.13.0/playdate/sound.nim:235:157: error: incompatible function pointer types passing 'void (void *, void *)' to parameter of type 'sndCallbackProc *' (aka 'void (*)(struct SoundSource *, void *)') [-Wincompatible-function-pointer-types]
                (*(*(*playdate__OOZOOZOOZOOZOOZOnimbleZpkgsZplaydate4548O4951O48ZplaydateZbindingsZapi_30).sound).sampleplayer).setFinishCallback((*this_0).Sup.resource, privateFinishCallback__OOZOOZOOZOOZOOZOnimbleZpkgsZplaydate4548O4951O48ZplaydateZsound_1396, NIM_NIL);
                                                                                                                                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

This is trying to use setFinishCallback like this (should be supported):

samplePlayer.setFinishCallback(
    proc(userData: pointer) =
        playdate.system.logToConsole("Sound finished playing.")
)

I'll investigate a bit.
In the meantime can you try squashing this PR into a single clean commit?
Would be easier to deal with

@samdze
Copy link
Owner

samdze commented Apr 3, 2024

Also note that this feature can be implemented using a different approach too, avoiding tables.
Check out how the menu item callbacks are implemented in system.nim.
The userdata pointer is leveraged to bridge the C callback to the Nim one.

Should be pretty much the same as what you're trying to do here.

@ninovanhooff
Copy link
Collaborator Author

Replaced by #67

@ninovanhooff ninovanhooff deleted the finishcallback branch November 10, 2024 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants