From b2aae23b3443a75cf163c3ee7a1c1477394fbc80 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 3 Mar 2007 04:40:05 +0000 Subject: SMF writing work. git-svn-id: http://svn.drobilla.net/lad/raul@343 a436a847-0d15-0410-975c-d299462d15a1 --- raul/JackDriver.h | 5 ++-- raul/MIDISink.h | 41 ++++++++++++++++++++++++++++++++ raul/Makefile.am | 4 +++- raul/SMFWriter.h | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 raul/MIDISink.h create mode 100644 raul/SMFWriter.h (limited to 'raul') diff --git a/raul/JackDriver.h b/raul/JackDriver.h index 8ec2572..cc42c02 100644 --- a/raul/JackDriver.h +++ b/raul/JackDriver.h @@ -45,8 +45,9 @@ public: void activate(); void deactivate(); - bool is_attached() const { return (_client != NULL); } - bool is_realtime() const { return _client && jack_is_realtime(_client); } + bool is_activated() const { return _is_activated; } + bool is_attached() const { return (_client != NULL); } + bool is_realtime() const { return _client && jack_is_realtime(_client); } void start_transport() { jack_transport_start(_client); } void stop_transport() { jack_transport_stop(_client); } diff --git a/raul/MIDISink.h b/raul/MIDISink.h new file mode 100644 index 0000000..fe5f4e8 --- /dev/null +++ b/raul/MIDISink.h @@ -0,0 +1,41 @@ +/* This file is part of Raul. + * Copyright (C) 2007 Dave Robillard + * + * Raul is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Raul is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef RAUL_MIDISINK_H +#define RAUL_MIDISINK_H + +#include +#include +#include + +namespace Raul { + + +/** Pure virtual base for anything you can write MIDI to. + */ +class MIDISink : public Deletable { +public: + virtual void write_event(BeatTime time, + size_t ev_size, + const unsigned char* ev) throw (std::logic_error) = 0; +}; + + +} // namespace Raul + +#endif // RAUL_MIDISINK_H + diff --git a/raul/Makefile.am b/raul/Makefile.am index 70aa03a..b1d5f12 100644 --- a/raul/Makefile.am +++ b/raul/Makefile.am @@ -28,7 +28,9 @@ raulinclude_HEADERS = \ Thread.h \ WeakPtr.h \ TimeSlice.h \ - Quantizer.h + Quantizer.h \ + MIDISink.h \ + SMFWriter.h if WITH_LIBLO raulinclude_HEADERS += AtomLiblo.h diff --git a/raul/SMFWriter.h b/raul/SMFWriter.h new file mode 100644 index 0000000..b512cff --- /dev/null +++ b/raul/SMFWriter.h @@ -0,0 +1,70 @@ +/* This file is part of Raul. + * Copyright (C) 2007 Dave Robillard + * + * Raul is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Raul is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef RAUL_SMFWRITER_H +#define RAUL_SMFWRITER_H + +#include +#include + +namespace Raul { + + +/** Standard Midi File (Type 0) Writer + */ +class SMFWriter : public Raul::MIDISink { +public: + SMFWriter(unsigned short ppqn=1920); + ~SMFWriter(); + + bool start(const std::string& filename, + BeatTime start_time=0) throw (std::logic_error); + + void write_event(BeatTime time, + size_t ev_size, + const unsigned char* ev) throw (std::logic_error); + + void flush(); + + void finish() throw (std::logic_error); + +protected: + static const uint32_t VAR_LEN_MAX = 0x0FFFFFFF; + + void write_header(); + void write_footer(); + + void write_chunk_header(char id[4], uint32_t length); + void write_chunk(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(MidiEvent& ev) const; + + std::string _filename; + FILE* _fd; + uint16_t _ppqn; + Raul::BeatTime _start_time; + Raul::BeatTime _last_ev_time; ///< Time last event was written relative to _start_time + uint32_t _track_size; + uint32_t _header_size; ///< size of SMF header, including MTrk chunk header +}; + + +} // namespace Raul + +#endif // RAUL_SMFWRITER_H + -- cgit v1.2.1