want to remove *SCRATCH* property after last track processed

Using Nyquist scripts in Audacity.
Post and download new plug-ins.

If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like

want to remove *SCRATCH* property after last track processed

Permanent link to this post Posted by stepheneb » Fri Jan 26, 2018 4:23 am

Pitch Report plugin is progressing well -- thanks for the help Steve!

I'm selecting all 12 tracks and running the PitchReport plugin.

The first time the plugin is run it looks for the existence of a PitchReport property on *SCRATCH* and if not found creates it with a value of t and prints a project header.

All the subsequent 11 invocations skip printing the project header.

The problem occurs if I run the plugin again. The PitchReport property on *SCRATCH* is still set.

Is there a way the plugin can tell when it is invoked on the last track? If so I could then remove the property then.

If not I'll probably need to create a separate plugin just to remove that property.

Here's what the current code looks like:

Code: Select all
(defun print-project-header ()
  (putprop '*SCRATCH* t 'PitchReport)
  (format t "~a~%window-time\t~a~%sample-time\t~a~%sample-step-time\t~a~%~%"
    (get '*project* 'name )
    window-time
    sample-time
    sample-step-time))

(defun generate-frequency-table ()
  (if (not (get '*SCRATCH* 'PitchReport)) (print-project-header))
  ...

(generate-frequency-table)
stepheneb
 
Posts: 13
Joined: Wed Jan 17, 2018 3:51 am
Operating System: OS X 10.11 El Capitan or later (macOS)

Re: want to remove *SCRATCH* property after last track proce

Permanent link to this post Posted by stepheneb » Fri Jan 26, 2018 6:14 am

Here's how I solved the problem:

*selection* has a tracks property that contains a list of track numbers selected I'm saving the length of this list as a *SCRATCH* property named pitch-report-track-count and incrementing another property named pitch-report-track-number every time the plugin is invoked.

After the plugin has finished an invocation I check if track-number = track-count. If so the plugin is processing the last track and removes the pitch-report-* properties from *SCRATCH*.

This allows the plugin to generate a correct report when re-run with different initial settings as well as after updates to the plugin code.

Here's an outline of the code:

Code: Select all
;nyquist plug-in
;type analyze
;name "Pitch Report"

...

(setq track-count 1)
(setq track-number 1)

...

(defun print-project-header ()
  (putprop '*SCRATCH* (length (get '*selection* 'tracks )) 'pitch-report-track-count)
  (putprop '*SCRATCH* 0 'pitch-report-track-number)
  (format t "~a~%window-time\t~a~%sample-time\t~a~%sample-step-time\t~a~%tracks\t~a~%~%"
    (get '*project* 'name )
    window-time
    sample-time
    sample-step-time
    (length (get '*selection* 'tracks ))))

(defun remove-pitch-report-scratch-properties ()
  (remprop '*SCRATCH* 'pitch-report-track-count)
  (remprop '*SCRATCH* 'pitch-report-track-number))

(defun generate-frequency-table ()
  (if (not (get '*SCRATCH* 'pitch-report-track-count)) (print-project-header))
  (setq track-count (get '*SCRATCH* 'pitch-report-track-count))
  (setq track-number (+ 1 (get '*SCRATCH* 'pitch-report-track-number)))
  (putprop '*SCRATCH* track-number 'pitch-report-track-number)

  ...

  (if (= track-count track-number) (remove-pitch-report-scratch-properties)))

(generate-frequency-table)
stepheneb
 
Posts: 13
Joined: Wed Jan 17, 2018 3:51 am
Operating System: OS X 10.11 El Capitan or later (macOS)

Re: want to remove *SCRATCH* property after last track proce

Permanent link to this post Posted by steve » Fri Jan 26, 2018 11:15 am

stepheneb wrote:Is there a way the plugin can tell when it is invoked on the last track?

Probably the simplest way:
Code: Select all
(if (= (length (get '*selection* 'tracks)) (get '*track* 'index))
    (noise)       ;last track
    (hzosc 440))  ;other tracks
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 46815
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: want to remove *SCRATCH* property after last track proce

Permanent link to this post Posted by stepheneb » Fri Jan 26, 2018 5:47 pm

Yes, that's *much* simpler. Printing project header JUST once now works fine without accessing *SCRATCH*. Thanks!
stepheneb
 
Posts: 13
Joined: Wed Jan 17, 2018 3:51 am
Operating System: OS X 10.11 El Capitan or later (macOS)


Return to Nyquist



Who is online

Users browsing this forum: No registered users and 2 guests