Update of /cvsroot/audacity/audacity-src/src
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv13129
Modified Files:
FreqWindow.cpp FreqWindow.h Menus.cpp
Log Message:
Make FreqWindow do all the work, and exploit non-modalness to give a new Replot
button.
Index: FreqWindow.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/FreqWindow.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- FreqWindow.h 18 Feb 2009 06:37:46 -0000 1.10
+++ FreqWindow.h 20 Feb 2009 01:04:39 -0000 1.11
@@ -59,8 +59,9 @@
const wxString & title, const wxPoint & pos);
virtual ~ FreqWindow();
+ void GetAudio();
- void Plot(int len, float *data, double rate);
+ void Plot();
void PlotMouseEvent(wxMouseEvent & event);
void PlotPaint(wxPaintEvent & event);
@@ -73,11 +74,13 @@
void OnFuncChoice(wxCommandEvent & event);
void OnAxisChoice(wxCommandEvent & event);
void OnExport(wxCommandEvent & event);
+ void OnReplot(wxCommandEvent & event);
void Recalc();
void DrawPlot();
private:
+ float *buffer;
#ifdef __WXMSW__
static const int fontSize = 8;
@@ -96,6 +99,7 @@
wxButton *mCloseButton;
wxButton *mExportButton;
+ wxButton *mReplotButton;
wxChoice *mAlgChoice;
wxChoice *mSizeChoice;
wxChoice *mFuncChoice;
Index: Menus.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/Menus.cpp,v
retrieving revision 1.438
retrieving revision 1.439
diff -u -d -r1.438 -r1.439
--- Menus.cpp 19 Feb 2009 07:06:24 -0000 1.438
+++ Menus.cpp 20 Feb 2009 01:04:39 -0000 1.439
@@ -3986,70 +3986,7 @@
void AudacityProject::OnPlotSpectrum()
{
- int selcount = 0;
- int i;
- double rate = 0;
- sampleCount len = 0;
- float *buffer = NULL;
- bool warning = false;
- TrackListIterator iter(mTracks);
- Track *t = iter.First();
- while (t) {
- if (t->GetSelected() && t->GetKind() == Track::Wave) {
- WaveTrack *track = (WaveTrack *)t;
- if (selcount==0) {
- rate = track->GetRate();
- sampleCount start, end;
- start = track->TimeToLongSamples(mViewInfo.sel0);
- end = track->TimeToLongSamples(mViewInfo.sel1);
- len = (sampleCount)(end - start);
- if (len > 1048576) {
- warning = true;
- len = 1048576;
- }
- buffer = new float[len];
- track->Get((samplePtr)buffer, floatSample, start, len);
- }
- else {
- if (track->GetRate() != rate) {
- wxMessageBox(_("To plot the spectrum, all selected tracks must
be the same sample rate."));
- delete[] buffer;
- return;
- }
- sampleCount start;
- start = track->TimeToLongSamples(mViewInfo.sel0);
- float *buffer2 = new float[len];
- track->Get((samplePtr)buffer2, floatSample, start, len);
- for(i=0; i<len; i++)
- buffer[i] += buffer2[i];
- delete[] buffer2;
- }
- selcount++;
- }
- t = iter.Next();
- }
-
- if (selcount == 0)
- return;
-
- if (selcount > 1)
- for(i=0; i<len; i++)
- buffer[i] /= selcount;
-
- if (warning) {
- wxString msg;
- msg.Printf(_("Too much audio was selected. Only the first %.1f seconds
of audio will be analyzed."),
- (len / rate));
- wxMessageBox(msg);
- }
-
InitFreqWindow(NULL);
- gFreqWindow->Plot(len, buffer, rate);
- gFreqWindow->Show(true);
- gFreqWindow->Raise();
- gFreqWindow->SetFocus();
-
- delete[] buffer;
}
Index: FreqWindow.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/FreqWindow.cpp,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- FreqWindow.cpp 18 Feb 2009 06:37:46 -0000 1.61
+++ FreqWindow.cpp 20 Feb 2009 01:04:39 -0000 1.62
@@ -80,7 +80,8 @@
FreqAlgChoiceID,
FreqSizeChoiceID,
FreqFuncChoiceID,
- FreqAxisChoiceID
+ FreqAxisChoiceID,
+ ReplotButtonID
};
FreqWindow *gFreqWindow = NULL;
@@ -92,15 +93,21 @@
void InitFreqWindow(wxWindow * parent)
{
- if (gFreqWindow)
- return;
+ if(!gFreqWindow)
+ {
+ wxPoint where;
- wxPoint where;
+ where.x = 150;
+ where.y = 150;
- where.x = 150;
- where.y = 150;
+ gFreqWindow = new FreqWindow(parent, -1, _("Frequency Analysis"), where);
+ }
- gFreqWindow = new FreqWindow(parent, -1, _("Frequency Analysis"), where);
+ gFreqWindow->GetAudio();
+ gFreqWindow->Plot();
+ gFreqWindow->Show(true);
+ gFreqWindow->Raise();
+ gFreqWindow->SetFocus();
}
// FreqWindow
@@ -114,6 +121,7 @@
EVT_CHOICE(FreqSizeChoiceID, FreqWindow::OnSizeChoice)
EVT_CHOICE(FreqFuncChoiceID, FreqWindow::OnFuncChoice)
EVT_CHOICE(FreqAxisChoiceID, FreqWindow::OnAxisChoice)
+ EVT_BUTTON(ReplotButtonID, FreqWindow::OnReplot)
END_EVENT_TABLE()
FreqWindow::FreqWindow(wxWindow * parent, wxWindowID id,
@@ -212,6 +220,10 @@
_("&Export..."));
mExportButton->SetName(_("Export"));
+ mReplotButton = new wxButton(this, ReplotButtonID,
+ _("&Replot"));
+ mReplotButton->SetName(_("Replot"));
+
mCloseButton = new wxButton(this, wxID_CANCEL,
_("Close"));
mCloseButton->SetName(_("Close"));
@@ -307,6 +319,8 @@
vs->Add( 1, 5, 0 );
+ wxFlexGridSizer *gs = new wxFlexGridSizer( 2 );
+
hs = new wxBoxSizer( wxHORIZONTAL );
hs->Add( algLabel, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, 5 );
hs->Add( mAlgChoice, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, 5 );
@@ -314,7 +328,8 @@
hs->Add( mSizeChoice, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, 5 );
hs->Add( 10, 1, 0 );
hs->Add( mExportButton, 0, wxALIGN_CENTER | wxALIGN_RIGHT | wxLEFT |
wxRIGHT, 5 );
- vs->Add( hs, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT | wxBOTTOM, 5
);
+ gs->Add( hs, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT , 5 );
+ gs->Add( mReplotButton, 0, wxALIGN_CENTER | wxALIGN_RIGHT | wxLEFT |
wxRIGHT | wxBOTTOM, 5 );
hs = new wxBoxSizer( wxHORIZONTAL );
hs->Add( funcLabel, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, 5 );
@@ -323,7 +338,9 @@
hs->Add( mAxisChoice, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, 5 );
hs->Add( 10, 1, 0 );
hs->Add( mCloseButton, 0, wxALIGN_CENTER | wxALIGN_RIGHT | wxLEFT |
wxRIGHT, 5 );
- vs->Add( hs, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT | wxBOTTOM, 5
);
+ gs->Add( hs, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT | wxBOTTOM, 5
);
+ // still some gs space for grid on-off control
+ vs->Add( gs, 0, wxEXPAND | wxBOTTOM, 0 );
vs->Add( mInfo, 0, wxEXPAND | wxBOTTOM, 0 );
@@ -345,6 +362,70 @@
delete mCrossCursor;
if (mData)
delete[]mData;
+ if(buffer)
+ delete[] buffer;
+}
+
+void FreqWindow::GetAudio()
+{
+ int selcount = 0;
+ int i;
+ bool warning = false;
+ sampleCount len;
+ double rate;
+ AudacityProject *p = GetActiveProject();
+ TrackListIterator iter(p->GetTracks());
+ Track *t = iter.First();
+ while (t) {
+ if (t->GetSelected() && t->GetKind() == Track::Wave) {
+ WaveTrack *track = (WaveTrack *)t;
+ if (selcount==0) {
+ rate = track->GetRate();
+ sampleCount start, end;
+ start = track->TimeToLongSamples(p->mViewInfo.sel0);
+ end = track->TimeToLongSamples(p->mViewInfo.sel1);
+ len = (sampleCount)(end - start);
+ if (len > 1048576) {
+ warning = true;
+ len = 1048576;
+ }
+ buffer = new float[len];
+ track->Get((samplePtr)buffer, floatSample, start, len);
+ }
+ else {
+ if (track->GetRate() != rate) {
+ wxMessageBox(_("To plot the spectrum, all selected tracks must
be the same sample rate."));
+ delete[] buffer;
+ return;
+ }
+ sampleCount start;
+ start = track->TimeToLongSamples(p->mViewInfo.sel0);
+ float *buffer2 = new float[len];
+ track->Get((samplePtr)buffer2, floatSample, start, len);
+ for(i=0; i<len; i++)
+ buffer[i] += buffer2[i];
+ delete[] buffer2;
+ }
+ selcount++;
+ }
+ t = iter.Next();
+ }
+
+ if (selcount == 0)
+ return;
+
+ if (selcount > 1)
+ for(i=0; i<len; i++)
+ buffer[i] /= selcount;
+
+ if (warning) {
+ wxString msg;
+ msg.Printf(_("Too much audio was selected. Only the first %.1f seconds
of audio will be analyzed."),
+ (len / rate));
+ wxMessageBox(msg);
+ }
+ mDataLen = len;
+ mRate = rate;
}
void FreqWindow::OnSize(wxSizeEvent & event)
@@ -823,15 +904,13 @@
this->Show(FALSE);
}
-void FreqWindow::Plot(int len, float *data, double rate)
+void FreqWindow::Plot()
{
- mRate = rate;
- mDataLen = len;
if (mData)
delete[]mData;
- mData = new float[len];
- for (int i = 0; i < len; i++)
- mData[i] = data[i];
+ mData = new float[mDataLen];
+ for (int i = 0; i < mDataLen; i++)
+ mData[i] = buffer[i];
Recalc();
wxSizeEvent dummy;
OnSize( dummy );
@@ -1112,6 +1191,11 @@
f.Close();
}
+void FreqWindow::OnReplot(wxCommandEvent & WXUNUSED(event))
+{
+ GetAudio();
+ gFreqWindow->Plot();
+}
BEGIN_EVENT_TABLE(FreqPlot, wxWindow)
EVT_ERASE_BACKGROUND(FreqPlot::OnErase)
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs