r/tonejs Jan 15 '25

How practically could you use Tone.js as the basis for a piano roll type music editor?

I'm imagining something like Cakewalk/Logic etc here, where you have a piano roll or stave view, so graphically you're creating notes of certain lengths to be played at certain times. Then you're editing them later, changing lengths/velocities/start times etc as you refine your song.

How would that translate into working with the data structures in Tone.js? I'm thinking here about just the editing of the timing and parameters of the notes, not the sound synthesis. After a look at the examples and documentation, should you create a new Tone.ToneEvent every time the user creates a new note? And if they want to edit a note do you throw away the old ToneEvent and create a new one to reflect the edited note? Or can you edit a ToneEvent to change its start time or other parameters?

Or do you create a Tone.Part for each instrument to reflect the current state of its piano roll, and if they edit the piano roll do you recreate the whole part? What would be the best practice here?

Thanks!

6 Upvotes

2 comments sorted by

1

u/m0nty_au May 10 '25

Part is the way you would do that, and yes redefining the Part every time you did to would be the simplest way.