objc2-core-midi 0.3.2

Bindings to the CoreMIDI framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidiinvalidclient?language=objc)
pub const kMIDIInvalidClient: OSStatus = -10830;
/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidiinvalidport?language=objc)
pub const kMIDIInvalidPort: OSStatus = -10831;
/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidiwrongendpointtype?language=objc)
pub const kMIDIWrongEndpointType: OSStatus = -10832;
/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidinoconnection?language=objc)
pub const kMIDINoConnection: OSStatus = -10833;
/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidiunknownendpoint?language=objc)
pub const kMIDIUnknownEndpoint: OSStatus = -10834;
/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidiunknownproperty?language=objc)
pub const kMIDIUnknownProperty: OSStatus = -10835;
/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidiwrongpropertytype?language=objc)
pub const kMIDIWrongPropertyType: OSStatus = -10836;
/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidinocurrentsetup?language=objc)
pub const kMIDINoCurrentSetup: OSStatus = -10837;
/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidimessagesenderr?language=objc)
pub const kMIDIMessageSendErr: OSStatus = -10838;
/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidiserverstarterr?language=objc)
pub const kMIDIServerStartErr: OSStatus = -10839;
/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidisetupformaterr?language=objc)
pub const kMIDISetupFormatErr: OSStatus = -10840;
/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidiwrongthread?language=objc)
pub const kMIDIWrongThread: OSStatus = -10841;
/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidiobjectnotfound?language=objc)
pub const kMIDIObjectNotFound: OSStatus = -10842;
/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidiidnotunique?language=objc)
pub const kMIDIIDNotUnique: OSStatus = -10843;
/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidinotpermitted?language=objc)
pub const kMIDINotPermitted: OSStatus = -10844;
/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidiunknownerror?language=objc)
pub const kMIDIUnknownError: OSStatus = -10845;

/// The base class of many CoreMIDI objects.
///
/// MIDIObject is the base class for many of the objects in CoreMIDI.  They have properties,
/// and often an "owner" object, from which they inherit any properties they do not
/// themselves have.
///
/// Developers may add their own private properties, whose names must begin with their
/// company's inverted domain name, as in Java package names, but with underscores instead
/// of dots, e.g.: com_apple_APrivateAppleProperty
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midiobjectref?language=objc)
pub type MIDIObjectRef = u32;

/// An object maintaining per-client state.
///
/// Derives from MIDIObjectRef, does not have an owner object.
///
/// To use CoreMIDI, an application creates a MIDIClientRef, to which it can add
/// MIDIPortRef's, through which it can send and receive MIDI.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midiclientref?language=objc)
pub type MIDIClientRef = MIDIObjectRef;

/// A MIDI connection port owned by a client.
///
/// Derives from MIDIObjectRef, owned by a MIDIClientRef.
///
/// A MIDIPortRef, which may be an input port or output port, is an object through which a
/// client may communicate with any number of MIDI sources or destinations.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midiportref?language=objc)
pub type MIDIPortRef = MIDIObjectRef;

/// A MIDI device or external device, containing entities.
///
/// Derives from MIDIObjectRef, does not have an owner object.
///
/// A MIDI device, which either attaches directly to the computer and is controlled by a
/// MIDI driver, or which is "external," meaning that it is connected to a driver-controlled
/// device via a standard MIDI cable.
///
/// A MIDIDeviceRef has properties and contains MIDIEntityRef's.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midideviceref?language=objc)
pub type MIDIDeviceRef = MIDIObjectRef;

/// A MIDI entity, owned by a device, containing endpoints.
///
/// Derives from MIDIObjectRef, owned by a MIDIDeviceRef.
///
/// Devices may have multiple logically distinct sub-components, e.g. a MIDI synthesizer and
/// a pair of MIDI ports, both addressable via a USB port.
///
/// By grouping a device's endpoints into entities, the system has enough information for an
/// application to make reasonable assumptions about how to communicate in a bi-directional
/// manner with each entity, as is desirable in MIDI librarian applications.
///
/// These sub-components are MIDIEntityRef's.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midientityref?language=objc)
pub type MIDIEntityRef = MIDIObjectRef;

/// A MIDI source or destination, owned by an entity.
///
/// Derives from MIDIObjectRef, owned by a MIDIEntityRef, unless it is a virtual endpoint,
/// in which case there is no owning entity.
///
/// Entities have any number of MIDIEndpointRef's, sources and destinations of 16-channel
/// MIDI streams.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midiendpointref?language=objc)
pub type MIDIEndpointRef = MIDIObjectRef;

/// A host clock time.
///
/// A host clock time representing the time of an event, as returned by
/// mach_absolute_time() or UpTime().
///
/// Since MIDI applications will tend to do a fair amount of math with the times of events,
/// it's more convenient to use a UInt64 than an AbsoluteTime.
///
/// See CoreAudio/HostTime.h.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/miditimestamp?language=objc)
pub type MIDITimeStamp = u64;

/// Signifies the type of a MIDIObject.
///
/// Signifies the real type of a MIDIObjectRef instance.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midiobjecttype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MIDIObjectType(pub i32);
impl MIDIObjectType {
    #[doc(alias = "kMIDIObjectType_Other")]
    pub const Other: Self = Self(-1);
    #[doc(alias = "kMIDIObjectType_Device")]
    pub const Device: Self = Self(0);
    #[doc(alias = "kMIDIObjectType_Entity")]
    pub const Entity: Self = Self(1);
    #[doc(alias = "kMIDIObjectType_Source")]
    pub const Source: Self = Self(2);
    #[doc(alias = "kMIDIObjectType_Destination")]
    pub const Destination: Self = Self(3);
    #[doc(alias = "kMIDIObjectType_ExternalDevice")]
    pub const ExternalDevice: Self = Self(0x10 | MIDIObjectType::Device.0);
    #[doc(alias = "kMIDIObjectType_ExternalEntity")]
    pub const ExternalEntity: Self = Self(0x10 | MIDIObjectType::Entity.0);
    #[doc(alias = "kMIDIObjectType_ExternalSource")]
    pub const ExternalSource: Self = Self(0x10 | MIDIObjectType::Source.0);
    #[doc(alias = "kMIDIObjectType_ExternalDestination")]
    pub const ExternalDestination: Self = Self(0x10 | MIDIObjectType::Destination.0);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for MIDIObjectType {
    const ENCODING: Encoding = i32::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for MIDIObjectType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidiobjecttype_externalmask?language=objc)
pub static kMIDIObjectType_ExternalMask: MIDIObjectType = MIDIObjectType(0x10);

/// A unique identifier for a MIDIObjectRef.
///
/// An integer which uniquely identifies a MIDIObjectRef.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midiuniqueid?language=objc)
pub type MIDIUniqueID = i32;

/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidiinvaliduniqueid?language=objc)
pub const kMIDIInvalidUniqueID: MIDIUniqueID = 0;

