Ah, I had forgotten anonymous classes are a thing.
Although, you don’t actually need the constructor to be public
to do that.
Not with standard Java at least.
I.e. the code is still valid if the constructor is protected
.
Also I wasn’t aware Java finally added a var
feature.
It’s slowly catching up with C#. Slowly. :P
That’s probably the better option.
Either that or make people manage their own instances.
Procedural
doesn’t technically need to even know about Mixer
…
I somewhat disagree with this.
It doesn’t seem to me that the sound’s channel is actually part of the sound,
the channel only makes sense in the context of playing the sound via Mixer
.
If it weren’t for the fact that Procedural
is stateful I’d say it ought to be possible to do:
Procedural sound = new SomeSound();
Mixer.setChannel(0, sound);
Mixer.setChannel(1, sound);
And it is actually possible to do:
Mixer.setChannel(0, new SomeSound());
Mixer.setChannel(1, new SomeSound());
At which point Procedural
's channel
is just wasting memory.
channel
only really exists to make play
possible,
and the play
function is purely shorthand for Mixer.setChannel(channel, sound)
,
which means it’s effectively just a convinience function.
I can’t imagine any other implementation that would make sense.
Also play
pretty much forces Procedural
to depend on Mixer
,
which means they end up being strongly coupled.
I’m not even sure the Procedural
part is right.
When I hear ‘procedural’ I think of procedural generation (e.g. bytebeat music rather than pre-generated sound data).
I think maybe SequentialSound
would have been more on the nose.
The semantics are different.
femto.sound
is sound as a concept, grouping together everything relating to sound generation,
femto.sound.Sound
is a particular instance of a sound.
A better alternative would probably be femto.audio.Sound
, but that means changing more things.