Factor out duplicated MidiByteArray

This commit is contained in:
David Robillard 2021-06-17 09:56:46 -04:00
parent cc6b58ef00
commit c6bdf8f2ff
36 changed files with 38 additions and 579 deletions

View file

@ -43,8 +43,6 @@ namespace PBD {
//#include "pbd/signals.h"
//#include "midi_byte_array.h"
#include "types.h"
#include "glibmm/main.h"

View file

@ -1,4 +1,7 @@
/*
* Copyright (C) 2006-2007 John Anderson
* Copyright (C) 2008-2016 Paul Davis <paul@linuxaudiosystems.com>
* Copyright (C) 2017 Ben Loftis <ben@harrisonconsoles.com>
* Copyright (C) 2018 Térence Clastres <t.clastres@gmail.com>
*
* This program is free software; you can redistribute it and/or modify

View file

@ -1,4 +1,7 @@
/*
* Copyright (C) 2006-2007 John Anderson
* Copyright (C) 2008-2016 Paul Davis <paul@linuxaudiosystems.com>
* Copyright (C) 2017 Ben Loftis <ben@harrisonconsoles.com>
* Copyright (C) 2018 Térence Clastres <t.clastres@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
@ -15,7 +18,8 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "midi_byte_array.h"
#include "control_protocol/midi_byte_array.h"
#include <iostream>
#include <string>

View file

@ -9,6 +9,7 @@ out = 'build'
controlcp_sources = [
'basic_ui.cc',
'control_protocol.cc',
'midi_byte_array.cc',
]
def options(opt):

View file

@ -40,8 +40,6 @@ namespace PBD {
//#include "pbd/signals.h"
//#include "midi_byte_array.h"
#include "types.h"
#include "glibmm/main.h"

View file

@ -36,10 +36,9 @@
#include "ardour/types.h"
#include "control_protocol/control_protocol.h"
#include "control_protocol/midi_byte_array.h"
#include "control_protocol/types.h"
#include "midi_byte_array.h"
namespace MIDI {
class Parser;
class Port;

View file

@ -22,7 +22,6 @@ def build(bld):
launch_control_xl.cc
controllers.cc
interface.cc
midi_byte_array.cc
leds.cc
gui.cc
'''

View file

@ -319,10 +319,6 @@
RelativePath="..\meter.cc"
>
</File>
<File
RelativePath="..\midi_byte_array.cc"
>
</File>
<File
RelativePath="..\pot.cc"
>
@ -425,10 +421,6 @@
RelativePath="..\meter.h"
>
</File>
<File
RelativePath="..\midi_byte_array.h"
>
</File>
<File
RelativePath="..\pot.h"
>

View file

@ -29,11 +29,11 @@
#include <boost/smart_ptr.hpp>
#include "control_protocol/midi_byte_array.h"
#include "pbd/controllable.h"
#include "pbd/signals.h"
#include "mackie_control_exception.h"
#include "midi_byte_array.h"
namespace ARDOUR {
class AutomationControl;

View file

@ -20,8 +20,9 @@
#ifndef __ardour_mackie_control_protocol_led_h__
#define __ardour_mackie_control_protocol_led_h__
#include "control_protocol/midi_byte_array.h"
#include "controls.h"
#include "midi_byte_array.h"
#include "types.h"
namespace ArdourSurface {

View file

@ -66,10 +66,10 @@
#include "ardour/types.h"
#include "ardour/audioengine.h"
#include "ardour/vca_manager.h"
#include "control_protocol/midi_byte_array.h"
#include "mackie_control_protocol.h"
#include "midi_byte_array.h"
#include "mackie_control_exception.h"
#include "device_profile.h"
#include "subview.h"

View file

@ -38,9 +38,9 @@
#include "midi++/types.h"
#include "ardour/types.h"
#include "control_protocol/control_protocol.h"
#include "control_protocol/midi_byte_array.h"
#include "types.h"
#include "midi_byte_array.h"
#include "controls.h"
#include "jog_wheel.h"
#include "timer.h"

View file

@ -19,7 +19,8 @@
#include "mackie_control_protocol.h"
#include "midi_byte_array.h"
#include "control_protocol/midi_byte_array.h"
#include "surface_port.h"
#include "pbd/pthread_utils.h"

View file

@ -20,8 +20,9 @@
#ifndef __ardour_mackie_control_protocol_meter_h__
#define __ardour_mackie_control_protocol_meter_h__
#include "control_protocol/midi_byte_array.h"
#include "controls.h"
#include "midi_byte_array.h"
namespace ArdourSurface {

View file

@ -1,97 +0,0 @@
/*
* Copyright (C) 2006-2007 John Anderson
* Copyright (C) 2008-2015 Paul Davis <paul@linuxaudiosystems.com>
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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)
{
/* note that this assumes that "st" is ASCII encoded
*/
mba.insert (mba.end(), st.begin(), st.end());
return mba;
}

View file

