Include stripped down libsmf code internally.
[ardour.git] / libs / evoral / evoral / SMF.hpp
index e0ac91b515e554be00eecf3310d43a4d0e32f223..313035f5e3a0f862f5c297ef7dc34efff6a3e677 100644 (file)
 #ifndef EVORAL_SMF_HPP
 #define EVORAL_SMF_HPP
 
-#include <string>
-#include <evoral/types.hpp>
+#include "evoral/StandardMIDIFile.hpp"
 
 namespace Evoral {
        
-class Event;
-class EventRingBuffer;
+template<typename Time> class Event;
+template<typename Time> class EventRingBuffer;
 
 
 /** Standard Midi File (Type 0)
  */
-class SMF {
+template<typename Time>
+class SMF : public StandardMIDIFile<Time> {
 public:
        SMF();
        virtual ~SMF();
 
        void seek_to_start() const;
        
-       uint16_t ppqn() const { return _ppqn; }
+       uint16_t ppqn()     const { return _ppqn; }
        bool     is_empty() const { return _empty; }
-       bool     eof() const { return feof(_fd); }
+       bool     eof()      const { return feof(_fd); }
        
-       EventTime last_event_time() const { return _last_ev_time; }
+       Time last_event_time() const { return _last_ev_time; }
        
-       void begin_write(nframes_t start_time);
-       void append_event_unlocked(uint32_t delta_t, const Evoral::Event& ev);
+       void begin_write(FrameTime start_time);
+       void append_event_unlocked(uint32_t delta_t, const Event<Time>& ev);
        void end_write();
        
        void flush();
@@ -55,6 +55,9 @@ protected:
        int  open(const std::string& path);
        void close();
        
+       int read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf) const;
+
+private:
        /** Used by flush_footer() to find the position to write the footer */
        void seek_to_footer_position();
        
@@ -65,16 +68,14 @@ protected:
        void     write_chunk(const char id[4], uint32_t length, void* data);
        size_t   write_var_len(uint32_t val);
        uint32_t read_var_len() const;
-       int      read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf) const;
 
-private:
        static const uint16_t _ppqn = 19200;
 
-       FILE*          _fd;
-       EventTime      _last_ev_time; ///< last frame time written, relative to source start
-       uint32_t       _track_size;
-       uint32_t       _header_size; ///< size of SMF header, including MTrk chunk header
-       bool           _empty; ///< true iff file contains(non-empty) events
+       FILE*    _fd;
+       Time     _last_ev_time; ///< last frame time written, relative to source start
+       uint32_t _track_size;
+       uint32_t _header_size; ///< size of SMF header, including MTrk chunk header
+       bool     _empty; ///< true iff file contains(non-empty) events
 };
 
 }; /* namespace Evoral */