2 Copyright (C) 2006 Paul Davis
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2 of the License, or (at your option)
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef __ardour_data_type_h__
20 #define __ardour_data_type_h__
24 #include <ardour/data_type.h>
25 #include <jack/jack.h>
30 /** A type of Data Ardour is capable of processing.
32 * The majority of this class is dedicated to conversion to and from various
33 * other type representations, simple comparison between then, etc. This code
34 * is deliberately 'ugly' so other code doesn't have to be.
39 /// WARNING: make REALLY sure you don't mess up indexes if you change this
46 /** Number of types (not including NIL).
47 * WARNING: make sure this matches Symbol!
49 static const size_t num_types = 2;
52 /** Helper for collections that store typed things by index (BufferSet, PortList).
53 * Guaranteed to be a valid index from 0 to (the number of available types - 1),
54 * because NIL is not included. No, this isn't pretty - purely for speed.
55 * See DataType::to_index().
57 inline static size_t symbol_index(const Symbol symbol)
58 { return (size_t)symbol - 1; }
60 DataType(const Symbol& symbol)
64 /** Construct from a string (Used for loading from XML and Ports)
65 * The string can be as in an XML file (eg "audio" or "midi"), or a
66 * Jack type string (from jack_port_type) */
67 DataType(const std::string& str) {
70 else if (str == JACK_DEFAULT_AUDIO_TYPE)
72 else if (str == "midi")
74 else if (str == JACK_DEFAULT_MIDI_TYPE)
80 /** Get the Jack type this DataType corresponds to */
81 const char* to_jack_type() const {
83 case AUDIO: return JACK_DEFAULT_AUDIO_TYPE;
84 case MIDI: return JACK_DEFAULT_MIDI_TYPE;
89 /** Inverse of the from-string constructor */
90 const char* to_string() const {
92 case AUDIO: return "audio";
93 case MIDI: return "midi";
94 default: return "unknown"; // reeeally shouldn't ever happen
98 Symbol to_symbol() const { return _symbol; }
99 inline size_t to_index() const { assert(_symbol != NIL); return symbol_index(_symbol); }
101 /** DataType iterator, for writing generic loops that iterate over all
107 iterator(size_t index) : _index(index) {}
109 DataType operator*() { return DataType((Symbol)_index); }
110 iterator& operator++() { ++_index; return *this; } // yes, prefix only
111 bool operator==(const iterator& other) { return (_index == other._index); }
112 bool operator!=(const iterator& other) { return (_index != other._index); }
115 friend class DataType;
120 static iterator begin() { return iterator(1); }
121 static iterator end() { return iterator(num_types+1); }
123 bool operator==(const Symbol symbol) { return (_symbol == symbol); }
124 bool operator!=(const Symbol symbol) { return (_symbol != symbol); }
126 bool operator==(const DataType other) { return (_symbol == other._symbol); }
127 bool operator!=(const DataType other) { return (_symbol != other._symbol); }
135 } // namespace ARDOUR
137 #endif // __ardour_data_type_h__