Update of /cvsroot/audacity/audacity-src/src/toolbars
In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv28452

Modified Files:
        ControlToolBar.h TranscriptionToolBar.cpp 
        TranscriptionToolBar.h ControlToolBar.cpp 
Log Message:
Use Control toolbar play functions when using Transcription toolbar.  (removes 
unmaintained duplication)
Cleaned up Transcription toolbar a little (at least the used functions)
Transcription toolbar was allocating TimeTracks in wrong project


Index: TranscriptionToolBar.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/toolbars/TranscriptionToolBar.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- TranscriptionToolBar.cpp    12 Mar 2007 09:23:15 -0000      1.7
+++ TranscriptionToolBar.cpp    25 Apr 2007 03:43:36 -0000      1.8
@@ -29,6 +29,7 @@
 
 #include "TranscriptionToolBar.h"
 
+#include "ControlToolBar.h"
 #include "../AllThemeResources.h"
 #include "../AudioIO.h"
 #include "../Experimental.h"
@@ -80,23 +81,16 @@
 TranscriptionToolBar::TranscriptionToolBar()
 : ToolBar(TranscriptionBarID, _("Transcription"), wxT("Transcription"))
 {
+   mPlaySpeed = 1.0;
+#ifdef EXPERIMENTAL_VOICE_DETECTION
+   mVk = new VoiceKey();
+#endif
 }
 
 TranscriptionToolBar::~TranscriptionToolBar()
 {
-   delete vk;  
-   
-   if (mBackgroundBitmap) delete mBackgroundBitmap;
-   if(mPlaySpeedSlider)delete mPlaySpeedSlider;
-   if (mTimeTrack) delete mTimeTrack;
-
 #ifdef EXPERIMENTAL_VOICE_DETECTION
-   if(mSensitivitySlider)delete mSensitivitySlider;
-
-   for (int i=0; i<TTBNumButtons; i++)
-      if(mButtons[i]) delete mButtons[i];
-
-   if(mKeyTypeChoice) delete mKeyTypeChoice;
+   delete mVk;
 #endif
 }
 
@@ -104,11 +98,9 @@
 {
    ToolBar::Create(parent);
 
-   vk = new VoiceKey();
    mBackgroundBrush.SetColour(wxColour(204, 204, 204));
    mBackgroundPen.SetColour(wxColour(204, 204, 204));
-   
-   mBackgroundBitmap = NULL;
+
    mBackgroundHeight = 0;
    mBackgroundWidth = 0;
 
@@ -124,17 +116,6 @@
    mButtons[TTB_MakeLabel]->Enable();
 #endif
 
-   AudacityProject * p = GetActiveProject();
-   if(p)
-      {
-         mTimeTrack = new TimeTrack(p->GetDirManager());
-         mTimeTrack->SetRangeUpper(100);
-         mTimeTrack->SetRangeLower(100);
-      }
-   else
-      mTimeTrack = NULL;
-   mPlaySpeed = 1.0;
-
    //Process a dummy event to set up the slider
    wxCommandEvent dummy;
    OnSpeedSlider(dummy);
@@ -146,7 +127,6 @@
 AButton *TranscriptionToolBar::AddButton(
    teBmps eFore, teBmps eDisabled,
    int id,
-//   bool processdownevents,
    const wxChar *label,
    const wxChar *tip)
 {
@@ -157,7 +137,6 @@
       eFore, eDisabled,
       wxWindowID(id),
       wxDefaultPosition, 
-//      processdownevents,
       false,
       theTheme.ImageSize( bmpRecoloredUpSmall ));
 
@@ -168,6 +147,7 @@
 #if wxUSE_TOOLTIPS
    r->SetToolTip(tip);
 #endif
+
    Add( r, 0, wxALIGN_CENTER );
 
    return r;
@@ -265,16 +245,14 @@
       return;
    }
   
-   if (event.GetKeyCode() == WXK_SPACE)
-      {
-         if (gAudioIO->IsBusy()) {
-            /*Do Stuff Here*/
-       
-         } else {
-       
-            /*Do other stuff Here*/
-         }
+   if (event.GetKeyCode() == WXK_SPACE) {
+      if (gAudioIO->IsBusy()) {
+         /*Do Stuff Here*/
       }
+      else {
+         /*Do other stuff Here*/
+      }
+   }
 }
 
 
