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

Making Tone.js modular #402

Closed
ricardomatias opened this issue Nov 14, 2018 · 20 comments
Closed

Making Tone.js modular #402

ricardomatias opened this issue Nov 14, 2018 · 20 comments

Comments

@ricardomatias
Copy link

@tambien, are there plans to make the library modular? F.ex separating it into multiple packages per domain.

Personally, I'm pondering externalising the part that it is related to the Time domain. I think there are plenty of cases where it's not necessary having an "audio engine". Another advantage would be as a lower barrier to people wanting to contribute, since it's quite daunting right now to delve into the code, even though it's well documented.

If there's an interest in doing so, then I'd draft some kind of roadmap. Otherwise, I'll just probably anyhow hack it away for myself.

@rain-sk
Copy link

rain-sk commented Nov 14, 2018 via email

@rain-sk
Copy link

rain-sk commented Nov 14, 2018 via email

@Idicious
Copy link
Contributor

Idicious commented Nov 15, 2018

You can already import the AMD source files seperately. For example import Transport from 'tone/Tone/core/Transport'. This works as long as you have a module bundler that support AMD imports, such as webpack. I'm not sure of the exact version this is possible from but if you get tone@next you can do this.
This works out of the box, importing Transport will also load all it's dependencies etc, the only ceaveat I've found so far is in order to use send/receive you have to import as import 'tone/Tone/core/Bus' because it only augments the Tone prototype and has no exports itself.
I'm currently working on a comprehensive typescript definition project that works with deep imports. I'm mostly done and using it already in a project.

@rain-sk
Copy link

rain-sk commented Nov 15, 2018

@Idicious I would be very interested to see this version you have!

@tambien
Copy link
Contributor

tambien commented Nov 15, 2018

this multipackage approach is something i've been looking into recently as well. i've registered @tonejs organization on npm. i was thinking of separating out @tonejs/shim and maybe @tonejs/core, but eventually could also separate out @tonejs/time as you mentioned and some other packages to make it easier to build more modular components on top of the library.

I looked into lerna a little, but i'm not sure that this is what i need exactly. i don't think i will move things into separate repos since they all rely on a common set of build tools and tests, but having a monorepo with multiple packages seems appealing. If anyone has experience with lerna or with monorepos, please chime in with how it might work in Tone.js.

@ricardomatias: As @Idicious mentioned, you can deep require every module and it will pull in it's dependencies if you're using something like webpack, so it's possible to grab some of the timing components without pulling in the entire audio engine part.

@rain-sk
Copy link

rain-sk commented Nov 15, 2018 via email

@fabb
Copy link

fabb commented Dec 9, 2018

In particular, I want to leverage Tone's timing and MIDI implementations without having to incorporate the Tone wrappers for the Audio context.

Maybe a related question on modularity: I imagine it might be desirable to use non-Tone.js AudioNodes inside of a project that uses Tone.js (or just its supposed timing/midi parts). These might be implemented without Tone.js in mind, and released as npm packages without a Tone.js dependency. They might be implemented in a way to be controlled with an interface of native AudioParams.
So to be pulled into a project using Tone.js, as far as I have understood there needs to be a wrapper layer that makes the AudioParams interface controllable with Tone.Signals that also supports scheduling and other Tone.js specific features.
That wrapper around that specific AudioNode synth/effect could even be published as an own npm package to be reusable for many projects. It would need a dependency on Tone.js, or if Signal could be extracted as a module, just on that.

If I got any concepts of Tone.js wrong, I‘m happy to learn more, I‘m just getting into this.

@Idicious
Copy link
Contributor

@fabb You already can connect a Tone node to a native audio node, the reverse would require using the currently undocumented audionode.input property.
So you can do nativenode.connect(tonenode.input) as well as tonenode.connect(nativenode)

@fabb
Copy link

fabb commented Dec 13, 2018

Thaht‘s nice! But how would I trigger notes based on Tone.js‘ Transport in this native audio node synth?

@rain-sk
Copy link

rain-sk commented Dec 13, 2018 via email

@Idicious
Copy link
Contributor

@spencerudnick This is ofcourse essentially what the Tone synths do.

@rain-sk
Copy link

rain-sk commented Dec 13, 2018 via email

@fabb
Copy link

fabb commented Dec 13, 2018

So I would actually mimick the interface of Tone synths in my wrapper, right? So for Tone it‘s actually no more a native audio node but it thinks it‘s a Tone synth?

@rain-sk
Copy link

rain-sk commented Dec 13, 2018 via email

@fabb
Copy link

fabb commented Dec 13, 2018

The magic of javascript... Let‘s see how hard it is to fulfil that interface. It would be awesome to extract a Tone.js wrapper for the audio node part of the Viktor NV-1 synth.
https://nicroto.github.io/viktor/

@tambien
Copy link
Contributor

tambien commented Dec 13, 2018

it shouldn't be a problem to mix native web audio nodes or other web audio modules as long as they share the same AudioContext. You don't need to mimic a Tone.js synth interface for it to be able to interoperate with Tone.Transport or any other Tone.js component.

@fabb
Copy link

fabb commented Dec 15, 2018

Ah ok, the creator of Viktor NV-1 synth already as extracted the non-UI synth part to a separate lib: https://github.com/nicroto/viktor-nv1-engine. It supports Web-MIDI messages, let's see how I can integrate this with Tone.

@fabb
Copy link

fabb commented Jan 3, 2019

You would need to create a wrapper interface for the native node, perhaps create a class which encompasses a gain and audio source. Then expose an interface which handles the incoming midi commands to control gain and frequency.

Ok, when I want to play the external synth using Tone Patterns, I need to somehow sync the attack and release commands to the provided time and duration (and maybe other parameters need to be synced as well using Tone.Signal).
I'm not yet completely sure how such a wrapper that bridges between Tone scheduler and the 3rd party instrument would need to look like, and if it could be generalized and broken out into a separate component.

@tambien
Copy link
Contributor

tambien commented Jan 3, 2019

The time value returned from the event classes (like Tone.Pattern) is just the raw Web Audio clock time. A native or third party component that can be scheduled using the AudioContext time could take this time and use it to synchronize with the Tone.Transport.

@tambien
Copy link
Contributor

tambien commented Jan 3, 2019

Going to close this issue since Tone currently has the ability to load individual modules, though i aspire to better grouping in the future and potentially releasing sub packages. I will reference this issue if/when that happens.

@tambien tambien closed this as completed Jan 3, 2019
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

5 participants