diff options
Diffstat (limited to 'libs/ardour')
-rw-r--r-- | libs/ardour/ardour/buffer.h | 32 | ||||
-rw-r--r-- | libs/ardour/route.cc | 10 | ||||
-rw-r--r-- | libs/ardour/session_state.cc | 17 |
3 files changed, 54 insertions, 5 deletions
diff --git a/libs/ardour/ardour/buffer.h b/libs/ardour/ardour/buffer.h index 5171f50697..f0ad3be67e 100644 --- a/libs/ardour/ardour/buffer.h +++ b/libs/ardour/ardour/buffer.h @@ -29,6 +29,10 @@ namespace ARDOUR { +/* Yes, this is a bit of a mess right now. I'll clean it up when everything + * using it works out.. */ + + /** A buffer of recordable/playable data. * * This is a datatype-agnostic base class for all buffers (there are no @@ -60,13 +64,17 @@ public: size_t size() const { return _size; } /** Type of this buffer. - * Based on this you can cast a Buffer* to the desired type. */ + * Based on this you can static cast a Buffer* to the desired type. */ virtual Type type() const { return _type; } /** Jack type (eg JACK_DEFAULT_AUDIO_TYPE) */ const char* jack_type() const { return type_to_jack_type(type()); } - /** Separate for creating ports (before a buffer exists to call jack_type on) */ + /** String type as saved in session XML files (eg "audio" or "midi") */ + const char* type_string() const { return type_to_string(type()); } + + /* The below static methods need to be separate from the above methods + * because the conversion is needed in places where there's no Buffer */ static const char* type_to_jack_type(Type t) { switch (t) { case AUDIO: return JACK_DEFAULT_AUDIO_TYPE; @@ -74,6 +82,24 @@ public: default: return ""; } } + + static const char* type_to_string(Type t) { + switch (t) { + case AUDIO: return "audio"; + case MIDI: return "midi"; + default: return "unknown"; // reeeally shouldn't ever happen + } + } + + /** Used for loading from XML (route default types etc) */ + static Type type_from_string(const string& str) { + if (str == "audio") + return AUDIO; + else if (str == "midi") + return MIDI; + else + return NIL; + } protected: Type _type; @@ -82,7 +108,7 @@ protected: }; -/* Since we only have two types, templates aren't worth it, yet.. */ +/* Inside every class with a type in it's name is a template waiting to get out... */ /** Buffer containing 32-bit floating point (audio) data. */ diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index 568bfddfc3..8ad402c66a 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -20,6 +20,7 @@ #include <cmath> #include <fstream> +#include <cassert> #include <sigc++/bind.h> #include <pbd/xml++.h> @@ -1346,6 +1347,10 @@ Route::state(bool full_state) snprintf (buf, sizeof (buf), "0x%x", _flags); node->add_property("flags", buf); } + + // FIXME: assumes there's only audio and MIDI types + node->add_property("default-type", Buffer::type_to_string(_default_type)); + node->add_property("active", _active?"yes":"no"); node->add_property("muted", _muted?"yes":"no"); node->add_property("soloed", _soloed?"yes":"no"); @@ -1541,6 +1546,11 @@ Route::set_state (const XMLNode& node) } else { _flags = Flag (0); } + + if ((prop = node.property ("default-type")) != 0) { + _default_type = Buffer::type_from_string(prop->value()); + assert(_default_type != Buffer::NIL); + } if ((prop = node.property ("phase-invert")) != 0) { set_phase_invert(prop->value()=="yes"?true:false, this); diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 9f21eb5c4e..a8cbd7bd78 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -74,6 +74,7 @@ #include <ardour/slave.h> #include <ardour/tempo.h> #include <ardour/audio_track.h> +#include <ardour/midi_track.h> #include <ardour/cycle_timer.h> #include <ardour/utils.h> #include <ardour/named_selection.h> @@ -1716,8 +1717,20 @@ Session::XMLRouteFactory (const XMLNode& node) return 0; } - if (node.property ("diskstream") != 0 || node.property ("diskstream-id") != 0) { - return new AudioTrack (*this, node); + bool has_diskstream = (node.property ("diskstream") != 0 || node.property ("diskstream-id") != 0); + + Buffer::Type type = Buffer::AUDIO; + const XMLProperty* prop = node.property("default-type"); + if (prop) + type = Buffer::type_from_string(prop->value()); + + assert(type != Buffer::NIL); + + if (has_diskstream) { + if (type == Buffer::AUDIO) + return new AudioTrack (*this, node); + else + return new MidiTrack (*this, node); } else { return new Route (*this, node); } |