@@ -282,176 +260,95 @@
 //This changes the state of the various buttons
 void TranscriptionToolBar::SetButton(bool down, AButton* button)
 {
-   if (down)
+   if (down) {
       button->PushDown();
-   else
+   }
+   else {
       button->PopUp();
+   }
 }
 
-
-
 void TranscriptionToolBar::GetSamples(WaveTrack *t, sampleCount *s0, 
sampleCount *slen)
 {
    // GetSamples attempts to translate the start and end selection markers 
into sample indices 
    // These selection numbers are doubles.
 
+   AudacityProject *p = GetActiveProject();
+   if (!p) {
+      return;
+   }
 
    //First, get the current selection. It is part of the mViewInfo, which is
    //part of the project
    
-   AudacityProject *p = GetActiveProject();
-   if(p) {
-      double start = p->GetSel0();
-      double end = p->GetSel1();
-          
-      sampleCount ss0 = sampleCount( (start - t->GetOffset()) * t->GetRate() );
-      sampleCount ss1 = sampleCount( (end - t->GetOffset()) * t->GetRate() );
+   double start = p->GetSel0();
+   double end = p->GetSel1();
+      
+   sampleCount ss0 = sampleCount( (start - t->GetOffset()) * t->GetRate() );
+   sampleCount ss1 = sampleCount( (end - t->GetOffset()) * t->GetRate() );
+
+   if (start < t->GetOffset()) {
+      ss0 = 0;
+   }
 
-      if (start < t->GetOffset())
-         ss0 = 0;
 #if 0
-      //This adjusts the right samplecount to the maximum sample.
-      if (ss1 >= t->GetNumSamples())
-         ss1 = t->GetNumSamples();
+   //This adjusts the right samplecount to the maximum sample.
+   if (ss1 >= t->GetNumSamples()) {
+      ss1 = t->GetNumSamples();
+   }
 #endif
 
-      if (ss1 < ss0)
-         ss1 = ss0;
-           
-
-      *s0 = ss0;
-      *slen = ss1 - ss0;
+   if (ss1 < ss0) {
+      ss1 = ss0;
    }
+
+   *s0 = ss0;
+   *slen = ss1 - ss0;
 }
 
 void TranscriptionToolBar::OnPlaySpeed(wxCommandEvent & event)
 {
- //If IO is busy, abort immediately
-   if (gAudioIO->IsBusy()){
-      SetButton(false,mButtons[TTB_PlaySpeed]);
+   // Pop up the button
+   SetButton(false, mButtons[TTB_PlaySpeed]); 
+
+   // If IO is busy, abort immediately
+   if (gAudioIO->IsBusy()) {
+      SetButton(false, mButtons[TTB_PlaySpeed]);
       return;
    }
 
+   // Can't do anything without an active project
    AudacityProject * p = GetActiveProject();
-   if(p)
-      {
-         
-         if(!mTimeTrack)
-            {   
-               AudacityProject * p = GetActiveProject();
-               if(p)
-                  {
-                     mTimeTrack = new TimeTrack(p->GetDirManager());
-                     mTimeTrack->SetRangeUpper((long int)mPlaySpeed);
-                     mTimeTrack->SetRangeLower((long int)mPlaySpeed);
-                  }
-               
-            }
+   if (!p) {
+      return;
+   }
 
-         if(mTimeTrack)
-            {   
-               mTimeTrack->SetRangeLower((long int)mPlaySpeed);
-               mTimeTrack->SetRangeUpper((long int)mPlaySpeed);
-            }
+   // Can't do anything without a time track
+   TimeTrack *tt = new TimeTrack(p->GetDirManager());
 
+   // Set the speed range
+   tt->SetRangeUpper((long int)mPlaySpeed);
+   tt->SetRangeLower((long int)mPlaySpeed);
 
+   // Get the current play region
+   double playRegionStart, playRegionEnd;
+   p->GetPlayRegion(&playRegionStart, &playRegionEnd);
 
-         double t0 = p->GetSel0();
-         double t1 = p->GetSel1();
-         double maxofmins,minofmaxs;
-         bool looped = false;
-         TrackList *t = p->GetTracks();
-             
-         // JS: clarified how the final play region is computed;
-         
-         if (t1 == t0) 
-            {
-               // msmeyer: When playing looped, we play the whole file, if
-               // no range is selected. Otherwise, we play from t0 to end
-               if (looped)
-                  {
-                     // msmeyer: always play from start
-                     t0 = t->GetStartTime();
-                  } else {
-                     // move t0 to valid range
-                     if (t0 < 0)
-                        t0 = t->GetStartTime();
-                     if (t0 > t->GetEndTime())
-                        t0 = t->GetEndTime();
-                  }
-         
-               // always play to end
-               t1 = t->GetEndTime();
-            }
-         else 
-            {
-               // always t0 < t1 right?
-               
-               // the set intersection between the play region and the
-               // valid range maximum of lower bounds
-               if (t0 < t->GetStartTime())
-                  maxofmins = t->GetStartTime();
-               else
-                  maxofmins = t0;
-               
-               // minimum of upper bounds
-               if (t1 > t->GetEndTime())
-                  minofmaxs = t->GetEndTime();
-               else
-                  minofmaxs = t1;
-               
-               // we test if the intersection has no volume 
-               if (minofmaxs <= maxofmins) {
-                  // no volume; play nothing
-                  return;
-               }
-               else {
-                  t0 = maxofmins;
-                  t1 = minofmaxs;
-               }
-            }
+   // Start playing
+   if (playRegionStart >= 0) {
+//      playRegionEnd = playRegionStart + (playRegionEnd-playRegionStart)* 
100.0/mPlaySpeed;
 
-         //Now, t1 is correct for the 'unwarped' wave.  This is how it 
_Should_ be, 
-         //but is not how it is.  Adjust t1 for the speed adjustment.
-         t1 = t0 + (t1-t0)* 100.0/mPlaySpeed;
-         
-         bool success = false;
-         if (t1 > t0) 
-            {
-               int token =   gAudioIO->StartStream(t->GetWaveTrackArray(false),
-                                                   WaveTrackArray(), 
mTimeTrack,
-                                                   p->GetRate(), t0, t1, p, 
looped);
-                                                   
-               if (token != 0) {
-                  success = true;
-                  p->SetAudioIOToken(token);
-                  
-               }
-            }
-         SetButton(false, mButtons[TTB_PlaySpeed]); 
-      }
+      p->GetControlToolBar()->PlayPlayRegion(playRegionStart,
+                                             playRegionEnd,
+                                             false,
+                                             false,
+                                             tt);
+   }
 }
 
 void TranscriptionToolBar::OnSpeedSlider(wxCommandEvent& event)
 {
    mPlaySpeed = (mPlaySpeedSlider->Get()) * 100;
-   if(!mTimeTrack)
-      {   
-         AudacityProject * p = GetActiveProject();
-         if(p)
-            {
-               mTimeTrack = new TimeTrack(p->GetDirManager());
-               mTimeTrack->SetRangeUpper((long int)mPlaySpeed);
-               mTimeTrack->SetRangeLower((long int)mPlaySpeed);
-            }
-
-      }
-
-   if(mTimeTrack)
-      {   
-         mTimeTrack->SetRangeLower((long int)mPlaySpeed);
-         mTimeTrack->SetRangeUpper((long int)mPlaySpeed);
-      }
 }
 
 void TranscriptionToolBar::OnStartOn(wxCommandEvent &event)
@@ -462,7 +359,7 @@
       return;
    }
        
-   vk->AdjustThreshold(GetSensitivity());
+   mVk->AdjustThreshold(GetSensitivity());
    AudacityProject *p = GetActiveProject();
        
  
@@ -479,7 +376,7 @@
          //if(len == 0)
          //len = (WaveTrack*)t->GetSequence()->GetNumSamples()-start;
         
-         sampleCount newstart = vk->OnForward(*(WaveTrack*)t,start,len);
+         sampleCount newstart = mVk->OnForward(*(WaveTrack*)t,start,len);
          double newpos = newstart / ((WaveTrack*)t)->GetRate();
         
          p->SetSel0(newpos);
@@ -496,7 +393,7 @@
       SetButton(false,mButtons[TTB_StartOff]);
       return;
    }
