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__
23 #include <ardour/data_type.h>
24 #include <jack/jack.h>
29 /** A type of Data Ardour is capable of processing.
31 * The majority of this class is dedicated to conversion to and from various
32 * other type representations, simple comparison between then, etc. This code
33 * is deliberately 'ugly' so other code doesn't have to be.
38 /// WARNING: make REALLY sure you don't mess up indexes if you change this
45 /** Number of types (not including NIL).
46 * WARNING: make sure this matches Symbol!
48 static const size_t num_types = 2;
50 DataType(const Symbol& symbol)
54 /** Construct from a string (Used for loading from XML and Ports)
55 * The string can be as in an XML file (eg "audio" or "midi"), or a
56 * Jack type string (from jack_port_type) */
57 DataType(const std::string& str) {
60 else if (str == JACK_DEFAULT_AUDIO_TYPE)
62 else if (str == "midi")
64 else if (str == JACK_DEFAULT_MIDI_TYPE)
70 /** Get the Jack type this DataType corresponds to */
71 const char* to_jack_type() const {
73 case AUDIO: return JACK_DEFAULT_AUDIO_TYPE;
74 case MIDI: return JACK_DEFAULT_MIDI_TYPE;
79 /** Inverse of the from-string constructor */
80 const char* to_string() const {
82 case AUDIO: return "audio";
83 case MIDI: return "midi";
84 default: return "unknown"; // reeeally shouldn't ever happen
88 //Symbol to_symbol() const { return _symbol; }
89 inline size_t to_index() const { return (size_t)_symbol - 1; }
91 /** DataType iterator, for writing generic loops that iterate over all
97 iterator(size_t index) : _index(index) {}
99 DataType operator*() { return DataType((Symbol)_index); }
100 iterator& operator++() { ++_index; return *this; } // yes, prefix only
101 bool operator==(const iterator& other) { return (_index == other._index); }
102 bool operator!=(const iterator& other) { return (_index != other._index); }
105 friend class DataType;
110 static iterator begin() { return iterator(1); }
111 static iterator end() { return iterator(num_types+1); }
113 bool operator==(const Symbol symbol) { return (_symbol == symbol); }
114 bool operator!=(const Symbol symbol) { return (_symbol != symbol); }
116 bool operator==(const DataType other) { return (_symbol == other._symbol); }
117 bool operator!=(const DataType other) { return (_symbol != other._symbol); }
125 } // namespace ARDOUR
127 #endif // __ardour_data_type_h__