Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

Partial.h

00001 #ifndef INCLUDE_PARTIAL_H
00002 #define INCLUDE_PARTIAL_H
00003 /*
00004  * This is the Loris C++ Class Library, implementing analysis, 
00005  * manipulation, and synthesis of digitized sounds using the Reassigned 
00006  * Bandwidth-Enhanced Additive Sound Model.
00007  *
00008  * Loris is Copyright (c) 1999-2004 by Kelly Fitz and Lippold Haken
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY, without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  *
00025  * Partial.h
00026  *
00027  * Definition of class Loris::Partial, and definitions and implementations of
00028  * classes of const and non-const iterators over Partials, and the exception
00029  * class InvalidPartial, thrown by some Partial members when invoked on a 
00030  * degenerate Partial having no Breakpoints.
00031  *
00032  * Kelly Fitz, 16 Aug 1999
00033  * loris@cerlsoundgroup.org
00034  *
00035  * http://www.cerlsoundgroup.org/Loris/
00036  *
00037  */
00038 
00039 #include "Breakpoint.h"
00040 #include "Exception.h"
00041 
00042 #include <map>
00043 //#include <utility>
00044 //#include <vector>
00045 
00046 //  begin namespace
00047 namespace Loris {
00048 
00049 class Partial_Iterator;
00050 class Partial_ConstIterator;
00051 
00052 // ---------------------------------------------------------------------------
00053 //  class Partial
00054 //
00092 //
00093 class Partial
00094 {   
00095 //  -- public interface --
00096 public:
00097 
00098 //  -- types --
00099 
00102     typedef std::map< double, Breakpoint > container_type;
00103     
00104     //  typedef std::vector< std::pair< double, Breakpoint > > container_type;
00105     //  see Partial.C for a discussion of issues surrounding the 
00106     //  choice of std::map as a Breakpoint container.
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 //  -- construction --
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 //  -- assignment --
00145 
00151     Partial & operator=( const Partial & other );
00152 
00153 //  -- container-dependent implementation --
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 //  -- access --
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 //  -- mutation --
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 //  -- parameter interpolation/extrapolation --
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 //  -- implementation --
00417 private:
00418 
00419     label_type _label;
00420     container_type _breakpoints;    //  Breakpoint envelope
00421      
00422 };  //  end of class Partial
00423 
00424 // ---------------------------------------------------------------------------
00425 //  class Partial_Iterator
00426 //
00433 //
00434 class Partial_Iterator
00435 {
00436 //  -- instance variables --
00437     typedef Partial::container_type BaseContainer;
00438     typedef BaseContainer::iterator BaseIterator;
00439     BaseIterator _iter;
00440     
00441 //  -- public interface --
00442 public:
00443 //  -- bidirectional iterator interface --
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 //  construction:
00451     
00454     Partial_Iterator( void ) {}
00455     
00456     //  (allow compiler to generate copy, assignment, and destruction)
00457     
00458 //  pre-increment/decrement:
00459 
00466     Partial_Iterator& operator ++ () { ++_iter; return *this; }
00467 
00474     Partial_Iterator& operator -- () { --_iter; return *this; }
00475 
00476 //  post-increment/decrement:
00477 
00486     Partial_Iterator operator ++ ( int ) { return Partial_Iterator( _iter++ ); } 
00487 
00496     Partial_Iterator operator -- ( int ) { return Partial_Iterator( _iter-- ); } 
00497     
00498 //  dereference (for treating Partial like a 
00499 //  STL collection of Breakpoints):
00500 
00505     Breakpoint & operator * ( void ) const { return breakpoint(); }
00506 
00507 
00512     //Breakpoint & operator * ( void ) { return breakpoint(); }
00513     
00518     Breakpoint * operator -> ( void ) const  { return & breakpoint(); }
00519 
00524     //Breakpoint * operator -> ( void )  { return & breakpoint(); }
00525         
00526 //  comparison:
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 //  -- time and Breakpoint access --
00549 
00554     Breakpoint & breakpoint( void ) const 
00555         { return _iter->second; }
00556 
00561     //Breakpoint & breakpoint( void ) 
00562     //  { return _iter->second; }
00563 
00568     double time( void ) const  
00569         { return _iter->first; }
00570 
00571 //  -- BaseIterator conversions --
00572 private:
00573     //  construction by GenericBreakpointContainer from a BaseIterator:
00574     Partial_Iterator( const BaseIterator & it ) :
00575         _iter(it) {}
00576 
00577     friend class Partial;
00578     
00579     //  befriend  Partial_ConstIterator, 
00580     //  for const construction from non-const:
00581     friend class Partial_ConstIterator; 
00582     
00583 };  //  end of class Partial_Iterator
00584 
00585 // ---------------------------------------------------------------------------
00586 //  class Partial_ConstIterator
00587 //
00594 //
00595 class Partial_ConstIterator
00596 {
00597 //  -- instance variables --
00598     typedef Partial::container_type BaseContainer;
00599     typedef BaseContainer::const_iterator BaseIterator;
00600     BaseIterator _iter;
00601     
00602 //  -- public interface --
00603 public:
00604 //  -- bidirectional iterator interface --
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 //  construction:
00612 
00615     Partial_ConstIterator( void ) {}
00616     
00621     Partial_ConstIterator( const Partial_Iterator & other ) :
00622         _iter( other._iter ) {}
00623     
00624     //  (allow compiler to generate copy, assignment, and destruction):
00625 
00626 //  pre-increment/decrement:
00627 
00634     Partial_ConstIterator& operator ++ () { ++_iter; return *this; }
00635 
00642     Partial_ConstIterator& operator -- () { --_iter; return *this; }
00643 
00644 //  post-increment/decrement:
00645 
00654     Partial_ConstIterator operator ++ ( int ) { return Partial_ConstIterator( _iter++ ); } 
00655 
00664     Partial_ConstIterator operator -- ( int ) { return Partial_ConstIterator( _iter-- ); } 
00665     
00666 //  dereference (for treating Partial like a 
00667 //  STL collection of Breakpoints):
00668 
00673     const Breakpoint & operator * ( void ) const { return breakpoint(); }
00674 
00679     const Breakpoint * operator -> ( void ) const { return & breakpoint(); }
00680     
00681 //  comparison:
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 //  -- time and Breakpoint access --
00704 
00709     const Breakpoint & breakpoint( void ) const 
00710         { return _iter->second; }
00711 
00716     double time( void ) const  
00717         { return _iter->first; }
00718     
00719 //  -- BaseIterator conversions --
00720 private:
00721     //  construction by GenericBreakpointContainer from a BaseIterator:
00722     Partial_ConstIterator( BaseIterator it ) :
00723         _iter(it) {}
00724     
00725     friend class Partial;
00726 
00727 };  //  end of class Partial_ConstIterator
00728 
00729 // ---------------------------------------------------------------------------
00730 //  class InvalidPartial
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 };  //  end of class InvalidPartial
00752 
00753 }   //  end of namespace Loris
00754 
00755 #endif /* ndef INCLUDE_PARTIAL_H */

Generated on Thu Apr 14 22:01:55 2005 for Loris by doxygen 1.3.4