X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fsurfaces%2Fmackie%2Fmidi_byte_array.cc;h=45d0439a75531052824e830071ee9c14dbebd8a3;hb=9740fb7d760c96acf9794e0e6bca710c7782c71b;hp=192af6a1ce3fe5f086b6815888ed8786eca1bae6;hpb=45d3ec1437cf661533bc7750c623865def4424df;p=ardour.git diff --git a/libs/surfaces/mackie/midi_byte_array.cc b/libs/surfaces/mackie/midi_byte_array.cc index 192af6a1ce..45d0439a75 100644 --- a/libs/surfaces/mackie/midi_byte_array.cc +++ b/libs/surfaces/mackie/midi_byte_array.cc @@ -24,75 +24,73 @@ #include #include #include +#include using namespace std; -MidiByteArray::MidiByteArray( size_t size, MIDI::byte array[] ) -: std::vector() +MidiByteArray::MidiByteArray (size_t size, MIDI::byte array[]) + : std::vector() { - for ( size_t i = 0; i < size; ++i ) + for (size_t i = 0; i < size; ++i) { - push_back( array[i] ); - } + push_back (array[i]); + } } -MidiByteArray::MidiByteArray( size_t count, MIDI::byte first, ... ) -: vector() +MidiByteArray::MidiByteArray (size_t count, MIDI::byte first, ...) + : vector() { - push_back( first ); + push_back (first); va_list var_args; - va_start( var_args, first ); - for ( size_t i = 1; i < count; ++i ) + va_start (var_args, first); + for (size_t i = 1; i < count; ++i) { - MIDI::byte b = va_arg( var_args, int ); - push_back( b ); + MIDI::byte b = va_arg (var_args, int); + push_back (b); } - va_end( var_args ); + va_end (var_args); } -boost::shared_array MidiByteArray::bytes() const -{ - MIDI::byte * buf = new MIDI::byte[size()]; - const_iterator it = begin(); - for( MIDI::byte * ptr = buf; it != end(); ++it ) - { - *ptr++ = *it; - } - return boost::shared_array( buf ); -} -void MidiByteArray::copy( size_t count, MIDI::byte * arr ) +void MidiByteArray::copy (size_t count, MIDI::byte * arr) { - for( size_t i = 0; i < count; ++i ) - { - push_back( arr[i] ); + for (size_t i = 0; i < count; ++i) { + push_back (arr[i]); } } -MidiByteArray & operator << ( MidiByteArray & mba, const MIDI::byte & b ) +MidiByteArray & operator << (MidiByteArray & mba, const MIDI::byte & b) { - mba.push_back( b ); + mba.push_back (b); return mba; } -MidiByteArray & operator << ( MidiByteArray & mba, const MidiByteArray & barr ) +MidiByteArray & operator << (MidiByteArray & mba, const MidiByteArray & barr) { - back_insert_iterator bit( mba ); - copy( barr.begin(), barr.end(), bit ); + back_insert_iterator bit (mba); + copy (barr.begin(), barr.end(), bit); return mba; } -ostream & operator << ( ostream & os, const MidiByteArray & 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 << " "; + 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.fill (fill); os << dec; os << "]"; return os; } + +MidiByteArray & operator << (MidiByteArray & mba, const std::string & st) +{ + /* note that this assumes that "st" is ASCII encoded + */ + + mba.insert (mba.end(), st.begin(), st.end()); + return mba; +}