FFI Help wrapping ObjC

Moderators: LCMark, LCfraser

PaulDaMacMan
Posts: 190
Joined: Wed Apr 24, 2013 4:53 pm

Re: FFI Help wrapping ObjC

Post by PaulDaMacMan » Mon Apr 30, 2018 8:24 pm

bn wrote:
Sat Apr 28, 2018 8:48 pm
Hi Paul,

I installed the library and the .mid files and .sf2 files

Works like a charm once I understood that not all .mid files play with all sound files.

Nice to have "boing" back...
It feels like a miracle, kind of, to me.
And I imagine you felt the same.

I am _almost_ tempted to look into ObjC and the MacOS APIs, but just almost :)

Congratulations

Kind regards
Bernd
Yes, that's right, the SoundFont.sf2 has to have an instrument patch / bank that corresponds to the MIDI channels that musical notes are set to or you won't hear a thing. I had to modify the patches in HyperSound.sf2 (from http://www.kreativekorp.com/software/soundfonts/) so that they would be set to the first sound (Piano) which a lot of single channel MIDI files use by default. There is a cross platform lib called FluidSynth that can do a lot more with Soundfont playback/rendering but that's a much bigger project! I'm just starting out with the lower hanging fruit while I learn the FFI wrapping ropes.

BTW, I updated a little over the weekend, added a check isPlaying and a Stop button.
NOTE: make sure you pass it good URLs that actually point to files or it will crash the engine.

PaulDaMacMan
Posts: 190
Joined: Wed Apr 24, 2013 4:53 pm

Re: FFI Help wrapping ObjC

Post by PaulDaMacMan » Wed May 02, 2018 5:10 pm

Almost done with this, I just need to add a setter for currentPosition and a setter for playback rate, and the inline documentation... and maybe a bit of error checking too :-D though I could just check for errors using LiveCode Script.

One thing I'm not quite sure about is how to add the callback for when the file is done playing.

Apple's documentation says this:

Code: Select all

Declaration
typedef void (^AVMIDIPlayerCompletionHandler)(void);
^ a declaration of a block object

So I just need to point that block to my own handler that will probably just post a message back to the engine but I'm not sure how to set that up in LCB.

Post Reply

Return to “LiveCode Builder”