-   vk->AdjustThreshold(GetSensitivity());
+   mVk->AdjustThreshold(GetSensitivity());
    AudacityProject *p = GetActiveProject();
    
    TrackList *tl = p->GetTracks();
@@ -513,7 +410,7 @@
          //if(len == 0)
          //len = (WaveTrack*)t->GetSequence()->GetNumSamples()-start;
          
-         sampleCount newstart = vk->OffForward(*(WaveTrack*)t,start,len);
+         sampleCount newstart = mVk->OffForward(*(WaveTrack*)t,start,len);
          double newpos = newstart / ((WaveTrack*)t)->GetRate();
          
          p->SetSel0(newpos);
@@ -534,7 +431,7 @@
       return;
    }
   
-   vk->AdjustThreshold(GetSensitivity());
+   mVk->AdjustThreshold(GetSensitivity());
    AudacityProject *p = GetActiveProject();
    TrackList *tl = p->GetTracks();
    TrackListIterator iter(tl);
@@ -553,7 +450,7 @@
                len = start;
                start = 0;
             }
-         sampleCount newEnd = vk->OnBackward(*(WaveTrack*)t,start+ len,len);
+         sampleCount newEnd = mVk->OnBackward(*(WaveTrack*)t,start+ len,len);
          double newpos = newEnd / ((WaveTrack*)t)->GetRate();
         
          p->SetSel1(newpos);
