From c3821a78162fe6d89455ab5ed4e925bafec2a845 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sun, 29 May 2011 01:54:19 +0000 Subject: totally untested initial code for MidiPlaylistSource, to provide for compound MIDI regions. putting it into SVN because my system might crash overnight :) git-svn-id: svn://localhost/ardour2/branches/3.0@9626 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/midi_playlist_source.cc | 191 ++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 libs/ardour/midi_playlist_source.cc (limited to 'libs/ardour/midi_playlist_source.cc') diff --git a/libs/ardour/midi_playlist_source.cc b/libs/ardour/midi_playlist_source.cc new file mode 100644 index 0000000000..c39d5e2389 --- /dev/null +++ b/libs/ardour/midi_playlist_source.cc @@ -0,0 +1,191 @@ +/* + Copyright (C) 2011 Paul Davis + + This program 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. + + This program 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 more 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., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifdef WAF_BUILD +#include "libardour-config.h" +#endif + +#include +#include + +#include +#include + +#include "pbd/error.h" +#include "pbd/convert.h" +#include "pbd/enumwriter.h" + +#include "ardour/midi_playlist.h" +#include "ardour/midi_playlist_source.h" +#include "ardour/midi_region.h" +#include "ardour/debug.h" +#include "ardour/filename_extensions.h" +#include "ardour/session.h" +#include "ardour/session_directory.h" +#include "ardour/session_playlists.h" +#include "ardour/source_factory.h" + +#include "i18n.h" + +using namespace std; +using namespace ARDOUR; +using namespace PBD; + +MidiPlaylistSource::MidiPlaylistSource (Session& s, const ID& orig, const std::string& name, boost::shared_ptr p, + uint32_t chn, frameoffset_t begin, framecnt_t len, Source::Flag flags) + : Source (s, DataType::AUDIO, name) + , MidiSource (s, name, flags) + , PlaylistSource (s, orig, name, p, DataType::AUDIO, begin, len, flags) +{ + ensure_buffers_for_level (_level); +} + +MidiPlaylistSource::MidiPlaylistSource (Session& s, const XMLNode& node) + : Source (s, node) + , MidiSource (s, node) + , PlaylistSource (s, node) +{ + /* PlaylistSources are never writable, renameable, removable or destructive */ + _flags = Flag (_flags & ~(Writable|CanRename|Removable|RemovableIfEmpty|RemoveAtDestroy|Destructive)); + + /* ancestors have already called ::set_state() in their XML-based + constructors. + */ + + if (set_state (node, Stateful::loading_state_version, false)) { + throw failed_constructor (); + } +} + +MidiPlaylistSource::~MidiPlaylistSource () +{ +} + +XMLNode& +MidiPlaylistSource::get_state () +{ + XMLNode& node (MidiSource::get_state ()); + + /* merge PlaylistSource state */ + + PlaylistSource::add_state (node); + + return node; +} + + +int +MidiPlaylistSource::set_state (const XMLNode& node, int version) +{ + return set_state (node, version, true); +} + +int +MidiPlaylistSource::set_state (const XMLNode& node, int version, bool with_descendants) +{ + if (with_descendants) { + if (Source::set_state (node, version) || + MidiSource::set_state (node, version) || + PlaylistSource::set_state (node, version)) { + return -1; + } + } + + ensure_buffers_for_level (_level); + + return 0; +} + +framecnt_t +MidiPlaylistSource::length (framepos_t) const +{ + pair extent = _playlist->get_extent(); + return extent.second - extent.first; +} + +framepos_t +MidiPlaylistSource::read_unlocked (Evoral::EventSink& dst, + framepos_t position, + framepos_t start, framecnt_t cnt, + MidiStateTracker* tracker) const +{ + boost::shared_ptr mp = boost::dynamic_pointer_cast (_playlist); + + if (!mp) { + return 0; + } + + return mp->read (dst, start, cnt); +} + +framepos_t +MidiPlaylistSource::write_unlocked (MidiRingBuffer& dst, + framepos_t position, + framecnt_t cnt) +{ + fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::write_unlocked() called - should be impossible") << endmsg; + /*NOTREACHED*/ + return 0; +} + +void +MidiPlaylistSource::append_event_unlocked_beats(const Evoral::Event& /*ev*/) +{ + fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::append_event_unlocked_beats() called - should be impossible") << endmsg; + /*NOTREACHED*/ +} + +void +MidiPlaylistSource::append_event_unlocked_frames(const Evoral::Event& ev, framepos_t source_start) +{ + fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::append_event_unlocked_frames() called - should be impossible") << endmsg; + /*NOTREACHED*/ +} + +void +MidiPlaylistSource::load_model (bool, bool) +{ + fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::load_model() called - should be impossible") << endmsg; + /*NOTREACHED*/ +} + +void +MidiPlaylistSource::destroy_model () +{ + fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::destroy_model() called - should be impossible") << endmsg; + /*NOTREACHED*/ +} + +void +MidiPlaylistSource::flush_midi () +{ +} + + +bool +MidiPlaylistSource::empty () const +{ + return !_playlist || _playlist->empty(); +} + +void +MidiPlaylistSource::ensure_buffers_for_level (uint32_t level) +{ +} + + -- cgit v1.2.3