mirror of
https://github.com/cookiengineer/audacity
synced 2026-01-13 08:05:52 +01:00
Fix fade direction limitation in Crossfade Tracks
This commit is contained in:
@@ -7,23 +7,32 @@
|
|||||||
;author "Steve Daulton"
|
;author "Steve Daulton"
|
||||||
;copyright "Released under terms of the GNU General Public License version 2"
|
;copyright "Released under terms of the GNU General Public License version 2"
|
||||||
|
|
||||||
;; crossfadetracks.ny by Steve Daulton Nov 2014.
|
;; crossfadetracks.ny by Steve Daulton Nov 2014 / Sep 2015
|
||||||
;; Released under terms of the GNU General Public License version 2:
|
;; Released under terms of the GNU General Public License version 2:
|
||||||
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html .
|
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html .
|
||||||
|
|
||||||
;control type "Fade type" choice "Constant Gain,Constant Power 1,Constant Power 2,Custom Curve" 0
|
;control type "Fade type" choice "Constant Gain,Constant Power 1,Constant Power 2,Custom Curve" 0
|
||||||
;control curve "Custom curve" real "" 0 0 1
|
;control curve "Custom curve" real "" 0 0 1
|
||||||
|
;control direction "Fade direction" choice "Automatic,Alternating Out / In,Alternating In / Out" 0
|
||||||
|
|
||||||
(defun crossfade (type)
|
|
||||||
|
(defun crossfade (type dir curve)
|
||||||
|
(setf fade-out
|
||||||
|
(case dir
|
||||||
|
(0 (equal (guessdirection) 'OUT)) ; auto
|
||||||
|
(1 (oddp (get '*track* 'index))) ; fade out odd
|
||||||
|
(T (evenp (get '*track* 'index))))) ; fade out even
|
||||||
(mult *track*
|
(mult *track*
|
||||||
(cond
|
(cond
|
||||||
((= (get '*track* 'index) 1) ; fade out.
|
(fade-out
|
||||||
(case type
|
(case type
|
||||||
(0 (pwlv 1 1 0))
|
(0 (pwlv 1 1 0))
|
||||||
(1 (osc (hz-to-step (/ (get-duration 4))) 1 *sine-table* 90))
|
(1 (osc (hz-to-step (/ (get-duration 4))) 1 *sine-table* 90))
|
||||||
(2 (s-sqrt (pwlv 1 1 0)))
|
(2 (s-sqrt (pwlv 1 1 0)))
|
||||||
(T (custom curve 0))))
|
(T (custom curve 0))))
|
||||||
(T ; else fade in.
|
(T ; else fade in.
|
||||||
|
; Control envelope sample rate must match sound so that lengths
|
||||||
|
; match exactly, otherwise we get a click at the end of the fade.
|
||||||
(setf *control-srate* *sound-srate*)
|
(setf *control-srate* *sound-srate*)
|
||||||
(case type
|
(case type
|
||||||
(0 (pwlv 0 1 1))
|
(0 (pwlv 0 1 1))
|
||||||
@@ -40,12 +49,24 @@
|
|||||||
(if (= inout 0)
|
(if (= inout 0)
|
||||||
(setf logcurve (pwev epsilon 1 1))
|
(setf logcurve (pwev epsilon 1 1))
|
||||||
(setf logcurve (pwev 1 1 epsilon)))
|
(setf logcurve (pwev 1 1 epsilon)))
|
||||||
|
; Scale and invert curve for 0 to unity gain.
|
||||||
(sum 1
|
(sum 1
|
||||||
(mult (/ -1 (- 1 epsilon))
|
(mult (/ -1 (- 1 epsilon))
|
||||||
(diff logcurve epsilon)))))
|
(diff logcurve epsilon)))))
|
||||||
|
|
||||||
|
(defun guessdirection ()
|
||||||
|
"If the selection is closer to the start of the
|
||||||
|
audio clip, fade in, otherwise fade out."
|
||||||
|
(let* ((start (get '*selection* 'start))
|
||||||
|
(end (get '*selection* 'end))
|
||||||
|
(clips (get '*track* 'clips))
|
||||||
|
(in-dist end)
|
||||||
|
(out-dist end))
|
||||||
|
(if (arrayp clips)
|
||||||
|
(setf clips (append (aref clips 0)(aref clips 1))))
|
||||||
|
(dotimes (i (length clips))
|
||||||
|
(setf in-dist (min in-dist (abs (- start (first (nth i clips))))))
|
||||||
|
(setf out-dist (min out-dist (abs (- end (second (nth i clips)))))))
|
||||||
|
(if (< in-dist out-dist) 'in 'out)))
|
||||||
|
|
||||||
(let ((tracks (length (get '*selection* 'tracks))))
|
(crossfade type direction curve)
|
||||||
(case tracks
|
|
||||||
(1 "Only 1 track selected.\n'Crossfade Tracks' requires 2 tracks.")
|
|
||||||
(2 (crossfade type))
|
|
||||||
(T "Too many tracks selected.\n'Crossfade Tracks' requires 2 tracks.")))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user