@ -1,77 +0,0 @@
/*
* Copyright (C) 2006-2007 John Anderson
* Copyright (C) 2008-2012 Paul Davis <paul@linuxaudiosystems.com>
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef midi_byte_array_h
#define midi_byte_array_h
#include <iostream>
#include <vector>
#include <boost/shared_array.hpp>
//#include <midi++/types.h>
namespace MIDI {
typedef unsigned char byte;
}
/**
To make building arrays of bytes easier. Thusly:
MidiByteArray mba;
mba << 0xf0 << 0x00 << 0xf7;
MidiByteArray buf;
buf << mba;
MidiByteArray direct( 3, 0xf0, 0x00, 0xf7 );
cout << mba << endl;
cout << buf << endl;
cout << direct << endl;
will all result in "f0 00 f7" being output to stdout
*/
class MidiByteArray : public std::vector<MIDI::byte>
{
public:
MidiByteArray() : std::vector<MIDI::byte>() {}
MidiByteArray( size_t count, MIDI::byte array[] );
/**
Accepts a preceding count, and then a list of bytes
*/
MidiByteArray( size_t count, MIDI::byte first, ... );
/// copy the given number of bytes from the given array
void copy( size_t count, MIDI::byte arr[] );
};
/// append the given byte to the end of the array
MidiByteArray & operator << ( MidiByteArray & mba, const MIDI::byte & b );
/// append the given string to the end of the array
MidiByteArray & operator << ( MidiByteArray & mba, const std::string & );
/// append the given array to the end of this array
MidiByteArray & operator << ( MidiByteArray & mba, const MidiByteArray & barr );
/// output the bytes as hex to the given stream
std::ostream & operator << ( std::ostream & os, const MidiByteArray & mba );
#endif

View file

