Update of /cvsroot/audacity/audacity-src/scripts
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv23045/scripts

Modified Files:
        pipe-test.pl 
Log Message:
Work on the time-alteration behaviour of effects, and associated general and 
scripting improvements.

New files:
src/commands/PreferenceCommands.cpp
src/commands/PreferenceCommands.h
src/commands/SetTrackInfoCommand.cpp
src/commands/SetTrackInfoCommand.h
src/effects/TimeWarper.cpp
src/effects/TimeWarper.h

(Mac & win projects not updated yet)

Introduced 'time warper' objects which describe how an effect changes time when
it is applied. Any effect can have one, but they are only used directly by
Generator, SBSMS, SoundTouch and ChangeSpeed at the moment.

WaveTrack::ClearAndPaste can now use one of these objects to adjust split
points that were in the original audio, which means the effects that use this
method no longer lose the clip structure. (Except for Nyquist). 'Silent' clips
appear where there was white space in the input, because of how these effects
work.

ClearAndPaste also now has a 'useHandlePaste' so that the track-specific
behaviour needed for moving labels can be done inside the method rather than
out. (Otherwise the new whitespace behaviour would only work for the first
tracks in groups).  It's not a particularly pleasant method and this area would
probably benefit from some rethinking after 2.0.

I haven't changed how effects move labels at all, but this could be adapted to
use the new time warpers. I noticed TimeScale moves the labels linearly which
isn't quite right.

I've also been using a script to test the effects, which would otherwise be
quite time consuming. I cleaned up the test script and added a
testClearAndPasters sub which does this test.

Also added some new commands:
SetTrackInfo (only for setting track name currently)
SetPreference and
GetPreference for directly adjusting preferences

Fixed a slight problem with the Select command, where it was incorrectly
reporting what it had selected.

Adjusted Noise generator to read duration preference in an Init method.





Index: pipe-test.pl
===================================================================
RCS file: /cvsroot/audacity/audacity-src/scripts/pipe-test.pl,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- pipe-test.pl        4 Aug 2009 04:19:22 -0000       1.7
+++ pipe-test.pl        16 Aug 2009 14:44:20 -0000      1.8
@@ -2,27 +2,44 @@
 
 # Test script for communicating with audacity via mod-script-pipe
 # Audacity should be running first, with the scripting plugin loaded.
+#
+# Note that currently, some menu commands require the project to be focused for
+# them to work.  Further information and a list of known problems is available
+# on the 'Scripting' page of the Audacity wiki.
 
-$screenshotDir = "/home/dan/Temp";
-
+use strict;
+use warnings;
 use Time::HiRes qw( gettimeofday tv_interval );
 
