xiRetimer

fit recorded audio to a tempo
git clone https://git.ce9e.org/xiRetimer.git

commit
df03c11e23d360bcb8eeb0ed4180f92de5c7ed62
parent
8342eeae2cb84201f12df7026c78fe83d4091357
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2010-11-04 22:52
waveshape

Diffstat

M src/curve.cpp 14 ++++++--------
M src/curve.h 4 ++--
M src/gui/xiRTMainFrame.cpp 110 ++++++++++++++++++++++++++++++++++---------------------------
M src/gui/xiRTMainFrame.h 18 +++++++++++++++---
M src/gui/xiRetimer_wxfb.cpp 6 ++++--
M src/gui/xiRetimer_wxfb.fbp 6 +++---
M src/gui/xiRetimer_wxfb.h 3 ++-
M src/playback.cpp 1 -
M src/sample.cpp 2 +-
M xiRetimer 0

10 files changed, 94 insertions, 70 deletions


diff --git a/src/curve.cpp b/src/curve.cpp

@@ -23,21 +23,19 @@ float Curve::get(float nn) {
   23    23   return sample->getOld(marker->new2old(marker->nnew2new(nn)));
   24    24 }
   25    25 
   26    -1 int MINMAXRES=15;
   27    -1 
   28    -1 float Curve::getMin(float nn, float l) {
   -1    26 float Curve::getMin(float nn, float l, int n) {
   29    27   float min=1;
   30    -1   for (int i=0; i<MINMAXRES; ++i) {
   31    -1     float g=get(nn+l*i/MINMAXRES);
   -1    28   for (int i=0; i<n; ++i) {
   -1    29     float g=get(nn+l*i/(float)n);
   32    30     if (g<min) min=g;
   33    31   }
   34    32   return min;
   35    33 }
   36    34 
   37    -1 float Curve::getMax(float nn, float l) {
   -1    35 float Curve::getMax(float nn, float l, int n) {
   38    36   float max=-1;
   39    -1   for (int i=0; i<MINMAXRES; ++i) {
   40    -1     float g=get(nn+l*i/MINMAXRES);
   -1    37   for (int i=0; i<n; ++i) {
   -1    38     float g=get(nn+l*i/(float)n);
   41    39     if (g>max) max=g;
   42    40   }
   43    41   return max;

diff --git a/src/curve.h b/src/curve.h

@@ -16,8 +16,8 @@ public:
   16    16   float getSeeker();
   17    17   // indirect access to sample
   18    18   float get(float nn);
   19    -1   float getMin(float nn, float l); // nicer looking waveform
   20    -1   float getMax(float nn, float l); // nicer looking waveform
   -1    19   float getMin(float nn, float l, int n=10); // nicer looking waveform
   -1    20   float getMax(float nn, float l, int n=10); // nicer looking waveform
   21    21   // indirect access to marker
   22    22   void addMarker();
   23    23   void removeMarker();

diff --git a/src/gui/xiRTMainFrame.cpp b/src/gui/xiRTMainFrame.cpp

@@ -2,15 +2,9 @@
    2     2 #include "xiRTAboutDialog.h"
    3     3 #include "xiRTPrefsDialog.h"
    4     4 
    5    -1 #include <wx/progdlg.h>
    6    -1 #include <wx/dcclient.h>
    7    -1 #include <wx/dcbuffer.h>
    8    -1 #include <wx/string.h>
    9    -1 #include <wx/filedlg.h>
   10    -1 
   11     5 #include <iostream>
   12     6 
   13    -1 // everything is living here
   -1     7 
   14     8 
   15     9 xiRTMainFrame::xiRTMainFrame( wxWindow* parent ) : MainFrame( parent ) {
   16    10   marker=new Marker();
@@ -21,13 +15,21 @@ xiRTMainFrame::xiRTMainFrame( wxWindow* parent ) : MainFrame( parent ) {
   21    15   height=100;
   22    16   Marker_move=false;
   23    17   Seeker_move=false;
   -1    18 
   -1    19   brushbg=new wxBrush(*wxBLACK);
   -1    20   penCurve=new wxPen(*wxBLUE,1);
   -1    21   penSeeker=new wxPen(*wxWHITE,1);
   -1    22   penMarker=new wxPen(wxColor(255,255,0),1);
   -1    23   wxBitmap waveform;
   -1    24   _updateWaveform=true;
   24    25 }
   25    26 
   -1    27 
   26    28 xiRTMainFrame::~xiRTMainFrame() {
   27    -1   delete[] curve;
   28    -1   delete[] playback;
   29    -1   delete[] sample;
   30    -1   delete[] marker;
   -1    29 //  delete[] curve;
   -1    30 //  delete[] playback;
   -1    31 //  delete[] sample;
   -1    32 //  delete[] marker;
   31    33 }
   32    34 
   33    35 // ************  mouse  **************
@@ -62,6 +64,7 @@ void xiRTMainFrame::OnLeftDClick( wxMouseEvent& event ) {
   62    64       if (event.m_x<=n+MARKERWIDTH/2 && event.m_x>=n-MARKERWIDTH/2) {
   63    65         curve->selectMarker(i);
   64    66         curve->removeMarker();
   -1    67         _updateWaveform=true;
   65    68         return;
   66    69       }
   67    70     }
@@ -71,8 +74,10 @@ void xiRTMainFrame::OnLeftDClick( wxMouseEvent& event ) {
   71    74 }
   72    75 
   73    76 void xiRTMainFrame::OnMotion( wxMouseEvent& event ) {
   74    -1   if (Marker_move)
   -1    77   if (Marker_move) {
   75    78     curve->setMarker(event.m_x/(float)width);
   -1    79     _updateWaveform=true;
   -1    80   }
   76    81   if (Seeker_move)
   77    82     playback->setSeeker(event.m_x/(float)width);
   78    83 }
@@ -80,13 +85,14 @@ void xiRTMainFrame::OnMotion( wxMouseEvent& event ) {
   80    85 // ************  file  **************
   81    86 void xiRTMainFrame::OnOpenClick( wxCommandEvent& event )
   82    87 {
   83    -1     wxFileDialog* dialog = new wxFileDialog( (wxWindow*)NULL );
   84    -1     dialog->Show();
   -1    88   wxFileDialog* dialog = new wxFileDialog( (wxWindow*)NULL );
   -1    89   dialog->Show();
   85    90 
   86    -1     if (dialog->ShowModal()==wxID_OK) {
   87    -1       wxString filename=dialog->GetPath();
   88    -1       sample->loadFile(filename.mb_str());
   89    -1     }
   -1    91   if (dialog->ShowModal()==wxID_OK) {
   -1    92     wxString filename=dialog->GetPath();
   -1    93     sample->loadFile(filename.mb_str());
   -1    94   }
   -1    95   _updateWaveform=true;
   90    96 }
   91    97 
   92    98 void xiRTMainFrame::OnExportClick( wxCommandEvent& event )
@@ -136,6 +142,7 @@ void xiRTMainFrame::OnHelpClick( wxCommandEvent& event )
  136   142 // ************  marker  **************
  137   143 void xiRTMainFrame::OnClearClick( wxCommandEvent& event ) {
  138   144   curve->clearMarker();
   -1   145   _updateWaveform=true;
  139   146 }
  140   147 
  141   148 
@@ -149,38 +156,43 @@ void xiRTMainFrame::OnProcessClick( wxCommandEvent& event ) {
  149   156     sample->process();
  150   157 }
  151   158 
  152    -1 void xiRTMainFrame::OnUpdateUI( wxUpdateUIEvent& event ) {paint();}
   -1   159 void xiRTMainFrame::OnPaint( wxUpdateUIEvent& event ) {
   -1   160 // TODO repaint also if UI update is not necessary, eg whe seeker is moving from playback
   -1   161   paint();
   -1   162 }
   -1   163 
   -1   164 void xiRTMainFrame::OnSize( wxSizeEvent& event ) {
   -1   165   _updateWaveform=true;
   -1   166 }
  153   167 
  154   168 
  155   169 // ***********************************
  156   170 void xiRTMainFrame::paint() {
  157    -1   // TODO dont repaint all the time
  158    -1   // TODO repaint also if UI update is not necessary, eg whe seeker is moving from playback
  159    -1   wxClientDC dc2(this);
  160    -1   dc2.GetSize(&width,&height);
  161    -1   wxBufferedDC dc(&dc2,wxSize(width,height));
  162    -1   int h=height-BEAT;
  163    -1 
  164    -1   wxBrush brush(*wxBLACK);
  165    -1   dc.SetBackground(brush);
  166    -1   wxPen penCurve(*wxBLUE,1);
  167    -1   wxPen penSeeker(*wxWHITE,1);
  168    -1   wxPen penMarker(wxColor(255,255,0),1);
  169    -1   dc.SetPen(penCurve);
  170    -1   dc.Clear();
  171    -1   for (int i=0; i<width; ++i) {
  172    -1     dc.DrawLine(i,int(curve->get(i/(float)(width-1))*h+height)/2,i+1,int(curve->get((i+1)/(float)(width-1))*h+height)/2);
  173    -1 // TODO nicer looking shape is too slow. Should be painted on an extra buffer
  174    -1 /*    
  175    -1     float min=curve->getMin(i/(float)width, 1/(float)width);
  176    -1     float max=curve->getMax(i/(float)width, 1/(float)width);
  177    -1     dc.DrawLine(i,int(min*h+height)/2,i,int(max*h+height)/2);
  178    -1 */
   -1   171   wxClientDC dc(this);
   -1   172   dc.GetSize(&width,&height);
   -1   173   wxBufferedDC bdc(&dc,wxSize(width,height));
   -1   174   // waveform
   -1   175   if (_updateWaveform) {
   -1   176     waveform.Create(width, height);
   -1   177     wxMemoryDC mdc;
   -1   178     mdc.SelectObject(waveform);
   -1   179     mdc.SetBackground(*brushbg);
   -1   180     mdc.Clear();
   -1   181     mdc.SetPen(*penCurve);
   -1   182     for (int i=0; i<width; ++i) {
   -1   183 //      mdc.DrawLine(i, int(curve->get(i/(float)width)*(height-BEAT)+height)/2, i+1, int(curve->get((i+1)/(float)width)*(height-BEAT)+height)/2);
   -1   184       float min=1+curve->getMin(i/(float)width, 1/(float)width);
   -1   185       float max=1+curve->getMax(i/(float)width, 1/(float)width);
   -1   186       mdc.DrawLine(i,int(min*height/2),i,int(max*height/2));
   -1   187     }
   -1   188     _updateWaveform=false;
  179   189   }
  180    -1   dc.SetPen(penMarker);
   -1   190   bdc.DrawBitmap(waveform,0,0,false);
   -1   191   // marker
   -1   192   bdc.SetPen(*penMarker);
  181   193   for (int i=0; i<curve->getMarkerLength(); ++i) {
  182   194     int n=int(curve->getMarker(i)*(width-1));
  183    -1     dc.DrawLine(n,0,n,height);
   -1   195     bdc.DrawLine(n,0,n,height);
  184   196     wxPoint ps[3];
  185   197     wxPoint p0(n-MARKERWIDTH/2,0);
  186   198     ps[0]=p0;
@@ -188,19 +200,19 @@ void xiRTMainFrame::paint() {
  188   200     ps[1]=p1;
  189   201     wxPoint p2(n+0,MARKERWIDTH*4/5);
  190   202     ps[2]=p2;
  191    -1     dc.DrawPolygon(3,ps);
   -1   203     bdc.DrawPolygon(3,ps);
  192   204   }
  193   205   // seeker
  194    -1   dc.SetPen(penSeeker);
   -1   206   bdc.SetPen(*penSeeker);
  195   207   playback->setSeeker(curve->getSeeker());
  196   208   int seek=int(curve->getSeeker()*(width-1));
  197    -1   dc.DrawLine(seek,0,seek,height);
   -1   209   bdc.DrawLine(seek,0,seek,height);
  198   210   //beats
  199    -1   dc.SetPen(penMarker);
   -1   211   bdc.SetPen(*penMarker);
  200   212   int step=int(width/curve->getBars()/curve->getBeatResolution());
  201   213   for (int i=0; i<width && step!=0; i+=step) {
  202    -1     dc.DrawLine(i,0,i,BEAT);  
   -1   214     bdc.DrawLine(i,0,i,BEAT);
  203   215   }
  204    -1 
  205   216 }
  206   217 
   -1   218 

diff --git a/src/gui/xiRTMainFrame.h b/src/gui/xiRTMainFrame.h

@@ -12,6 +12,11 @@ Subclass of MainFrame, which is generated by wxFormBuilder.
   12    12 #include "../playback.h"
   13    13 #include "../curve.h"
   14    14 
   -1    15 #include <wx/progdlg.h>
   -1    16 #include <wx/dcclient.h>
   -1    17 #include <wx/dcbuffer.h>
   -1    18 #include <wx/string.h>
   -1    19 #include <wx/filedlg.h>
   15    20 
   16    21 /** Implementing MainFrame */
   17    22 class xiRTMainFrame : public MainFrame
@@ -37,10 +42,11 @@ protected:
   37    42   // misc
   38    43   void OnPrefsClick( wxCommandEvent& event );
   39    44   void OnProcessClick( wxCommandEvent& event );
   40    -1   void OnUpdateUI( wxUpdateUIEvent& event );
   -1    45   void OnPaint( wxUpdateUIEvent& event );
   -1    46   void OnSize( wxSizeEvent& event );
   41    47 
   42    48   void paint();
   43    -1   void paintSeeker();
   -1    49   bool _updateWaveform;
   44    50   static const int MARKERWIDTH=15;
   45    51   static const int BEAT=15;
   46    52   
@@ -53,7 +59,13 @@ Marker* marker;
   53    59 Sample* sample;
   54    60 Playback* playback;
   55    61 Curve* curve;
   56    -1 	
   -1    62 
   -1    63 wxBrush* brushbg;
   -1    64 wxPen* penCurve;
   -1    65 wxPen* penSeeker;
   -1    66 wxPen* penMarker;
   -1    67 wxBitmap waveform;
   -1    68 
   57    69 public:
   58    70 	/** Constructor */
   59    71 	xiRTMainFrame( wxWindow* parent );

diff --git a/src/gui/xiRetimer_wxfb.cpp b/src/gui/xiRetimer_wxfb.cpp

@@ -137,7 +137,8 @@ wxInitAllImageHandlers();
  137   137 	this->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( MainFrame::OnLeftDown ) );
  138   138 	this->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( MainFrame::OnLeftUp ) );
  139   139 	this->Connect( wxEVT_MOTION, wxMouseEventHandler( MainFrame::OnMotion ) );
  140    -1 	this->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( MainFrame::OnUpdateUI ) );
   -1   140 	this->Connect( wxEVT_SIZE, wxSizeEventHandler( MainFrame::OnSize ) );
   -1   141 	this->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( MainFrame::OnPaint ) );
  141   142 	this->Connect( m_open->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrame::OnOpenClick ) );
  142   143 	this->Connect( m_export->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrame::OnExportClick ) );
  143   144 	this->Connect( m_prefs->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrame::OnPrefsClick ) );
@@ -157,7 +158,8 @@ MainFrame::~MainFrame()
  157   158 	this->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( MainFrame::OnLeftDown ) );
  158   159 	this->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( MainFrame::OnLeftUp ) );
  159   160 	this->Disconnect( wxEVT_MOTION, wxMouseEventHandler( MainFrame::OnMotion ) );
  160    -1 	this->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( MainFrame::OnUpdateUI ) );
   -1   161 	this->Disconnect( wxEVT_SIZE, wxSizeEventHandler( MainFrame::OnSize ) );
   -1   162 	this->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( MainFrame::OnPaint ) );
  161   163 	this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrame::OnOpenClick ) );
  162   164 	this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrame::OnExportClick ) );
  163   165 	this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrame::OnPrefsClick ) );

