Making (some) stereo plugins work on split mono but panned tracks

If you’ve used Audacity a bit with stereo, you’d know it has a bit of a split personality. Meaning that to change just on channel, you have to “Split Stereo Track”, which splits it into to two mono tracks that have the proper L and R pan slider set. (If you choose “split to Mono” instead, these pan sliders will be centered instead.)

But it’s pretty annoying to have to split and merge back to stereo all the time. So, for some of my plugins I’ve managed make them work on the “split stereo” tracks too.

As example I’ve uploaded on github a modification of Steve Daulton’s Isomod to have different amplitude phases on each channel. I chose that one because it’s probably the simplest one to understand. The essence of the trick to make it work for split stereo (as in the image above) is to read pan data for the split tracks.

;; converts mono track pan slider to phase: -1..1 to phaseL..phaseR
(defun phase-from-signed-pan (signed-pan)
   (let ((unsigned-pan (* (+ 1.0 signed-pan) 0.5)))
      (+ phaseL (* (- phaseR phaseL) unsigned-pan))))

;; if stereo track make array of phases for multichan-expand else compute one phase using mono track pan
(setq multichan-phase
   (if (arrayp *track*)
       (vector (phase-from-signed-pan -1) (phase-from-signed-pan 1))
       ; ^^ ignoring stereo track pan b/c it has different semantics than mono pan
       (phase-from-signed-pan (get '*track* 'pan))))

(multichan-expand #'isomod-with-phase *track* multichan-phase)

It’s only possible with this simple technique if the L and R channels can be calculated separately, i.e. if there’s no data dependency between the channels, otherwise it gets more complicated as you’d need to save the relevant temp data to a scratch etc.

Perhaps also worth mentioning here is that to quickly get a selection on both tracks one way it to make a diagonal move with the mouse, i.e. start dragging the section on one track, but finish on the other. In fact you can go back to the original track while dragging; as long as you enter some other track briefly with the mouse while drag-selecting will result in a multi-track selection of the same time span.

That’s neat :nerd:

Just a couple of little details about your code (neither of which affect functionality):

Because the plug-in does not use Audacity’s translations (only available for plug-ins that are shipped with Audacity), header lines should begin with a semi-colon rather than a dollar sign.

$copyright (_ "Released under terms of the GNU General Public License version 2")

should be

;copyright (_ "Released under terms of the GNU General Public License version 2")

The ;info header is now obsolete (see:
If you want to retain any of the info as comments, just format it as normal comments. For example:

;; We Rame's stereo version with phase amplitude per channel. 
;; From: Isochronic Modulator by Steve Daulton.
;; 'Pulse Width' controls the length of each pulse.
;; 'Fade Time' adjusts the fade in/out speed of the pulses.
;; The modulation frequency (speed) and depth transform
;; gradually from the initial settings to the final settings.
;; Plug-in provided as an audio processing effect.
;; The author does not endorse or claim any relevance
;; to the theory or practice of brainwave entrainment."
;; Changelog for the mod
;;   0.1: Initial version with phases added. Always returns a vector, so it doesn't work on split tracks.
;;   0.2: Made it work on split tracks. Requires v4 plug-in support to read pan info from Audacity.