Debian Codegraph @

portmidi/patches/mac_limit_rate_override.patch

raw
1 Index: pm_mac/pmmacosxcm.c
2 ===================================================================
3 --- pm_mac/pmmacosxcm.c (revision 234)
4 +++ pm_mac/pmmacosxcm.c (working copy)
5 @@ -63,7 +63,9 @@
6
7 Note that this distorts accurate timestamps somewhat.
8 */
9 +#ifndef LIMIT_RATE
10 #define LIMIT_RATE 1
11 +#endif
12
13 #define SYSEX_BUFFER_SIZE 128
14
15 @@ -107,11 +109,13 @@
16 /* allow for running status (is running status possible here? -rbd): -cpr */
17 unsigned char last_command;
18 int32_t last_msg_length;
19 +#if LIMIT_RATE
20 /* limit midi data rate (a CoreMidi requirement): */
21 UInt64 min_next_time; /* when can the next send take place? */
22 int byte_count; /* how many bytes in the next packet list? */
23 Float64 us_per_host_tick; /* host clock frequency, units of min_next_time */
24 UInt64 host_ticks_per_byte; /* host clock units per byte at maximum rate */
25 +#endif
26 } midi_macosxcm_node, *midi_macosxcm_type;
27
28 /* private function declarations */
29 @@ -427,11 +431,13 @@
30 m->packet = NULL;
31 m->last_command = 0;
32 m->last_msg_length = 0;
33 +#if LIMIT_RATE
34 m->min_next_time = 0;
35 m->byte_count = 0;
36 m->us_per_host_tick = 1000000.0 / AudioGetHostClockFrequency();
37 m->host_ticks_per_byte = (UInt64) (1000000.0 /
38 (m->us_per_host_tick * MAX_BYTES_PER_S));
39 +#endif
40 return pmNoError;
41 }
42
43 @@ -477,6 +483,7 @@
44 assert(endpoint);
45 if (m->packet != NULL) {
46 /* out of space, send the buffer and start refilling it */
47 + #if LIMIT_RATE
48 /* before we can send, maybe delay to limit data rate. OS X allows
49 * 15KB/s. */
50 UInt64 now = AudioGetCurrentHostTime();
51 @@ -484,10 +491,11 @@
52 usleep((useconds_t)
53 ((m->min_next_time - now) * m->us_per_host_tick));
54 }
55 + m->min_next_time = now + m->byte_count * m->host_ticks_per_byte;
56 + m->byte_count = 0;
57 + #endif
58 macHostError = MIDISend(portOut, endpoint, m->packetList);
59 m->packet = NULL; /* indicate no data in packetList now */
60 - m->min_next_time = now + m->byte_count * m->host_ticks_per_byte;
61 - m->byte_count = 0;
62 if (macHostError != noErr) goto send_packet_error;
63 }
64 return pmNoError;
65 @@ -514,7 +522,9 @@
66 m->packet = MIDIPacketListAdd(m->packetList, sizeof(m->packetBuffer),
67 m->packet, timestamp, messageLength,
68 message);
69 +#if LIMIT_RATE
70 m->byte_count += messageLength;
71 +#endif
72 if (m->packet == NULL) {
73 /* out of space, send the buffer and start refilling it */
74 /* make midi->packet non-null to fool midi_write_flush into sending */
75 @@ -567,13 +577,15 @@
76 messageLength = midi_length(what);
77
78 /* make sure we go foreward in time */
79 - if (timestamp < m->min_next_time) timestamp = m->min_next_time;
80 -
81 - #ifdef LIMIT_RATE
82 - if (timestamp < m->last_time)
83 - timestamp = m->last_time;
84 + if (timestamp < m->last_time)
85 + timestamp = m->last_time;
86 +#if LIMIT_RATE
87 + if (timestamp < m->min_next_time)
88 + timestamp = m->min_next_time;
89 m->last_time = timestamp + messageLength * m->host_ticks_per_byte;
90 - #endif
91 +#else
92 + m->last_time = timestamp;
93 +#endif
94
95 /* Add this message to the packet list */
96 return send_packet(midi, message, messageLength, timestamp);
97 @@ -613,15 +625,17 @@
98 assert(m);
99
100 /* make sure we go foreward in time */
101 + if (m->sysex_timestamp < m->last_time)
102 + m->sysex_timestamp = m->last_time;
103 +
104 +#if LIMIT_RATE
105 if (m->sysex_timestamp < m->min_next_time)
106 m->sysex_timestamp = m->min_next_time;
107 -
108 - #ifdef LIMIT_RATE
109 - if (m->sysex_timestamp < m->last_time)
110 - m->sysex_timestamp = m->last_time;
111 - m->last_time = m->sysex_timestamp + m->sysex_byte_count *
112 - m->host_ticks_per_byte;
113 - #endif
114 + m->last_time = m->sysex_timestamp + m->sysex_byte_count *
115 + m->host_ticks_per_byte;
116 +#else
117 + m->last_time = m->sysex_timestamp;
118 +#endif
119
120 /* now send what's in the buffer */
121 err = send_packet(midi, m->sysex_buffer, m->sysex_byte_count,