/// Specifies a MIDI protocol variant.
///
/// MIDI 1.0.
///
/// MIDI 2.0.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midiprotocolid?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MIDIProtocolID(pub i32);
impl MIDIProtocolID {
    #[doc(alias = "kMIDIProtocol_1_0")]
    pub const Protocol_1_0: Self = Self(1);
    #[doc(alias = "kMIDIProtocol_2_0")]
    pub const Protocol_2_0: Self = Self(2);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for MIDIProtocolID {
    const ENCODING: Encoding = i32::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for MIDIProtocolID {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// A callback function for notifying clients of state changes.
///
/// This callback function is called when some aspect of the current MIDI setup changes. It
/// is called on the runloop (thread) on which MIDIClientCreate was first called.
///
///
/// Parameter `message`: A structure containing information about what changed.
///
/// Parameter `refCon`: The client's refCon passed to MIDIClientCreate.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midinotifyproc?language=objc)
pub type MIDINotifyProc =
    Option<unsafe extern "C-unwind" fn(NonNull<MIDINotification>, *mut c_void)>;

/// A callback block for notifying clients of state changes.
///
/// This block is called when some aspect of the current MIDI setup changes. It
/// is called on an arbitrary thread chosen by the implementation; thread-safety
/// is the responsibility of the block.
///
///
/// Parameter `message`: A structure containing information about what changed.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midinotifyblock?language=objc)
#[cfg(feature = "block2")]
pub type MIDINotifyBlock = *mut block2::DynBlock<dyn Fn(NonNull<MIDINotification>)>;

/// A block receiving MIDI input.
///
/// This is a callback block through which a client receives incoming MIDI messages.
///
/// A MIDIReceiveBlock is passed to the MIDIInputPortCreateWithProtocol and
/// MIDIDestinationCreateWithProtocol functions.  The CoreMIDI framework will create a
/// high-priority receive thread on your client's behalf, and from that thread, your
/// MIDIReceiveBlock will be called when incoming MIDI messages arrive.
///
///
/// Parameter `evtlist`: The incoming MIDI message(s).
///
/// Parameter `srcConnRefCon`: A refCon you passed to MIDIPortConnectSource, which
/// identifies the source of the data.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midireceiveblock?language=objc)
#[cfg(feature = "block2")]
pub type MIDIReceiveBlock = *mut block2::DynBlock<dyn Fn(NonNull<MIDIEventList>, *mut c_void)>;

/// A function receiving MIDI input.
///
/// This is a callback function through which a client receives incoming MIDI messages.
///
/// A MIDIReadProc function pointer is passed to the MIDIInputPortCreate and
/// MIDIDestinationCreate functions.  The CoreMIDI framework will create a high-priority
/// receive thread on your client's behalf, and from that thread, your MIDIReadProc will be
/// called when incoming MIDI messages arrive.
///
///
/// Parameter `pktlist`: The incoming MIDI message(s).
///
/// Parameter `readProcRefCon`: The refCon you passed to MIDIInputPortCreate or
/// MIDIDestinationCreate
///
/// Parameter `srcConnRefCon`: A refCon you passed to MIDIPortConnectSource, which
/// identifies the source of the data.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midireadproc?language=objc)
#[deprecated = "use MIDIReceiveBlock and MIDIEventLists"]
pub type MIDIReadProc =
    Option<unsafe extern "C-unwind" fn(NonNull<MIDIPacketList>, *mut c_void, *mut c_void)>;

/// A block receiving MIDI input.
///
/// This is a callback block through which a client receives incoming MIDI messages.
///
/// A MIDIReadBlock is passed to the MIDIInputPortCreateWithBlock and
/// MIDIDestinationCreateWithBlock functions.  The CoreMIDI framework will create a
/// high-priority receive thread on your client's behalf, and from that thread, your
/// MIDIReadProc will be called when incoming MIDI messages arrive.
///
///
/// Parameter `pktlist`: The incoming MIDI message(s).
///
/// Parameter `srcConnRefCon`: A refCon you passed to MIDIPortConnectSource, which
/// identifies the source of the data.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midireadblock?language=objc)
#[deprecated = "use MIDIReceiveBlock and MIDIEventLists"]
#[cfg(feature = "block2")]
pub type MIDIReadBlock = *mut block2::DynBlock<dyn Fn(NonNull<MIDIPacketList>, *mut c_void)>;

/// A function called when a system-exclusive event has been completely sent.
///
/// Callback function to notify the client of the completion of a call to MIDISendSysex.
///
///
/// Parameter `request`: The MIDISysexSendRequest which has completed, or been
/// aborted.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midicompletionproc?language=objc)
pub type MIDICompletionProc = Option<unsafe extern "C-unwind" fn(NonNull<MIDISysexSendRequest>)>;

/// A function called when a UMP system-exclusive or system-exclusive 8-bit event has been completely sent.
///
/// Callback function to notify the client of the completion of a call to MIDISendSysexUMP or MIDISendSysex8.
///
///
/// Parameter `request`: The MIDISysexSendRequestUMP which has completed, or been
/// aborted.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midicompletionprocump?language=objc)
pub type MIDICompletionProcUMP =
    Option<unsafe extern "C-unwind" fn(NonNull<MIDISysexSendRequestUMP>)>;

/// A series of simultaneous MIDI events in UMP format.
///
///
/// WARNING: When using MIDIEventPacket in C++ be aware of the following:
///
/// MIDIEventPacket is a variable-length struct and should ALWAYS be passed-by-pointer
/// rather than passed-by-reference. Conversion from a MIDIEventPacket reference to a pointer
/// is undefined behavior and can lead to the unintended truncation of data.
///
/// Field: timeStamp
/// The time at which the events occurred, if receiving MIDI,
/// or, if sending MIDI, the time at which the events are to
/// be played.  Zero means "now."  The time stamp applies
/// applies to each UMP in the word stream.
/// Field: wordCount
/// The number of valid MIDI 32-bit words which follow, in data. (It
/// may be larger than 64 words if the packet is dynamically
/// allocated.)
/// Field: words
/// A variable-length stream of native-endian 32-bit Universal MIDI Packets.
/// Running status is not allowed.  In the case of system-exclusive
/// messages, a packet may only contain a single message, or portion
/// of one, with no other MIDI events.
///
/// Messages must always be syntactically complete; for example, for 64-bit
/// message types, both words must be present in the same packet. The same
/// MIDI message constraints from above apply here.
///
/// (This is declared to be 64 words in length so clients don't have to
/// create custom data structures in simple situations.)
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midieventpacket?language=objc)
#[repr(C, packed(4))]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MIDIEventPacket {
    pub timeStamp: MIDITimeStamp,
    pub wordCount: u32,
    pub words: [u32; 64],
}

#[cfg(feature = "objc2")]
unsafe impl Encode for MIDIEventPacket {
    const ENCODING: Encoding = Encoding::Struct(
        "MIDIEventPacket",
        &[
            <MIDITimeStamp>::ENCODING,
            <u32>::ENCODING,
            <[u32; 64]>::ENCODING,
        ],
    );
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for MIDIEventPacket {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// A variable-length list of MIDIEventPackets.
///
///
/// The timestamps in the list must be in ascending order.
///
/// Note that the packets in the list, while defined as an array, may not be
/// accessed as an array, since they are variable-length.  To iterate through
/// the packets in an event list, use a loop such as:
///
/// ```text
/// MIDIEventPacket *packet =
/// &packetList
/// ->packet[0];
/// for (unsigned i = 0; i
/// <
/// packetList->numPackets; ++i) {
/// ...
/// packet = MIDIEventPacketNext(packet);
/// }
/// ```
///
/// WARNING: When using MIDIEventList in C++ be aware of the following:
///
/// MIDIEventList is a variable-length struct and should ALWAYS be passed-by-pointer
/// rather than passed-by-reference. Conversion from a MIDIEventList reference to a pointer
/// is undefined behavior and can lead to the unintended truncation of data.
///
/// Field: protocol
/// The MIDI protocol variant of the events in the list.
/// Field: numPackets
/// The number of MIDIEventPacket structs in the list.
/// Field: packet
/// An open-ended array of variable-length MIDIEventPacket structs.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midieventlist?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MIDIEventList {
    pub protocol: MIDIProtocolID,
    pub numPackets: u32,
    pub packet: [MIDIEventPacket; 1],
}

#[cfg(feature = "objc2")]
unsafe impl Encode for MIDIEventList {
    const ENCODING: Encoding = Encoding::Struct(
        "MIDIEventList",
        &[
            <MIDIProtocolID>::ENCODING,
            <u32>::ENCODING,
            <[MIDIEventPacket; 1]>::ENCODING,
        ],
    );
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for MIDIEventList {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// A collection of simultaneous MIDI events.
///
///
/// WARNING: When using MIDIPacket in C++ be aware of the following:
///
/// MIDIPacket is a variable-length struct and should ALWAYS be passed-by-pointer
/// rather than passed-by-reference. Conversion from a MIDIPacket reference to a pointer
/// is undefined behavior and can lead to the unintended truncation of data.
///
/// Field: timeStamp
/// The time at which the events occurred, if receiving MIDI,
/// or, if sending MIDI, the time at which the events are to
/// be played.  Zero means "now."  The time stamp applies
/// to the first MIDI byte in the packet.
/// Field: length
/// The number of valid MIDI bytes which follow, in data. (It
/// may be larger than 256 bytes if the packet is dynamically
/// allocated.)
/// Field: data
/// A variable-length stream of MIDI messages.  Running status
/// is not allowed.  In the case of system-exclusive
/// messages, a packet may only contain a single message, or
/// portion of one, with no other MIDI events.
///
/// The MIDI messages in the packet must always be complete,
/// except for system-exclusive.
///
/// (This is declared to be 256 bytes in length so clients
/// don't have to create custom data structures in simple
/// situations.)
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midipacket?language=objc)
#[repr(C, packed(4))]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MIDIPacket {
    pub timeStamp: MIDITimeStamp,
    pub length: u16,
    pub data: [Byte; 256],
}

#[cfg(feature = "objc2")]
unsafe impl Encode for MIDIPacket {
    const ENCODING: Encoding = Encoding::Struct(
        "MIDIPacket",
        &[
            <MIDITimeStamp>::ENCODING,
            <u16>::ENCODING,
            <[Byte; 256]>::ENCODING,
        ],
    );
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for MIDIPacket {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// A list of MIDI events being received from, or being sent to,
/// one endpoint.
///
///
/// The timestamps in the packet list must be in ascending order.
///
/// Note that the packets in the list, while defined as an array, may not be
/// accessed as an array, since they are variable-length.  To iterate through
/// the packets in a packet list, use a loop such as:
///
/// ```text
/// MIDIPacket *packet =
/// &packetList
/// ->packet[0];
/// for (unsigned i = 0; i
/// <
/// packetList->numPackets; ++i) {
/// ...
/// packet = MIDIPacketNext(packet);
/// }
/// ```
///
/// The MIDIPacketNext macro is especially important when considering that
/// the alignment requirements of MIDIPacket may differ between CPU architectures.
/// On Intel and PowerPC, MIDIPacket is unaligned. On ARM, MIDIPacket must be
/// 4-byte aligned.
///
/// WARNING: When using MIDIPacketList in C++ be aware of the following:
///
/// MIDIPacketList is a variable-length struct and should ALWAYS be passed-by-pointer
/// rather than passed-by-reference. Conversion from a MIDIPacketList reference to a pointer
/// is undefined behavior and can lead to the unintended truncation of data.
///
/// Field: numPackets
/// The number of MIDIPackets in the list.
/// Field: packet
/// An open-ended array of variable-length MIDIPackets.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midipacketlist?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MIDIPacketList {
    pub numPackets: u32,
    pub packet: [MIDIPacket; 1],
}

#[cfg(feature = "objc2")]
unsafe impl Encode for MIDIPacketList {
    const ENCODING: Encoding = Encoding::Struct(
        "MIDIPacketList",
        &[<u32>::ENCODING, <[MIDIPacket; 1]>::ENCODING],
    );
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for MIDIPacketList {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// A request to transmit a system-exclusive event.
///
///
/// This represents a request to send a single system-exclusive MIDI event to
/// a MIDI destination asynchronously.
///
/// Field: destination
/// The endpoint to which the event is to be sent.
/// Field: data
/// Initially, a pointer to the sys-ex event to be sent.
/// MIDISendSysex will advance this pointer as bytes are
/// sent.
/// Field: bytesToSend
/// Initially, the number of bytes to be sent.  MIDISendSysex
/// will decrement this counter as bytes are sent.
/// Field: complete
/// The client may set this to true at any time to abort
/// transmission.  The implementation sets this to true when
/// all bytes have been sent.
/// Field: completionProc
/// Called when all bytes have been sent, or after the client
/// has set complete to true.
/// Field: completionRefCon
/// Passed as a refCon to completionProc.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midisysexsendrequest?language=objc)
#[repr(C)]
#[allow(unpredictable_function_pointer_comparisons)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MIDISysexSendRequest {
    pub destination: MIDIEndpointRef,
    pub data: NonNull<Byte>,
    pub bytesToSend: u32,
    pub complete: Boolean,
    pub reserved: [Byte; 3],
    pub completionProc: MIDICompletionProc,
    pub completionRefCon: *mut c_void,
}

#[cfg(feature = "objc2")]
unsafe impl Encode for MIDISysexSendRequest {
    const ENCODING: Encoding = Encoding::Struct(
        "MIDISysexSendRequest",
        &[
            <MIDIEndpointRef>::ENCODING,
            <NonNull<Byte>>::ENCODING,
            <u32>::ENCODING,
            <Boolean>::ENCODING,
            <[Byte; 3]>::ENCODING,
            <MIDICompletionProc>::ENCODING,
            <*mut c_void>::ENCODING,
        ],
    );
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for MIDISysexSendRequest {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// A request to transmit a UMP system-exclusive event.
///
///
/// This represents a request to send a single UMP system-exclusive MIDI event to
/// a MIDI destination asynchronously.
///
/// Field: destination
/// The endpoint to which the event is to be sent.
/// Field: words
/// Initially, a pointer to the UMP SysEx event to be sent.
/// MIDISendUMPSysex will advance this pointer as data is
/// sent.
/// Field: wordsToSend
/// Initially, the number of words to be sent.  MIDISendUMPSysex
/// will decrement this counter as data is sent.
/// Field: complete
/// The client may set this to true at any time to abort
/// transmission.  The implementation sets this to true when
/// all data been transmitted.
/// Field: completionProc
/// Called when all bytes have been sent, or after the client
/// has set complete to true.
/// Field: completionRefCon
/// Passed as a refCon to completionProc.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midisysexsendrequestump?language=objc)
#[repr(C)]
#[allow(unpredictable_function_pointer_comparisons)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MIDISysexSendRequestUMP {
    pub destination: MIDIEndpointRef,
    pub words: NonNull<u32>,
    pub wordsToSend: u32,
    pub complete: Boolean,
    pub completionProc: MIDICompletionProcUMP,
    pub completionRefCon: *mut c_void,
}

#[cfg(feature = "objc2")]
unsafe impl Encode for MIDISysexSendRequestUMP {
    const ENCODING: Encoding = Encoding::Struct(
        "MIDISysexSendRequestUMP",
        &[
            <MIDIEndpointRef>::ENCODING,
            <NonNull<u32>>::ENCODING,
            <u32>::ENCODING,
            <Boolean>::ENCODING,
            <MIDICompletionProcUMP>::ENCODING,
            <*mut c_void>::ENCODING,
        ],
    );
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for MIDISysexSendRequestUMP {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Signifies the type of a MIDINotification.
///
///
/// Some aspect of the current MIDISetup has changed.  No data.  Should ignore this message if
/// messages 2-6 are handled.
///
/// A device, entity or endpoint was added. Structure is MIDIObjectAddRemoveNotification. New in
/// Mac OS X 10.2.
///
/// A device, entity or endpoint was removed. Structure is MIDIObjectAddRemoveNotification. New
/// in Mac OS X 10.2.
///
/// An object's property was changed. Structure is MIDIObjectPropertyChangeNotification. New in
/// Mac OS X 10.2.
///
/// A persistent MIDI Thru connection was created or destroyed.  No data.  New in Mac OS X 10.2.
///
/// No data.  New in Mac OS X 10.2.
///
/// A driver I/O error occurred.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midinotificationmessageid?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MIDINotificationMessageID(pub i32);
impl MIDINotificationMessageID {
    #[doc(alias = "kMIDIMsgSetupChanged")]
    pub const MsgSetupChanged: Self = Self(1);
    #[doc(alias = "kMIDIMsgObjectAdded")]
    pub const MsgObjectAdded: Self = Self(2);
    #[doc(alias = "kMIDIMsgObjectRemoved")]
    pub const MsgObjectRemoved: Self = Self(3);
    #[doc(alias = "kMIDIMsgPropertyChanged")]
    pub const MsgPropertyChanged: Self = Self(4);
    #[doc(alias = "kMIDIMsgThruConnectionsChanged")]
    pub const MsgThruConnectionsChanged: Self = Self(5);
    #[doc(alias = "kMIDIMsgSerialPortOwnerChanged")]
    pub const MsgSerialPortOwnerChanged: Self = Self(6);
    #[doc(alias = "kMIDIMsgIOError")]
    pub const MsgIOError: Self = Self(7);
    #[doc(alias = "kMIDIMsgInternalStart")]
    pub const MsgInternalStart: Self = Self(0x1000);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for MIDINotificationMessageID {
    const ENCODING: Encoding = i32::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for MIDINotificationMessageID {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// A message describing a system state change.
///
/// A MIDINotification is a structure passed to a MIDINotifyProc or MIDINotifyBlock, when
/// CoreMIDI wishes to inform a client of a change in the state of the system.
///
/// Field: messageID
/// type of message
/// Field: messageSize
/// size of the entire message, including messageID and
/// messageSize
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midinotification?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MIDINotification {
    pub messageID: MIDINotificationMessageID,
    pub messageSize: u32,
}

#[cfg(feature = "objc2")]
unsafe impl Encode for MIDINotification {
    const ENCODING: Encoding = Encoding::Struct(
        "MIDINotification",
        &[<MIDINotificationMessageID>::ENCODING, <u32>::ENCODING],
    );
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for MIDINotification {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// A message describing the addition or removal of an object.
///
/// Field: messageID
/// type of message
/// Field: messageSize
/// size of the entire message, including messageID and messageSize
/// Field: parent
/// the parent of the added or removed object (possibly NULL)
/// Field: parentType
/// the type of the parent object (undefined if parent is NULL)
/// Field: child
/// the added or removed object
/// Field: childType
/// the type of the added or removed object
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midiobjectaddremovenotification?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MIDIObjectAddRemoveNotification {
    pub messageID: MIDINotificationMessageID,
    pub messageSize: u32,
    pub parent: MIDIObjectRef,
    pub parentType: MIDIObjectType,
    pub child: MIDIObjectRef,
    pub childType: MIDIObjectType,
}

#[cfg(feature = "objc2")]
unsafe impl Encode for MIDIObjectAddRemoveNotification {
    const ENCODING: Encoding = Encoding::Struct(
        "MIDIObjectAddRemoveNotification",
        &[
            <MIDINotificationMessageID>::ENCODING,
            <u32>::ENCODING,
            <MIDIObjectRef>::ENCODING,
            <MIDIObjectType>::ENCODING,
            <MIDIObjectRef>::ENCODING,
            <MIDIObjectType>::ENCODING,
        ],
    );
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for MIDIObjectAddRemoveNotification {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// A message describing the addition or removal of an object.
///
/// Field: messageID
/// type of message
/// Field: messageSize
/// size of the entire message, including messageID and messageSize
/// Field: object
/// the object whose property has changed
/// Field: objectType
/// the type of the object whose property has changed
/// Field: propertyName
/// the name of the changed property
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midiobjectpropertychangenotification?language=objc)
#[cfg(feature = "objc2-core-foundation")]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MIDIObjectPropertyChangeNotification {
    pub messageID: MIDINotificationMessageID,
    pub messageSize: u32,
    pub object: MIDIObjectRef,
    pub objectType: MIDIObjectType,
    pub propertyName: NonNull<CFString>,
}

#[cfg(all(feature = "objc2", feature = "objc2-core-foundation"))]
unsafe impl Encode for MIDIObjectPropertyChangeNotification {
    const ENCODING: Encoding = Encoding::Struct(
        "MIDIObjectPropertyChangeNotification",
        &[
            <MIDINotificationMessageID>::ENCODING,
            <u32>::ENCODING,
            <MIDIObjectRef>::ENCODING,
            <MIDIObjectType>::ENCODING,
            <NonNull<CFString>>::ENCODING,
        ],
    );
}

#[cfg(all(feature = "objc2", feature = "objc2-core-foundation"))]
unsafe impl RefEncode for MIDIObjectPropertyChangeNotification {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/coremidi/midiioerrornotification?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MIDIIOErrorNotification {
    pub messageID: MIDINotificationMessageID,
    pub messageSize: u32,
    pub driverDevice: MIDIDeviceRef,
    pub errorCode: OSStatus,
}

#[cfg(feature = "objc2")]
unsafe impl Encode for MIDIIOErrorNotification {
    const ENCODING: Encoding = Encoding::Struct(
        "MIDIIOErrorNotification",
        &[
            <MIDINotificationMessageID>::ENCODING,
            <u32>::ENCODING,
            <MIDIDeviceRef>::ENCODING,
            <OSStatus>::ENCODING,
        ],
    );
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for MIDIIOErrorNotification {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern "C" {
    /// device/entity/endpoint property, string
    ///
    /// Devices, entities, and endpoints may all have names.  The recommended way to display an
    /// endpoint's name is to ask for the endpoint name, and display only that name if it is
    /// unique.  If it is non-unique, prepend the device name.
    ///
    /// A setup editor may allow the user to set the names of both driver-owned and external
    /// devices.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyname?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyName: &'static CFString;
}

extern "C" {
    /// device/endpoint property, string
    ///
    /// Drivers should set this property on their devices.
    ///
    /// Setup editors may allow the user to set this property on external devices.
    ///
    /// Creators of virtual endpoints may set this property on their endpoints.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertymanufacturer?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyManufacturer: &'static CFString;
}

extern "C" {
    /// device/endpoint property, string
    ///
    /// Drivers should set this property on their devices.
    ///
    /// Setup editors may allow the user to set this property on external devices.
    ///
    /// Creators of virtual endpoints may set this property on their endpoints.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertymodel?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyModel: &'static CFString;
}

extern "C" {
    /// devices, entities, endpoints all have unique ID's, integer
    ///
    /// The system assigns unique ID's to all objects.  Creators of virtual endpoints may set
    /// this property on their endpoints, though doing so may fail if the chosen ID is not
    /// unique.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyuniqueid?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyUniqueID: &'static CFString;
}

extern "C" {
    /// device/entity property, integer
    ///
    /// The entity's system-exclusive ID, in user-visible form
    ///
    /// Drivers may set this property on their devices or entities.
    ///
    /// Setup editors may allow the user to set this property on external devices.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertydeviceid?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyDeviceID: &'static CFString;
}

extern "C" {
    /// endpoint property, integer
    ///
    /// The value is a bitmap of channels on which the object receives: 1=ch 1, 2=ch 2, 4=ch 3
    /// ... 0x8000=ch 16.
    ///
    /// Drivers may set this property on their entities or endpoints.
    ///
    /// Setup editors may allow the user to set this property on external endpoints.
    ///
    /// Virtual destination may set this property on their endpoints.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyreceivechannels?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyReceiveChannels: &'static CFString;
}

extern "C" {
    /// endpoint property, integer
    ///
    /// The value is a bitmap of channels on which the object transmits: 1=ch 1, 2=ch 2, 4=ch 3
    /// ... 0x8000=ch 16.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertytransmitchannels?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyTransmitChannels: &'static CFString;
}

extern "C" {
    /// device/entity/endpoint property, integer
    ///
    /// Set by the owning driver; should not be touched by other clients.
    /// The value is the maximum rate, in bytes/second, at which sysex messages may
    /// be sent reliably to this object. (The default value is 3125, as with MIDI 1.0)
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertymaxsysexspeed?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyMaxSysExSpeed: &'static CFString;
}

extern "C" {
    /// device/entity/endpoint property, integer
    ///
    /// Set by the owning driver; should not be touched by other clients. If it is non-zero,
    /// then it is a recommendation of how many microseconds in advance clients should schedule
    /// output. Clients should treat this value as a minimum.  For devices with a non-zero
    /// advance schedule time, drivers will receive outgoing messages to the device at the time
    /// they are sent by the client, via MIDISend, and the driver is responsible for scheduling
    /// events to be played at the right times according to their timestamps.
    ///
    /// As of CoreMIDI 1.3, this property may also be set on virtual destinations (but only the
    /// creator of the destination should do so). When a client sends to a virtual destination
    /// with an advance schedule time of 0, the virtual destination receives its messages at
    /// their scheduled delivery time.  If a virtual destination has a non-zero advance schedule
    /// time, it receives timestamped messages as soon as they are sent, and must do its own
    /// internal scheduling of received events.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyadvancescheduletimemusec?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyAdvanceScheduleTimeMuSec: &'static CFString;
}

extern "C" {
    /// entity/endpoint property, integer
    ///
    /// 0 if there are external MIDI connectors, 1 if not.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyisembeddedentity?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyIsEmbeddedEntity: &'static CFString;
}

extern "C" {
    /// entity/endpoint property, integer
    ///
    /// 1 if the endpoint broadcasts messages to all of the other endpoints in the device, 0 if
    /// not.  Set by the owning driver; should not be touched by other clients.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyisbroadcast?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyIsBroadcast: &'static CFString;
}

extern "C" {
    /// device property, integer
    ///
    /// Some MIDI interfaces cannot route MIDI realtime messages to individual outputs; they are
    /// broadcast.  On such devices the inverse is usually also true -- incoming realtime
    /// messages cannot be identified as originating from any particular source.
    ///
    /// When this property is set on a driver device, it signifies the 0-based index of the
    /// entity on which incoming realtime messages from the device will appear to have
    /// originated from.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertysinglerealtimeentity?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertySingleRealtimeEntity: &'static CFString;
}

extern "C" {
    /// device/entity/endpoint property, integer or CFDataRef
    ///
    /// UniqueID of an external device/entity/endpoint attached to this one. As of Mac OS X
    /// 10.3, Audio MIDI Setup maintains endpoint-to-external endpoint connections (in 10.2, it
    /// connected devices to devices).
    ///
    /// The property is non-existant or 0 if there is no connection.
    ///
    /// Beginning with CoreMIDI 1.3 (Mac OS X 10.2), this property may also be a CFDataRef containing an array of
    /// big-endian SInt32's, to allow specifying that a driver object connects to multiple
    /// external objects (via MIDI thru-ing or splitting).
    ///
    /// This property may also exist for external devices/entities/endpoints, in which case it
    /// signifies a MIDI Thru connection to another external device/entity/endpoint (again,
    /// it is strongly recommended that it be an endpoint).
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyconnectionuniqueid?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyConnectionUniqueID: &'static CFString;
}

extern "C" {
    /// device/entity/endpoint property, integer
    ///
    /// 1 = device is offline (is temporarily absent), 0 = present. Set by the owning driver, on
    /// the device; should not be touched by other clients. Property is inherited from the
    /// device by its entities and endpoints.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyoffline?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyOffline: &'static CFString;
}

extern "C" {
    /// device/entity/endpoint property, integer
    ///
    /// 1 = endpoint is private, hidden from other clients. May be set on a device or entity,
    /// but they will still appear in the API; only affects whether the owned endpoints are
    /// hidden.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyprivate?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyPrivate: &'static CFString;
}

extern "C" {
    /// device/entity/endpoint property, string
    ///
    /// Name of the driver that owns a device. Set by the owning driver, on the device; should
    /// not be touched by other clients. Property is inherited from the device by its entities
    /// and endpoints.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertydriverowner?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyDriverOwner: &'static CFString;
}

extern "C" {
    /// device/entity/endpoint property, CFData containing AliasHandle.
    ///
    /// An alias to the device's current factory patch name file.
    ///
    /// Added in CoreMIDI 1.1 (Mac OS X 10.1).  DEPRECATED as of CoreMIDI 1.3. Use
    /// kMIDIPropertyNameConfiguration instead.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyfactorypatchnamefile?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated]
    pub static kMIDIPropertyFactoryPatchNameFile: &'static CFString;
}

extern "C" {
    /// device/entity/endpoint property, CFData containing AliasHandle
    ///
    /// An alias to the device's current user patch name file.
    ///
    /// Added in CoreMIDI 1.1 (Mac OS X 10.1).  DEPRECATED as of CoreMIDI 1.3. Use
    /// kMIDIPropertyNameConfiguration instead.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyuserpatchnamefile?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated]
    pub static kMIDIPropertyUserPatchNameFile: &'static CFString;
}

extern "C" {
    /// device/entity/endpoint property, CFDictionary
    ///
    /// This specifies the device's current patch, note and control name values using the
    /// MIDINameDocument XML format.  This specification requires the use of higher-level,
    /// OS-specific constructs outside of the specification to fully define the current names
    /// for a device.
    ///
    /// The MIDINameConfiguration property is implementated as a CFDictionary:
    ///
    /// key "master" maps to a CFDataRef containing an AliasHandle referring to the device's
    /// master name document. This is deprecated as of Mac OS X 10.10.
    ///
    /// key "masterDocumentPath" maps to a CFStringRef containing the filesystem path to the device's
    /// master name document. (This is new as of Mac OS X 10.10, but since the CoreMIDI
    /// implementation does not parse this dictionary, the convention can be safely ported
    /// to earlier versions of Mac OS X.)
    ///
    /// key "banks" maps to a CFDictionaryRef.  This dictionary's keys are CFStringRef names of
    /// patchBank elements in the master document, and its values are each a CFDictionaryRef:
    /// key "file" maps to a CFDataRef containing an AliasHandle to a document containing
    /// patches that override those in the master document, and key "patchNameList" maps to a
    /// CFStringRef which is the name of the patchNameList element in the overriding document.
    ///
    /// key "currentChannelNameSets" maps to a 16-element CFArrayRef, each element of which is a
    /// CFStringRef of the name of the current mode for each of the 16 MIDI channels.
    ///
    /// key "currentDeviceMode" maps to a CFStringRef containing the name of the device's mode.
    ///
    /// Clients setting this property must take particular care to preserve dictionary values
    /// other than the ones they are interested in changing and to properly structure the
    /// dictionary.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertynameconfiguration?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated]
    pub static kMIDIPropertyNameConfiguration: &'static CFString;
}

extern "C" {
    /// device/entity/endpoint property, CFDictionary
    ///
    /// This specifies the device's current patch, note and control name values using the
    /// MIDINameDocument XML format.  This specification requires the use of higher-level,
    /// OS-specific constructs outside of the specification to fully define the current names
    /// for a device.
    ///
    /// The MIDINameConfiguration property is implementated as a CFDictionary:
    ///
    /// key "masterDocumentPath" maps to a CFStringRef containing the filesystem path to the device's
    /// master name document.
    ///
    /// key "banks" maps to a CFDictionaryRef.  This dictionary's keys are CFStringRef names of
    /// patchBank elements in the master document, and its values are each a CFDictionaryRef:
    /// key "file" maps to a CFDataRef containing URL bookmark data to a document containing
    /// patches that override those in the master document, and key "patchNameList" maps to a
    /// CFStringRef which is the name of the patchNameList element in the overriding document.
    ///
    /// key "currentChannelNameSets" maps to a 16-element CFArrayRef, each element of which is a
    /// CFStringRef of the name of the current mode for each of the 16 MIDI channels.
    ///
    /// key "currentDeviceMode" maps to a CFStringRef containing the name of the device's mode.
    ///
    /// Clients setting this property must take particular care to preserve dictionary values
    /// other than the ones they are interested in changing and to properly structure the
    /// dictionary.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertynameconfigurationdictionary?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyNameConfigurationDictionary: &'static CFString;
}

extern "C" {
    /// device property, CFStringRef which is a full POSIX path to a device or external device's
    /// icon, stored in any standard graphic file format such as JPEG, GIF, PNG and TIFF are all
    /// acceptable.  (See CFURL for functions to convert between POSIX paths and other ways of
    /// specifying files.)  The image's maximum size should be 128x128.
    ///
    /// Drivers should set the icon on the devices they add.
    ///
    /// A studio setup editor should allow the user to choose icons for external devices.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyimage?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyImage: &'static CFString;
}

extern "C" {
    /// device/entity/endpoint property, integer, returns the driver version API of the owning
    /// driver (only for driver- owned devices).  Drivers need not set this property;
    /// applications should not write to it.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertydriverversion?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyDriverVersion: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity implements
    /// the General MIDI specification.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertysupportsgeneralmidi?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertySupportsGeneralMIDI: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity implements
    /// the MIDI Machine Control portion of the MIDI specification.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertysupportsmmc?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertySupportsMMC: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity can route
    /// MIDI messages to or from other external MIDI devices (as with MIDI patch bays). This
    /// should NOT be set on devices which are controlled by drivers.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertycanroute?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyCanRoute: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity  responds
    /// to MIDI beat clock messages.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyreceivesclock?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyReceivesClock: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity responds
    /// to MIDI Time Code messages.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyreceivesmtc?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyReceivesMTC: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity responds
    /// to MIDI Note On messages.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyreceivesnotes?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyReceivesNotes: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity responds
    /// to MIDI program change messages.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyreceivesprogramchanges?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyReceivesProgramChanges: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity responds
    /// to MIDI bank select MSB messages (control 0).
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyreceivesbankselectmsb?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyReceivesBankSelectMSB: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity responds
    /// to MIDI bank select LSB messages (control 32).
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyreceivesbankselectlsb?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyReceivesBankSelectLSB: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity transmits
    /// MIDI beat clock messages.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertytransmitsclock?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyTransmitsClock: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity transmits
    /// MIDI Time Code messages.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertytransmitsmtc?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyTransmitsMTC: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity transmits
    /// MIDI note messages.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertytransmitsnotes?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyTransmitsNotes: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity transmits
    /// MIDI program change messages.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertytransmitsprogramchanges?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyTransmitsProgramChanges: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity transmits
    /// MIDI bank select MSB messages (control 0).
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertytransmitsbankselectmsb?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyTransmitsBankSelectMSB: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity transmits
    /// MIDI bank select LSB messages (control 32).
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertytransmitsbankselectlsb?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyTransmitsBankSelectLSB: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the MIDI pan messages (control
    /// 10), when sent to the device or entity, cause undesirable effects when playing stereo
    /// sounds (e.g. converting the signal to mono).
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertypandisruptsstereo?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyPanDisruptsStereo: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity plays
    /// audio samples in response to MIDI note messages.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyissampler?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyIsSampler: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity's sound
    /// presets tend to be collections of non-transposable samples (e.g. drum kits).
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyisdrummachine?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyIsDrumMachine: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity mixes
    /// external audio signals, controlled by MIDI messages.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyismixer?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyIsMixer: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device or entity is
    /// primarily a MIDI-controlled audio effect unit (i.e. does not generate sound on its own).
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyiseffectunit?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyIsEffectUnit: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0-16). Indicates the maximum number of MIDI channels on
    /// which a device may simultaneously receive MIDI Channel Messages. Common values are 0
    /// (devices which only respond to System Messages), 1 (non-multitimbral devices), and 16
    /// (fully multitimbral devices). Other values are possible, for example devices which are
    /// multi-timbral but have fewer than 16 "parts".
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertymaxreceivechannels?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyMaxReceiveChannels: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates the maximum number of MIDI channels on
    /// which a device may simultaneously transmit MIDI Channel Messages. Common values are 0, 1
    /// and 16.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertymaxtransmitchannels?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyMaxTransmitChannels: &'static CFString;
}

extern "C" {
    /// device property, string, contains the full path to an application which knows how to
    /// configure this driver-owned devices. Drivers may set this property on their owned
    /// devices. Applications must not write to it.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertydriverdeviceeditorapp?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyDriverDeviceEditorApp: &'static CFString;
}

extern "C" {
    /// device/entity property, integer (0/1). Indicates whether the device implements the MIDI
    /// Show Control specification.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertysupportsshowcontrol?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertySupportsShowControl: &'static CFString;
}

extern "C" {
    /// device/entity/endpoint property, string.
    ///
    /// Provides the Apple-recommended user-visible name for an endpoint, by combining the
    /// device and endpoint names.
    ///
    /// For objects other than endpoints, the display name is the same as the name.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertydisplayname?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyDisplayName: &'static CFString;
}

extern "C" {
    /// constant        kMIDIPropertyProtocolID
    ///
    /// device/entity/endpoint property (UMP-native), MIDIProtocolID. Indicates the native protocol in which
    /// the endpoint communicates. The value is set by the system on endpoints, when they are
    /// created. Drivers may dynamically change the protocol of an endpoint as a result of a MIDI-CI
    /// negotiation, by setting this property on the endpoint. Clients can observe changes to
    /// this property.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyprotocolid?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyProtocolID: &'static CFString;
}

extern "C" {
    /// constant        kMIDIPropertyUMPActiveGroupBitmap
    ///
    /// entity and endpoint property (UMP-native), 16-bit unsigned integer. If present, describes which
    /// groups are currently active and available for message transmission. The most significant bit
    /// represents group 16, and the least significant bit represents group 1.
    ///
    /// If a driver sets this property on a UMP-native endpoint provided for legacy MIDI 1.0 compatibility,
    /// only a single bit of the bitfield may be used. As a convenience, MIDI messages sent to a driver-
    /// created destination provided for legacy MIDI 1.0 compatibility will have all messages converted
    /// to the supported group prior to delivery.
    ///
    /// Any UMP-native endpoint lacking this property and subsequently defined property
    /// kMIDIPropertyCanTransmitGroupless is assumed to handle/transmit all UMP traffic.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyumpactivegroupbitmap?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyUMPActiveGroupBitmap: &'static CFString;
}

extern "C" {
    /// constant        kMIDIPropertyUMPCanTransmitGroupless
    ///
    /// entity and endpoint property (UMP-native), integer. If this property is present and set to 1,
    /// the referenced MIDI object is or has (an) endpoint/endpoints capable of transmitting UMP
    /// messages with no group (e.g., message type 0 and message type F).
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyumpcantransmitgroupless?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyUMPCanTransmitGroupless: &'static CFString;
}

extern "C" {
    /// constant        kMIDIPropertyAssociatedEndpoint
    ///
    /// endpoint property, MIDIUniqueID. If this property is present, the indicated endpoint should be
    /// used for bidirectional communication purposes, (e.g. UMP Endpoint pairing or MIDI-CI devices).
    /// When setting this property on an endpoint, it should also be set on the assocated endpoint to
    /// create a bidirectional mapping.
    ///
    /// Note: This value is a MIDIUniqueID, use MIDIObjectFindByUniqueID to resolve it to a MIDIObjectRef.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmidipropertyassociatedendpoint?language=objc)
    #[cfg(feature = "objc2-core-foundation")]
    pub static kMIDIPropertyAssociatedEndpoint: &'static CFString;
}

extern "C-unwind" {
    /// Creates a MIDIClient object.
    ///
    ///
    /// Parameter `name`: The client's name.
    ///
    /// Parameter `notifyProc`: An optional (may be NULL) callback function through which the client
    /// will receive notifications of changes to the system.
    ///
    /// Parameter `notifyRefCon`: A refCon passed back to notifyRefCon
    ///
    /// Parameter `outClient`: On successful return, points to the newly-created MIDIClientRef.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// Note that notifyProc will always be called on the run loop which was current when
    /// MIDIClientCreate was first called.
    ///
    /// # Safety
    ///
    /// - `notify_proc` must be implemented correctly.
    /// - `notify_ref_con` must be a valid pointer or null.
    /// - `out_client` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MIDIClientCreate(
        name: &CFString,
        notify_proc: MIDINotifyProc,
        notify_ref_con: *mut c_void,
        out_client: NonNull<MIDIClientRef>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Creates a MIDIClient object.
    ///
    ///
    /// Parameter `name`: The client's name.
    ///
    /// Parameter `outClient`: On successful return, points to the newly-created MIDIClientRef.
    ///
    /// Parameter `notifyBlock`: An optional (may be NULL) block via which the client
    /// will receive notifications of changes to the system.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// Note that notifyBlock is called on a thread chosen by the implementation.
    /// Thread-safety is the block's responsibility.
    ///
    /// # Safety
    ///
    /// - `out_client` must be a valid pointer.
    /// - `notify_block` must be a valid pointer or null.
    #[cfg(all(feature = "block2", feature = "objc2-core-foundation"))]
    pub fn MIDIClientCreateWithBlock(
        name: &CFString,
        out_client: NonNull<MIDIClientRef>,
        notify_block: MIDINotifyBlock,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Disposes a MIDIClient object.
    ///
    ///
    /// Parameter `client`: The client to dispose.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// It is not essential to call this function; the CoreMIDI framework will automatically
    /// dispose all MIDIClients when an application terminates. However, if this method is
    /// called to dispose the last/only MIDIClient owned by an application, the MIDI server may
    /// exit if there are no other MIDIClients remaining in the system, causing all subsequent calls
    /// to MIDIClientCreate and MIDIClientCreateWithBlock by that application to fail. For this reason,
    /// disposing all of an application's MIDIClients is strongly discouraged.
    pub fn MIDIClientDispose(client: MIDIClientRef) -> OSStatus;
}

extern "C-unwind" {
    /// Creates an input port through which the client may receive
    /// incoming MIDI messages from any MIDI source.
    ///
    ///
    /// Parameter `client`: The client to own the newly-created port.
    ///
    /// Parameter `portName`: The name of the port.
    ///
    /// Parameter `protocol`: The MIDI protocol variant to be delivered to this port. The system
    /// will automatically convert to this protocol as needed.
    ///
    /// Parameter `outPort`: On successful return, points to the newly-created
    /// MIDIPort.
    ///
    /// Parameter `receiveBlock`: The MIDIReceiveBlock which will be called with incoming MIDI, from sources
    /// connected to this port.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// After creating a port, use MIDIPortConnectSource to establish an input connection from
    /// any number of sources to your port.
    ///
    /// readBlock will be called on a separate high-priority thread owned by CoreMIDI.
    ///
    /// # Safety
    ///
    /// - `out_port` must be a valid pointer.
    /// - `receive_block` must be a valid pointer.
    #[cfg(all(feature = "block2", feature = "objc2-core-foundation"))]
    pub fn MIDIInputPortCreateWithProtocol(
        client: MIDIClientRef,
        port_name: &CFString,
        protocol: MIDIProtocolID,
        out_port: NonNull<MIDIPortRef>,
        receive_block: MIDIReceiveBlock,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Creates an input port through which the client may receive
    /// incoming MIDI messages from any MIDI source.
    ///
    ///
    /// Parameter `client`: The client to own the newly-created port.
    ///
    /// Parameter `portName`: The name of the port.
    ///
    /// Parameter `readProc`: The MIDIReadProc which will be called with incoming MIDI,
    /// from sources connected to this port.
    ///
    /// Parameter `refCon`: The refCon passed to readHook.
    ///
    /// Parameter `outPort`: On successful return, points to the newly-created
    /// MIDIPort.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// After creating a port, use MIDIPortConnectSource to establish an input connection from
    /// any number of sources to your port.
    ///
    /// readProc will be called on a separate high-priority thread owned by CoreMIDI.
    ///
    /// # Safety
    ///
    /// - `read_proc` must be implemented correctly.
    /// - `ref_con` must be a valid pointer or null.
    /// - `out_port` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated]
    pub fn MIDIInputPortCreate(
        client: MIDIClientRef,
        port_name: &CFString,
        read_proc: MIDIReadProc,
        ref_con: *mut c_void,
        out_port: NonNull<MIDIPortRef>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Creates an input port through which the client may receive
    /// incoming MIDI messages from any MIDI source.
    ///
    ///
    /// Parameter `client`: The client to own the newly-created port.
    ///
    /// Parameter `portName`: The name of the port.
    ///
    /// Parameter `outPort`: On successful return, points to the newly-created
    /// MIDIPort.
    ///
    /// Parameter `readBlock`: The MIDIReadBlock which will be called with incoming MIDI, from sources
    /// connected to this port.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// After creating a port, use MIDIPortConnectSource to establish an input connection from
    /// any number of sources to your port.
    ///
    /// readBlock will be called on a separate high-priority thread owned by CoreMIDI.
    ///
    /// # Safety
    ///
    /// - `out_port` must be a valid pointer.
    /// - `read_block` must be a valid pointer.
    #[cfg(all(feature = "block2", feature = "objc2-core-foundation"))]
    #[deprecated]
    pub fn MIDIInputPortCreateWithBlock(
        client: MIDIClientRef,
        port_name: &CFString,
        out_port: NonNull<MIDIPortRef>,
        read_block: MIDIReadBlock,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Creates an output port through which the client may send
    /// outgoing MIDI messages to any MIDI destination.
    ///
    ///
    /// Parameter `client`: The client to own the newly-created port
    ///
    /// Parameter `portName`: The name of the port.
    ///
    /// Parameter `outPort`: On successful return, points to the newly-created
    /// MIDIPort.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// Output ports provide a mechanism for MIDI merging.  CoreMIDI assumes that each output
    /// port will be responsible for sending only a single MIDI stream to each destination,
    /// although a single port may address all of the destinations in the system.
    ///
    /// Multiple output ports are only necessary when an application is capable of directing
    /// multiple simultaneous MIDI streams to the same destination.
    ///
    /// # Safety
    ///
    /// `out_port` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MIDIOutputPortCreate(
        client: MIDIClientRef,
        port_name: &CFString,
        out_port: NonNull<MIDIPortRef>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Disposes a MIDIPort object.
    ///
    ///
    /// Parameter `port`: The port to dispose.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// It is not usually necessary to call this function; when an application's MIDIClient's
    /// are automatically disposed at termination, or explicitly, via MIDIClientDispose, the
    /// client's ports are automatically disposed at that time.
    pub fn MIDIPortDispose(port: MIDIPortRef) -> OSStatus;
}

extern "C-unwind" {
    /// Establishes a connection from a source to a client's input port.
    ///
    ///
    /// Parameter `port`: The port to which to create the connection.  This port's
    /// readProc is called with incoming MIDI from the source.
    ///
    /// Parameter `source`: The source from which to create the connection.
    ///
    /// Parameter `connRefCon`: This refCon is passed to the port's MIDIReadProc or MIDIReadBlock, as a way to
    /// identify the source.
    ///
    /// Returns: An OSStatus result code.
    ///
    /// # Safety
    ///
    /// `conn_ref_con` must be a valid pointer or null.
    pub fn MIDIPortConnectSource(
        port: MIDIPortRef,
        source: MIDIEndpointRef,
        conn_ref_con: *mut c_void,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Closes a previously-established source-to-input port
    /// connection.
    ///
    ///
    /// Parameter `port`: The port whose connection is being closed.
    ///
    /// Parameter `source`: The source from which to close a connection to the
    /// specified port.
    ///
    /// Returns: An OSStatus result code.
    pub fn MIDIPortDisconnectSource(port: MIDIPortRef, source: MIDIEndpointRef) -> OSStatus;
}

extern "C-unwind" {
    /// Returns the number of devices in the system.
    ///
    ///
    /// Returns: The number of devices in the system, or 0 if an error
    /// occurred.
    pub fn MIDIGetNumberOfDevices() -> ItemCount;
}

extern "C-unwind" {
    /// Returns one of the devices in the system.
    ///
    ///
    /// Parameter `deviceIndex0`: The index (0...MIDIGetNumberOfDevices()-1) of the device
    /// to return.
    ///
    /// Returns: A reference to a device, or NULL if an error occurred.
    ///
    ///
    /// Use this to enumerate the devices in the system.
    ///
    /// To enumerate the entities in the system, you can walk through the devices, then walk
    /// through the devices' entities.
    ///
    /// Note: If a client iterates through the devices and entities in the system, it will not
    /// ever visit any virtual sources and destinations created by other clients.  Also, a
    /// device iteration will return devices which are "offline" (were present in the past but
    /// are not currently present), while iterations through the system's sources and
    /// destinations will not include the endpoints of offline devices.
    ///
    /// Thus clients should usually use MIDIGetNumberOfSources, MIDIGetSource,
    /// MIDIGetNumberOfDestinations and MIDIGetDestination, rather iterating through devices and
    /// entities to locate endpoints.
    pub fn MIDIGetDevice(device_index0: ItemCount) -> MIDIDeviceRef;
}

extern "C-unwind" {
    /// Returns the number of entities in a given device.
    ///
    ///
    /// Parameter `device`: The device being queried.
    ///
    ///
    /// Returns: The number of entities the device contains, or 0 if an
    /// error occurred.
    pub fn MIDIDeviceGetNumberOfEntities(device: MIDIDeviceRef) -> ItemCount;
}

extern "C-unwind" {
    /// Returns one of a given device's entities.
    ///
    ///
    /// Parameter `device`: The device being queried.
    ///
    /// Parameter `entityIndex0`: The index (0...MIDIDeviceGetNumberOfEntities(device)-1)
    /// of the entity to return
    ///
    ///
    /// Returns: A reference to an entity, or NULL if an error occurred.
    pub fn MIDIDeviceGetEntity(device: MIDIDeviceRef, entity_index0: ItemCount) -> MIDIEntityRef;
}

extern "C-unwind" {
    /// Returns the number of sources in a given entity.
    ///
    ///
    /// Parameter `entity`: The entity being queried
    ///
    ///
    /// Returns: The number of sources the entity contains, or 0 if an
    /// error occurred.
    pub fn MIDIEntityGetNumberOfSources(entity: MIDIEntityRef) -> ItemCount;
}

extern "C-unwind" {
    /// Returns one of a given entity's sources.
    ///
    ///
    /// Parameter `entity`: The entity being queried.
    ///
    /// Parameter `sourceIndex0`: The index (0...MIDIEntityGetNumberOfSources(entity)-1) of
    /// the source to return
    ///
    ///
    /// Returns: A reference to a source, or NULL if an error occurred.
    pub fn MIDIEntityGetSource(entity: MIDIEntityRef, source_index0: ItemCount) -> MIDIEndpointRef;
}

extern "C-unwind" {
    /// Returns the number of destinations in a given entity.
    ///
    ///
    /// Parameter `entity`: The entity being queried
    ///
    ///
    /// Returns: The number of destinations the entity contains, or 0
    /// if an error occurred.
    pub fn MIDIEntityGetNumberOfDestinations(entity: MIDIEntityRef) -> ItemCount;
}

extern "C-unwind" {
    /// Returns one of a given entity's destinations.
    ///
    ///
    /// Parameter `entity`: The entity being queried.
    ///
    /// Parameter `destIndex0`: The index (0...MIDIEntityGetNumberOfDestinations(entity)
    /// - 1) of the destination to return
    ///
    ///
    /// Returns: A reference to a destination, or NULL if an error occurred.
    pub fn MIDIEntityGetDestination(
        entity: MIDIEntityRef,
        dest_index0: ItemCount,
    ) -> MIDIEndpointRef;
}

extern "C-unwind" {
    /// Returns an entity's device.
    ///
    ///
    /// Parameter `inEntity`: The entity being queried.
    ///
    /// Parameter `outDevice`: On successful return, the entity's owning device.
    ///
    /// # Safety
    ///
    /// `out_device` must be a valid pointer or null.
    pub fn MIDIEntityGetDevice(
        in_entity: MIDIEntityRef,
        out_device: *mut MIDIDeviceRef,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Returns the number of sources in the system.
    ///
    ///
    /// Returns: The number of sources in the system, or 0 if an error
    /// occurred.
    pub fn MIDIGetNumberOfSources() -> ItemCount;
}

extern "C-unwind" {
    /// Returns one of the sources in the system.
    ///
    ///
    /// Parameter `sourceIndex0`: The index (0...MIDIGetNumberOfSources()-1) of the source
    /// to return
    ///
    /// Returns: A reference to a source, or NULL if an error occurred.
    pub fn MIDIGetSource(source_index0: ItemCount) -> MIDIEndpointRef;
}

extern "C-unwind" {
    /// Returns the number of destinations in the system.
    ///
    ///
    /// Returns: The number of destinations in the system, or 0 if an error
    /// occurred.
    pub fn MIDIGetNumberOfDestinations() -> ItemCount;
}

extern "C-unwind" {
    /// Returns one of the destinations in the system.
    ///
    ///
    /// Parameter `destIndex0`: The index (0...MIDIGetNumberOfDestinations()-1) of the
    /// destination to return
    ///
    /// Returns: A reference to a destination, or NULL if an error occurred.
    pub fn MIDIGetDestination(dest_index0: ItemCount) -> MIDIEndpointRef;
}

extern "C-unwind" {
    /// Returns an endpoint's entity.
    ///
    ///
    /// Parameter `inEndpoint`: The endpoint being queried.
    ///
    /// Parameter `outEntity`: On exit, the endpoint's owning entity, or NULL if none.
    ///
    ///
    /// Virtual sources and destinations don't have entities.
    ///
    /// # Safety
    ///
    /// `out_entity` must be a valid pointer or null.
    pub fn MIDIEndpointGetEntity(
        in_endpoint: MIDIEndpointRef,
        out_entity: *mut MIDIEntityRef,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Creates a virtual destination in a client.
    ///
    ///
    /// Parameter `client`: The client owning the virtual destination.
    ///
    /// Parameter `name`: The name of the virtual destination.
    ///
    /// Parameter `protocol`: The MIDI protocol variant to be delivered to this destination. The system
    /// will automatically convert to this protocol as needed.
    ///
    /// Parameter `outDest`: On successful return, a pointer to the newly-created
    /// destination.
    ///
    /// Parameter `readBlock`: The MIDIReceiveBlock to be called when a client sends MIDI to the virtual
    /// destination.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// The specified readBlock gets called when clients send MIDI to your virtual destination.
    ///
    /// Drivers need not call this; when they create devices and entities, sources and
    /// destinations are created at that time.
    ///
    /// After creating a virtual destination, it's a good idea to assign it the same unique ID
    /// it had the last time your application created it. (Although you should be prepared for
    /// this to fail in the unlikely event of a collision.) This will permit other clients
    /// to retain persistent references to your virtual destination more easily.
    ///
    /// See the discussion of kMIDIPropertyAdvanceScheduleTimeMuSec for notes about the
    /// relationship between when a sender sends MIDI to the destination and when it is
    /// received.
    ///
    /// # Safety
    ///
    /// - `out_dest` must be a valid pointer.
    /// - `read_block` must be a valid pointer.
    #[cfg(all(feature = "block2", feature = "objc2-core-foundation"))]
    pub fn MIDIDestinationCreateWithProtocol(
        client: MIDIClientRef,
        name: &CFString,
        protocol: MIDIProtocolID,
        out_dest: NonNull<MIDIEndpointRef>,
        read_block: MIDIReceiveBlock,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Creates a virtual destination in a client.
    ///
    ///
    /// Parameter `client`: The client owning the virtual destination.
    ///
    /// Parameter `name`: The name of the virtual destination.
    ///
    /// Parameter `readProc`: The MIDIReadProc to be called when a client sends MIDI to
    /// the virtual destination.
    ///
    /// Parameter `refCon`: The refCon to be passed to the readProc.
    ///
    /// Parameter `outDest`: On successful return, a pointer to the newly-created
    /// destination.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// The specified readProc gets called when clients send MIDI to your virtual destination.
    ///
    /// Drivers need not call this; when they create devices and entities, sources and
    /// destinations are created at that time.
    ///
    /// After creating a virtual destination, it's a good idea to assign it the same unique ID
    /// it had the last time your application created it. (Although you should be prepared for
    /// this to fail in the unlikely event of a collision.) This will permit other clients
    /// to retain persistent references to your virtual destination more easily.
    ///
    /// See the discussion of kMIDIPropertyAdvanceScheduleTimeMuSec for notes about the
    /// relationship between when a sender sends MIDI to the destination and when it is
    /// received.
    ///
    /// # Safety
    ///
    /// - `read_proc` must be implemented correctly.
    /// - `ref_con` must be a valid pointer or null.
    /// - `out_dest` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated]
    pub fn MIDIDestinationCreate(
        client: MIDIClientRef,
        name: &CFString,
        read_proc: MIDIReadProc,
        ref_con: *mut c_void,
        out_dest: NonNull<MIDIEndpointRef>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Creates a virtual destination in a client.
    ///
    ///
    /// Parameter `client`: The client owning the virtual destination.
    ///
    /// Parameter `name`: The name of the virtual destination.
    ///
    /// Parameter `outDest`: On successful return, a pointer to the newly-created
    /// destination.
    ///
    /// Parameter `readBlock`: The MIDIReadBlock to be called when a client sends MIDI to the virtual
    /// destination.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// The specified readBlock gets called when clients send MIDI to your virtual destination.
    ///
    /// Drivers need not call this; when they create devices and entities, sources and
    /// destinations are created at that time.
    ///
    /// After creating a virtual destination, it's a good idea to assign it the same unique ID
    /// it had the last time your application created it. (Although you should be prepared for
    /// this to fail in the unlikely event of a collision.) This will permit other clients
    /// to retain persistent references to your virtual destination more easily.
    ///
    /// See the discussion of kMIDIPropertyAdvanceScheduleTimeMuSec for notes about the
    /// relationship between when a sender sends MIDI to the destination and when it is
    /// received.
    ///
    /// # Safety
    ///
    /// - `out_dest` must be a valid pointer.
    /// - `read_block` must be a valid pointer.
    #[cfg(all(feature = "block2", feature = "objc2-core-foundation"))]
    #[deprecated]
    pub fn MIDIDestinationCreateWithBlock(
        client: MIDIClientRef,
        name: &CFString,
        out_dest: NonNull<MIDIEndpointRef>,
        read_block: MIDIReadBlock,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Creates a virtual source in a client.
    ///
    ///
    /// Parameter `client`: The client owning the virtual source.
    ///
    /// Parameter `name`: The name of the virtual source.
    ///
    /// Parameter `protocol`: The MIDI protocol variant to be sent from this source. The system
    /// will automatically convert from this protocol to the protocol of
    /// the destination as needed.
    ///
    /// Parameter `outSrc`: On successful return, a pointer to the newly-created
    /// source.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// Drivers need not call this; when they create devices and entities, sources and
    /// destinations are created at that time.
    ///
    /// After creating a virtual source, use MIDIReceivedEventList to transmit MIDI messages from your
    /// virtual source to any clients connected to the virtual source.
    ///
    /// After creating a virtual source, it's a good idea to assign it the same unique ID it had
    /// the last time your application created it. (Although you should be prepared for this to
    /// fail in the unlikely event of a collision.) This will permit other clients to retain
    /// persistent references to your virtual source more easily.
    ///
    /// # Safety
    ///
    /// `out_src` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MIDISourceCreateWithProtocol(
        client: MIDIClientRef,
        name: &CFString,
        protocol: MIDIProtocolID,
        out_src: NonNull<MIDIEndpointRef>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Creates a virtual source in a client.
    ///
    ///
    /// Parameter `client`: The client owning the virtual source.
    ///
    /// Parameter `name`: The name of the virtual source.
    ///
    /// Parameter `outSrc`: On successful return, a pointer to the newly-created
    /// source.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// Drivers need not call this; when they create devices and entities, sources and
    /// destinations are created at that time.
    ///
    /// After creating a virtual source, use MIDIReceived to transmit MIDI messages from your
    /// virtual source to any clients connected to the virtual source.
    ///
    /// After creating a virtual source, it's a good idea to assign it the same unique ID it had
    /// the last time your application created it. (Although you should be prepared for this to
    /// fail in the unlikely event of a collision.) This will permit other clients to retain
    /// persistent references to your virtual source more easily.
    ///
    /// # Safety
    ///
    /// `out_src` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated]
    pub fn MIDISourceCreate(
        client: MIDIClientRef,
        name: &CFString,
        out_src: NonNull<MIDIEndpointRef>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Disposes a virtual source or destination your client created.
    ///
    ///
    /// Parameter `endpt`: The endpoint to be disposed.
    ///
    ///
    /// Returns: An OSStatus result code.
    pub fn MIDIEndpointDispose(endpt: MIDIEndpointRef) -> OSStatus;
}

extern "C-unwind" {
    /// Returns the number of external MIDI devices in the system.
    ///
    ///
    /// Returns: The number of external devices in the system, or 0 if an error
    /// occurred.
    ///
    ///
    /// External MIDI devices are MIDI devices connected to driver endpoints via a standard MIDI
    /// cable. Their presence is completely optional, only when a UI (such as Audio MIDI Setup)
    /// adds them.
    pub fn MIDIGetNumberOfExternalDevices() -> ItemCount;
}

extern "C-unwind" {
    /// Returns one of the external devices in the system.
    ///
    ///
    /// Parameter `deviceIndex0`: The index (0...MIDIGetNumberOfDevices()-1) of the device
    /// to return.
    ///
    /// Returns: A reference to a device, or NULL if an error occurred.
    ///
    ///
    /// Use this to enumerate the external devices in the system.
    pub fn MIDIGetExternalDevice(device_index0: ItemCount) -> MIDIDeviceRef;
}

extern "C-unwind" {
    /// Gets an object's integer-type property.
    ///
    ///
    /// Parameter `obj`: The object whose property is to be returned.
    ///
    /// Parameter `propertyID`: Name of the property to return.
    ///
    /// Parameter `outValue`: On successful return, the value of the property.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// (See the MIDIObjectRef documentation for information about properties.)
    ///
    /// # Safety
    ///
    /// `out_value` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MIDIObjectGetIntegerProperty(
        obj: MIDIObjectRef,
        property_id: &CFString,
        out_value: NonNull<i32>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Sets an object's integer-type property.
    ///
    ///
    /// Parameter `obj`: The object whose property is to be altered.
    ///
    /// Parameter `propertyID`: Name of the property to set.
    ///
    /// Parameter `value`: New value of the property.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// (See the MIDIObjectRef documentation for information about properties.)
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MIDIObjectSetIntegerProperty(
        obj: MIDIObjectRef,
        property_id: &CFString,
        value: i32,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Gets an object's string-type property.
    ///
    ///
    /// Parameter `obj`: The object whose property is to be returned.
    ///
    /// Parameter `propertyID`: Name of the property to return.
    ///
    /// Parameter `str`: On successful return, the value of the property.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// (See the MIDIObjectRef documentation for information about properties.)
    ///
    /// # Safety
    ///
    /// `str` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MIDIObjectGetStringProperty(
        obj: MIDIObjectRef,
        property_id: &CFString,
        str: NonNull<*const CFString>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Sets an object's string-type property.
    ///
    ///
    /// Parameter `obj`: The object whose property is to be altered.
    ///
    /// Parameter `propertyID`: Name of the property to set.
    ///
    /// Parameter `str`: New value of the property.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// (See the MIDIObjectRef documentation for information about properties.)
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MIDIObjectSetStringProperty(
        obj: MIDIObjectRef,
        property_id: &CFString,
        str: &CFString,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Gets an object's data-type property.
    ///
    ///
    /// (See the MIDIObjectRef documentation for information
    /// about properties.)
    ///
    ///
    /// Parameter `obj`: The object whose property is to be returned.
    ///
    /// Parameter `propertyID`: Name of the property to return.
    ///
    /// Parameter `outData`: On successful return, the value of the property.
    ///
    /// Returns: An OSStatus result code.
    ///
    /// # Safety
    ///
    /// `out_data` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MIDIObjectGetDataProperty(
        obj: MIDIObjectRef,
        property_id: &CFString,
        out_data: NonNull<*const CFData>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Sets an object's data-type property.
    ///
    ///
    /// Parameter `obj`: The object whose property is to be altered.
    ///
    /// Parameter `propertyID`: Name of the property to set.
    ///
    /// Parameter `data`: New value of the property.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// (See the MIDIObjectRef documentation for information about properties.)
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MIDIObjectSetDataProperty(
        obj: MIDIObjectRef,
        property_id: &CFString,
        data: &CFData,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Gets an object's dictionary-type property.
    ///
    ///
    /// Parameter `obj`: The object whose property is to be returned.
    ///
    /// Parameter `propertyID`: Name of the property to return.
    ///
    /// Parameter `outDict`: On successful return, the value of the property.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// (See the MIDIObjectRef documentation for information about properties.)
    ///
    /// # Safety
    ///
    /// `out_dict` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MIDIObjectGetDictionaryProperty(
        obj: MIDIObjectRef,
        property_id: &CFString,
        out_dict: NonNull<*const CFDictionary>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Sets an object's dictionary-type property.
    ///
    ///
    /// Parameter `obj`: The object whose property is to be altered.
    ///
    /// Parameter `propertyID`: Name of the property to set.
    ///
    /// Parameter `dict`: New value of the property.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// (See the MIDIObjectRef documentation for information about properties.)
    ///
    /// # Safety
    ///
    /// `dict` generics must be of the correct type.
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MIDIObjectSetDictionaryProperty(
        obj: MIDIObjectRef,
        property_id: &CFString,
        dict: &CFDictionary,
    ) -> OSStatus;
}

/// Gets all of an object's properties.
///
///
/// Parameter `obj`: The object whose properties are to be returned.
///
/// Parameter `outProperties`: On successful return, the object's properties.
///
/// Parameter `deep`: true if the object's child objects are to be included
/// (e.g. a device's entities, or an entity's endpoints).
///
/// Returns: An OSStatus result code.
///
///
/// Returns a CFPropertyList of all of an object's properties. The property list may be a
/// dictionary or an array. Dictionaries map property names (CFString) to values, which may
/// be CFNumber, CFString, or CFData.  Arrays are arrays of such values.
///
/// Properties which an object inherits from its owning object (if any) are not included.
///
/// # Safety
///
/// `out_properties` must be a valid pointer.
#[cfg(feature = "objc2-core-foundation")]
#[inline]
pub unsafe extern "C-unwind" fn MIDIObjectGetProperties(
    obj: MIDIObjectRef,
    out_properties: NonNull<*const CFPropertyList>,
    deep: bool,
) -> OSStatus {
    extern "C-unwind" {
        fn MIDIObjectGetProperties(
            obj: MIDIObjectRef,
            out_properties: NonNull<*const CFPropertyList>,
            deep: Boolean,
        ) -> OSStatus;
    }
    unsafe { MIDIObjectGetProperties(obj, out_properties, deep as _) }
}

extern "C-unwind" {
    /// Removes an object's property.
    ///
    ///
    /// Parameter `obj`: The object whose property is to be removed.
    ///
    /// Parameter `propertyID`: The property to be removed.
    ///
    /// Returns: An OSStatus result code.
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MIDIObjectRemoveProperty(obj: MIDIObjectRef, property_id: &CFString) -> OSStatus;
}

extern "C-unwind" {
    /// Locates a device, external device, entity, or endpoint
    /// by its uniqueID.
    ///
    /// Parameter `inUniqueID`: The uniqueID of the object to search for.  (This should
    /// be the result of an earlier call to MIDIObjectGetIntegerProperty
    /// for the property kMIDIPropertyUniqueID).
    ///
    /// Parameter `outObject`: The returned object, or 0 if the object was not found or
    /// an error occurred.  This should be cast to the appropriate
    /// type (MIDIDeviceRef, MIDIEntityRef, MIDIEndpointRef),
    /// according to *outObjectType.
    ///
    /// Parameter `outObjectType`: On exit, the type of object which was found; undefined
    /// if none found.
    ///
    /// Returns: An OSStatus error code, including kMIDIObjectNotFound if there
    /// is no object with the specified uniqueID.
    ///
    /// # Safety
    ///
    /// - `out_object` must be a valid pointer or null.
    /// - `out_object_type` must be a valid pointer or null.
    pub fn MIDIObjectFindByUniqueID(
        in_unique_id: MIDIUniqueID,
        out_object: *mut MIDIObjectRef,
        out_object_type: *mut MIDIObjectType,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Sends MIDI to a destination.
    ///
    ///
    /// Parameter `port`: The output port through which the MIDI is to be sent.
    ///
    /// Parameter `dest`: The destination to receive the events.
    ///
    /// Parameter `evtlist`: The MIDI events to be sent.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// Events with future timestamps are scheduled for future delivery.  CoreMIDI performs
    /// any needed MIDI merging.
    ///
    /// # Safety
    ///
    /// `evtlist` must be a valid pointer.
    pub fn MIDISendEventList(
        port: MIDIPortRef,
        dest: MIDIEndpointRef,
        evtlist: NonNull<MIDIEventList>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Sends MIDI to a destination.
    ///
    ///
    /// Parameter `port`: The output port through which the MIDI is to be sent.
    ///
    /// Parameter `dest`: The destination to receive the events.
    ///
    /// Parameter `pktlist`: The MIDI events to be sent.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// Events with future timestamps are scheduled for future delivery.  CoreMIDI performs
    /// any needed MIDI merging.
    ///
    /// # Safety
    ///
    /// `pktlist` must be a valid pointer.
    #[deprecated]
    pub fn MIDISend(
        port: MIDIPortRef,
        dest: MIDIEndpointRef,
        pktlist: NonNull<MIDIPacketList>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Sends a single system-exclusive event, asynchronously.
    ///
    ///
    /// Parameter `request`: Contains the destination, and a pointer to the MIDI data to be sent.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// request->data must point to a single MIDI system-exclusive message, or portion thereof.
    ///
    /// # Safety
    ///
    /// `request` must be a valid pointer.
    pub fn MIDISendSysex(request: NonNull<MIDISysexSendRequest>) -> OSStatus;
}

extern "C-unwind" {
    /// Sends a single UMP system-exclusive event, asynchronously.
    ///
    ///
    /// Parameter `umpRequest`: Contains the destination, and a pointer to the MIDI data to be sent.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// request->words must point to a single MIDI system-exclusive message, or portion thereof.
    ///
    /// # Safety
    ///
    /// `ump_request` must be a valid pointer.
    pub fn MIDISendUMPSysex(ump_request: NonNull<MIDISysexSendRequestUMP>) -> OSStatus;
}

extern "C-unwind" {
    /// Sends single system-exclusive 8-bit event, asynchronously.
    ///
    ///
    /// Parameter `umpRequest`: Contains the destination, and a pointer to the 8-bit system-exclusive data to be sent.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// request->data must point to a single MIDI system-exclusive message, or portion thereof.
    ///
    /// # Safety
    ///
    /// `ump_request` must be a valid pointer.
    pub fn MIDISendUMPSysex8(ump_request: NonNull<MIDISysexSendRequestUMP>) -> OSStatus;
}

impl MIDIEventPacket {
    /// Gets MIDI 1.0 SysEx bytes on the indicated group.
    ///
    ///
    /// Parameter `pkt`: A MIDIEventPacket containing UMP system-exclusive data.
    ///
    ///
    /// Parameter `groupIndex`: The target group index, 0 to 15.
    ///
    ///
    /// Parameter `outData`: When successful, a CFDataRef byte stream of extracted system-exclusive data.
    ///
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// pkt must contain a single MIDI system-exclusive message on groupIndex, or portion thereof.
    ///
    /// # Safety
    ///
    /// - `pkt` must be a valid pointer.
    /// - `out_data` must be a valid pointer.
    #[doc(alias = "MIDIEventPacketSysexBytesForGroup")]
    #[cfg(feature = "objc2-core-foundation")]
    #[inline]
    pub unsafe fn sysex_bytes_for_group(
        pkt: NonNull<MIDIEventPacket>,
        group_index: u8,
        out_data: NonNull<*const CFData>,
    ) -> OSStatus {
        extern "C-unwind" {
            fn MIDIEventPacketSysexBytesForGroup(
                pkt: NonNull<MIDIEventPacket>,
                group_index: u8,
                out_data: NonNull<*const CFData>,
            ) -> OSStatus;
        }
        unsafe { MIDIEventPacketSysexBytesForGroup(pkt, group_index, out_data) }
    }
}

extern "C-unwind" {
    /// Distributes incoming MIDI from a source to the client input ports
    /// which are connected to that source.
    ///
    ///
    /// Parameter `src`: The source which is transmitting MIDI.
    ///
    /// Parameter `evtlist`: The MIDI events to be transmitted.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// Drivers should call this function when receiving MIDI from a source.
    ///
    /// Clients which have created virtual sources, using MIDISourceCreateWithProtocol, should call this
    /// function when the source is generating MIDI.
    ///
    /// Unlike MIDISendEventList(), a timestamp of 0 is not equivalent to "now"; the driver or virtual
    /// source is responsible for putting proper timestamps in the packets.
    ///
    /// # Safety
    ///
    /// `evtlist` must be a valid pointer.
    pub fn MIDIReceivedEventList(src: MIDIEndpointRef, evtlist: NonNull<MIDIEventList>)
        -> OSStatus;
}

extern "C-unwind" {
    /// Distributes incoming MIDI from a source to the client input ports
    /// which are connected to that source.
    ///
    ///
    /// Parameter `src`: The source which is transmitting MIDI.
    ///
    /// Parameter `pktlist`: The MIDI events to be transmitted.
    ///
    /// Returns: An OSStatus result code.
    ///
    ///
    /// Drivers should call this function when receiving MIDI from a source.
    ///
    /// Clients which have created virtual sources, using MIDISourceCreate, should call this
    /// function when the source is generating MIDI.
    ///
    /// Unlike MIDISend(), a timestamp of 0 is not equivalent to "now"; the driver or virtual
    /// source is responsible for putting proper timestamps in the packets.
    ///
    /// # Safety
    ///
    /// `pktlist` must be a valid pointer.
    #[deprecated]
    pub fn MIDIReceived(src: MIDIEndpointRef, pktlist: NonNull<MIDIPacketList>) -> OSStatus;
}

extern "C-unwind" {
    /// Unschedules previously-sent packets.
    ///
    ///
    /// Parameter `dest`: All pending events scheduled to be sent to this destination
    /// are unscheduled.  If NULL, the operation applies to
    /// all destinations.
    ///
    ///
    /// Clients may use MIDIFlushOutput to cancel the sending of packets that were previously
    /// scheduled for future delivery.
    pub fn MIDIFlushOutput(dest: MIDIEndpointRef) -> OSStatus;
}

extern "C-unwind" {
    /// Stops and restarts MIDI I/O.
    ///
    ///
    /// This is useful for forcing CoreMIDI to ask its drivers to rescan for hardware.
    ///
    ///
    /// Returns: An OSStatus result code.
    pub fn MIDIRestart() -> OSStatus;
}

impl MIDIEventPacket {
    // TODO: pub fn MIDIEventPacketNext(pkt: NonNull<MIDIEventPacket>,)-> Option<NonNull<MIDIEventPacket>>;
}

impl MIDIEventList {
    /// Prepares a MIDIEventList to be built up dynamically.
    ///
    ///
    /// Parameter `evtlist`: The event list to be initialized.
    ///
    ///
    /// Returns: A pointer to the first MIDIEventPacket in the event list.
    ///
    /// # Safety
    ///
    /// `evtlist` must be a valid pointer.
    #[doc(alias = "MIDIEventListInit")]
    #[inline]
    pub unsafe fn init(
        evtlist: NonNull<MIDIEventList>,
        protocol: MIDIProtocolID,
    ) -> NonNull<MIDIEventPacket> {
        extern "C-unwind" {
            fn MIDIEventListInit(
                evtlist: NonNull<MIDIEventList>,
                protocol: MIDIProtocolID,
            ) -> Option<NonNull<MIDIEventPacket>>;
        }
        let ret = unsafe { MIDIEventListInit(evtlist, protocol) };
        ret.expect("function was marked as returning non-null, but actually returned NULL")
    }

    /// Adds a MIDI event to a MIDIEventList.
    ///
    ///
    /// Parameter `evtlist`: The event list to which the event is to be added.
    ///
    /// Parameter `listSize`: The capacity, in bytes, of the event list.
    ///
    /// Parameter `curPacket`: A packet pointer returned by a previous call to
    /// MIDIEventListInit or MIDIEventListAdd for this packet
    /// list.
    ///
    /// Parameter `time`: The new event's time.
    ///
    /// Parameter `wordCount`: The number of valid MIDI 32-bit words which follow, in data.
    ///
    /// Parameter `words`: The new event.  May be a single MIDI event, or a partial
    /// sys-ex event.  Running status is
    /// <b>
    /// not
    /// </b>
    /// permitted.
    ///
    /// Returns: Returns null if there was not room in the packet for the
    /// event; otherwise returns a packet pointer which should be
    /// passed as curPacket in a subsequent call to this function.
    ///
    ///
    /// The maximum size of a event list is 65536 bytes. Large sysex messages must be sent in
    /// smaller event lists.
    ///
    /// Note that events must use the same protocol as was passed to MIDIEventListInit().
    ///
    /// # Safety
    ///
    /// - `evtlist` must be a valid pointer.
    /// - `cur_packet` must be a valid pointer.
    /// - `words` must be a valid pointer.
    #[doc(alias = "MIDIEventListAdd")]
    #[inline]
    pub unsafe fn add(
        evtlist: NonNull<MIDIEventList>,
        list_size: ByteCount,
        cur_packet: NonNull<MIDIEventPacket>,
        time: MIDITimeStamp,
        word_count: ByteCount,
        words: NonNull<u32>,
    ) -> NonNull<MIDIEventPacket> {
        extern "C-unwind" {
            fn MIDIEventListAdd(
                evtlist: NonNull<MIDIEventList>,
                list_size: ByteCount,
                cur_packet: NonNull<MIDIEventPacket>,
                time: MIDITimeStamp,
                word_count: ByteCount,
                words: NonNull<u32>,
            ) -> Option<NonNull<MIDIEventPacket>>;
        }
        let ret =
            unsafe { MIDIEventListAdd(evtlist, list_size, cur_packet, time, word_count, words) };
        ret.expect("function was marked as returning non-null, but actually returned NULL")
    }
}

impl MIDIPacket {
    // TODO: pub fn MIDIPacketNext(pkt: NonNull<MIDIPacket>,)-> Option<NonNull<MIDIPacket>>;
}

impl MIDIPacketList {
    /// Prepares a MIDIPacketList to be built up dynamically.
    ///
    ///
    /// Parameter `pktlist`: The packet list to be initialized.
    ///
    ///
    /// Returns: A pointer to the first MIDIPacket in the packet list.
    ///
    /// # Safety
    ///
    /// `pktlist` must be a valid pointer.
    #[doc(alias = "MIDIPacketListInit")]
    #[deprecated]
    #[inline]
    pub unsafe fn init(pktlist: NonNull<MIDIPacketList>) -> NonNull<MIDIPacket> {
        extern "C-unwind" {
            fn MIDIPacketListInit(pktlist: NonNull<MIDIPacketList>) -> Option<NonNull<MIDIPacket>>;
        }
        let ret = unsafe { MIDIPacketListInit(pktlist) };
        ret.expect("function was marked as returning non-null, but actually returned NULL")
    }

    /// Adds a MIDI event to a MIDIPacketList.
    ///
    ///
    /// Parameter `pktlist`: The packet list to which the event is to be added.
    ///
    /// Parameter `listSize`: The size, in bytes, of the packet list.
    ///
    /// Parameter `curPacket`: A packet pointer returned by a previous call to
    /// MIDIPacketListInit or MIDIPacketListAdd for this packet
    /// list.
    ///
    /// Parameter `time`: The new event's time.
    ///
    /// Parameter `nData`: The length of the new event, in bytes.
    ///
    /// Parameter `data`: The new event.  May be a single MIDI event, or a partial
    /// sys-ex event.  Running status is
    /// <b>
    /// not
    /// </b>
    /// permitted.
    ///
    /// Returns: Returns null if there was not room in the packet for the
    /// event; otherwise returns a packet pointer which should be
    /// passed as curPacket in a subsequent call to this function.
    ///
    ///
    /// The maximum size of a packet list is 65536 bytes. Large sysex messages must be sent in
    /// smaller packet lists.
    ///
    /// # Safety
    ///
    /// - `pktlist` must be a valid pointer.
    /// - `cur_packet` must be a valid pointer.
    /// - `data` must be a valid pointer.
    #[doc(alias = "MIDIPacketListAdd")]
    #[deprecated]
    #[inline]
    pub unsafe fn add(
        pktlist: NonNull<MIDIPacketList>,
        list_size: ByteCount,
        cur_packet: NonNull<MIDIPacket>,
        time: MIDITimeStamp,
        n_data: ByteCount,
        data: NonNull<Byte>,
    ) -> NonNull<MIDIPacket> {
        extern "C-unwind" {
            fn MIDIPacketListAdd(
                pktlist: NonNull<MIDIPacketList>,
                list_size: ByteCount,
                cur_packet: NonNull<MIDIPacket>,
                time: MIDITimeStamp,
                n_data: ByteCount,
                data: NonNull<Byte>,
            ) -> Option<NonNull<MIDIPacket>>;
        }
        let ret = unsafe { MIDIPacketListAdd(pktlist, list_size, cur_packet, time, n_data, data) };
        ret.expect("function was marked as returning non-null, but actually returned NULL")
    }
}

extern "C-unwind" {
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated = "renamed to `MIDIEventPacket::sysex_bytes_for_group`"]
    pub fn MIDIEventPacketSysexBytesForGroup(
        pkt: NonNull<MIDIEventPacket>,
        group_index: u8,
        out_data: NonNull<*const CFData>,
    ) -> OSStatus;
}

#[deprecated = "renamed to `MIDIEventList::init`"]
#[inline]
pub unsafe extern "C-unwind" fn MIDIEventListInit(
    evtlist: NonNull<MIDIEventList>,
    protocol: MIDIProtocolID,
) -> NonNull<MIDIEventPacket> {
    extern "C-unwind" {
        fn MIDIEventListInit(
            evtlist: NonNull<MIDIEventList>,
            protocol: MIDIProtocolID,
        ) -> Option<NonNull<MIDIEventPacket>>;
    }
    let ret = unsafe { MIDIEventListInit(evtlist, protocol) };
    ret.expect("function was marked as returning non-null, but actually returned NULL")
}

#[deprecated = "renamed to `MIDIEventList::add`"]
#[inline]
pub unsafe extern "C-unwind" fn MIDIEventListAdd(
    evtlist: NonNull<MIDIEventList>,
    list_size: ByteCount,
    cur_packet: NonNull<MIDIEventPacket>,
    time: MIDITimeStamp,
    word_count: ByteCount,
    words: NonNull<u32>,
) -> NonNull<MIDIEventPacket> {
    extern "C-unwind" {
        fn MIDIEventListAdd(
            evtlist: NonNull<MIDIEventList>,
            list_size: ByteCount,
            cur_packet: NonNull<MIDIEventPacket>,
            time: MIDITimeStamp,
            word_count: ByteCount,
            words: NonNull<u32>,
        ) -> Option<NonNull<MIDIEventPacket>>;
    }
    let ret = unsafe { MIDIEventListAdd(evtlist, list_size, cur_packet, time, word_count, words) };
    ret.expect("function was marked as returning non-null, but actually returned NULL")
}

#[deprecated = "renamed to `MIDIPacketList::init`"]
#[inline]
pub unsafe extern "C-unwind" fn MIDIPacketListInit(
    pktlist: NonNull<MIDIPacketList>,
) -> NonNull<MIDIPacket> {
    extern "C-unwind" {
        fn MIDIPacketListInit(pktlist: NonNull<MIDIPacketList>) -> Option<NonNull<MIDIPacket>>;
    }
    let ret = unsafe { MIDIPacketListInit(pktlist) };
    ret.expect("function was marked as returning non-null, but actually returned NULL")
}

#[deprecated = "renamed to `MIDIPacketList::add`"]
#[inline]
pub unsafe extern "C-unwind" fn MIDIPacketListAdd(
    pktlist: NonNull<MIDIPacketList>,
    list_size: ByteCount,
    cur_packet: NonNull<MIDIPacket>,
    time: MIDITimeStamp,
    n_data: ByteCount,
    data: NonNull<Byte>,
) -> NonNull<MIDIPacket> {
    extern "C-unwind" {
        fn MIDIPacketListAdd(
            pktlist: NonNull<MIDIPacketList>,
            list_size: ByteCount,
            cur_packet: NonNull<MIDIPacket>,
            time: MIDITimeStamp,
            n_data: ByteCount,
            data: NonNull<Byte>,
        ) -> Option<NonNull<MIDIPacket>>;
    }
    let ret = unsafe { MIDIPacketListAdd(pktlist, list_size, cur_packet, time, n_data, data) };
    ret.expect("function was marked as returning non-null, but actually returned NULL")
}