1. I think I got Callbacks now?
- Posted by Icy_Viking Mar 19, 2023
- 1087 views
Hello all,
While I am still trying to work with callbacks. I think I am slowly starting to figure them out or how to wrap them. I just want to make sure that I am doing it right.
[https://github.com/SFML/CSFML/blob/master/include/SFML/Audio/SoundRecorder.h] - for reference
typedef sfBool (*sfSoundRecorderStartCallback)(void*); ///< Type of the callback used when starting a capture typedef sfBool (*sfSoundRecorderProcessCallback)(const sfInt16*, size_t, void*); ///< Type of the callback used to process audio data typedef void (*sfSoundRecorderStopCallback)(void*); ///< Type of the callback used when stopping a capture
public function sfSoundRecorderStartCallback(atom cap) atom id = cap return id end function public constant sfSoundRecorderStartCallback_cb = call_back(routine_id("sfSoundRecorderStartCallback"),{C_POINTER},C_BOOL) public function sfSoundRecorderProcessCallback(atom in16,atom size,atom user) atom id = in16 atom s = size atom u = user return id end function public constant sfSoundRecorderProcessCallback_cb = call_back(routine_id("sfSoundRecorderProcessCallback"),{C_POINTER,C_SIZE_T,C_POINTER},C_BOOL) public function sfSoundRecorderStopCallback(atom user) atom id = user return id end function public constant sfSoundRecorderStopCallback_cb = call_back(routine_id("sfSoundRecorderStopCallback"),{}) constant C_CALLBACK = C_POINTER export constant xsfSoundRecorder_create = define_c_func(aud,"+sfSoundRecorder_create",{C_CALLBACK,C_CALLBACK,C_CALLBACK,C_POINTER},C_POINTER) public function sfSoundRecorder_create(atom onStart,atom onProcess,atom onStop,atom ud) return c_func(xsfSoundRecorder_create,{onStart,onProcess,onStop,ud}) end function
2. Re: I think I got Callbacks now?
- Posted by ghaberek (admin) Mar 19, 2023
- 997 views
While I am still trying to work with callbacks. I think I am slowly starting to figure them out or how to wrap them. I just want to make sure that I am doing it right.
I really wish library authors would do better to give names to parameters even when they're optional. It goes a long way towards helping consumers of those libraries understand how to use it.
The documentation could spell it out, which would be nice, but in this case it just says "Callback function which will be called each time there's audio data to process" without describing what the audio data is.
If we dig through the source code we can see that those callback parameters all have names:
typedef sfBool (*sfSoundRecorderStartCallback)(void* userData); typedef sfBool (*sfSoundRecorderProcessCallback)(const sfInt16* samples, size_t sampleCount, void* userData); typedef void (*sfSoundRecorderStopCallback)(void* userData);
So yes, you're pretty close. But I think knowing that the const sfInt16* parameter is called "samples" and size_t parameter is called "sampleCount" helps indicate that this is a pointer to an array.
Knowing that, the callback can peek the values from memory so it has something to work with.
public function sfSoundRecorderProcessCallback(atom psamples,atom sampleCount,atom userData) -- read the samples array (Int16 is two-byte signed integer, so use peek2s) sequence samples = peek2s({ psamples, sampleCount }) -- do something with the samples here return 1 -- onProcessSamples expects true/false response end function public constant sfSoundRecorderProcessCallback_cb = call_back(routine_id("sfSoundRecorderProcessCallback"),{C_POINTER,C_SIZE_T,C_POINTER},C_BOOL)
That being what it is, one thing that's important is that a wrapper itself isn't necessarily responsible for callbacks; whoever is using the library is going to need to set those up and pass them to the function calls.
One caveat to this is that you could set up a sort-of intermediate callback "handler" that would get called by the library, perhaps to do some kind of setup or cleanup, and would then call the user's function directly.
-Greg
3. Re: I think I got Callbacks now?
- Posted by Icy_Viking Mar 19, 2023
- 971 views
So I am getting the hang of it. Thanks Greg. Yeah I kinda figured its the user who is one who is going to have to use the callbacks. Though a function that can do setup or cleanup is also a good idea.
4. Re: I think I got Callbacks now?
- Posted by petelomax Mar 20, 2023
- 878 views
I really wish library authors would do better to give names to parameters even when they're optional. It goes a long way towards helping consumers of those libraries understand how to use it.
Oh that rings so true. Can't quite remember now but last week I was staring at the GTK docs and a "fill" parameter, and in about seven different places it said something like "The fill parameter contains the fill setting for the control." I still have absolutely no idea what it was - a bool, an enum, a width, a colour... My pet hate is "heredoc", wherever I see "it's better than nothing" I just plead back at the screen NO IT ******* **** ****** ISN'T. I fondly remember the beautiful docs Rob and Juno produced that just oozed care and attention out of every line, and trust me I know full well how much time and effort that can absorb, but I just want to cry when faced with something like this (a completely random link from the index) - and I mean who exactly does that actually help, ever?
5. Re: I think I got Callbacks now?
- Posted by ghaberek (admin) Mar 20, 2023
- 862 views
Oh that rings so true. Can't quite remember now but last week I was staring at the GTK docs and a "fill" parameter, and in about seven different places it said something like "The fill parameter contains the fill setting for the control." I still have absolutely no idea what it was - a bool, an enum, a width, a colour... My pet hate is "heredoc", wherever I see "it's better than nothing" I just plead back at the screen NO IT ******* **** ****** ISN'T. I fondly remember the beautiful docs Rob and Juno produced that just oozed care and attention out of every line, and trust me I know full well how much time and effort that can absorb, but I just want to cry when faced with something like this (a completely random link from the index) - and I mean who exactly does that actually help, ever?
Agreed. The original RDS docs were beautiful but at times felt too sparse, while the current auto-generated docs are hard to look at, hard to navigate, and too verbose. And I intend to address this as I'm very unhappy with the state of eudoc and creole but it's a few iterations out. First I need to get my template parser into the standard library and then I need a Markdown library because I am not writing any new docs on Betamax Creole. Then I need to revisit the placement and organization of source material. And most importantly, if we're going to continue publishing docs on the internet then I need a new home for that, because I do not want it to be an integrated part of this website. Too many eggs in one basket and all that.
-Greg
6. Re: I think I got Callbacks now?
- Posted by katsmeow Mar 20, 2023
- 826 views
On the other paw, what is OE/Phix doing to encourage writers and proofreaders to work on this problem?
I mean, people who write docs, or term papers, or data sheets, , not people who admin their computer and are fluent in all the online archival and distributed software management systems. We've seen plenty of methods on how to make fixing mistakes or omissions impossible. Right now, if someone did donate fixes to the documentation, it would be refused! I mean, already this year, documentation fixes have been refused more than once!
Kat
7. Re: I think I got Callbacks now?
- Posted by ghaberek (admin) Mar 20, 2023
- 804 views
On the other paw, what is OE/Phix doing to encourage writers and proofreaders to work on this problem?
Nothing anymore. At this point I've stopped asking for that and figured I'd just get to it when I get to it.
I mean, people who write docs, or term papers, or data sheets, , not people who admin their computer and are fluent in all the online archival and distributed software management systems.
But... this is a programming forum for a programming community for a particular programming language, so I would expect to find here mostly... programmers? I'm not pulling in people off the street. And most of us been here for a long time. I don't think it's unreasonable to ask programmers, regardless of their skill or experience or knowledge, to learn code versioning commands (git) or to sign up on a website (GitHub) or to run a few commands to execute some code (creole, eudoc, etc.).
We've seen plenty of methods on how to make fixing mistakes or omissions impossible. Right now, if someone did donate fixes to the documentation, it would be refused! I mean, already this year, documentation fixes have been refused more than once!
This is patently false. Who's refusing things? The path for contributing changes currently remains as it's been, which is described here: https://openeuphoria.org/forum/134522.wc. Anyone is welcome to work on an alternative in the mean time. Some folks tried to use the wiki for documentation (which seems unwise to me) and that seems to have fallen off at some point. I'm not refusing to work on an alternative method but I am not spending any time on it right now either.
-Greg
8. Re: I think I got Callbacks now?
- Posted by katsmeow Mar 20, 2023
- 785 views
On the other paw, what is OE/Phix doing to encourage writers and proofreaders to work on this problem?
Nothing anymore. At this point I've stopped asking for that and figured I'd just get to it when I get to it.
I mean, people who write docs, or term papers, or data sheets, , not people who admin their computer and are fluent in all the online archival and distributed software management systems.
But... this is a programming forum for a programming community for a particular programming language, so I would expect to find here mostly... programmers? I'm not pulling in people off the street. And most of us been here for a long time. I don't think it's unreasonable to ask programmers, regardless of their skill or experience or knowledge, to learn code versioning commands (git) or to sign up on a website (GitHub) or to run a few commands to execute some code (creole, eudoc, etc.).
I didn't need to know a ton of medical data to proof read my mom's master degree dissertation when i was in high school 50 years ago (the prof made a note in the margin about the style, spelling, and readability). Neither was i going to get a master's degree to qualify to correct her mistakes. The last 30 years i was intent on Ai code, not git, github, creole, etc etc. I take the same view of jumping thru hoops here as to jump hoops to qualify to correct wikipedia: no. Now, i post the error to the irc channel where 100 people idle, if they don't fix it, they must like it the way it is.
We've seen plenty of methods on how to make fixing mistakes or omissions impossible. Right now, if someone did donate fixes to the documentation, it would be refused! I mean, already this year, documentation fixes have been refused more than once!
This is patently false. Who's refusing things?
I take the same view of jumping thru hoops here as to jump hoops to qualify to correct wikipedia: no. No one pays me to find or report mistakes here, so this is not a goal of mine. You* have not made it easy to click a button and report the error, and you have said like only 2(?) people have credentials to make changes, and they won't come out until next version release anyhow, in the meantime the public-facing webpage is in error. We are different kinds of people, we do different things.
*"you" may include jimcbrown and others.
Kat
9. Re: I think I got Callbacks now?
- Posted by jimcbrown (admin) Mar 20, 2023
- 779 views
*"you" may include jimcbrown and others.
Kat
Thanks for the shout-out!
On the other paw, what is OE/Phix doing to encourage writers and proofreaders to work on this problem?
Nothing anymore. At this point I've stopped asking for that
Understandable, considering how few volunteers we seem able to attract that way.
But... this is a programming forum for a programming community for a particular programming language, so I would expect to find here mostly... programmers? I'm not pulling in people off the street. And most of us been here for a long time. I don't think it's unreasonable to ask programmers, regardless of their skill or experience or knowledge, to learn code versioning commands (git) or to sign up on a website (GitHub) or to run a few commands to execute some code (creole, eudoc, etc.).
Agreed. Often the coder is also the best documenter.
I mean, people who write docs, or term papers, or data sheets, , not people who admin their computer and are fluent in all the online archival and distributed software management systems.
I didn't need to know a ton of medical data to proof read my mom's master degree dissertation when i was in high school 50 years ago (the prof made a note in the margin about the style, spelling, and readability). Neither was i going to get a master's degree to qualify to correct her mistakes.
Thinking back, when _tom was around, he was really great at this! So yes, while for the time being it makes sense to attract coders to help with docs, we should remain open to letting non-programming folks help out too if they're interested.
The last 30 years i was intent on Ai code, not git, github, creole, etc etc. I take the same view of jumping thru hoops here as to jump hoops to qualify to correct wikipedia: no. Now, i post the error to the irc channel where 100 people idle, if they don't fix it, they must like it the way it is.
Do they ever unidle? Perhaps they remain blissfully unaware. It's a bit like talking to your wall, I imagine.
I take the same view of jumping thru hoops here as to jump hoops to qualify to correct wikipedia: no. No one pays me to find or report mistakes here, so this is not a goal of mine.
I think that's fair. It's also a fundamental issue - if we had the funds to afford to pay folks to deal with this, it would have been dealt with already.
I think it would not even cost that much. Just a few hundred dollars for a task on upwork.com or the like and we could easily find someone to handle it. But no one considers these tasks important enough to even donate this much to support the effort.
You* have not made it easy to click a button and report the error,
I'd actually not agree with this. There's not much more involved in making a ticket on this forum, than doing this.
Reporting is easy.
and you have said like only 2(?) people have credentials to make changes, and they won't come out until next version release anyhow, in the meantime the public-facing webpage is in error. We are different kinds of people, we do different things.
Hmm, I suppose we should consider having the docs on the website get generated automatically from the latest bleeding-edge master (rather than using a manual process and the latest released version). That would at least allow developers to put up a PR to fix doc changes faster, and allow for the website to get updated once the PR was merged and approved.
Perhaps it's not as good as providing a speedy path for noncoders to fix documentation on the website, but it's a step in the right direction.
and figured I'd just get to it when I get to it.
I think for now, this is the best that we can do, especially for noncoders who can't handle the github workflow - have them report it to ghaberek and let him fix it when he has time to get to it.