pure-data/portmidi/patches/mac_limit_rate_override.patch

Index: pm_mac/pmmacosxcm.c
===================================================================
--- pm_mac/pmmacosxcm.c	(revision 234)
+++ pm_mac/pmmacosxcm.c	(working copy)
@@ -63,7 +63,9 @@
 
      Note that this distorts accurate timestamps somewhat.
  */
+#ifndef LIMIT_RATE
 #define LIMIT_RATE 1
+#endif
 
 #define SYSEX_BUFFER_SIZE 128
 
@@ -107,11 +109,13 @@
     /* allow for running status (is running status possible here? -rbd): -cpr */
     unsigned char last_command; 
     int32_t last_msg_length;
+#if LIMIT_RATE
     /* limit midi data rate (a CoreMidi requirement): */
     UInt64 min_next_time; /* when can the next send take place? */
     int byte_count; /* how many bytes in the next packet list? */
     Float64 us_per_host_tick; /* host clock frequency, units of min_next_time */
     UInt64 host_ticks_per_byte; /* host clock units per byte at maximum rate */
+#endif
 } midi_macosxcm_node, *midi_macosxcm_type;
 
 /* private function declarations */
@@ -427,11 +431,13 @@
     m->packet = NULL;
     m->last_command = 0;
     m->last_msg_length = 0;
+#if LIMIT_RATE
     m->min_next_time = 0;
     m->byte_count = 0;
     m->us_per_host_tick = 1000000.0 / AudioGetHostClockFrequency();
     m->host_ticks_per_byte = (UInt64) (1000000.0 / 
                                        (m->us_per_host_tick * MAX_BYTES_PER_S));
+#endif
     return pmNoError;
 }
 
@@ -477,6 +483,7 @@
     assert(endpoint);
     if (m->packet != NULL) {
         /* out of space, send the buffer and start refilling it */
+    #if LIMIT_RATE
         /* before we can send, maybe delay to limit data rate. OS X allows
          * 15KB/s. */
         UInt64 now = AudioGetCurrentHostTime();
@@ -484,10 +491,11 @@
             usleep((useconds_t) 
                    ((m->min_next_time - now) * m->us_per_host_tick));
         }
+        m->min_next_time = now + m->byte_count * m->host_ticks_per_byte;
+        m->byte_count = 0;
+    #endif
         macHostError = MIDISend(portOut, endpoint, m->packetList);
         m->packet = NULL; /* indicate no data in packetList now */
-        m->min_next_time = now + m->byte_count * m->host_ticks_per_byte;
-        m->byte_count = 0;
         if (macHostError != noErr) goto send_packet_error;
     }
     return pmNoError;
@@ -514,7 +522,9 @@
     m->packet = MIDIPacketListAdd(m->packetList, sizeof(m->packetBuffer), 
                                   m->packet, timestamp, messageLength, 
                                   message);
+#if LIMIT_RATE
     m->byte_count += messageLength;
+#endif
     if (m->packet == NULL) {
         /* out of space, send the buffer and start refilling it */
         /* make midi->packet non-null to fool midi_write_flush into sending */
@@ -567,13 +577,15 @@
     messageLength = midi_length(what);
         
     /* make sure we go foreward in time */
-    if (timestamp < m->min_next_time) timestamp = m->min_next_time;
-
-    #ifdef LIMIT_RATE
-        if (timestamp < m->last_time)
-            timestamp = m->last_time;
+    if (timestamp < m->last_time)
+        timestamp = m->last_time;
+#if LIMIT_RATE
+    if (timestamp < m->min_next_time)
+        timestamp = m->min_next_time;
 	m->last_time = timestamp + messageLength * m->host_ticks_per_byte;
-    #endif
+#else
+    m->last_time = timestamp;
+#endif
 
     /* Add this message to the packet list */
     return send_packet(midi, message, messageLength, timestamp);
@@ -613,15 +625,17 @@
     assert(m);
     
     /* make sure we go foreward in time */
+    if (m->sysex_timestamp < m->last_time)
+        m->sysex_timestamp = m->last_time;
+
+#if LIMIT_RATE
     if (m->sysex_timestamp < m->min_next_time) 
         m->sysex_timestamp = m->min_next_time;
-
-    #ifdef LIMIT_RATE
-        if (m->sysex_timestamp < m->last_time) 
-            m->sysex_timestamp = m->last_time;
-        m->last_time = m->sysex_timestamp + m->sysex_byte_count *
-                                            m->host_ticks_per_byte;
-    #endif
+    m->last_time = m->sysex_timestamp + m->sysex_byte_count *
+                                        m->host_ticks_per_byte;
+#else
+    m->last_time = m->sysex_timestamp;
+#endif
     
     /* now send what's in the buffer */
     err = send_packet(midi, m->sysex_buffer, m->sysex_byte_count,