diff --git a/src/gui/xiRetimer_wxfb.fbp b/src/gui/xiRetimer_wxfb.fbp

@@ -73,8 +73,8 @@
   73    73             <event name="OnRightDown"></event>
   74    74             <event name="OnRightUp"></event>
   75    75             <event name="OnSetFocus"></event>
   76    -1             <event name="OnSize"></event>
   77    -1             <event name="OnUpdateUI">OnUpdateUI</event>
   -1    76             <event name="OnSize">OnSize</event>
   -1    77             <event name="OnUpdateUI">OnPaint</event>
   78    78             <object class="wxBoxSizer" expanded="1">
   79    79                 <property name="minimum_size"></property>
   80    80                 <property name="name">bSizer3</property>
@@ -608,7 +608,7 @@
  608   608                 </object>
  609   609             </object>
  610   610         </object>
  611    -1         <object class="Dialog" expanded="1">
   -1   611         <object class="Dialog" expanded="0">
  612   612             <property name="bg"></property>
  613   613             <property name="center"></property>
  614   614             <property name="context_help"></property>

diff --git a/src/gui/xiRetimer_wxfb.h b/src/gui/xiRetimer_wxfb.h

@@ -48,7 +48,8 @@ class MainFrame : public wxFrame
   48    48 		virtual void OnLeftDown( wxMouseEvent& event ) { event.Skip(); }
   49    49 		virtual void OnLeftUp( wxMouseEvent& event ) { event.Skip(); }
   50    50 		virtual void OnMotion( wxMouseEvent& event ) { event.Skip(); }
   51    -1 		virtual void OnUpdateUI( wxUpdateUIEvent& event ) { event.Skip(); }
   -1    51 		virtual void OnSize( wxSizeEvent& event ) { event.Skip(); }
   -1    52 		virtual void OnPaint( wxUpdateUIEvent& event ) { event.Skip(); }
   52    53 		virtual void OnOpenClick( wxCommandEvent& event ) { event.Skip(); }
   53    54 		virtual void OnExportClick( wxCommandEvent& event ) { event.Skip(); }
   54    55 		virtual void OnPrefsClick( wxCommandEvent& event ) { event.Skip(); }

diff --git a/src/playback.cpp b/src/playback.cpp

@@ -61,7 +61,6 @@ int Playback::start() {
   61    61     for (int i=0; i<length; ++i) {
   62    62       idata[i]=int(sample->get(i/(float)length)*128);
   63    63     }
   64    -1 std::cout << length << " ";
   65    64     /* Put the sound data in the slot (it starts playing immediately) */
   66    65     sounds.dlen = length;
   67    66     sounds.data = idata;

diff --git a/src/sample.cpp b/src/sample.cpp

@@ -108,7 +108,7 @@ Therefore it reads data from odata and writes to data.
  108   108   data=new float[length];
  109   109   switch (getStretchMode()) {
  110   110     // rubberband
  111    -1     case 0: RBprocess(odata, olength, data, length, marker); break;
   -1   111     case 1: RBprocess(odata, olength, data, length, marker); break;
  112   112     default: {
  113   113       for (int i=0; i<length; ++i) {
  114   114         data[i]=getOld(marker->new2old(marker->nnew2new(i/(float)length)));

diff --git a/xiRetimer b/xiRetimer

Binary files differ.