Closed banjerluke closed 2 years ago
Updated initial comment.
Did a little more hacking on it today, though not nearly as much as yesterday.
I did some testing to ensure that the audio files would be available in the Bundle, and, well, π©. Turns out they're not updated with hot code pushes, and I think that's going to be a problem (long story). So I think the way to go is for WebCode to pass an ArrayBuffer (which pops out as a Data object in Swift) with each MP3 file to the plugin. I was going to just stub out a function for that, but your code was very clearly written so I was able to pretty easily move the non-audio-package parts into SampleStorage
and add a function to AudioManager
to store any samples provided as Data objects. Looks good to me but the real test will be when we hook it up to a real Cordova project.
Beyond that, I did a little more refactoring:
muted
setter to Channel
, which still needs to be implemented.setupChannels
to AudioManager
to isolate that from other setup tasks.I also started running into a very strange bug, which I didn't have before. Basically, I can play any sample in the "test" channel and it works just fine, but if I play it in "guitar" or "drums" it fails with a 'player started when in a disconnected state' error. All the channels should be identical so I'm quite perplexed as to what's going on, but hopefully you can figure it out. Maybe I'm initing the channels wrong somehow...
Once I started pulling on threads, I just kind of kept going. To my great surprise, I was able to get it compiling after all the changes! π
So, quick summary of what's changed:
SamplePlayerPool
is out, as discussed.SamplePlayback
(replacesSamplePlayer
) is pretty fleshed out, save for some TODOs; handles instantiation and manipulation of sample audio player.SampleManager
is out; seemed an unnecessary layer once moving logic elsewhere.AudioManager
instantiatesSamplePlayback
directly.Channel
holds the channel mixer, and functions to manipulate it.CordovaPathConversion.swift
is a little utility class to retrieve the Bundle url for a Cordova asset, which we can use later.AudioManager
has a bunch of new functions, which are pretty much a 1-to-1 mapping to what will be received from Cordova. It also holds references to all channels, samples, and sample playbacks.ViewController
sets up two channels, pans them for testing, and is updated to use the new classes. (Rapid-fire tapping works!)Your mission, should you choose to accept it:
TODO
comments littered through the code.AudioManager
, so errors should bubble up to the function inAudioManager
.AudioManager
functions can also throw exceptions; we'll catch them in the Cordova "bridge" Swift file and return the Cordova failure callback with some sort of error code/information.Then I suppose we can look at getting this all into Cordova, although I feel like that might be better to do live, as a team...
Really appreciate your help with all this!