00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef RAUL_SMF_WRITER_HPP
00019 #define RAUL_SMF_WRITER_HPP
00020
00021 #include <stdexcept>
00022 #include <raul/MIDISink.hpp>
00023
00024 namespace Raul {
00025
00026
00029 class SMFWriter : public Raul::MIDISink {
00030 public:
00031 SMFWriter(unsigned short ppqn=1920);
00032 ~SMFWriter();
00033
00034 bool start(const std::string& filename,
00035 BeatTime start_time=0) throw (std::logic_error);
00036
00037 uint16_t ppqn() const { return _ppqn; }
00038
00039 void write_event(BeatTime time,
00040 size_t ev_size,
00041 const unsigned char* ev) throw (std::logic_error);
00042
00043 void flush();
00044
00045 void finish() throw (std::logic_error);
00046
00047 protected:
00048 static const uint32_t VAR_LEN_MAX = 0x0FFFFFFF;
00049
00050 void write_header();
00051 void write_footer();
00052
00053 void write_chunk_header(const char id[4], uint32_t length);
00054 void write_chunk(const char id[4], uint32_t length, void* data);
00055 size_t write_var_len(uint32_t val);
00056
00057 std::string _filename;
00058 FILE* _fd;
00059 uint16_t _ppqn;
00060 Raul::BeatTime _start_time;
00061 Raul::BeatTime _last_ev_time;
00062 uint32_t _track_size;
00063 uint32_t _header_size;
00064 };
00065
00066
00067 }
00068
00069 #endif // RAUL_SMF_WRITER_HPP
00070