fix up some const-ness issues starting from Evoral::Event::set(), and intersect with removing Mackie..MidiByteArray::bytes() method which made a copy of the data every time we wrote it
git-svn-id: svn://localhost/ardour2/branches/3.0@12124 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
@@ -60,7 +60,7 @@ struct Event {
|
||||
|
||||
const Event& operator=(const Event& copy);
|
||||
|
||||
void set(uint8_t* buf, uint32_t size, Time t);
|
||||
void set(const uint8_t* buf, uint32_t size, Time t);
|
||||
|
||||
inline bool operator==(const Event& other) const {
|
||||
if (_type != other._type)
|
||||
|
||||
@@ -118,7 +118,7 @@ Event<Timestamp>::operator=(const Event& copy)
|
||||
|
||||
template<typename Timestamp>
|
||||
void
|
||||
Event<Timestamp>::set(uint8_t* buf, uint32_t size, Timestamp t)
|
||||
Event<Timestamp>::set (const uint8_t* buf, uint32_t size, Timestamp t)
|
||||
{
|
||||
if (_owns_buf) {
|
||||
if (_size < size) {
|
||||
@@ -126,7 +126,11 @@ Event<Timestamp>::set(uint8_t* buf, uint32_t size, Timestamp t)
|
||||
}
|
||||
memcpy (_buf, buf, size);
|
||||
} else {
|
||||
_buf = buf;
|
||||
/* XXX this is really dangerous given the
|
||||
const-ness of buf. The API should really
|
||||
intervene here.
|
||||
*/
|
||||
_buf = const_cast<uint8_t*> (buf);
|
||||
}
|
||||
|
||||
_original_time = t;
|
||||
|
||||
@@ -246,11 +246,11 @@ IPMIDIPort::open_sockets (int base_port, const string& ifname)
|
||||
}
|
||||
|
||||
int
|
||||
IPMIDIPort::write (byte* msg, size_t msglen, timestamp_t /* ignored */) {
|
||||
IPMIDIPort::write (const byte* msg, size_t msglen, timestamp_t /* ignored */) {
|
||||
|
||||
if (sockout) {
|
||||
Glib::Mutex::Lock lm (write_lock);
|
||||
if (::sendto (sockout, (char *) msg, msglen, 0, (struct sockaddr *) &addrout, sizeof(struct sockaddr_in)) < 0) {
|
||||
if (::sendto (sockout, (const char *) msg, msglen, 0, (struct sockaddr *) &addrout, sizeof(struct sockaddr_in)) < 0) {
|
||||
::perror("sendto");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ JackMIDIPort::drain (int check_interval_usecs)
|
||||
}
|
||||
|
||||
int
|
||||
JackMIDIPort::write(byte * msg, size_t msglen, timestamp_t timestamp)
|
||||
JackMIDIPort::write (const byte * msg, size_t msglen, timestamp_t timestamp)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class IPMIDIPort : public Port {
|
||||
XMLNode& get_state () const;
|
||||
void set_state (const XMLNode&);
|
||||
|
||||
int write (byte *msg, size_t msglen, timestamp_t timestamp);
|
||||
int write (const byte *msg, size_t msglen, timestamp_t timestamp);
|
||||
int read (byte *buf, size_t bufsize);
|
||||
void parse (framecnt_t timestamp);
|
||||
int selectable () const;
|
||||
|
||||
@@ -54,7 +54,7 @@ class JackMIDIPort : public Port {
|
||||
void cycle_end ();
|
||||
|
||||
void parse (framecnt_t timestamp);
|
||||
int write (byte *msg, size_t msglen, timestamp_t timestamp);
|
||||
int write (const byte *msg, size_t msglen, timestamp_t timestamp);
|
||||
int read (byte *buf, size_t bufsize);
|
||||
void drain (int check_interval_usecs);
|
||||
int selectable () const { return xthread.selectable(); }
|
||||
|
||||
@@ -67,7 +67,7 @@ class Port {
|
||||
* @param timestamp Time stamp in frames of this message (relative to cycle start)
|
||||
* @return number of bytes successfully written
|
||||
*/
|
||||
virtual int write (byte *msg, size_t msglen, timestamp_t timestamp) = 0;
|
||||
virtual int write (const byte *msg, size_t msglen, timestamp_t timestamp) = 0;
|
||||
|
||||
/** Read raw bytes from a port.
|
||||
* @param buf memory to store read data in
|
||||
|
||||
@@ -28,80 +28,67 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
MidiByteArray::MidiByteArray( size_t size, MIDI::byte array[] )
|
||||
: std::vector<MIDI::byte>()
|
||||
MidiByteArray::MidiByteArray (size_t size, MIDI::byte array[])
|
||||
: std::vector<MIDI::byte>()
|
||||
{
|
||||
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<MIDI::byte>()
|
||||
MidiByteArray::MidiByteArray (size_t count, MIDI::byte first, ...)
|
||||
: vector<MIDI::byte>()
|
||||
{
|
||||
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<MIDI::byte> 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<MIDI::byte>( 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<MidiByteArray> bit( mba );
|
||||
copy( barr.begin(), barr.end(), bit );
|
||||
back_insert_iterator<MidiByteArray> 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 )
|
||||
MidiByteArray & operator << (MidiByteArray & mba, const std::string & st)
|
||||
{
|
||||
for ( string::const_iterator it = st.begin(); it != st.end(); ++it )
|
||||
{
|
||||
for (string::const_iterator it = st.begin(); it != st.end(); ++it) {
|
||||
mba << *it;
|
||||
}
|
||||
return mba;
|
||||
|
||||
@@ -57,9 +57,6 @@ public:
|
||||
*/
|
||||
MidiByteArray( size_t count, MIDI::byte first, ... );
|
||||
|
||||
/// return smart pointer to a copy of the bytes
|
||||
boost::shared_array<MIDI::byte> bytes() const;
|
||||
|
||||
/// copy the given number of bytes from the given array
|
||||
void copy( size_t count, MIDI::byte arr[] );
|
||||
};
|
||||
|
||||
@@ -117,11 +117,19 @@ SurfacePort::write (const MidiByteArray & mba)
|
||||
|
||||
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("port %1 write %2\n", output_port().name(), mba));
|
||||
|
||||
int count = output_port().write (mba.bytes().get(), mba.size(), 0);
|
||||
if (mba[0] != 0xf0 && mba.size() > 3) {
|
||||
std::cerr << "TOO LONG WRITE: " << mba << std::endl;
|
||||
}
|
||||
|
||||
/* this call relies on std::vector<T> using contiguous storage. not
|
||||
* actually guaranteed by the standard, but way, way beyond likely.
|
||||
*/
|
||||
|
||||
if (count != (int)mba.size()) {
|
||||
int count = output_port().write (&mba[0], mba.size(), 0);
|
||||
|
||||
if (errno == 0) {
|
||||
if (count != (int) mba.size()) {
|
||||
|
||||
if (errno == 0) {
|
||||
|
||||
cout << "port overflow on " << output_port().name() << ". Did not write all of " << mba << endl;
|
||||
|
||||
|
||||
@@ -11,5 +11,5 @@
|
||||
<JogWheel value="yes"/>
|
||||
<TouchSenseFaders value="yes"/>
|
||||
<LogicControlButtons value="yes"/>
|
||||
<UsesIPMIDI value="yes"/>
|
||||
<UsesIPMIDI value="no"/>
|
||||
</MackieProtocolDevice>
|
||||
|
||||
Reference in New Issue
Block a user