summaryrefslogtreecommitdiff
path: root/libs/surfaces/mackie/midi_byte_array.cc
blob: ffb94a03a9cf04862ed847e7fe626db7f62a400c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
	Copyright (C) 2006,2007 John Anderson

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "midi_byte_array.h"

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstdarg>
#include <iomanip>
#include <stdexcept>

using namespace std;

MidiByteArray::MidiByteArray (size_t size, MIDI::byte array[])
  : std::vector<MIDI::byte>()
{
	for  (size_t i = 0; i < size; ++i)
	{
		push_back (array[i]);
	}
}

MidiByteArray::MidiByteArray (size_t count, MIDI::byte first, ...)
  : vector<MIDI::byte>()
{
	push_back (first);
	va_list var_args;
	va_start (var_args, first);
	for  (size_t i = 1; i < count; ++i)
	{
		MIDI::byte b = va_arg (var_args, int);
		push_back (b);
	}
	va_end (var_args);
}


void MidiByteArray::copy (size_t count, MIDI::byte * arr)
{
	for (size_t i = 0; i < count; ++i) {
		push_back (arr[i]);
	}
}

MidiByteArray & operator <<  (MidiByteArray & mba, const MIDI::byte & b)
{
	mba.push_back (b);
	return mba;
}

MidiByteArray & operator <<  (MidiByteArray & mba, const MidiByteArray & barr)
{
	back_insert_iterator<MidiByteArray> bit (mba);
	copy (barr.begin(), barr.end(), bit);
	return mba;
}

ostream & operator <<  (ostream & os, const MidiByteArray & mba)
{
	os << "[";
	char fill = os.fill('0');
	for (MidiByteArray::const_iterator it = mba.begin(); it != mba.end(); ++it) {
		if  (it != mba.begin()) os << " ";
		os << hex << setw(2) << (int)*it;
	}
	os.fill (fill);
	os << dec;
	os << "]";
	return os;
}

MidiByteArray & operator <<  (MidiByteArray & mba, const std::string & st)
{
	for  (string::const_iterator it = st.begin(); it != st.end(); ++it) {
		mba << *it;
	}
	return mba;
}