summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2012-04-30 15:54:13 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2012-04-30 15:54:13 +0000
commiteaa7cc5a73416c4b8672ccbf8e53c049e7279285 (patch)
tree6ea2bb241ba27f90464fb3c1c7596d77e61fe6cd
parentf99dc6d2ab5acd69268f993ea2bb628d70728426 (diff)
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
-rw-r--r--libs/evoral/evoral/Event.hpp2
-rw-r--r--libs/evoral/src/Event.cpp8
-rw-r--r--libs/midi++2/ipmidi_port.cc4
-rw-r--r--libs/midi++2/jack_midi_port.cc2
-rw-r--r--libs/midi++2/midi++/ipmidi_port.h2
-rw-r--r--libs/midi++2/midi++/jack_midi_port.h2
-rw-r--r--libs/midi++2/midi++/port.h2
-rw-r--r--libs/surfaces/mackie/midi_byte_array.cc65
-rw-r--r--libs/surfaces/mackie/midi_byte_array.h3
-rw-r--r--libs/surfaces/mackie/surface_port.cc14
-rw-r--r--mcp/nucleus.device2
11 files changed, 51 insertions, 55 deletions
diff --git a/libs/evoral/evoral/Event.hpp b/libs/evoral/evoral/Event.hpp
index da8036c8f6..5c287fd714 100644
--- a/libs/evoral/evoral/Event.hpp
+++ b/libs/evoral/evoral/Event.hpp
@@ -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)
diff --git a/libs/evoral/src/Event.cpp b/libs/evoral/src/Event.cpp
index d0e0e8ac3a..e315d811e0 100644
--- a/libs/evoral/src/Event.cpp
+++ b/libs/evoral/src/Event.cpp
@@ -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;
diff --git a/libs/midi++2/ipmidi_port.cc b/libs/midi++2/ipmidi_port.cc
index 50777634f1..6eac803936 100644
--- a/libs/midi++2/ipmidi_port.cc
+++ b/libs/midi++2/ipmidi_port.cc
@@ -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;
}
diff --git a/libs/midi++2/jack_midi_port.cc b/libs/midi++2/jack_midi_port.cc
index 729fc789d4..162e2a5f1b 100644
--- a/libs/midi++2/jack_midi_port.cc
+++ b/libs/midi++2/jack_midi_port.cc
@@ -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;
diff --git a/libs/midi++2/midi++/ipmidi_port.h b/libs/midi++2/midi++/ipmidi_port.h
index 7df9642321..0441626565 100644
--- a/libs/midi++2/midi++/ipmidi_port.h
+++ b/libs/midi++2/midi++/ipmidi_port.h
@@ -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;
diff --git a/libs/midi++2/midi++/jack_midi_port.h b/libs/midi++2/midi++/jack_midi_port.h
index e381120a99..b8d208c77a 100644
--- a/libs/midi++2/midi++/jack_midi_port.h
+++ b/libs/midi++2/midi++/jack_midi_port.h
@@ -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(); }
diff --git a/libs/midi++2/midi++/port.h b/libs/midi++2/midi++/port.h
index a2315f7284..40a413f562 100644
--- a/libs/midi++2/midi++/port.h
+++ b/libs/midi++2/midi++/port.h
@@ -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
diff --git a/libs/surfaces/mackie/midi_byte_array.cc b/libs/surfaces/mackie/midi_byte_array.cc
index 1c27c82be1..1e94e781c0 100644
--- a/libs/surfaces/mackie/midi_byte_array.cc
+++ b/libs/surfaces/mackie/midi_byte_array.cc
@@ -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;
diff --git a/libs/surfaces/mackie/midi_byte_array.h b/libs/surfaces/mackie/midi_byte_array.h
index 7176367189..372e48ab90 100644
--- a/libs/surfaces/mackie/midi_byte_array.h
+++ b/libs/surfaces/mackie/midi_byte_array.h
@@ -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[] );
};
diff --git a/libs/surfaces/mackie/surface_port.cc b/libs/surfaces/mackie/surface_port.cc
index bf5e7417ab..9d0296a9a4 100644
--- a/libs/surfaces/mackie/surface_port.cc
+++ b/libs/surfaces/mackie/surface_port.cc
@@ -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.
+ */
+
+ int count = output_port().write (&mba[0], mba.size(), 0);
- if (count != (int)mba.size()) {
+ if (count != (int) mba.size()) {
- if (errno == 0) {
+ if (errno == 0) {
cout << "port overflow on " << output_port().name() << ". Did not write all of " << mba << endl;
diff --git a/mcp/nucleus.device b/mcp/nucleus.device
index 1456d4e8a7..7ab3eb8146 100644
--- a/mcp/nucleus.device
+++ b/mcp/nucleus.device
@@ -11,5 +11,5 @@
<JogWheel value="yes"/>
<TouchSenseFaders value="yes"/>
<LogicControlButtons value="yes"/>
- <UsesIPMIDI value="yes"/>
+ <UsesIPMIDI value="no"/>
</MackieProtocolDevice>