Depending on exactly what you are doing there may be easier ways to trim the start of a selection, but in answer to your question:
The “trimming” is done with the function (extract-abs) http://www.audacity-forum.de/download/edgar/nyquist/nyquist-doc/manual/part6.html#index405
The syntax is: (extract-abs start stop beh) where start and stop are in seconds.
Because we are trimming a sound, we must convert this to a behaviour (extract only works on behaviours and not directly on sounds - see here for more information: http://www.audacity-forum.de/download/edgar/nyquist/nyquist-doc/manual/part3.html#23 ) and we do this using the function (cue sound)
In the original code, we extract from time=0 to time=(duration-t) where “duration” is the original length of the selection and “t” is the amount being trimmed.
To trim from the beginning of the track rather than the end, we need to make start=(the amount of time to trim) and stop=(total length of the selection).
So instead of
(extract-abs 0 (- (get-duration 1) cut)(cue s-out))
we would have
(extract-abs cut (get-duration 1) (cue s-out))
If we are going this far, then we may as well allow both options like this:
;control trm-start "Trim from start" real "milliseconds" 150 0 1000
;control trm-end "Trim from end" real "milliseconds" 150 0 1000
(defun trim (s-out scut ecut)
(setq scut (/ scut 1000.0))
(setq ecut (/ ecut 1000.0))
(extract-abs scut (- (get-duration 1) ecut)(cue s-out)))
(multichan-expand #' trim s trm-start trm-end)
One slight problem with this is; what happens if the total amount being trimmed is greater than the length of the selection?
In such a case it would be useful to have a meaningful error message, so as a matter of good practice we should test the input data (from the slider controls) to ensure that it is valid, and output a meaningful error message if there’s a problem.
To do this we can initialise a variable to an empty string, and add text to it if there are errors.
Let’s call this variable “err-msg”
(any words after a semi-colon are comments and are ignored by Nyquist)
(setq scut (/ scut 1000.0)) ; convert to seconds
(setq ecut (/ ecut 1000.0)) ; convert to seconds
(setq err-msg "") ; initialise error message to empty string
; trimmed amounts scut and ecut cannot be negative
(if (or (< scut 0)(< ecut 0))
(setq err-msg (strcat err-msg "Trim amounts cannot be negative")))
;trimmed length must be greater than zero
(if (>= (+ scut ecut)(get-duration 1))
(setq err-msg (strcat err-msg "Total amount being trimmed must be less than length of selection.n")))
Then before processing the audio, test the length of the error message. If it is zero, no errors have occurred and we can process the audio. If the length is greater than 0 then errors have occurred and we need to output an error message:
(if (> (length err-msg) 0) ; if length of error message greater than 0
(format nil (strcat "Errorn" err-msg)) ; output error message
(multichan-expand #' trim s scut ecut)) ; else process audio
Putting it all together:
;nyquist plug-in
;type process
;version 1
;type process
;name "Trim Selection"
;action "Trimming end(s) of selection..."
;info "By Steve Daulton. Released under GPL v2.nTrims selected length from end(s) of selection."
;; By Steve Daulton. September 2010.
;; Released under terms of the GNU General Public License version 2
;; http://www.opensource.org/licenses/gpl-license.php
;control scut "Trim from start" real "milliseconds" 0 0 1000
;control ecut "Trim from end" real "milliseconds" 0 0 1000
(setq scut (/ scut 1000.0)) ; convert to seconds
(setq ecut (/ ecut 1000.0)) ; convert to seconds
(setq err-msg "") ; initialise error message to empty string
; trimmed amounts scut and ecut cannot be negative
(if (or (< scut 0)(< ecut 0))
(setq err-msg (strcat err-msg "Trim amounts cannot be negative.n")))
;trimmed length must be greater than zero
(if (>= (+ scut ecut)(get-duration 1))
(setq err-msg (strcat err-msg "Total amount being trimmed must be less than length of selection.n")))
(defun trim (s-out scut ecut)
(extract-abs scut (- (get-duration 1) ecut)(cue s-out)))
(if (> (length err-msg) 0) ; if length of error message greater than 0
(format nil (strcat "Errorn" err-msg)) ; output error message
(multichan-expand #' trim s scut ecut)) ; else process audio
and here it is as a plug-in: trim.ny