@ -30,12 +30,12 @@
#include "pbd/signals.h"
#include "ardour/types.h"
#include "control_protocol/midi_byte_array.h"
#include "control_protocol/types.h"
#include "control_group.h"
#include "types.h"
#include "mackie_control_protocol.h"
#include "midi_byte_array.h"
#include "device_info.h"
namespace ARDOUR {

View file

@ -24,8 +24,8 @@
#include "pbd/signals.h"
#include "control_protocol/midi_byte_array.h"
#include "midi_byte_array.h"
#include "types.h"
namespace MIDI {

View file

@ -25,7 +25,7 @@
#include <cstdarg>
#include <iomanip>
#include "midi_byte_array.h"
#include "control_protocol/midi_byte_array.h"
using namespace std;

View file

@ -28,7 +28,6 @@ def build(bld):
mackie_control_protocol.cc
mcp_buttons.cc
meter.cc
midi_byte_array.cc
pot.cc
strip.cc
subview.cc

View file

@ -1,115 +0,0 @@
/*
* Copyright (C) 2016 Paul Davis <paul@linuxaudiosystems.com>
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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)
{
/* note that this assumes that "st" is ASCII encoded
*/
mba.insert (mba.end(), st.begin(), st.end());
return mba;
}
bool
MidiByteArray::compare_n (const MidiByteArray& other, MidiByteArray::size_type n) const
{
MidiByteArray::const_iterator us = begin();
MidiByteArray::const_iterator them = other.begin();
while (n && us != end() && them != other.end()) {
if ((*us) != (*them)) {
return false;
}
--n;
++us;
++them;
}
return true;
}

View file

@ -1,78 +0,0 @@
/*
* Copyright (C) 2016 Paul Davis <paul@linuxaudiosystems.com>
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef midi_byte_array_h
#define midi_byte_array_h
#include <iostream>
#include <vector>
#include <boost/shared_array.hpp>
//#include <midi++/types.h>
namespace MIDI {
typedef unsigned char byte;
}
/**
To make building arrays of bytes easier. Thusly:
MidiByteArray mba;
mba << 0xf0 << 0x00 << 0xf7;
MidiByteArray buf;
buf << mba;
MidiByteArray direct( 3, 0xf0, 0x00, 0xf7 );
cout << mba << endl;
cout << buf << endl;
cout << direct << endl;
will all result in "f0 00 f7" being output to stdout
*/
class MidiByteArray : public std::vector<MIDI::byte>
{
public:
MidiByteArray() : std::vector<MIDI::byte>() {}
MidiByteArray( size_t count, MIDI::byte array[] );
bool compare_n (const MidiByteArray& other, MidiByteArray::size_type len) const;
/**
Accepts a preceding count, and then a list of bytes
*/
MidiByteArray( size_t count, MIDI::byte first, ... );
/// copy the given number of bytes from the given array
void copy( size_t count, MIDI::byte arr[] );
};
/// append the given byte to the end of the array
MidiByteArray & operator << ( MidiByteArray & mba, const MIDI::byte & b );
/// append the given string to the end of the array
MidiByteArray & operator << ( MidiByteArray & mba, const std::string & );
/// append the given array to the end of this array
MidiByteArray & operator << ( MidiByteArray & mba, const MidiByteArray & barr );
/// output the bytes as hex to the given stream
std::ostream & operator << ( std::ostream & os, const MidiByteArray & mba );
#endif

View file

@ -36,12 +36,11 @@
#include "ardour/types.h"
#include "control_protocol/control_protocol.h"
#include "control_protocol/midi_byte_array.h"
#include "control_protocol/types.h"
#include "gtkmm2ext/colors.h"
#include "midi_byte_array.h"
namespace Pango {
class Layout;
}

View file

@ -22,7 +22,6 @@ def build(bld):
buttons.cc
canvas.cc
interface.cc
midi_byte_array.cc
leds.cc
level_meter.cc
gui.cc

View file

@ -29,8 +29,9 @@
#include "pbd/controllable.h"
#include "pbd/signals.h"
#include "control_protocol/midi_byte_array.h"
#include "us2400_control_exception.h"
#include "midi_byte_array.h"
namespace ARDOUR {
class AutomationControl;

View file

@ -19,8 +19,9 @@
#ifndef __ardour_us2400_control_protocol_led_h__
#define __ardour_us2400_control_protocol_led_h__
#include "control_protocol/midi_byte_array.h"
#include "controls.h"
#include "midi_byte_array.h"
#include "types.h"
namespace ArdourSurface {

View file

@ -19,8 +19,9 @@
#ifndef __ardour_us2400_control_protocol_meter_h__
#define __ardour_us2400_control_protocol_meter_h__
#include "control_protocol/midi_byte_array.h"
#include "controls.h"
#include "midi_byte_array.h"
namespace ArdourSurface {

View file

@ -1,96 +0,0 @@
/*
* Copyright (C) 2017 Ben Loftis <ben@harrisonconsoles.com>
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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)
{
/* note that this assumes that "st" is ASCII encoded
*/
mba.insert (mba.end(), st.begin(), st.end());
return mba;
}

View file

@ -1,76 +0,0 @@
/*
* Copyright (C) 2017 Ben Loftis <ben@harrisonconsoles.com>
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef midi_byte_array_h
#define midi_byte_array_h
#include <iostream>
#include <vector>
#include <boost/shared_array.hpp>
//#include <midi++/types.h>
namespace MIDI {
typedef unsigned char byte;
}
/**
To make building arrays of bytes easier. Thusly:
MidiByteArray mba;
mba << 0xf0 << 0x00 << 0xf7;
MidiByteArray buf;
buf << mba;
MidiByteArray direct( 3, 0xf0, 0x00, 0xf7 );
cout << mba << endl;
cout << buf << endl;
cout << direct << endl;
will all result in "f0 00 f7" being output to stdout
*/
class MidiByteArray : public std::vector<MIDI::byte>
{
public:
MidiByteArray() : std::vector<MIDI::byte>() {}
MidiByteArray( size_t count, MIDI::byte array[] );
/**
Accepts a preceding count, and then a list of bytes
*/
MidiByteArray( size_t count, MIDI::byte first, ... );
/// copy the given number of bytes from the given array
void copy( size_t count, MIDI::byte arr[] );
};
/// append the given byte to the end of the array
MidiByteArray & operator << ( MidiByteArray & mba, const MIDI::byte & b );
/// append the given string to the end of the array
MidiByteArray & operator << ( MidiByteArray & mba, const std::string & );
/// append the given array to the end of this array
MidiByteArray & operator << ( MidiByteArray & mba, const MidiByteArray & barr );
/// output the bytes as hex to the given stream
std::ostream & operator << ( std::ostream & os, const MidiByteArray & mba );
#endif

View file

@ -29,12 +29,12 @@
#include "pbd/signals.h"
#include "ardour/types.h"
#include "control_protocol/midi_byte_array.h"
#include "control_protocol/types.h"
#include "control_group.h"
#include "types.h"
#include "us2400_control_protocol.h"
#include "midi_byte_array.h"
#include "device_info.h"
namespace ARDOUR {

View file

@ -22,8 +22,8 @@
#include "pbd/signals.h"
#include "control_protocol/midi_byte_array.h"
#include "midi_byte_array.h"
#include "types.h"
namespace MIDI {

View file

@ -6,7 +6,7 @@
#include <cstdarg>
#include <iomanip>
#include "midi_byte_array.h"
#include "control_protocol/midi_byte_array.h"
using namespace std;

View file

@ -60,9 +60,10 @@
#include "ardour/audioengine.h"
#include "ardour/vca_manager.h"
#include "control_protocol/midi_byte_array.h"
#include "us2400_control_protocol.h"
#include "midi_byte_array.h"
#include "us2400_control_exception.h"
#include "device_profile.h"
#include "surface_port.h"

View file

@ -33,9 +33,9 @@
#include "midi++/types.h"
#include "ardour/types.h"
#include "control_protocol/control_protocol.h"
#include "control_protocol/midi_byte_array.h"
#include "types.h"
#include "midi_byte_array.h"
#include "controls.h"
#include "jog_wheel.h"
#include "timer.h"

View file

@ -18,7 +18,8 @@
#include "us2400_control_protocol.h"
#include "midi_byte_array.h"
#include "control_protocol/midi_byte_array.h"
#include "surface_port.h"
#include "pbd/pthread_utils.h"

View file

@ -28,7 +28,6 @@ def build(bld):
us2400_control_protocol.cc
mcp_buttons.cc
meter.cc
midi_byte_array.cc
pot.cc
strip.cc
surface.cc