@@ -574,7 +471,7 @@
       SetButton(false,mButtons[TTB_EndOff]);
       return;
    }
-   vk->AdjustThreshold(GetSensitivity());
+   mVk->AdjustThreshold(GetSensitivity());
    AudacityProject *p = GetActiveProject();
    TrackList *tl = p->GetTracks();
    TrackListIterator iter(tl);
@@ -591,7 +488,7 @@
                len = start;
                start = 0;
             }
-         sampleCount newEnd = vk->OffBackward(*(WaveTrack*)t,start+ len,len);
+         sampleCount newEnd = mVk->OffBackward(*(WaveTrack*)t,start+ len,len);
          double newpos = newEnd / ((WaveTrack*)t)->GetRate();
         
          p->SetSel1(newpos);
@@ -614,7 +511,7 @@
    }
        
 
-   vk->AdjustThreshold(GetSensitivity());
+   mVk->AdjustThreshold(GetSensitivity());
    AudacityProject *p = GetActiveProject();
    
    
@@ -632,8 +529,8 @@
          //len = (WaveTrack*)t->GetSequence()->GetNumSamples()-start;
         
          double rate =  ((WaveTrack*)t)->GetRate();
-         sampleCount newstart = vk->OffBackward(*(WaveTrack*)t,start,start);
-         sampleCount newend   = 
vk->OffForward(*(WaveTrack*)t,start+len,(int)(tl->GetEndTime()*rate));
+         sampleCount newstart = mVk->OffBackward(*(WaveTrack*)t,start,start);
+         sampleCount newend   = 
mVk->OffForward(*(WaveTrack*)t,start+len,(int)(tl->GetEndTime()*rate));
 
          //reset the selection bounds.
          p->SetSel0(newstart / rate);
@@ -654,7 +551,7 @@
       return;
    }
 
-   vk->AdjustThreshold(GetSensitivity());
+   mVk->AdjustThreshold(GetSensitivity());
    AudacityProject *p = GetActiveProject();
    
    
@@ -671,8 +568,8 @@
          //if(len == 0)
          //len = (WaveTrack*)t->GetSequence()->GetNumSamples()-start;
          double rate =  ((WaveTrack*)t)->GetRate();
-         sampleCount newstart = vk->OnBackward(*(WaveTrack*)t,start,start);
-         sampleCount newend   = 
vk->OnForward(*(WaveTrack*)t,start+len,(int)(tl->GetEndTime()*rate));
+         sampleCount newstart = mVk->OnBackward(*(WaveTrack*)t,start,start);
+         sampleCount newend   = 
mVk->OnForward(*(WaveTrack*)t,start+len,(int)(tl->GetEndTime()*rate));
 
          //reset the selection bounds.
          p->SetSel0(newstart /  rate);
@@ -707,8 +604,8 @@
          sampleCount start,len;
          GetSamples((WaveTrack*)t, &start,&len);
         
-         vk->CalibrateNoise(*((WaveTrack*)t),start,len);
-         vk->AdjustThreshold(3);
+         mVk->CalibrateNoise(*((WaveTrack*)t),start,len);
+         mVk->AdjustThreshold(3);
                
          mButtons[TTB_StartOn]->Enable();
          mButtons[TTB_StartOff]->Enable();
@@ -749,7 +646,7 @@
 
    wxBusyCursor busy;
 
