• Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

SMFWriter.hpp

00001 /* This file is part of Raul.
00002  * Copyright (C) 2007-2009 David 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 <string>
00023 
00024 #include "raul/MIDISink.hpp"
00025 #include "raul/TimeStamp.hpp"
00026 
00027 namespace Raul {
00028 
00029 
00033 class SMFWriter : public Raul::MIDISink {
00034 public:
00035     explicit SMFWriter(TimeUnit unit);
00036     ~SMFWriter();
00037 
00038     bool start(const std::string& filename,
00039                TimeStamp          start_time) throw (std::logic_error);
00040 
00041     TimeUnit unit() const { return _unit; }
00042 
00043     void write_event(TimeStamp            time,
00044                      size_t               ev_size,
00045                      const unsigned char* ev) throw (std::logic_error);
00046 
00047     void flush();
00048 
00049     void finish() throw (std::logic_error);
00050 
00051 protected:
00052     static const uint32_t VAR_LEN_MAX = 0x0FFFFFFF;
00053 
00054     void write_header();
00055     void write_footer();
00056 
00057     void     write_chunk_header(const char id[4], uint32_t length);
00058     void     write_chunk(const char id[4], uint32_t length, void* data);
00059     size_t   write_var_len(uint32_t val);
00060 
00061     std::string     _filename;
00062     FILE*           _fd;
00063     TimeUnit        _unit;
00064     Raul::TimeStamp _start_time;
00065     Raul::TimeStamp _last_ev_time; 
00066     uint32_t        _track_size;
00067     uint32_t        _header_size; 
00068 };
00069 
00070 
00071 } // namespace Raul
00072 
00073 #endif // RAUL_SMF_WRITER_HPP
00074 

Generated on Tue Jan 11 2011 18:26:17 for RAUL by  doxygen 1.7.1