xiRetimer

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

commit
2ee17b61dcca8af236477cd62198c44af1bcdb33
parent
2fbadab87e33360d4f49eb04c59571a689395e00
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2010-11-03 19:11
clean structure

Diffstat

M src/curve.cpp 25 +++++++------------------
M src/curve.h 13 ++++++-------
M src/gui/xiRTMainFrame.cpp 65 +++++++++++++++++++++++++++++++------------------------------
M src/gui/xiRTMainFrame.h 10 +++++++---
M src/playback.h 5 ++++-
M xiRetimer 0

6 files changed, 57 insertions, 61 deletions


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

@@ -4,10 +4,10 @@
    4     4 
    5     5 // TODO change first and last marker
    6     6 
    7    -1 Curve::Curve() {
    8    -1   marker=new Marker();
    9    -1   sample=new Sample(marker);
   10    -1   seeker=0;
   -1     7 Curve::Curve(Marker* m, Sample* s, Playback* p) {
   -1     8   marker=m;
   -1     9   sample=s;
   -1    10   playback=p;
   11    11   tempo=90;
   12    12   selMarker=-1;
   13    13   beatResolution=1;
@@ -23,9 +23,8 @@ float Curve::get(float nn) {
   23    23   return sample->getOld(marker->new2old(marker->nnew2new(nn)));
   24    24 }
   25    25 
   26    -1 float Curve::getSeeker() {return seeker;}
   27    -1 void Curve::setSeeker(float nn) {
   28    -1   if (nn>=0 && nn<=1) seeker=nn;
   -1    26 float Curve::getSeeker() {
   -1    27   return playback->getSeeker();
   29    28 }
   30    29 
   31    30 float Curve::getBars() {
@@ -43,7 +42,7 @@ void Curve::setBeatResolution(float n) {beatResolution=n;}
   43    42 float Curve::getBeatResolution() {return beatResolution;}
   44    43 
   45    44 void Curve::addMarker() {
   46    -1   float n=marker->nnew2new(seeker);
   -1    45   float n=marker->nnew2new(getSeeker());
   47    46   marker->add(marker->new2old(n),n);
   48    47   // update selMarker
   49    48 /*
@@ -75,15 +74,5 @@ void Curve::selectMarker(int i) {
   75    74 int Curve::getMarkerLength() {return marker->getLength();}
   76    75 float Curve::getMarker(int i) {return marker->new2nnew(marker->getNew(i));}
   77    76 
   78    -1 void Curve::print() {
   79    -1   for (int i=0; i<100; ++i) { // 100 or any number 
   80    -1     for (float j=-1; j<get(i); j+=0.1)
   81    -1       std::cout << "+";
   82    -1     if (std::abs(getSeeker()-i)<0.01)
   83    -1       std::cout << " *";
   84    -1     std::cout << std::endl;
   85    -1   }
   86    -1 }
   87    -1 
   88    77 void Curve::clearMarker() {marker->reset();}
   89    78 

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

@@ -2,21 +2,19 @@
    2     2 #define __XICURVE_H
    3     3 
    4     4 #include <iostream>
   -1     5 #include "marker.h"
    5     6 #include "sample.h"
   -1     7 #include "playback.h"
    6     8 
    7     9 // main part of the gui
    8    10 // layer between screen and backend. Converts everything to screen (0-1) values
    9    11 class Curve {
   10    12 public:
   11    -1   Curve(); 
   -1    13   Curve(Marker* m, Sample* s, Playback* p); 
   12    14   ~Curve();
   13    -1   float getSeeker();
   14    -1   void setSeeker(float nn);
   15    -1   void print();
   16    -1   // direct access to sample
   17    -1   Sample* sample;
   18    15   // indirect access to sample
   19    16   float get(float nn);
   -1    17   float getSeeker();
   20    18   // indirect access to marker
   21    19   void addMarker();
   22    20   void removeMarker();
@@ -32,8 +30,9 @@ public:
   32    30   void setTempo(int bpm);
   33    31   int getTempo();
   34    32 private:
   35    -1   float seeker; // 0-1
   36    33   Marker* marker;
   -1    34   Sample* sample;
   -1    35   Playback* playback;
   37    36   int tempo; // bpm
   38    37   int selMarker;
   39    38   float beatResolution;

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

@@ -10,9 +10,13 @@
   10    10 
   11    11 #include <iostream>
   12    12 
   -1    13 // everything is living here
   -1    14 
   13    15 xiRTMainFrame::xiRTMainFrame( wxWindow* parent ) : MainFrame( parent ) {
   14    -1   curve;
   15    -1   playback=new Playback(curve.sample);
   -1    16   marker=new Marker();
   -1    17   sample=new Sample(marker);
   -1    18   playback=new Playback(sample);
   -1    19   curve=new Curve(marker, sample, playback);
   16    20   width=100; // anything greater than 2
   17    21   height=100;
   18    22   Marker_move=false;
@@ -25,20 +29,19 @@ xiRTMainFrame::~xiRTMainFrame() {}
   25    29 void xiRTMainFrame::OnLeftDown( wxMouseEvent& event ) {
   26    30   // check for Marker Select
   27    31   if (event.m_y<=MARKERWIDTH*4/5) {
   28    -1     for (int i=0; i<curve.getMarkerLength(); ++i) {
   29    -1       int n=int(curve.getMarker(i)*(width-1));
   -1    32     for (int i=0; i<curve->getMarkerLength(); ++i) {
   -1    33       int n=int(curve->getMarker(i)*(width-1));
   30    34       if (event.m_x<=n+MARKERWIDTH/2 && event.m_x>=n-MARKERWIDTH/2) {
   31    -1         curve.selectMarker(i);
   -1    35         curve->selectMarker(i);
   32    36         Marker_move=true;
   33    37         return;
   34    38       }
   35    39     }
   36    40   }
   37    41   // if not returned set Seeker
   38    -1   curve.setSeeker(event.m_x/(float)width);
   39    -1   playback->setSeeker(curve.getSeeker());
   -1    42   playback->setSeeker(event.m_x/(float)width);
   40    43   Seeker_move=true;
   41    -1   curve.selectMarker(-1);  //deselct
   -1    44   curve->selectMarker(-1);  //deselct
   42    45 }
   43    46 
   44    47 void xiRTMainFrame::OnLeftUp( wxMouseEvent& event ) {
@@ -49,24 +52,24 @@ void xiRTMainFrame::OnLeftUp( wxMouseEvent& event ) {
   49    52 void xiRTMainFrame::OnLeftDClick( wxMouseEvent& event ) {
   50    53   // check for Marker Select
   51    54   if (event.m_y<=MARKERWIDTH*4/5) {
   52    -1     for (int i=0; i<curve.getMarkerLength(); ++i) {
   53    -1       int n=int(curve.getMarker(i)*(width-1));
   -1    55     for (int i=0; i<curve->getMarkerLength(); ++i) {
   -1    56       int n=int(curve->getMarker(i)*(width-1));
   54    57       if (event.m_x<=n+MARKERWIDTH/2 && event.m_x>=n-MARKERWIDTH/2) {
   55    -1         curve.selectMarker(i);
   56    -1         curve.removeMarker();
   -1    58         curve->selectMarker(i);
   -1    59         curve->removeMarker();
   57    60         return;
   58    61       }
   59    62     }
   60    63   }
   61    -1   curve.setSeeker(event.m_x/(float)width);
   62    -1   curve.addMarker();
   -1    64   playback->setSeeker(event.m_x/(float)width);
   -1    65   curve->addMarker();
   63    66 }
   64    67 
   65    68 void xiRTMainFrame::OnMotion( wxMouseEvent& event ) {
   66    69   if (Marker_move)
   67    -1     curve.setMarker(event.m_x/(float)width);
   -1    70     curve->setMarker(event.m_x/(float)width);
   68    71   if (Seeker_move)
   69    -1     curve.setSeeker(event.m_x/(float)width);
   -1    72     playback->setSeeker(event.m_x/(float)width);
   70    73 }
   71    74 
   72    75 // ************  file  **************
@@ -77,7 +80,7 @@ void xiRTMainFrame::OnOpenClick( wxCommandEvent& event )
   77    80 
   78    81     if (dialog->ShowModal()==wxID_OK) {
   79    82       wxString filename=dialog->GetPath();
   80    -1       curve.sample->loadFile(filename.mb_str());
   -1    83       sample->loadFile(filename.mb_str());
   81    84     }
   82    85 }
   83    86 
@@ -88,25 +91,22 @@ void xiRTMainFrame::OnExportClick( wxCommandEvent& event )
   88    91 
   89    92     if (dialog->ShowModal()==wxID_OK) {
   90    93       wxString filename=dialog->GetPath();
   91    -1       curve.sample->process();
   92    -1       curve.sample->writeFile(filename.mb_str());
   -1    94       sample->process();
   -1    95       sample->writeFile(filename.mb_str());
   93    96     }
   94    97 }
   95    98 
   96    99 // ************  playback  **************
   97   100 void xiRTMainFrame::OnStartClick( wxCommandEvent& event ) {
   98    -1   curve.setSeeker(0);
   -1   101   playback->setSeeker(0);
   99   102 }
  100   103 
  101   104 void xiRTMainFrame::OnPlayClick( wxCommandEvent& event ) {
  102    -1 std::cout << "play ";
  103    -1   int err;
  104    -1   err=playback->play();
  105    -1 std::cout << err << std::endl;
   -1   105   playback->play();
  106   106 }
  107   107 
  108   108 void xiRTMainFrame::OnEndClick( wxCommandEvent& event ) {
  109    -1   curve.setSeeker(1);
   -1   109   playback->setSeeker(1);
  110   110 }
  111   111 
  112   112 // ************  general  **************
@@ -130,7 +130,7 @@ void xiRTMainFrame::OnHelpClick( wxCommandEvent& event )
  130   130 
  131   131 // ************  marker  **************
  132   132 void xiRTMainFrame::OnClearClick( wxCommandEvent& event ) {
  133    -1   curve.clearMarker();
   -1   133   curve->clearMarker();
  134   134 }
  135   135 
  136   136 
@@ -141,7 +141,7 @@ void xiRTMainFrame::OnProcessClick( wxCommandEvent& event ) {
  141   141     wxProgressDialog::wxProgressDialog* dialog = new wxProgressDialog( _T("processing..."), _T("please wait") );
  142   142     dialog ->Show();
  143   143 */
  144    -1     curve.sample->process();
   -1   144     sample->process();
  145   145 }
  146   146 
  147   147 void xiRTMainFrame::OnUpdateUI( wxUpdateUIEvent& event ) {paint();}
@@ -165,11 +165,11 @@ void xiRTMainFrame::paint() {
  165   165   dc.Clear();
  166   166   // TODO nicer looking shape
  167   167   for (int i=0; i<width-1; ++i) {
  168    -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);
   -1   168     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);
  169   169   }
  170   170   dc.SetPen(penMarker);
  171    -1   for (int i=0; i<curve.getMarkerLength(); ++i) {
  172    -1     int n=int(curve.getMarker(i)*(width-1));
   -1   171   for (int i=0; i<curve->getMarkerLength(); ++i) {
   -1   172     int n=int(curve->getMarker(i)*(width-1));
  173   173     dc.DrawLine(n,0,n,height);
  174   174     wxPoint ps[3];
  175   175     wxPoint p0(n-MARKERWIDTH/2,0);
@@ -182,11 +182,12 @@ void xiRTMainFrame::paint() {
  182   182   }
  183   183   // seeker
  184   184   dc.SetPen(penSeeker);
  185    -1   int seek=int(playback->getSeeker()*(width-1));
   -1   185   playback->setSeeker(curve->getSeeker()); // TODO mainloop stuff
   -1   186   int seek=int(curve->getSeeker()*(width-1));
  186   187   dc.DrawLine(seek,0,seek,height);
  187   188   //beats
  188   189   dc.SetPen(penMarker);
  189    -1   int step=int(width/curve.getBars()/curve.getBeatResolution());
   -1   190   int step=int(width/curve->getBars()/curve->getBeatResolution());
  190   191   for (int i=0; i<width && step!=0; i+=step) {
  191   192     dc.DrawLine(i,0,i,BEAT);  
  192   193   }

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

@@ -7,9 +7,10 @@ Subclass of MainFrame, which is generated by wxFormBuilder.
    7     7 */
    8     8 
    9     9 #include "xiRetimer_wxfb.h"
   -1    10 #include "../marker.h"
   10    11 #include "../sample.h"
   11    -1 #include "../curve.h"
   12    12 #include "../playback.h"
   -1    13 #include "../curve.h"
   13    14 
   14    15 
   15    16 /** Implementing MainFrame */
@@ -42,12 +43,15 @@ protected:
   42    43   static const int MARKERWIDTH=15;
   43    44   static const int BEAT=15;
   44    45   
   45    -1   Curve curve;
   46    -1   Playback* playback;
   47    46   int width;
   48    47   int height;
   49    48   bool Marker_move;
   50    49   bool Seeker_move;
   -1    50 
   -1    51 Marker* marker;
   -1    52 Sample* sample;
   -1    53 Playback* playback;
   -1    54 Curve* curve;
   51    55 	
   52    56 public:
   53    57 	/** Constructor */

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

@@ -1,3 +1,6 @@
   -1     1 #ifndef __XIPLAYBACK_H
   -1     2 #define __XIPLAYBACK_H
   -1     3 
    1     4 #include <iostream>
    2     5 
    3     6 #include "SDL.h"
@@ -17,4 +20,4 @@ private:
   17    20   void stop();
   18    21 };
   19    22 
   20    -1 
   -1    23 #endif

diff --git a/xiRetimer b/xiRetimer

Binary files differ.