summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour/data_type.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-08-11 03:24:57 +0000
committerDavid Robillard <d@drobilla.net>2006-08-11 03:24:57 +0000
commit30c08ba655330232767554c48bda1975bfb5628c (patch)
treec6bf6b62de69afdd6b2a42ef3a7d9f80e0f65f7c /libs/ardour/ardour/data_type.h
parentab6f1ed9bafa869648b6e94ee5186ff317b32c3e (diff)
- Changed IO's vector<Port*>'s to PortList
- Added new Port classes, code to drive them - Added PortList, which is a filthy mess ATM (nevermind that, it's the interface that's important at this stage) - Added ChanCount, though it isn't very thoroughly used yet. That's the next step.... - Fixed a few bugs relating to loading sessions saved with trunk - Fixed a few random other bugs Slowly working towards type agnosticism while keeping all the former code/logic intact is the name of the game here Warning: Removing ports is currently (intentionally) broken due solely to laziness. git-svn-id: svn://localhost/ardour2/branches/midi@786 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/ardour/data_type.h')
-rw-r--r--libs/ardour/ardour/data_type.h80
1 files changed, 69 insertions, 11 deletions
diff --git a/libs/ardour/ardour/data_type.h b/libs/ardour/ardour/data_type.h
index d49ed108cd..cbb88afccf 100644
--- a/libs/ardour/ardour/data_type.h
+++ b/libs/ardour/ardour/data_type.h
@@ -19,54 +19,112 @@
#ifndef __ardour_data_type_h__
#define __ardour_data_type_h__
+#include <string>
+#include <ardour/data_type.h>
#include <jack/jack.h>
namespace ARDOUR {
+
+/** A type of Data Ardour is capable of processing.
+ *
+ * The majority of this class is dedicated to conversion to and from various
+ * other type representations, simple comparison between then, etc. This code
+ * is deliberately 'ugly' so other code doesn't have to be.
+ */
class DataType
{
public:
+ /// WARNING: make REALLY sure you don't mess up indexes if you change this
enum Symbol {
NIL = 0,
AUDIO,
MIDI
};
+
+ /** Number of types (not including NIL).
+ * WARNING: make sure this matches Symbol!
+ */
+ static const size_t num_types = 2;
+
+
+ /** Helper for collections that store typed things by index (BufferSet, PortList).
+ * Guaranteed to be a valid index from 0 to (the number of available types - 1),
+ * because NIL is not included. No, this isn't pretty - purely for speed.
+ * See DataType::to_index().
+ */
+ inline static size_t symbol_index(const Symbol symbol)
+ { return (size_t)symbol - 1; }
DataType(const Symbol& symbol)
: _symbol(symbol)
{}
- /** Construct from a string (Used for loading from XML) */
- DataType(const string& str) {
+ /** Construct from a string (Used for loading from XML and Ports)
+ * The string can be as in an XML file (eg "audio" or "midi"), or a
+ * Jack type string (from jack_port_type) */
+ DataType(const std::string& str) {
if (str == "audio")
_symbol = AUDIO;
- //else if (str == "midi")
- // _symbol = MIDI;
+ else if (str == JACK_DEFAULT_AUDIO_TYPE)
+ _symbol = AUDIO;
+ else if (str == "midi")
+ _symbol = MIDI;
+ else if (str == JACK_DEFAULT_MIDI_TYPE)
+ _symbol = MIDI;
else
_symbol = NIL;
}
- bool operator==(const Symbol symbol) { return _symbol == symbol; }
- bool operator!=(const Symbol symbol) { return _symbol != symbol; }
-
/** Get the Jack type this DataType corresponds to */
- const char* to_jack_type() {
+ const char* to_jack_type() const {
switch (_symbol) {
case AUDIO: return JACK_DEFAULT_AUDIO_TYPE;
- //case MIDI: return JACK_DEFAULT_MIDI_TYPE;
+ case MIDI: return JACK_DEFAULT_MIDI_TYPE;
default: return "";
}
}
/** Inverse of the from-string constructor */
- const char* to_string() {
+ const char* to_string() const {
switch (_symbol) {
case AUDIO: return "audio";
- //case MIDI: return "midi";
+ case MIDI: return "midi";
default: return "unknown"; // reeeally shouldn't ever happen
}
}
+ Symbol to_symbol() const { return _symbol; }
+ inline size_t to_index() const { return symbol_index(_symbol); }
+
+ /** DataType iterator, for writing generic loops that iterate over all
+ * available types.
+ */
+ class iterator {
+ public:
+
+ iterator(size_t index) : _index(index) {}
+
+ DataType operator*() { return DataType((Symbol)_index); }
+ iterator& operator++() { ++_index; return *this; } // yes, prefix only
+ bool operator==(const iterator& other) { return (_index == other._index); }
+ bool operator!=(const iterator& other) { return (_index != other._index); }
+
+ private:
+ friend class DataType;
+
+ size_t _index;
+ };
+
+ static iterator begin() { return iterator(1); }
+ static iterator end() { return iterator(num_types+1); }
+
+ bool operator==(const Symbol symbol) { return (_symbol == symbol); }
+ bool operator!=(const Symbol symbol) { return (_symbol != symbol); }
+
+ bool operator==(const DataType other) { return (_symbol == other._symbol); }
+ bool operator!=(const DataType other) { return (_symbol != other._symbol); }
+
private:
Symbol _symbol;
};