libGDF
EventHeader.h
00001 //
00002 // This file is part of libGDF.
00003 //
00004 // libGDF is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU Lesser General Public License as
00006 // published by the Free Software Foundation, either version 3 of
00007 // the License, or (at your option) any later version.
00008 //
00009 // libGDF is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with libGDF.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // Copyright 2010 Martin Billinger, Christoph Eibel
00018 
00019 #ifndef __EVENTHEADER_H_INCLUDED__
00020 #define __EVENTHEADER_H_INCLUDED__
00021 
00022 #include "GDF/Types.h"
00023 #include <vector>
00024 
00025 #define GDF_MAXNUM_EVENTS 16777215
00026 
00027 namespace gdf
00028 {
00029     struct Mode1Event
00030     {
00031         bool operator<( const Mode1Event &e ) const { return position < e.position; }
00032         uint32 position;
00033         uint16 type;
00034     };
00035 
00036     struct Mode3Event
00037     {
00038         bool operator<( const Mode3Event &e ) const { return position < e.position; }
00039         uint32 position;
00040         uint16 type;
00041         uint16 channel;
00042         union {
00043             uint32 duration;
00044             float32 value;
00045         };
00046     };
00047 
00049     class EventHeader
00050     {
00051     public:
00052 
00054         EventHeader( );
00055 
00057         virtual ~EventHeader( );
00058 
00060         void toStream( std::ostream &stream );
00061 
00063         void fromStream( std::istream &stream );
00064 
00066 
00070         void setMode( uint8 mode );
00071 
00073 
00075         void setSamplingRate( float32 fs );
00076 
00078         uint8 getMode( ) { return m_mode; }
00079 
00081         float32 getSamplingRate( ) { return m_efs; }
00082 
00084         uint32 getNumEvents( );
00085 
00087         void getEvent( uint32 index, Mode1Event &ev );
00088 
00090         std::vector<Mode1Event> getMode1Events () const;
00091 
00093         std::vector<Mode3Event> getMode3Events () const;
00094 
00096         void getEvent( uint32 index, Mode3Event &ev );
00097 
00099         void addEvent( const Mode1Event &ev );
00100 
00102         void addEvent( const Mode3Event &ev );
00103 
00105         void sort( );
00106 
00108         void clear( );
00109 
00110     private:
00111         uint8 m_mode;
00112         //uint32 m_num_ev;  /// only 3 bytes are used. Maximum is 16777215
00113         float32 m_efs;    
00114 
00115         std::vector<Mode1Event> m_mode1;
00116         std::vector<Mode3Event> m_mode3;
00117     };
00118 }
00119 
00120 #endif // EVENTHEADER_H
 All Data Structures Functions Variables Friends