2008-06-02 17:41:35 -04:00
|
|
|
/*
|
|
|
|
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>
|
2008-12-12 17:55:03 -05:00
|
|
|
#include <stdexcept>
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2012-04-30 11:54:13 -04:00
|
|
|
MidiByteArray::MidiByteArray (size_t size, MIDI::byte array[])
|
|
|
|
: std::vector<MIDI::byte>()
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-04-30 11:54:13 -04:00
|
|
|
for (size_t i = 0; i < size; ++i)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-04-30 11:54:13 -04:00
|
|
|
push_back (array[i]);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-30 11:54:13 -04:00
|
|
|
MidiByteArray::MidiByteArray (size_t count, MIDI::byte first, ...)
|
|
|
|
: vector<MIDI::byte>()
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-04-30 11:54:13 -04:00
|
|
|
push_back (first);
|
2008-06-02 17:41:35 -04:00
|
|
|
va_list var_args;
|
2012-04-30 11:54:13 -04:00
|
|
|
va_start (var_args, first);
|
|
|
|
for (size_t i = 1; i < count; ++i)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-04-30 11:54:13 -04:00
|
|
|
MIDI::byte b = va_arg (var_args, int);
|
|
|
|
push_back (b);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2012-04-30 11:54:13 -04:00
|
|
|
va_end (var_args);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-30 11:54:13 -04:00
|
|
|
void MidiByteArray::copy (size_t count, MIDI::byte * arr)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-04-30 11:54:13 -04:00
|
|
|
for (size_t i = 0; i < count; ++i) {
|
|
|
|
push_back (arr[i]);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-30 11:54:13 -04:00
|
|
|
MidiByteArray & operator << (MidiByteArray & mba, const MIDI::byte & b)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-04-30 11:54:13 -04:00
|
|
|
mba.push_back (b);
|
2008-06-02 17:41:35 -04:00
|
|
|
return mba;
|
|
|
|
}
|
|
|
|
|
2012-04-30 11:54:13 -04:00
|
|
|
MidiByteArray & operator << (MidiByteArray & mba, const MidiByteArray & barr)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-04-30 11:54:13 -04:00
|
|
|
back_insert_iterator<MidiByteArray> bit (mba);
|
|
|
|
copy (barr.begin(), barr.end(), bit);
|
2008-06-02 17:41:35 -04:00
|
|
|
return mba;
|
|
|
|
}
|
|
|
|
|
2012-04-30 11:54:13 -04:00
|
|
|
ostream & operator << (ostream & os, const MidiByteArray & mba)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
os << "[";
|
|
|
|
char fill = os.fill('0');
|
2012-04-30 11:54:13 -04:00
|
|
|
for (MidiByteArray::const_iterator it = mba.begin(); it != mba.end(); ++it) {
|
|
|
|
if (it != mba.begin()) os << " ";
|
2008-06-02 17:41:35 -04:00
|
|
|
os << hex << setw(2) << (int)*it;
|
|
|
|
}
|
2012-04-30 11:54:13 -04:00
|
|
|
os.fill (fill);
|
2008-06-02 17:41:35 -04:00
|
|
|
os << dec;
|
|
|
|
os << "]";
|
|
|
|
return os;
|
|
|
|
}
|
2008-12-12 17:55:03 -05:00
|
|
|
|
2012-04-30 11:54:13 -04:00
|
|
|
MidiByteArray & operator << (MidiByteArray & mba, const std::string & st)
|
2008-12-12 17:55:03 -05:00
|
|
|
{
|
2012-04-30 11:54:13 -04:00
|
|
|
for (string::const_iterator it = st.begin(); it != st.end(); ++it) {
|
2008-12-12 17:55:03 -05:00
|
|
|
mba << *it;
|
|
|
|
}
|
|
|
|
return mba;
|
|
|
|
}
|