· 2 minute read

Swiping for days

After more than a day of troubleshooting I wanted to get some stuff done. First item on the list, add support to swipe to mute multiple stems at once.

It would work like this: You click and hold on a stem and then swipe over other stems. Any stem you swipe over will also be muted or umuted, depending on the first one you clicked. So if only the first stem was playing, then you'd start swiping on the second one to the last and they'd all be unmuted, regardless of their current state.

This seemed pretty straight forward but I still had to plan out a way to store the data and how to interact with it. Please welcome, User Intent!
Since I had reworked the controller code, everything was now stored in each controller object. This meant I could easily add this swiping action. I started off by creating a new object stored per controller called Intent. It looks like this:

intent: {
    action: int,
    holdLog: array
}

This object gets filled on the first frame that the user clicks on the stem. It checks whether the user meant to mute or unmute (the action) and stores the stem in the holdLog array. Why, you ask? Well, multiple reasons. First of since this code runs on every frame, it's used to check that the currently selected stem is different from the last in the array, if it's the same this code gets skipped. I'm using a relatively new feature to be able to get a negative index of an array via holdLog.at(-1). See the .at MDN page for more info.

I tested this out and it worked perfectly. Love it when stuff goes well.