-   vk->AdjustThreshold(GetSensitivity());
+   mVk->AdjustThreshold(GetSensitivity());
    AudacityProject *p = GetActiveProject();
    TrackList *tl = p->GetTracks();
    TrackListIterator iter(tl);
@@ -781,7 +678,7 @@
                
                lastlen = len;
                
-               newStart = vk->OnForward(*(WaveTrack*)t,start,len);
+               newStart = mVk->OnForward(*(WaveTrack*)t,start,len);
 
                //JKC: If no start found then don't add any labels.
                if( newStart==start)
@@ -798,7 +695,7 @@
                //OK, now we have found a new starting point.  A 'word' should 
be at least 
                //50 ms long, so jump ahead minWordSize
                
-               newEnd   = vk->OffForward(*(WaveTrack*)t,newStart+minWordSize, 
len);
+               newEnd   = mVk->OffForward(*(WaveTrack*)t,newStart+minWordSize, 
len);
                
                //If newEnd didn't move, we should give up, because
                // there isn't another end before the end of the selection.
@@ -870,19 +767,19 @@
    switch(value)
       {
       case 0:
-         vk->SetKeyType(true,0,0,0,0);
+         mVk->SetKeyType(true,0,0,0,0);
          break;
       case 1:
-         vk->SetKeyType(0,true,0,0,0);
+         mVk->SetKeyType(0,true,0,0,0);
          break;
       case 2:
-         vk->SetKeyType(0,0,true,0,0);
+         mVk->SetKeyType(0,0,true,0,0);
          break;
       case 3:
-         vk->SetKeyType(0,0,0,true,0);
+         mVk->SetKeyType(0,0,0,true,0);
          break;
       case 4:
-         vk->SetKeyType(0,0,0,0,true);
+         mVk->SetKeyType(0,0,0,0,true);
          break;
       }
 

Index: ControlToolBar.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/toolbars/ControlToolBar.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ControlToolBar.h    22 Oct 2006 19:35:43 -0000      1.2
+++ ControlToolBar.h    25 Apr 2007 03:43:36 -0000      1.3
@@ -26,6 +26,7 @@
 class AButton;
 class AudacityProject;
 class TrackList;
+class TimeTrack;
 
 class ControlToolBar:public ToolBar {
 
@@ -61,7 +62,8 @@
    // Play the region [t0,t1]
    void PlayPlayRegion(double t0, double t1,
                        bool looped = false,
-                       bool cutpreview = false);
+                       bool cutpreview = false,
+                       TimeTrack *timetrack = NULL);
    void PlayDefault();
    
    // Stop playing

Index: ControlToolBar.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/toolbars/ControlToolBar.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- ControlToolBar.cpp  29 Mar 2007 18:17:26 -0000      1.9
+++ ControlToolBar.cpp  25 Apr 2007 03:43:36 -0000      1.10
@@ -416,7 +416,8 @@
 
 void ControlToolBar::PlayPlayRegion(double t0, double t1,
                                     bool looped /* = false */,
-                                    bool cutpreview /* = false */)
+                                    bool cutpreview /* = false */,
+                                    TimeTrack *timetrack /* = NULL */)
 {
    if (gAudioIO->IsBusy()) {
       mPlay->PopUp();
@@ -508,8 +509,11 @@
                return;
             }
          } else {
+            if (!timetrack) {
+               timetrack = t->GetTimeTrack();
+            }
             token = gAudioIO->StartStream(t->GetWaveTrackArray(false),
-                                  WaveTrackArray(), t->GetTimeTrack(),
+                                  WaveTrackArray(), timetrack,
                                   p->GetRate(), t0, t1, p, looped);
          }
          if (token != 0) {

Index: TranscriptionToolBar.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/toolbars/TranscriptionToolBar.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- TranscriptionToolBar.h      16 Sep 2006 05:54:37 -0000      1.1
+++ TranscriptionToolBar.h      25 Apr 2007 03:43:36 -0000      1.2
@@ -107,11 +107,10 @@
    double mPlaySpeed;
    ASlider *mSensitivitySlider;
    double mSensitivity;
-   VoiceKey *vk;
+   VoiceKey *mVk;
    
    wxBrush mBackgroundBrush;
    wxPen mBackgroundPen;
-   wxBitmap *mBackgroundBitmap;
    int mBackgroundWidth;
    int mBackgroundHeight;
 


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to