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;
51 DataType(const Symbol& symbol)
55 /** Construct from a string (Used for loading from XML and Ports)
56 * The string can be as in an XML file (eg "audio" or "midi"), or a
57 * Jack type string (from jack_port_type) */
58 DataType(const std::string& str) {
61 else if (str == JACK_DEFAULT_AUDIO_TYPE)
63 else if (str == "midi")
65 else if (str == JACK_DEFAULT_MIDI_TYPE)
71 /** Get the Jack type this DataType corresponds to */
72 const char* to_jack_type() const {
74 case AUDIO: return JACK_DEFAULT_AUDIO_TYPE;
75 case MIDI: return JACK_DEFAULT_MIDI_TYPE;
80 /** Inverse of the from-string constructor */
81 const char* to_string() const {
83 case AUDIO: return "audio";
84 case MIDI: return "midi";
85 default: return "unknown"; // reeeally shouldn't ever happen
89 //Symbol to_symbol() const { return _symbol; }
90 inline size_t to_index() const { return (size_t)_symbol - 1; }
92 /** DataType iterator, for writing generic loops that iterate over all
98 iterator(size_t index) : _index(index) {}
100 DataType operator*() { return DataType((Symbol)_index); }
101 iterator& operator++() { ++_index; return *this; } // yes, prefix only
102 bool operator==(const iterator& other) { return (_index == other._index); }
103 bool operator!=(const iterator& other) { return (_index != other._index); }
106 friend class DataType;
111 static iterator begin() { return iterator(1); }
112 static iterator end() { return iterator(num_types+1); }
114 bool operator==(const Symbol symbol) { return (_symbol == symbol); }
115 bool operator!=(const Symbol symbol) { return (_symbol != symbol); }
117 bool operator==(const DataType other) { return (_symbol == other._symbol); }
118 bool operator!=(const DataType other) { return (_symbol != other._symbol); }
126 } // namespace ARDOUR
128 #endif // __ardour_data_type_h__