- commit
- 4333a8ae6297269bd79f3a097702d845e0d93b3d
- parent
- 269e22f4e5c0c00e2da0b528f2f793dc586ed268
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2010-11-05 20:56
progress dialog
Diffstat
| M | src/gui/xiRTMainFrame.cpp | 25 | ++++++++++++++++--------- |
| M | src/gui/xiRTMainFrame.h | 1 | + |
| M | src/rbprocess.h | 9 | ++++++--- |
| M | src/sample.cpp | 42 | ++++++++++++++++++++++++++++++++++++++---- |
| M | src/sample.h | 12 | +++++++++++- |
| M | xiRetimer | 0 |
6 files changed, 72 insertions, 17 deletions
diff --git a/src/gui/xiRTMainFrame.cpp b/src/gui/xiRTMainFrame.cpp
@@ -26,6 +26,7 @@ xiRTMainFrame::xiRTMainFrame( wxWindow* parent ) : MainFrame( parent ) {
26 26
27 27
28 28 xiRTMainFrame::~xiRTMainFrame() {
-1 29 // TODO destroy objects
29 30 // delete[] curve;
30 31 // delete[] playback;
31 32 // delete[] sample;
@@ -91,8 +92,9 @@ void xiRTMainFrame::OnOpenClick( wxCommandEvent& event )
91 92 if (dialog->ShowModal()==wxID_OK) {
92 93 wxString filename=dialog->GetPath();
93 94 sample->loadFile(filename.mb_str());
-1 95 process();
-1 96 _updateWaveform=true;
94 97 }
95 -1 _updateWaveform=true;
96 98 }
97 99
98 100 void xiRTMainFrame::OnExportClick( wxCommandEvent& event )
@@ -147,14 +149,7 @@ void xiRTMainFrame::OnClearClick( wxCommandEvent& event ) {
147 149
148 150
149 151 // ************ misc **************
150 -1 void xiRTMainFrame::OnProcessClick( wxCommandEvent& event ) {
151 -1 // TODO Link process with process bar
152 -1 /*
153 -1 wxProgressDialog::wxProgressDialog* dialog = new wxProgressDialog( _T("processing..."), _T("please wait") );
154 -1 dialog ->Show();
155 -1 */
156 -1 sample->process();
157 -1 }
-1 152 void xiRTMainFrame::OnProcessClick( wxCommandEvent& event ) {process();}
158 153
159 154 void xiRTMainFrame::OnPaint( wxUpdateUIEvent& event ) {
160 155 // TODO repaint also if UI update is not necessary, eg whe seeker is moving from playback
@@ -167,6 +162,18 @@ void xiRTMainFrame::OnSize( wxSizeEvent& event ) {
167 162
168 163
169 164 // ***********************************
-1 165 void xiRTMainFrame::process() {
-1 166 sample->process();
-1 167
-1 168 wxProgressDialog::wxProgressDialog* dialog = new wxProgressDialog( _T("processing..."), _T("please wait") );
-1 169 dialog ->Show();
-1 170 while (sample->getProcessing()) {
-1 171 dialog->Update(int(sample->getFinished()*100));
-1 172 }
-1 173 dialog->Show(false);
-1 174 // TODO deatroy dialog
-1 175 }
-1 176
170 177 void xiRTMainFrame::paint() {
171 178 wxClientDC dc(this);
172 179 dc.GetSize(&width,&height);
diff --git a/src/gui/xiRTMainFrame.h b/src/gui/xiRTMainFrame.h
@@ -46,6 +46,7 @@ protected: 46 46 void OnSize( wxSizeEvent& event ); 47 47 48 48 void paint(); -1 49 void process(); 49 50 bool _updateWaveform; 50 51 static const int MARKERWIDTH=15; 51 52 static const int BEAT=15;
diff --git a/src/rbprocess.h b/src/rbprocess.h
@@ -2,6 +2,7 @@ 2 2 #define __XIRBPROCESS_H 3 3 4 4 #include "marker.h" -1 5 #include "sample.h" 5 6 #include <rubberband/RubberBandStretcher.h> 6 7 7 8 /* @@ -9,10 +10,9 @@ this is called by sample.process() 9 10 this uses the rubberband library 10 11 */ 11 1212 -1 void RBprocess(float* odata, int olength, float* data, int length, Marker* marker) {13 -1 // TODO better Quality by loading more into the buffer than needed-1 13 void RBprocess(float* odata, int olength, float* data, int length, Marker* marker, Sample* caller) { 14 1415 -1 const int bufferLength=4096; // important-1 15 const int bufferLength=4096; 16 16 float **ibuf = new float *[1]; 17 17 ibuf[0]=new float[bufferLength]; 18 18 float **obuf = new float *[1]; @@ -56,6 +56,9 @@ void RBprocess(float* odata, int olength, float* data, int length, Marker* marke 56 56 avail2+=avail; 57 57 58 58 delete[] obuf[0]; -1 59 -1 60 // update ProgressBar -1 61 caller->setFinished(i/(float)olength); 59 62 } 60 63 for (int i=avail2; i<length; ++i) { 61 64 data[i]=0;
diff --git a/src/sample.cpp b/src/sample.cpp
@@ -1,5 +1,6 @@ 1 1 #include "sample.h" 2 2 #include "rbprocess.h" -1 3 #include <pthread.h> 3 4 4 5 Sample::Sample(Marker* m) { 5 6 marker=m; @@ -7,7 +8,9 @@ Sample::Sample(Marker* m) { 7 8 data=new float[0]; 8 9 olength=0; 9 10 odata=new float[0];10 -1 stretchMode=-1;-1 11 stretchMode=0; -1 12 _processing=false; -1 13 _finished=0; 11 14 } 12 15 13 16 Sample::~Sample() { @@ -23,6 +26,7 @@ int Sample::getGuessedLength() { 23 26 } 24 27 25 28 float Sample::get(float nn) { -1 29 if (_processing) return NULL; 26 30 int i=int(length*nn); 27 31 if (i<0 || i>=length) return NULL; 28 32 return data[i]; @@ -35,10 +39,15 @@ float Sample::getOld(float o) { 35 39 } 36 40 37 41 int Sample::getStretchMode() {return stretchMode;}38 -1 void Sample::setStretchMode(int m) {stretchMode=m;}-1 42 -1 43 void Sample::setStretchMode(int m) { -1 44 if (_processing) return; -1 45 stretchMode=m; -1 46 } 39 47 40 48 int Sample::loadFile(const char* fileName) { 41 49 // TODO multi filetype support -1 50 if (_processing) return 1; 42 51 SNDFILE *sndfile; 43 52 sfinfo; 44 53 // open file @@ -74,6 +83,7 @@ int Sample::loadFile(const char* fileName) { 74 83 75 84 int Sample::writeFile(const char* fileNameOut) { 76 85 // TODO multi filetype support -1 86 if (_processing) return 1; 77 87 if (length<=0) { 78 88 std::cerr << "ERROR: Load a file first" << std::endl; 79 89 return 1; @@ -98,6 +108,22 @@ int Sample::writeFile(const char* fileNameOut) { 98 108 } 99 109 100 110 int Sample::process() { -1 111 // process_bg(); -1 112 if (_processing) return 1; -1 113 setFinished(0); -1 114 pthread_t thread; -1 115 pthread_create(&thread, NULL, Sample::EntryPoint, (void*)this); -1 116 _processing=true; -1 117 return 0; -1 118 } -1 119 -1 120 void* Sample::EntryPoint(void* pthis) -1 121 { -1 122 Sample* pt = (Sample*)pthis; -1 123 pt->process_bg(); -1 124 } -1 125 -1 126 int Sample::process_bg() { 101 127 /* 102 128 This function does the nmain thing: it stretches the original data as defined by the marker object. 103 129 Therefore it reads data from odata and writes to data. @@ -108,13 +134,21 @@ Therefore it reads data from odata and writes to data. 108 134 data=new float[length]; 109 135 switch (getStretchMode()) { 110 136 // rubberband111 -1 case 1: RBprocess(odata, olength, data, length, marker); break;-1 137 case 1: RBprocess(odata, olength, data, length, marker, this); break; 112 138 default: { 113 139 for (int i=0; i<length; ++i) { 114 140 data[i]=getOld(marker->new2old(marker->nnew2new(i/(float)length))); -1 141 setFinished(i/(float)length); 115 142 } 116 143 } 117 144 }118 -1-1 145 setFinished(1); -1 146 _processing=false; -1 147 pthread_exit((void*)0); 119 148 } 120 149 -1 150 bool Sample::getProcessing() {return _processing;} -1 151 -1 152 void Sample::setFinished(float f) {_finished=f;} -1 153 float Sample::getFinished() {return _finished;} -1 154
diff --git a/src/sample.h b/src/sample.h
@@ -26,6 +26,9 @@ public: 26 26 SF_INFO sfinfo; 27 27 int getStretchMode(); 28 28 void setStretchMode(int m); -1 29 bool getProcessing(); -1 30 float getFinished(); -1 31 void setFinished(float f); 29 32 private: 30 33 float *data; 31 34 int length; @@ -33,6 +36,10 @@ private: 33 36 int olength; 34 37 float *odata; 35 38 int stretchMode; -1 39 static void * EntryPoint(void*); -1 40 int process_bg(); -1 41 bool _processing; -1 42 float _finished; 36 43 }; 37 44 38 45 /* @@ -41,7 +48,10 @@ int main() { 41 48 Sample s(m); 42 49 m->add(0.5,0.3); 43 50 int error;44 -1 error=s.loadFile("test.wav");-1 51 error=s.loadFile("../../test.wav"); -1 52 while (s.getProcessing()) { -1 53 std::cout << int(s.getFinished()*100) << "%" << std::endl; -1 54 } 45 55 error=s.writeFile("testo.wav"); 46 56 } 47 57 */