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

feat: Make it possible to "instance" SoLoud? #35

Closed
2 tasks
filiph opened this issue Mar 8, 2024 · 3 comments
Closed
2 tasks

feat: Make it possible to "instance" SoLoud? #35

filiph opened this issue Mar 8, 2024 · 3 comments

Comments

@filiph
Copy link
Collaborator

filiph commented Mar 8, 2024

Description

SoLoud is currently always a singleton. There's a single SoLoud underlying engine, and the Dart API exposes it via SoLoud(). We could go that way but I wonder if it's possible (even easy?) to make SoLoud instanced.

This would mean that every time you call SoLoud(), you'd get a new instance of the engine. You could have multiple running at the same time.

PROs:

  • Idiomatic way of configuring the engine. For example, we could have final engine = SoLoud(sampleRate: 44100);.
  • Idiomatic way of passing the engine around. You create an instance, and then you provide it. This is in contrast with the current state, in which you can access the singleton instance via SoLoud() from anywhere. There is no way a controller/facade can "hide" SoLoud() from you via encapsulation.
  • More robust testing. (One test cannot influence another.)
  • Easier to avoid bugs such as fix: Crash when opening a malformed mp3 file #31 (comment), where one part of the app "forgets" to do something and there's a crash in another part of the app.

CONs:

  • More work.
  • A breaking change (even the example uses SoLoud() to access the same instance).

Requirements

  • Verify that this is even something that the underlying (C++) engine supports
  • Calls to SoLoud() create an instance that is independent from all other SoLoud() instances
@filiph
Copy link
Collaborator Author

filiph commented Mar 9, 2024

Hey @alnitak, this will evidently need some thinking, but a first, relatively straightforward thing to answer would be:

Is SoLoud (the underlying C library) capable of being instanced?

If that's not the case, then we can clearly close this issue.

@alnitak
Copy link
Owner

alnitak commented Mar 9, 2024

Is SoLoud (the underlying C library) capable of being instanced?

I was thinking about this. Is not possible to have for example 2 SoLoud instances because there can be only one player instance on C side.
But, yes, you can implement final engine = SoLoud(sampleRate: 44100); easily, but this engine will have that sampleRate for its entire life cycle.
So I think we can close this.

@filiph
Copy link
Collaborator Author

filiph commented Mar 9, 2024

Ok, this is really helpful. If it's not possible to have two instances on the C side, it shouldn't be possible to have two instances on the Dart side. This simplifies things. Thanks for the quick reply!

@filiph filiph closed this as completed Mar 9, 2024
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

No branches or pull requests

2 participants