2 Copyright (C) 2006,2007 John Anderson
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #include "midi_byte_array.h"
31 MidiByteArray::MidiByteArray( size_t size, MIDI::byte array[] )
32 : std::vector<MIDI::byte>()
34 for ( size_t i = 0; i < size; ++i )
36 push_back( array[i] );
40 MidiByteArray::MidiByteArray( size_t count, MIDI::byte first, ... )
41 : vector<MIDI::byte>()
45 va_start( var_args, first );
46 for ( size_t i = 1; i < count; ++i )
48 MIDI::byte b = va_arg( var_args, int );
54 boost::shared_array<MIDI::byte> MidiByteArray::bytes() const
56 MIDI::byte * buf = new MIDI::byte[size()];
57 const_iterator it = begin();
58 for( MIDI::byte * ptr = buf; it != end(); ++it )
62 return boost::shared_array<MIDI::byte>( buf );
65 void MidiByteArray::copy( size_t count, MIDI::byte * arr )
67 for( size_t i = 0; i < count; ++i )
73 MidiByteArray & operator << ( MidiByteArray & mba, const MIDI::byte & b )
79 MidiByteArray & operator << ( MidiByteArray & mba, const MidiByteArray & barr )
81 back_insert_iterator<MidiByteArray> bit( mba );
82 copy( barr.begin(), barr.end(), bit );
86 ostream & operator << ( ostream & os, const MidiByteArray & mba )
89 char fill = os.fill('0');
90 for( MidiByteArray::const_iterator it = mba.begin(); it != mba.end(); ++it )
92 if ( it != mba.begin() ) os << " ";
93 os << hex << setw(2) << (int)*it;
101 MidiByteArray & operator << ( MidiByteArray & mba, const std::string & st )
103 for ( string::const_iterator it = st.begin(); it != st.end(); ++it )