/builddir/build/BUILD/raul-0.4.0/raul/SMFWriter.hpp

00001 /* This file is part of Raul.
00002  * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
00003  * 
00004  * Raul is free software; you can redistribute it and/or modify it under the
00005  * terms of the GNU General Public License as published by the Free Software
00006  * Foundation; either version 2 of the License, or (at your option) any later
00007  * version.
00008  * 
00009  * Raul is distributed in the hope that it will be useful, but WITHOUT ANY
00010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
00012  * 
00013  * You should have received a copy of the GNU General Public License along
00014  * with this program; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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 } // namespace Raul
00068 
00069 #endif // RAUL_SMF_WRITER_HPP
00070 

Generated on Wed Apr 9 08:14:41 2008 for RAUL by  doxygen 1.5.1