Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/tonal/Segmentation.hxx

Go to the documentation of this file.
00001 #ifndef Segmentation_hxx
00002 #define Segmentation_hxx
00003 
00004 #include <vector>
00005 #include <algorithm>
00006 #include <iterator>
00007 #include <cmath>
00008 #include <sstream>
00009 #include "../defs.h"
00010 //#include "Array.hxx"
00011 //#include "XMLAdapter.hxx"
00012 
00013 namespace CLAM
00014 {
00015         typedef float TData;
00016 
00017         class Segmentation
00018         {
00019         public:
00020                 class InsertedOutOfBounds : public std::exception
00021                 {
00022                         public:
00023                         const char * what() const throw () { return "Segmentation point inserted out of limits";}
00024                 };
00025                 typedef std::vector<double> TimePositions;
00026         public:
00027                 Segmentation()
00028                         : _current(0)
00029                         , _maxPosition(0)
00030                 {
00031                 }
00032                 Segmentation(double maxPosition)
00033                         : _current(0)
00034                         , _maxPosition(maxPosition)
00035                 {
00036                 }
00037                 virtual ~Segmentation();
00041                 virtual unsigned insert(double timePosition)=0;
00048                 virtual void remove(unsigned segment)=0;
00055                 virtual unsigned pickOffset(double timePosition, double tolerance) const=0;
00062                 virtual unsigned pickOnset(double timePosition, double tolerance) const=0;
00066                 virtual unsigned pickSegmentBody(double timePosition) const=0;
00072                 virtual void dragOnset(unsigned segment, double newTimePosition)=0;
00078                 virtual void dragOffset(unsigned segment, double newTimePosition)=0;
00079 
00080                 //virtual void fillArray(DataArray& segmentation) const =0;
00084                 virtual void takeArray(const TData * begin, const TData * end) =0;
00085 
00086                 const char * GetClassName() const { return "Segmentation"; }
00087 
00088                 /*void StoreOn(Storage & storage) const
00089                 {
00090                         XMLAdapter<double> adapter(_maxPosition, "max", false);
00091                         storage.Store(adapter);
00092                         CLAM::DataArray array;
00093                         fillArray(array);
00094                         array.StoreOn(storage);
00095                 }*/
00096 
00097                 /*void LoadFrom(Storage & storage) 
00098                 {
00099                         double newmaxPosition;
00100                         XMLAdapter<double> adapter(newmaxPosition, "max", false);
00101                         if(storage.Load(adapter))
00102                         {
00103                                 maxPosition(newmaxPosition);
00104                         }
00105                         else    {
00106                                 //when the maxPos is not present, set it to a large number
00107                                 maxPosition(100000);
00108                         }
00109                         DataArray array;
00110                         array.LoadFrom(storage);
00111                         const unsigned size = array.Size();
00112                         const TData* ptr=array.GetPtr(); 
00113                         takeArray(ptr, ptr+size);
00114                         
00115                 }*/
00116 
00117                 void select(unsigned segment)
00118                 {
00119                         _selection[segment]=true;
00120                 }
00121                 void deselect(unsigned segment)
00122                 {
00123                         _selection[segment]=false;
00124                 }
00125                 void clearSelection()
00126                 {
00127                         for (unsigned i=0; i<_selection.size(); i++)
00128                                 _selection[i]=false;
00129                 }
00130 
00134                 std::string boundsAsString() const
00135                 {
00136                         std::ostringstream os;
00137                         for (unsigned i=0; i<_offsets.size(); i++)
00138                         {
00139                                 if (_selection[i]) os << "+";
00140                                 os << "(" << _onsets[i] << "," << _offsets[i] << ") ";
00141                         }
00142                         return os.str();
00143                 }
00144 
00148                 const TimePositions & onsets() const
00149                 {
00150                         return _onsets;
00151                 }
00155                 const TimePositions & offsets() const
00156                 {
00157                         return _offsets;
00158                 }
00162                 const std::vector<std::string> & labels() const
00163                 {
00164                         return _labels;
00165                 }
00169                 void setLabel(unsigned segment, std::string label)
00170                 {
00171                         if (segment>=_labels.size()) return; // Invalid segment
00172                         _labels[segment] = label;
00173                 }
00177                 const std::vector<bool> & selections() const
00178                 {
00179                         return _selection;
00180                 }
00184                 unsigned current() const
00185                 {
00186                         return _current;
00187                 }
00191                 void current(unsigned index)
00192                 {
00193                         if (index>=_onsets.size()) return;
00194                         _current = index;
00195                 }
00196                 double maxPosition() const
00197                 {
00198                         return _maxPosition;
00199                 }
00200                 virtual void maxPosition(double maxPosition)
00201                 {
00202                         _maxPosition = maxPosition;
00203                 }
00204                 void xUnits(const std::string & units)
00205                 {
00206                         _xUnits=units;
00207                 }
00208                 const std::string & xUnits() const
00209                 {
00210                         return _xUnits;
00211                 }
00212         protected:
00213                 TimePositions _onsets;
00214                 TimePositions _offsets;
00215                 std::vector<std::string> _labels;
00216                 std::vector<bool> _selection;
00217                 unsigned _current;
00218                 double _maxPosition;
00219                 std::string _xUnits;
00220         };
00221 
00222 }
00223 
00224 
00225 
00226 #endif//Segmentation_hxx
00227 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines