fix up some const-ness issues starting from Evoral::Event::set(), and intersect with...
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 30 Apr 2012 15:54:13 +0000 (15:54 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 30 Apr 2012 15:54:13 +0000 (15:54 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@12124 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/evoral/evoral/Event.hpp
libs/evoral/src/Event.cpp
libs/midi++2/ipmidi_port.cc
libs/midi++2/jack_midi_port.cc
libs/midi++2/midi++/ipmidi_port.h
libs/midi++2/midi++/jack_midi_port.h
libs/midi++2/midi++/port.h
libs/surfaces/mackie/midi_byte_array.cc
libs/surfaces/mackie/midi_byte_array.h
libs/surfaces/mackie/surface_port.cc
mcp/nucleus.device

index da8036c8f60510f3cbd02c1fb2aa9deaba05f4e9..5c287fd714c752849df92999b674f76a24e45f25 100644 (file)
@@ -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)
index d0e0e8ac3a4ea9bd22c57a3c4f07d80b9a761aa3..e315d811e06f95d7f5da140c64cfc1c7ec6a2094 100644 (file)
@@ -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;
index 50777634f1146d88d2d0ffbebeb37d17e69b3bee..6eac8039360295c287f2c7fbf9deb5aa7bb95b8b 100644 (file)
@@ -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;
                }
index 729fc789d470847ab918e708d9c0d7a4f44c727b..162e2a5f1ba321ee7fd8f43098adbc41270d755f 100644 (file)
@@ -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;
 
index 7df964232150c768ef04e50ce41ca629eafdfd7b..0441626565639dd02e611ddc0e5de1a39b238aaf 100644 (file)
@@ -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;
index e381120a99375c02d33c2e6255af531553b82601..b8d208c77a4118e923b2a665a658d6c35f54cba4 100644 (file)
@@ -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(); }
index a2315f72844c7c1cc467b6cac9506227bbfcfa11..40a413f5624da6ecd9b284179330aae303042923 100644 (file)
@@ -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
index 1c27c82be1c1e3f1cc6224f31e59ded21dead893..1e94e781c0a6b49ecaf4dade253da3ad5bdbf4cf 100644 (file)
 
 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;
index 7176367189d3c391eed4320be02111fb06a3dcaf..372e48ab90b59764c5afbf9ef235016b46c6a673 100644 (file)
@@ -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[] );
 };
index bf5e7417ab5259be6c304ee3abd958b7cc6b46f4..9d0296a9a4d5355eadf463fb16ddb1c6970f6593 100644 (file)
@@ -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;
 
index 1456d4e8a776540591f16348fddb459e1d7656ea..7ab3eb8146214fa1defac40e53c75b1bb105c0c7 100644 (file)
@@ -11,5 +11,5 @@
   <JogWheel value="yes"/>
   <TouchSenseFaders value="yes"/>
   <LogicControlButtons value="yes"/>
-  <UsesIPMIDI value="yes"/>
+  <UsesIPMIDI value="no"/>
 </MackieProtocolDevice>