00001 #ifndef INCLUDE_PARTIAL_H
00002 #define INCLUDE_PARTIAL_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "Breakpoint.h"
00040 #include "Exception.h"
00041
00042 #include <map>
00043
00044
00045
00046
00047 namespace Loris {
00048
00049 class Partial_Iterator;
00050 class Partial_ConstIterator;
00051
00052
00053
00054
00092
00093 class Partial
00094 {
00095
00096 public:
00097
00098
00099
00102 typedef std::map< double, Breakpoint > container_type;
00103
00104
00105
00106
00107
00109 typedef int label_type;
00110
00112 typedef Partial_Iterator iterator;
00113
00115 typedef Partial_ConstIterator const_iterator;
00116
00118 typedef container_type::size_type size_type;
00119
00120
00121
00123 Partial( void );
00124
00132 Partial( const_iterator beg, const_iterator end );
00133
00139 Partial( const Partial & other );
00140
00142 ~Partial( void );
00143
00144
00145
00151 Partial & operator=( const Partial & other );
00152
00153
00154
00158 iterator begin( void );
00159
00163 const_iterator begin( void ) const;
00164
00169 iterator end( void );
00170
00175 const_iterator end( void ) const;
00176
00186 iterator erase( iterator beg, iterator end );
00187
00196 iterator findAfter( double time );
00197
00206 const_iterator findAfter( double time ) const;
00207
00217 iterator insert( double time, const Breakpoint & bp );
00218
00222 size_type size( void ) const;
00223
00224
00225
00230 double duration( void ) const;
00231
00236 double endTime( void ) const;
00237
00242 Breakpoint & first( void );
00243
00248 const Breakpoint & first( void ) const;
00249
00254 double initialPhase( void ) const;
00255
00257 label_type label( void ) const;
00258
00263 Breakpoint & last( void );
00264
00269 const Breakpoint & last( void ) const;
00270
00272 size_type numBreakpoints( void ) const;
00273
00278 double startTime( void ) const;
00279
00280
00281
00288 void absorb( const Partial & other );
00289
00291 void setLabel( label_type l );
00292
00303 iterator erase( iterator pos );
00304
00311 iterator findNearest( double time );
00312
00319 const_iterator findNearest( double time ) const;
00320
00333 Partial split( iterator pos );
00334
00335
00336
00344 static const double ShortestSafeFadeTime;
00345
00360 double amplitudeAt( double time, double fadeTime = ShortestSafeFadeTime ) const;
00361
00372 double bandwidthAt( double time ) const;
00373
00383 double frequencyAt( double time ) const;
00384
00395 double phaseAt( double time ) const;
00396
00414 Breakpoint parametersAt( double time, double fadeTime = ShortestSafeFadeTime ) const;
00415
00416
00417 private:
00418
00419 label_type _label;
00420 container_type _breakpoints;
00421
00422 };
00423
00424
00425
00426
00433
00434 class Partial_Iterator
00435 {
00436
00437 typedef Partial::container_type BaseContainer;
00438 typedef BaseContainer::iterator BaseIterator;
00439 BaseIterator _iter;
00440
00441
00442 public:
00443
00444 typedef BaseIterator::iterator_category iterator_category;
00445 typedef Breakpoint value_type;
00446 typedef BaseIterator::difference_type difference_type;
00447 typedef Breakpoint * pointer;
00448 typedef Breakpoint & reference;
00449
00450
00451
00454 Partial_Iterator( void ) {}
00455
00456
00457
00458
00459
00466 Partial_Iterator& operator ++ () { ++_iter; return *this; }
00467
00474 Partial_Iterator& operator -- () { --_iter; return *this; }
00475
00476
00477
00486 Partial_Iterator operator ++ ( int ) { return Partial_Iterator( _iter++ ); }
00487
00496 Partial_Iterator operator -- ( int ) { return Partial_Iterator( _iter-- ); }
00497
00498
00499
00500
00505 Breakpoint & operator * ( void ) const { return breakpoint(); }
00506
00507
00512
00513
00518 Breakpoint * operator -> ( void ) const { return & breakpoint(); }
00519
00524
00525
00526
00527
00534 friend bool operator == ( const Partial_Iterator & lhs,
00535 const Partial_Iterator & rhs )
00536 { return lhs._iter == rhs._iter; }
00537
00544 friend bool operator != ( const Partial_Iterator & lhs,
00545 const Partial_Iterator & rhs )
00546 { return lhs._iter != rhs._iter; }
00547
00548
00549
00554 Breakpoint & breakpoint( void ) const
00555 { return _iter->second; }
00556
00561
00562
00563
00568 double time( void ) const
00569 { return _iter->first; }
00570
00571
00572 private:
00573
00574 Partial_Iterator( const BaseIterator & it ) :
00575 _iter(it) {}
00576
00577 friend class Partial;
00578
00579
00580
00581 friend class Partial_ConstIterator;
00582
00583 };
00584
00585
00586
00587
00594
00595 class Partial_ConstIterator
00596 {
00597
00598 typedef Partial::container_type BaseContainer;
00599 typedef BaseContainer::const_iterator BaseIterator;
00600 BaseIterator _iter;
00601
00602
00603 public:
00604
00605 typedef BaseIterator::iterator_category iterator_category;
00606 typedef Breakpoint value_type;
00607 typedef BaseIterator::difference_type difference_type;
00608 typedef const Breakpoint * pointer;
00609 typedef const Breakpoint & reference;
00610
00611
00612
00615 Partial_ConstIterator( void ) {}
00616
00621 Partial_ConstIterator( const Partial_Iterator & other ) :
00622 _iter( other._iter ) {}
00623
00624
00625
00626
00627
00634 Partial_ConstIterator& operator ++ () { ++_iter; return *this; }
00635
00642 Partial_ConstIterator& operator -- () { --_iter; return *this; }
00643
00644
00645
00654 Partial_ConstIterator operator ++ ( int ) { return Partial_ConstIterator( _iter++ ); }
00655
00664 Partial_ConstIterator operator -- ( int ) { return Partial_ConstIterator( _iter-- ); }
00665
00666
00667
00668
00673 const Breakpoint & operator * ( void ) const { return breakpoint(); }
00674
00679 const Breakpoint * operator -> ( void ) const { return & breakpoint(); }
00680
00681
00682
00689 friend bool operator == ( const Partial_ConstIterator & lhs,
00690 const Partial_ConstIterator & rhs )
00691 { return lhs._iter == rhs._iter; }
00692
00699 friend bool operator != ( const Partial_ConstIterator & lhs,
00700 const Partial_ConstIterator & rhs )
00701 { return lhs._iter != rhs._iter; }
00702
00703
00704
00709 const Breakpoint & breakpoint( void ) const
00710 { return _iter->second; }
00711
00716 double time( void ) const
00717 { return _iter->first; }
00718
00719
00720 private:
00721
00722 Partial_ConstIterator( BaseIterator it ) :
00723 _iter(it) {}
00724
00725 friend class Partial;
00726
00727 };
00728
00729
00730
00731
00734
00735 class InvalidPartial : public InvalidObject
00736 {
00737 public:
00738
00748 InvalidPartial( const std::string & str, const std::string & where = "" ) :
00749 InvalidObject( std::string("Invalid Partial -- ").append( str ), where ) {}
00750
00751 };
00752
00753 }
00754
00755 #endif