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