-sub startUp{
-   # TODO: Maybe get the pipe names from audacity?
-   if ($^O eq 'MSWin32') {
-      $Name = 'Srv';
-      $ToSrvName = '\\\\.\\pipe\\To'.$Name.'Pipe';
-      $FromSrvName = '\\\\.\\pipe\\From'.$Name.'Pipe';
-   } elsif ($^O eq 'linux') {
-      $UID = $<;
-      $ToSrvName = '/tmp/audacity_script_pipe.to.'.$UID;
-      $FromSrvName = '/tmp/audacity_script_pipe.from.'.$UID;
-   } elsif ($^O eq 'darwin') {
-      $UID = $<;
-      $ToSrvName = '/tmp/audacity_script_pipe.to.'.$UID;
-      $FromSrvName = '/tmp/audacity_script_pipe.from.'.$UID;      
-   }
+# Where should screenshots be saved?
+our $screenshotDir = "/home/dan/Temp";
 
+# Variables for pipe names
+our $Name;
+our $UID;
+our $ToSrvName;
+our $FromSrvName;
+
+# For timing
+our $t0;
+
+# TODO: Maybe get the pipe names from audacity?
+if ($^O eq 'MSWin32') {
+   $Name = 'Srv';
+   $ToSrvName = '\\\\.\\pipe\\To'.$Name.'Pipe';
+   $FromSrvName = '\\\\.\\pipe\\From'.$Name.'Pipe';
+} elsif ($^O eq 'linux') {
+   $UID = $<;
+   $ToSrvName = '/tmp/audacity_script_pipe.to.'.$UID;
+   $FromSrvName = '/tmp/audacity_script_pipe.from.'.$UID;
+} elsif ($^O eq 'darwin') {
+   $UID = $<;
+   $ToSrvName = '/tmp/audacity_script_pipe.to.'.$UID;
+   $FromSrvName = '/tmp/audacity_script_pipe.from.'.$UID;
+}
+
+# Open pipes
+sub startUp{
    open( TO_SRV, "+<$ToSrvName" )
       or die "Could not open $ToSrvName";
    open( FROM_SRV, "+<$FromSrvName" )
@@ -33,6 +50,7 @@
    select((select(TO_SRV),$|=1)[0]);
 }
 
+# Close pipes
 sub finish{
    print "Done. Press return to end.";
    <>;
@@ -40,15 +58,16 @@
    close FROM_SRV;
 }
 
+# Subroutines for measuring how long a command takes to complete
 sub startTiming{
    $t0 = [gettimeofday];
 }
-
 sub stopTiming{
    my $elapsed = tv_interval ( $t0, [gettimeofday] );
    print "[Total time for command: $elapsed seconds.]\n";
 }
 
+# Write a command to the pipe
 sub sendCommand{
    my $command = shift;
    if ($^O eq 'MSWin32') {
@@ -60,19 +79,46 @@
    print "[$command]\n";
 }
 
+# Send (and time) a command, and print responses
 sub doCommand{
    startTiming();
    sendCommand(shift);
 
-   while(my $ttt = <FROM_SRV>) {
-      chomp($ttt);
-      last if ($ttt eq '');
-      print "$ttt\n";
-   }
+   my @resps = getResponses();
+   map { print "$_\n"; } @resps;
 
    stopTiming();
    print "\n";
-   return $ttt;
+   return @resps;
+}
+
+# Return an array of all responses
+sub getResponses{
+   my $resp;
+   my @responses;
+
+   while($resp = <FROM_SRV>) {
+      chomp($resp);
+      last if ($resp eq '');
+      push(@responses, $resp);
+   }
+
+   return @responses;
+}
+
+# Get the value of a preference
+sub getPref{
+   my $name = shift;
+   sendCommand("GetPreference: PrefName=$name");
+   my @resps = getResponses();
+   return shift(@resps);
+}
+
+# Set the value of a preference
+sub setPref{
+   my $name = shift;
+   my $val = shift;
+   doCommand("SetPreference: PrefName=$name PrefValue=$val");
 }
 
 # Send a screenshot command
@@ -140,21 +186,33 @@
    doCommand("Help: CommandName=$cmdName");
 }
 
+# Get help on all of the listed commands
+sub fullHelp{
+   my @cmds = qw(BatchCommand CompareAudio MenuCommand GetAllMenuCommands 
GetTrackInfo Help Message Screenshot Select SetTrackInfo);
+   foreach my $cmd (@cmds){
+      help($cmd);
+   }
+}
+
 # From script, this works like an 'echo'
 sub message{
    my $msg = shift;
    doCommand("Message: MessageString=$msg");
 }
 
+# Send a CompareAudio command with a given threshold
 sub compareAudio{
    my $threshold = shift;
    doCommand("CompareAudio: Threshold=$threshold");
 }
+
+# Delete all tracks
 sub deleteAll{
    doCommand("Select: Mode=All");
    menuCommand("RemoveTracks");
 }
 
+# A test of the CompareAudio command
 sub compareTest{
    deleteAll();
 
@@ -163,10 +221,10 @@
    menuCommand("NewAudioTrack");
    doCommand("Chirp:");
 
-   $j = 0;
+   my $j = 0;
    while($j < 3)
    {
-      $i = 0;
+      my $i = 0;
       while($i < 6){
          doCommand("Select: Mode=Range StartTime=5.0 EndTime=8.0 FirstTrack=0 
LastTrack=0");
 
@@ -179,23 +237,18 @@
    }
 }
 
+# Print some info returned by the GetTrackInfo command
 sub getTrackInfo{
-   $trackID = shift;
+   my $trackID = shift;
    sendCommand("GetTrackInfo: Type=Name TrackIndex=0");
-   my $name = <FROM_SRV>;
-   chomp($name);
-   <FROM_SRV>;
-   <FROM_SRV>;
+   my @resps = getResponses();
+   my $name = shift(@resps);
    sendCommand("GetTrackInfo: Type=StartTime TrackIndex=0");
-   my $startTime = <FROM_SRV>;
-   chomp($startTime);
-   <FROM_SRV>;
-   <FROM_SRV>;
+   @resps = getResponses();
+   my $startTime = shift(@resps);
    sendCommand("GetTrackInfo: Type=EndTime TrackIndex=0");
-   my $endTime = <FROM_SRV>;
-   chomp($endTime);
-   <FROM_SRV>;
-   <FROM_SRV>;
+   @resps = getResponses();
+   my $endTime = shift(@resps);
 
    print "     Name: $name\n";
    print "StartTime: $startTime\n";
@@ -218,30 +271,92 @@
    deleteAll();
 }
 
-# Send some test commands
-# (Delay between sends so it's clearer what's going on)
+# Play for three seconds, then stop
+sub playAndStop{
+   menuCommand("Play");
+   sleep(3.0);
+   menuCommand("Stop");
+}
+
+# Select part of a stereo track
+sub selectRegion{
+   my $track = shift;
+   my $start = shift;
+   my $end = shift;
+   my $t1 = $track + 1;
+   doCommand("Select: Mode=Range FirstTrack=$track LastTrack=$t1 
StartTime=$start EndTime=$end");
+}
+
+# Run testing on the effects that use the ClearAndPaste method
+# Allows the user to check whether effects transform time correctly
+sub testClearAndPasters{
+
+   # Which effects to test, and with what parameters
+   my @clearAndPasters = (
+      "Unchanged:", # control: nonexistent command, so does nothing
+                    # (so 'batch command not recognised' isn't an error)
+      "Noise:",    # generate
+      "NoiseRemoval:",                 # misc clear&paste
+      "ChangeSpeed: Percentage=-10.0", # misc clear&paste
+      "ChangeSpeed: Percentage=40.0", # misc clear&paste
+      "ChangeTempo: Percentage=-20.0", # soundtouch
+      "ChangeTempo: Percentage=80.0", # soundtouch
+      "ChangePitch: Percentage=25.0", # soundtouch
+      "ChangePitch: Percentage=-80.0", # soundtouch
+      "TimeScale: RateStart=-80.0 RateEnd=150.0 HalfStepsStart=-5.0 
HalfStepsEnd=8.0 PreAnalyze=no",                      # SBSMS
+   ); # nyquist can't be called currently
+
+   # Allow time for user to give the project window focus (workaround for menu
+   # command problem)
+   sleep(1.0);
+   deleteAll();
+   my $len = 20.0;
+
+   # Since there aren't proper generator commands yet, we use the preferences
+   # to control the duration
+   my $origDuration = getPref("/CsPresets/NoiseGen_Duration");
+   setPref("/CsPresets/NoiseGen_Duration", $len);
+
+   # For each effect to test:
+   # * Create some stereo noise, and chop two pieces out of it
+   # * Add some labels, then apply the effect
+   # @splits determines where the splits are
+   my @splits = map {$_ * $len} (0.999, 0.2, 0.5, 0.6, 0.8, 0.1, 0.9);
+   my $trackNum = 0;
+   foreach my $effect (@clearAndPasters) {
+      menuCommand("NewStereoTrack");
+      selectRegion($trackNum, 0.0, $splits[0]);
+      doCommand("Noise:");
+      selectRegion($trackNum, $splits[1], $splits[2]);
+      menuCommand("SplitDelete");
+      menuCommand("AddLabel");
+      selectRegion($trackNum, $splits[3], $splits[4]);
+      menuCommand("SplitDelete");
+      menuCommand("AddLabel");
+
+      # Apply the effect
+      selectRegion($trackNum, $splits[5], $splits[6]);
+      doCommand($effect);
+
+      # Make and set the track name
+      my @splat = split(':', $effect);
+      my $name = $splat[0];
+      doCommand("SetTrackInfo: TrackIndex=$trackNum Type=Name Name=$name");
+      doCommand("Select: Mode=None");
+
+      $trackNum = $trackNum + 3;
+   }
+
+   # Set duration back to what it was before
+   setPref("/CsPresets/NoiseGen_Duration", $origDuration);
+}
+
+###############################################################################
 
 startUp();
-fullTest();
 
-#screenshot($screenshotDir, "window", "None");
-#sleep($delay);
-#doCommand( "BatchCommand: CommandName=Amplify ParamString=Ratio=0.1" );
-#sleep($delay);
-#doCommand( "Echo: Delay=1.0 Decay=0.5" );
-#sleep($delay);
-#doCommand( "Amplify: Ratio=2.0" );
-#sleep($delay);
-#doCommand( "Echo: Delay=1.0 Decay=0.5" );
-#sleep($delay);
-#doCommand( "ExportMp3" );
-#sleep($delay);
-#doCommand( "<Not a valid command>");
+# Send some test commands
 
-#print "> ";
-#while($input = <>) {
-#   chomp($input);
-#   print "> ";
-#}
+testClearAndPasters();
 
 finish();


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Audacity-cvs mailing list
Audacity-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to