Consistent use of abort() /* NOTREACHED */
[ardour.git] / libs / surfaces / mackie / midi_byte_array.h
1 /*
2  * Copyright (C) 2006-2007 John Anderson
3  * Copyright (C) 2008-2012 Paul Davis <paul@linuxaudiosystems.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 #ifndef midi_byte_array_h
20 #define midi_byte_array_h
21
22 #include <iostream>
23 #include <vector>
24
25 #include <boost/shared_array.hpp>
26
27 //#include <midi++/types.h>
28 namespace MIDI {
29         typedef unsigned char byte;
30 }
31
32 /**
33         To make building arrays of bytes easier. Thusly:
34
35         MidiByteArray mba;
36         mba << 0xf0 << 0x00 << 0xf7;
37
38         MidiByteArray buf;
39         buf << mba;
40
41         MidiByteArray direct( 3, 0xf0, 0x00, 0xf7 );
42
43         cout << mba << endl;
44         cout << buf << endl;
45         cout << direct << endl;
46
47         will all result in "f0 00 f7" being output to stdout
48 */
49 class MidiByteArray : public std::vector<MIDI::byte>
50 {
51 public:
52         MidiByteArray() : std::vector<MIDI::byte>() {}
53
54         MidiByteArray( size_t count, MIDI::byte array[] );
55
56         /**
57                 Accepts a preceding count, and then a list of bytes
58         */
59         MidiByteArray( size_t count, MIDI::byte first, ... );
60
61         /// copy the given number of bytes from the given array
62         void copy( size_t count, MIDI::byte arr[] );
63 };
64
65 /// append the given byte to the end of the array
66 MidiByteArray & operator << ( MidiByteArray & mba, const MIDI::byte & b );
67
68 /// append the given string to the end of the array
69 MidiByteArray & operator << ( MidiByteArray & mba, const std::string & );
70
71 /// append the given array to the end of this array
72 MidiByteArray & operator << ( MidiByteArray & mba, const MidiByteArray & barr );
73
74 /// output the bytes as hex to the given stream
75 std::ostream & operator << ( std::ostream & os, const MidiByteArray & mba );
76
77 #endif