00001
00002
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
00040
00041
00042 #include "Marker.h"
00043 #include "Partial.h"
00044
00045 #if defined(NO_TEMPLATE_MEMBERS)
00046 #include "PartialList.h"
00047 #endif
00048
00049 #include <string>
00050 #include <vector>
00051
00052
00053 namespace Loris {
00054
00055
00056
00057
00063
00064 class SpcFile
00065 {
00066
00067 public:
00068
00069
00070
00073 typedef std::vector< Marker > markers_type;
00074
00077 typedef std::vector< Partial > partials_type;
00078
00079
00080
00085 explicit SpcFile( const std::string & filename );
00086
00099 #if !defined(NO_TEMPLATE_MEMBERS)
00100 template<typename Iter>
00101 SpcFile( Iter begin_partials, Iter end_partials, double midiNoteNum = 60 );
00102 #else
00103 SpcFile( PartialList::const_iterator begin_partials,
00104 PartialList::const_iterator end_partials,
00105 double midiNoteNum = 60 );
00106 #endif
00107
00113 explicit SpcFile( double midiNoteNum = 60 );
00114
00115
00116
00117
00118
00120 markers_type & markers( void );
00121
00123 const markers_type & markers( void ) const;
00124
00127 double midiNoteNumber( void ) const;
00128
00131 const partials_type & partials( void ) const;
00132
00136 double sampleRate( void ) const;
00137
00138
00139
00152 void addPartial( const Loris::Partial & p );
00153
00168 void addPartial( const Loris::Partial & p, int label );
00169
00188 #if !defined(NO_TEMPLATE_MEMBERS)
00189 template<typename Iter>
00190 void addPartials( Iter begin_partials, Iter end_partials );
00191 #else
00192 void addPartials( PartialList::const_iterator begin_partials,
00193 PartialList::const_iterator end_partials );
00194 #endif
00195
00199 void setMidiNoteNumber( double nn );
00200
00206 void setSampleRate( double rate );
00207
00208
00209
00226 void write( const std::string & filename, double endApproachTime = 0 );
00227
00244 void writeSinusoidal( const std::string & filename, double endApproachTime = 0 );
00245
00268 void write( const std::string & filename, bool enhanced,
00269 double endApproachTime = 0 );
00270
00271 private:
00272
00273 partials_type partials_;
00274 markers_type markers_;
00275
00276 double notenum_;
00277 double rate_;
00278
00279
00280 static const int MinNumPartials;
00281
00282
00283
00284
00285 static const double DefaultRate;
00286
00287
00288 void readSpcData( const std::string & filename );
00289 void growPartials( partials_type::size_type sz );
00290
00291 };
00292
00293
00294
00295
00296
00309 #if !defined(NO_TEMPLATE_MEMBERS)
00310 template< typename Iter >
00311 SpcFile::SpcFile( Iter begin_partials, Iter end_partials, double midiNoteNum ) :
00312 #else
00313 SpcFile::SpcFile( PartialList::const_iterator begin_partials,
00314 PartialList::const_iterator end_partials,
00315 double midiNoteNum ) :
00316 #endif
00317
00318 notenum_( midiNoteNum ),
00319 rate_( DefaultRate )
00320 {
00321 growPartials( MinNumPartials );
00322 addPartials( begin_partials, end_partials );
00323 }
00324
00325
00326
00327
00346 #if !defined(NO_TEMPLATE_MEMBERS)
00347 template<typename Iter>
00348 void SpcFile::addPartials( Iter begin_partials, Iter end_partials )
00349 #else
00350 void SpcFile::addPartials( PartialList::const_iterator begin_partials,
00351 PartialList::const_iterator end_partials )
00352 #endif
00353 {
00354 while ( begin_partials != end_partials )
00355 {
00356
00357
00358 if ( 0 != begin_partials->label() && 257 > begin_partials->label() )
00359 {
00360 addPartial( *begin_partials );
00361 }
00362 ++begin_partials;
00363 }
00364 }
00365
00366 }
00367
00368