objc2-audio-toolbox 0.3.2

Bindings to the AudioToolbox 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
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;
#[cfg(feature = "objc2-core-midi")]
use objc2_core_midi::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusiceventtype_null?language=objc)
pub const kMusicEventType_NULL: u32 = 0;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusiceventtype_extendednote?language=objc)
pub const kMusicEventType_ExtendedNote: u32 = 1;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusiceventtype_extendedtempo?language=objc)
pub const kMusicEventType_ExtendedTempo: u32 = 3;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusiceventtype_user?language=objc)
pub const kMusicEventType_User: u32 = 4;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusiceventtype_meta?language=objc)
pub const kMusicEventType_Meta: u32 = 5;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusiceventtype_midinotemessage?language=objc)
pub const kMusicEventType_MIDINoteMessage: u32 = 6;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusiceventtype_midichannelmessage?language=objc)
pub const kMusicEventType_MIDIChannelMessage: u32 = 7;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusiceventtype_midirawdata?language=objc)
pub const kMusicEventType_MIDIRawData: u32 = 8;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusiceventtype_parameter?language=objc)
pub const kMusicEventType_Parameter: u32 = 9;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusiceventtype_aupreset?language=objc)
pub const kMusicEventType_AUPreset: u32 = 10;

/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musiceventtype?language=objc)
pub type MusicEventType = u32;

/// Flags used to customise loading behaviour
///
/// If this flag is set the resultant Sequence will contain:
/// a tempo track
/// a track for each track found in the SMF
/// This is the default behavior
///
/// If this flag is set the resultant Sequence will contain:
/// a tempo track
/// 1 track for each MIDI Channel that is found in the SMF
/// 1 track for SysEx or MetaEvents - this will be the last track
/// in the sequence after the LoadSMFWithFlags calls
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicsequenceloadflags?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MusicSequenceLoadFlags(pub u32);
bitflags::bitflags! {
    impl MusicSequenceLoadFlags: u32 {
        #[doc(alias = "kMusicSequenceLoadSMF_PreserveTracks")]
        const SMF_PreserveTracks = 0;
        #[doc(alias = "kMusicSequenceLoadSMF_ChannelsToTracks")]
        const SMF_ChannelsToTracks = 1<<0;
    }
}

unsafe impl Encode for MusicSequenceLoadFlags {
    const ENCODING: Encoding = u32::ENCODING;
}

unsafe impl RefEncode for MusicSequenceLoadFlags {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// A sequence type
///
/// Different sequence types to describe the basic mode of operation of a sequence's time line
/// You cannot change a music sequence's type to samples/seconds if there are tempo events
/// The type will also define how the sequence is saved to a MIDI file:
/// Beats - normal midi file
/// Seconds - midi file with SMPTE time
/// Samples - cannot be saved to a midi file
///
/// The default/normal type of a sequence.
/// Tempo track defines the number of beats per second and can have multiple tempo events
///
/// A music sequence with a single 60bpm tempo event
///
/// A music sequence with a single tempo event that represents the audio sample rate
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicsequencetype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MusicSequenceType(pub u32);
impl MusicSequenceType {
    #[doc(alias = "kMusicSequenceType_Beats")]
    pub const Beats: Self = Self(0x62656174);
    #[doc(alias = "kMusicSequenceType_Seconds")]
    pub const Seconds: Self = Self(0x73656373);
    #[doc(alias = "kMusicSequenceType_Samples")]
    pub const Samples: Self = Self(0x73616d70);
}

unsafe impl Encode for MusicSequenceType {
    const ENCODING: Encoding = u32::ENCODING;
}

unsafe impl RefEncode for MusicSequenceType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// describes different types of files that can be parsed by a music sequence
///
/// let the system read iMelody files and read and write MIDI files (and any future types)
///
/// read and write MIDI files
///
/// read iMelody files
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicsequencefiletypeid?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MusicSequenceFileTypeID(pub u32);
impl MusicSequenceFileTypeID {
    #[doc(alias = "kMusicSequenceFile_AnyType")]
    pub const AnyType: Self = Self(0);
    #[doc(alias = "kMusicSequenceFile_MIDIType")]
    pub const MIDIType: Self = Self(0x6d696469);
    #[doc(alias = "kMusicSequenceFile_iMelodyType")]
    pub const iMelodyType: Self = Self(0x696d656c);
}

unsafe impl Encode for MusicSequenceFileTypeID {
    const ENCODING: Encoding = u32::ENCODING;
}

unsafe impl RefEncode for MusicSequenceFileTypeID {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// controls the behaviour of the create file calls
///
/// Does not overwrite existing files.  Attempts to save over an existing file
/// will return kAudio_FilePermissionError
///
/// Erase an existing file when creating a new file
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicsequencefileflags?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MusicSequenceFileFlags(pub u32);
bitflags::bitflags! {
    impl MusicSequenceFileFlags: u32 {
        #[doc(alias = "kMusicSequenceFileFlags_Default")]
        const Default = 0;
        #[doc(alias = "kMusicSequenceFileFlags_EraseFile")]
        const EraseFile = 1;
    }
}

unsafe impl Encode for MusicSequenceFileFlags {
    const ENCODING: Encoding = u32::ENCODING;
}

unsafe impl RefEncode for MusicSequenceFileFlags {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// The type used to refer to time values in a music sequence
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musictimestamp?language=objc)
pub type MusicTimeStamp = f64;

/// The parameters to specify a MIDI note
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/midinotemessage?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MIDINoteMessage {
    pub channel: u8,
    pub note: u8,
    pub velocity: u8,
    pub releaseVelocity: u8,
    pub duration: f32,
}

unsafe impl Encode for MIDINoteMessage {
    const ENCODING: Encoding = Encoding::Struct(
        "MIDINoteMessage",
        &[
            <u8>::ENCODING,
            <u8>::ENCODING,
            <u8>::ENCODING,
            <u8>::ENCODING,
            <f32>::ENCODING,
        ],
    );
}

unsafe impl RefEncode for MIDINoteMessage {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// The parameters to specify a MIDI channel message
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/midichannelmessage?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MIDIChannelMessage {
    pub status: u8,
    pub data1: u8,
    pub data2: u8,
    pub reserved: u8,
}

unsafe impl Encode for MIDIChannelMessage {
    const ENCODING: Encoding = Encoding::Struct(
        "MIDIChannelMessage",
        &[
            <u8>::ENCODING,
            <u8>::ENCODING,
            <u8>::ENCODING,
            <u8>::ENCODING,
        ],
    );
}

unsafe impl RefEncode for MIDIChannelMessage {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Generally used to represent a MIDI SysEx message
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/midirawdata?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MIDIRawData {
    pub length: u32,
    pub data: [u8; 1],
}

unsafe impl Encode for MIDIRawData {
    const ENCODING: Encoding =
        Encoding::Struct("MIDIRawData", &[<u32>::ENCODING, <[u8; 1]>::ENCODING]);
}

unsafe impl RefEncode for MIDIRawData {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// The parameters to specify a MIDI meta event
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/midimetaevent?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MIDIMetaEvent {
    pub metaEventType: u8,
    pub unused1: u8,
    pub unused2: u8,
    pub unused3: u8,
    pub dataLength: u32,
    pub data: [u8; 1],
}

unsafe impl Encode for MIDIMetaEvent {
    const ENCODING: Encoding = Encoding::Struct(
        "MIDIMetaEvent",
        &[
            <u8>::ENCODING,
            <u8>::ENCODING,
            <u8>::ENCODING,
            <u8>::ENCODING,
            <u32>::ENCODING,
            <[u8; 1]>::ENCODING,
        ],
    );
}

unsafe impl RefEncode for MIDIMetaEvent {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Provides a general struct for specifying a user defined event.
///
/// the size in bytes of the data
///
/// size bytes of user defined event data
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musiceventuserdata?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MusicEventUserData {
    pub length: u32,
    pub data: [u8; 1],
}

unsafe impl Encode for MusicEventUserData {
    const ENCODING: Encoding = Encoding::Struct(
        "MusicEventUserData",
        &[<u32>::ENCODING, <[u8; 1]>::ENCODING],
    );
}

unsafe impl RefEncode for MusicEventUserData {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// The parameters to specify an extended note on event
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/extendednoteonevent?language=objc)
#[cfg(all(feature = "AUComponent", feature = "MusicDevice"))]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ExtendedNoteOnEvent {
    pub instrumentID: MusicDeviceInstrumentID,
    pub groupID: MusicDeviceGroupID,
    pub duration: f32,
    pub extendedParams: MusicDeviceNoteParams,
}

#[cfg(all(feature = "AUComponent", feature = "MusicDevice"))]
unsafe impl Encode for ExtendedNoteOnEvent {
    const ENCODING: Encoding = Encoding::Struct(
        "ExtendedNoteOnEvent",
        &[
            <MusicDeviceInstrumentID>::ENCODING,
            <MusicDeviceGroupID>::ENCODING,
            <f32>::ENCODING,
            <MusicDeviceNoteParams>::ENCODING,
        ],
    );
}

#[cfg(all(feature = "AUComponent", feature = "MusicDevice"))]
unsafe impl RefEncode for ExtendedNoteOnEvent {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// The parameters to specify a parameter event to an audio unit.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/parameterevent?language=objc)
#[cfg(feature = "AUComponent")]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ParameterEvent {
    pub parameterID: AudioUnitParameterID,
    pub scope: AudioUnitScope,
    pub element: AudioUnitElement,
    pub value: AudioUnitParameterValue,
}

#[cfg(feature = "AUComponent")]
unsafe impl Encode for ParameterEvent {
    const ENCODING: Encoding = Encoding::Struct(
        "ParameterEvent",
        &[
            <AudioUnitParameterID>::ENCODING,
            <AudioUnitScope>::ENCODING,
            <AudioUnitElement>::ENCODING,
            <AudioUnitParameterValue>::ENCODING,
        ],
    );
}

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

/// specifies the value for a tempo in beats per minute
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/extendedtempoevent?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ExtendedTempoEvent {
    pub bpm: f64,
}

unsafe impl Encode for ExtendedTempoEvent {
    const ENCODING: Encoding = Encoding::Struct("ExtendedTempoEvent", &[<f64>::ENCODING]);
}

unsafe impl RefEncode for ExtendedTempoEvent {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// The parameters to specify a preset for an audio unit.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/aupresetevent?language=objc)
#[cfg(all(feature = "AUComponent", feature = "objc2-core-foundation"))]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct AUPresetEvent {
    pub scope: AudioUnitScope,
    pub element: AudioUnitElement,
    pub preset: NonNull<CFPropertyList>,
}

#[cfg(all(feature = "AUComponent", feature = "objc2-core-foundation"))]
unsafe impl Encode for AUPresetEvent {
    const ENCODING: Encoding = Encoding::Struct(
        "AUPresetEvent",
        &[
            <AudioUnitScope>::ENCODING,
            <AudioUnitElement>::ENCODING,
            <NonNull<CFPropertyList>>::ENCODING,
        ],
    );
}

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

/// A display representation of a musical time in beats.
///
/// A clock's internal representation of musical time is in beats based on the
/// beginning of the timeline. Normally, such times should be displayed to the user
/// in terms of bars, beats, and subbeats (sometimes called "units" or "parts per
/// quarter" [PPQ]). This data structure is such a display representation.
///
/// By convention, bar 1 is the beginning of the sequence. Beat 1 is the first beat
/// of the measure. In 4/4 time, beat will have a value from 1 to 4. Music
/// applications often use beat divisions such as 480 and 960.
///
///
/// A measure number.
///
/// A beat number (1..n).
///
/// The numerator of the fractional number of beats.
///
/// The denominator of the fractional number of beats.
///
/// Must be 0.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/cabarbeattime?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CABarBeatTime {
    pub bar: i32,
    pub beat: u16,
    pub subbeat: u16,
    pub subbeatDivisor: u16,
    pub reserved: u16,
}

unsafe impl Encode for CABarBeatTime {
    const ENCODING: Encoding = Encoding::Struct(
        "CABarBeatTime",
        &[
            <i32>::ENCODING,
            <u16>::ENCODING,
            <u16>::ENCODING,
            <u16>::ENCODING,
            <u16>::ENCODING,
        ],
    );
}

unsafe impl RefEncode for CABarBeatTime {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/opaquemusicplayer?language=objc)
#[repr(C)]
#[derive(Debug)]
pub struct OpaqueMusicPlayer {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

unsafe impl RefEncode for OpaqueMusicPlayer {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Encoding::Struct("OpaqueMusicPlayer", &[]));
}

/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicplayer?language=objc)
pub type MusicPlayer = *mut OpaqueMusicPlayer;

/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/opaquemusicsequence?language=objc)
#[repr(C)]
#[derive(Debug)]
pub struct OpaqueMusicSequence {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

unsafe impl RefEncode for OpaqueMusicSequence {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Encoding::Struct("OpaqueMusicSequence", &[]));
}

/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicsequence?language=objc)
pub type MusicSequence = *mut OpaqueMusicSequence;

/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/opaquemusictrack?language=objc)
#[repr(C)]
#[derive(Debug)]
pub struct OpaqueMusicTrack {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

unsafe impl RefEncode for OpaqueMusicTrack {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Encoding::Struct("OpaqueMusicTrack", &[]));
}

/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musictrack?language=objc)
pub type MusicTrack = *mut OpaqueMusicTrack;

/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/opaquemusiceventiterator?language=objc)
#[repr(C)]
#[derive(Debug)]
pub struct OpaqueMusicEventIterator {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

unsafe impl RefEncode for OpaqueMusicEventIterator {
    const ENCODING_REF: Encoding =
        Encoding::Pointer(&Encoding::Struct("OpaqueMusicEventIterator", &[]));
}

/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musiceventiterator?language=objc)
pub type MusicEventIterator = *mut OpaqueMusicEventIterator;

/// See MusicSequenceSetUserCallback
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicsequenceusercallback?language=objc)
pub type MusicSequenceUserCallback = Option<
    unsafe extern "C-unwind" fn(
        *mut c_void,
        MusicSequence,
        MusicTrack,
        MusicTimeStamp,
        NonNull<MusicEventUserData>,
        MusicTimeStamp,
        MusicTimeStamp,
    ),
>;

/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudiotoolboxerr_invalidsequencetype?language=objc)
pub const kAudioToolboxErr_InvalidSequenceType: OSStatus = -10846;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudiotoolboxerr_trackindexerror?language=objc)
pub const kAudioToolboxErr_TrackIndexError: OSStatus = -10859;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudiotoolboxerr_tracknotfound?language=objc)
pub const kAudioToolboxErr_TrackNotFound: OSStatus = -10858;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudiotoolboxerr_endoftrack?language=objc)
pub const kAudioToolboxErr_EndOfTrack: OSStatus = -10857;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudiotoolboxerr_startoftrack?language=objc)
pub const kAudioToolboxErr_StartOfTrack: OSStatus = -10856;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudiotoolboxerr_illegaltrackdestination?language=objc)
pub const kAudioToolboxErr_IllegalTrackDestination: OSStatus = -10855;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudiotoolboxerr_nosequence?language=objc)
pub const kAudioToolboxErr_NoSequence: OSStatus = -10854;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudiotoolboxerr_invalideventtype?language=objc)
pub const kAudioToolboxErr_InvalidEventType: OSStatus = -10853;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudiotoolboxerr_invalidplayerstate?language=objc)
pub const kAudioToolboxErr_InvalidPlayerState: OSStatus = -10852;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudiotoolboxerr_cannotdoincurrentcontext?language=objc)
pub const kAudioToolboxErr_CannotDoInCurrentContext: OSStatus = -10863;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudiotoolboxerror_notrackdestination?language=objc)
pub const kAudioToolboxError_NoTrackDestination: OSStatus = -66720;

/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/ksequencetrackproperty_loopinfo?language=objc)
pub const kSequenceTrackProperty_LoopInfo: u32 = 0;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/ksequencetrackproperty_offsettime?language=objc)
pub const kSequenceTrackProperty_OffsetTime: u32 = 1;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/ksequencetrackproperty_mutestatus?language=objc)
pub const kSequenceTrackProperty_MuteStatus: u32 = 2;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/ksequencetrackproperty_solostatus?language=objc)
pub const kSequenceTrackProperty_SoloStatus: u32 = 3;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/ksequencetrackproperty_automatedparameters?language=objc)
pub const kSequenceTrackProperty_AutomatedParameters: u32 = 4;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/ksequencetrackproperty_tracklength?language=objc)
pub const kSequenceTrackProperty_TrackLength: u32 = 5;
/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/ksequencetrackproperty_timeresolution?language=objc)
pub const kSequenceTrackProperty_TimeResolution: u32 = 6;

/// Used to control the looping behaviour of a track
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musictrackloopinfo?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MusicTrackLoopInfo {
    pub loopDuration: MusicTimeStamp,
    pub numberOfLoops: i32,
}

unsafe impl Encode for MusicTrackLoopInfo {
    const ENCODING: Encoding = Encoding::Struct(
        "MusicTrackLoopInfo",
        &[<MusicTimeStamp>::ENCODING, <i32>::ENCODING],
    );
}

unsafe impl RefEncode for MusicTrackLoopInfo {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern "C-unwind" {
    /// Create a new music player
    ///
    /// A music player is used to play a sequence back. This call is used to create a player
    /// When a sequence is to be played by a player, it can play to either an AUGraph, a MIDI Destination or a
    /// mixture/combination of both.
    ///
    /// Parameter `outPlayer`: the newly created player
    ///
    /// # Safety
    ///
    /// `out_player` must be a valid pointer.
    pub fn NewMusicPlayer(out_player: NonNull<MusicPlayer>) -> OSStatus;
}

extern "C-unwind" {
    /// Dispose a music player
    ///
    /// Parameter `inPlayer`: the player to dispose
    ///
    /// # Safety
    ///
    /// `in_player` must be a valid pointer.
    pub fn DisposeMusicPlayer(in_player: MusicPlayer) -> OSStatus;
}

extern "C-unwind" {
    /// Set the sequence for the player to play
    ///
    /// A Sequence cannot be set on a player while it is playing. Setting a sequence
    /// will overide the currently set sequence.
    ///
    /// Parameter `inPlayer`: the player
    ///
    /// Parameter `inSequence`: the sequence for the player to play
    ///
    /// # Safety
    ///
    /// - `in_player` must be a valid pointer.
    /// - `in_sequence` must be a valid pointer or null.
    pub fn MusicPlayerSetSequence(in_player: MusicPlayer, in_sequence: MusicSequence) -> OSStatus;
}

extern "C-unwind" {
    /// Get the sequence attached to a player
    ///
    /// If the player does not have a sequence set, this will return the _NoSequence error
    ///
    /// Parameter `inPlayer`: the player
    ///
    /// Parameter `outSequence`: the sequence currently set on the player
    ///
    /// # Safety
    ///
    /// - `in_player` must be a valid pointer.
    /// - `out_sequence` must be a valid pointer.
    pub fn MusicPlayerGetSequence(
        in_player: MusicPlayer,
        out_sequence: NonNull<MusicSequence>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Set the current time on the player
    ///
    /// The Get and Set Time calls take a specification of time as beats. This positions the player
    /// to the specified time based on the currently set sequence. No range checking on the time value
    /// is done. This can be set on a playing player (in which case playing will be resumed from the
    /// new time).
    ///
    /// Parameter `inPlayer`: the player
    ///
    /// Parameter `inTime`: the new time value
    ///
    /// # Safety
    ///
    /// `in_player` must be a valid pointer.
    pub fn MusicPlayerSetTime(in_player: MusicPlayer, in_time: MusicTimeStamp) -> OSStatus;
}

extern "C-unwind" {
    /// Get the current time of the player
    ///
    /// The Get and Set Time calls take a specification of time as beats. This retrieves the player's
    /// current time. If it is playing this time is the time of the player at the time the call was made.
    ///
    /// Parameter `inPlayer`: the player
    ///
    /// Parameter `outTime`: the current time value
    ///
    /// # Safety
    ///
    /// - `in_player` must be a valid pointer.
    /// - `out_time` must be a valid pointer.
    pub fn MusicPlayerGetTime(
        in_player: MusicPlayer,
        out_time: NonNull<MusicTimeStamp>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Returns the host time that will be (or was) played at the specified beat.
    ///
    /// This call is only valid if the player is playing and will return an error if the player is not playing
    /// or if the starting position of the player (its "starting beat") was after the specified beat.
    /// For general translation of beats to time in a sequence, see the MusicSequence calls for beat
    /// <
    /// ->seconds.
    ///
    /// The call uses the player's sequence's tempo map to translate a beat time from the starting time and beat
    /// of the player.
    ///
    /// Parameter `inPlayer`: the player
    ///
    /// Parameter `inBeats`: the specified beat-time value
    ///
    /// Parameter `outHostTime`: the corresponding host time
    ///
    /// # Safety
    ///
    /// - `in_player` must be a valid pointer.
    /// - `out_host_time` must be a valid pointer.
    pub fn MusicPlayerGetHostTimeForBeats(
        in_player: MusicPlayer,
        in_beats: MusicTimeStamp,
        out_host_time: NonNull<u64>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Returns the beat that will be (or was) played at the specified host time.
    ///
    /// This call is only valid if the player is playing and will return an error if the player is not playing
    /// or if the starting time of the player was after the specified host time.
    /// For general translation of beats to time in a sequence, see the MusicSequence calls for beat
    /// <
    /// ->seconds.
    ///
    /// The call uses the player's sequence's tempo map to retrieve a beat time from the starting and specified host time.
    ///
    ///
    /// Parameter `inPlayer`: the player
    ///
    /// Parameter `inHostTime`: the specified host time value
    ///
    /// Parameter `outBeats`: the corresponding beat time
    ///
    /// # Safety
    ///
    /// - `in_player` must be a valid pointer.
    /// - `out_beats` must be a valid pointer.
    pub fn MusicPlayerGetBeatsForHostTime(
        in_player: MusicPlayer,
        in_host_time: u64,
        out_beats: NonNull<MusicTimeStamp>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Prepare the player for playing
    ///
    /// Allows the player to prepare its state so that starting is has a lower latency. If a player is started without
    /// being prerolled, the player will pre-roll itself and then start.
    ///
    /// Parameter `inPlayer`: the player
    ///
    /// # Safety
    ///
    /// `in_player` must be a valid pointer.
    pub fn MusicPlayerPreroll(in_player: MusicPlayer) -> OSStatus;
}

extern "C-unwind" {
    /// Start the player
    ///
    /// If the player has not been prerolled, it will pre-roll itself and then start.
    ///
    /// Parameter `inPlayer`: the player
    ///
    /// # Safety
    ///
    /// `in_player` must be a valid pointer.
    pub fn MusicPlayerStart(in_player: MusicPlayer) -> OSStatus;
}

extern "C-unwind" {
    /// Stop the player
    ///
    /// Parameter `inPlayer`: the player
    ///
    /// # Safety
    ///
    /// `in_player` must be a valid pointer.
    pub fn MusicPlayerStop(in_player: MusicPlayer) -> OSStatus;
}

extern "C-unwind" {
    /// Returns the playing state of the player. "Is it playing?"
    ///
    /// This call returns a non-zero value in outIsPlaying if the player has been
    /// started and not stopped. It may have "played" past the events of the attached
    /// MusicSequence, but it is still considered to be playing (and its time value increasing)
    /// until it is explicitly stopped
    ///
    /// Parameter `inPlayer`: the player
    ///
    /// Parameter `outIsPlaying`: false if not, true (non-zero) if is playing
    ///
    /// # Safety
    ///
    /// - `in_player` must be a valid pointer.
    /// - `out_is_playing` must be a valid pointer.
    pub fn MusicPlayerIsPlaying(
        in_player: MusicPlayer,
        out_is_playing: NonNull<Boolean>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Scale the playback rate of the player
    ///
    /// Parameter `inPlayer`: the player
    ///
    /// Parameter `inScaleRate`: a scalar that will be applied to the playback rate. If 2, playback is twice as fast, if
    /// 0.5 it is half as fast. As a scalar, the value must be greater than zero.
    ///
    /// # Safety
    ///
    /// `in_player` must be a valid pointer.
    pub fn MusicPlayerSetPlayRateScalar(in_player: MusicPlayer, in_scale_rate: f64) -> OSStatus;
}

extern "C-unwind" {
    /// Get the playback rate scalar of the player
    ///
    /// Parameter `inPlayer`: the player
    ///
    /// Parameter `outScaleRate`: the current scalar being applied to the player. Default value is 1.0
    ///
    /// # Safety
    ///
    /// - `in_player` must be a valid pointer.
    /// - `out_scale_rate` must be a valid pointer.
    pub fn MusicPlayerGetPlayRateScalar(
        in_player: MusicPlayer,
        out_scale_rate: NonNull<f64>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Create a new empty sequence
    ///
    /// A new music sequence will only have a tempo track (with a default tempo of 120 bpm),
    /// and the default type is beat based.
    ///
    /// When a sequence is to be played by a player, it can play to either an AUGraph, a MIDI Destination or a
    /// mixture/combination of both. See MusicSequenceSetAUGraph and MusicSequenceSetMIDIEndpoint for the generic
    /// destination assignments. Specific tracks can also be assigned nodes of a graph or a MIDI endpoint as targets
    /// for the events that they contain; see MusicTrackSetDestNode and MusicTrackSetDestMIDIEndpoint.
    ///
    ///
    /// Parameter `outSequence`: the new sequence
    ///
    /// # Safety
    ///
    /// `out_sequence` must be a valid pointer.
    pub fn NewMusicSequence(out_sequence: NonNull<MusicSequence>) -> OSStatus;
}

extern "C-unwind" {
    /// Dispose the sequence
    ///
    /// A sequence cannot be disposed while a MusicPlayer has it.
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// # Safety
    ///
    /// `in_sequence` must be a valid pointer.
    pub fn DisposeMusicSequence(in_sequence: MusicSequence) -> OSStatus;
}

extern "C-unwind" {
    /// Add a new (empty) track to the sequence
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `outTrack`: the new track (it is always appended to any existing tracks)
    ///
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `out_track` must be a valid pointer.
    pub fn MusicSequenceNewTrack(
        in_sequence: MusicSequence,
        out_track: NonNull<MusicTrack>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Remove and dispose a track from a sequence
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `inTrack`: the track to remove and dispose
    ///
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `in_track` must be a valid pointer.
    pub fn MusicSequenceDisposeTrack(in_sequence: MusicSequence, in_track: MusicTrack) -> OSStatus;
}

extern "C-unwind" {
    /// The number of tracks in a sequence.
    /// The track count and accessors exclude the tempo track (which is treated as a special case)
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `outNumberOfTracks`: the number of tracks
    ///
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `out_number_of_tracks` must be a valid pointer.
    pub fn MusicSequenceGetTrackCount(
        in_sequence: MusicSequence,
        out_number_of_tracks: NonNull<u32>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Get a track at the specified index
    ///
    /// Index is zero based. It will return kAudio_ParamError if index is not in the range: 0
    /// <
    /// TrackCount
    /// The track count and accessors exclude the tempo track (which is treated as a special case)
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `inTrackIndex`: the index
    ///
    /// Parameter `outTrack`: the track at that index
    ///
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `out_track` must be a valid pointer.
    pub fn MusicSequenceGetIndTrack(
        in_sequence: MusicSequence,
        in_track_index: u32,
        out_track: NonNull<MusicTrack>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Get the index for a specific track
    ///
    /// Index is zero based. It will return an error if the track is not a member of the sequence.
    /// The track count and accessors exclude the tempo track (which is treated as a special case)
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `outTrackIndex`: the index of the track
    ///
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `in_track` must be a valid pointer.
    /// - `out_track_index` must be a valid pointer.
    pub fn MusicSequenceGetTrackIndex(
        in_sequence: MusicSequence,
        in_track: MusicTrack,
        out_track_index: NonNull<u32>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Get the tempo track of the sequence
    ///
    /// Each sequence has a single tempo track. All tempo events are placed into this tempo track (as well
    /// as other appropriate events (time sig for instance from a MIDI file). The tempo track, once retrieved
    /// can be edited and iterated upon as any other track. Non-tempo events in a tempo track are ignored.
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `outTrack`: the tempo track of the sequence
    ///
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `out_track` must be a valid pointer.
    pub fn MusicSequenceGetTempoTrack(
        in_sequence: MusicSequence,
        out_track: NonNull<MusicTrack>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Set the graph to be associated with the sequence
    ///
    /// A sequence can be associated with an AUGraph and this graph will be used to render the events as
    /// controlled by the sequence when it is played. By default, all of the tracks of a sequence will
    /// find the first AUNode that is an instance of an Apple MusicDevice audio unit (see MusicSequenceGetAUGraph).
    /// Specific nodes of the graph can be targeted for different tracks (see MusicTrackSetDestNode).  To render a
    /// multi-track GM MIDI sequence on iOS, create a custom graph with a MIDISynth audio unit as the MusicDevice.
    /// If inGraph is set to NULL, the sequence will reset to use the default graph.
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `inGraph`: the graph
    ///
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `in_graph` must be a valid pointer or null.
    #[cfg(feature = "AUGraph")]
    pub fn MusicSequenceSetAUGraph(in_sequence: MusicSequence, in_graph: AUGraph) -> OSStatus;
}

extern "C-unwind" {
    /// Gets the graph currently associated with a sequence
    ///
    /// By default if no graph is assigned to a sequence then the sequence will create a default graph.
    /// This default graph contains a MusicDevice and a DynamicsProcessor and all tracks will be targeted
    /// to the MusicDevice.  On macOS, this MusicDevice is an instance of a software synthesizer that is
    /// compatible with the GM and GS MIDI standards.  On iOS, it is an instance of a monotimbral software
    /// synthesizer designed to render events from a single MIDI channel.  To render multi-track GM MIDI
    /// sequences on iOS, create a custom graph with a MIDISynth audio unit as the MusicDevice.
    ///
    /// This call will thus either return the graph as set by the user, or this default graph.
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `outGraph`: the graph
    ///
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `out_graph` must be a valid pointer.
    #[cfg(feature = "AUGraph")]
    pub fn MusicSequenceGetAUGraph(
        in_sequence: MusicSequence,
        out_graph: NonNull<AUGraph>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Makes the target of all of the tracks in the sequence a MIDI endpoint
    ///
    /// This is a convenience function, and is equivalent to iterating through all of the tracks in a sequence
    /// and targeting each track to the MIDI endpoint
    ///
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `inEndpoint`: the MIDI endpoint
    ///
    /// # Safety
    ///
    /// `in_sequence` must be a valid pointer.
    #[cfg(feature = "objc2-core-midi")]
    pub fn MusicSequenceSetMIDIEndpoint(
        in_sequence: MusicSequence,
        in_endpoint: MIDIEndpointRef,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Set the sequence type (the default is beats)
    ///
    /// These two calls allow you to get and set a MusicSequence type; specifying
    /// kMusicSequenceType_Beats        = 'beat',
    /// kMusicSequenceType_Seconds        = 'secs',
    /// kMusicSequenceType_Samples        = 'samp'
    ///
    /// The sequence type can be set to beats at any time. The sequence type can only be set to
    /// seconds or samples if there are NO tempo events already in the sequence.
    ///
    /// For beats - it can have as many tempo events as you want
    /// For Samples and Seconds - you should add a single tempo event after setting the type
    /// Samples - the tempo is the desired sample rate - e.g. 44100 and each "beat" in the sequence will be
    /// interpreted as a sample count at that sample rate (so beat == 44100 is a second)
    /// Seconds - the tempo should be set to 60 - a beat is a second.
    ///
    /// Beats is the default (and is the behaviour on pre 10.5 systems)
    ///
    /// A meta event of interest for Seconds based MIDI files is the SMPTE Offset meta event - stored in the tempo track.
    /// The sequence doesn't do anything with this event (except store/write it)
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `inType`: the sequence type
    ///
    /// # Safety
    ///
    /// `in_sequence` must be a valid pointer.
    pub fn MusicSequenceSetSequenceType(
        in_sequence: MusicSequence,
        in_type: MusicSequenceType,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Get the sequence type
    ///
    /// See SetSequence for a full description
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `outType`: the type
    ///
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `out_type` must be a valid pointer.
    pub fn MusicSequenceGetSequenceType(
        in_sequence: MusicSequence,
        out_type: NonNull<MusicSequenceType>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Load the data contained within the referenced file to the sequence
    ///
    /// This function will parse the file referenced by the URL and add the events to the sequence.
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `inFileRef`: a file:// URL that references a file
    ///
    /// Parameter `inFileTypeHint`: provides a hint to the sequence on the file type being imported. Can be zero in many cases.
    ///
    /// Parameter `inFlags`: flags that can control how the data is parsed in the file and laid out in the tracks
    /// that will be created and added to the sequence in this operation
    ///
    /// # Safety
    ///
    /// `in_sequence` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MusicSequenceFileLoad(
        in_sequence: MusicSequence,
        in_file_ref: &CFURL,
        in_file_type_hint: MusicSequenceFileTypeID,
        in_flags: MusicSequenceLoadFlags,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Load the data to the sequence
    ///
    /// This function will parse the data and add the events to the sequence. The data provided needs to
    /// be of a particular file type as specified by the fileTypeHint.
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `inData`: the contents of a valid file loaded into a CFData object
    ///
    /// Parameter `inFileTypeHint`: provides a hint to the sequence on the file type being imported. Can be zero in many cases.
    ///
    /// Parameter `inFlags`: flags that can control how the data is parsed in the file and laid out in the tracks
    /// that will be created and added to the sequence in this operation
    ///
    /// # Safety
    ///
    /// `in_sequence` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MusicSequenceFileLoadData(
        in_sequence: MusicSequence,
        in_data: &CFData,
        in_file_type_hint: MusicSequenceFileTypeID,
        in_flags: MusicSequenceLoadFlags,
    ) -> OSStatus;
}

// TODO: pub fn MusicSequenceSetSMPTEResolution(fps: SignedByte,ticks: Byte,) -> i16;

// TODO: pub fn MusicSequenceGetSMPTEResolution(in_res: i16,fps: NonNull<SignedByte>,ticks: NonNull<Byte>,);

extern "C-unwind" {
    /// Create a file from a sequence
    ///
    /// This function can be (and is most commonly) used to create a MIDI file from the events in a sequence.
    /// Only MIDI based events are used when creating the MIDI file. MIDI files are normally beat based, but
    /// can also have a SMPTE (or real-time rather than beat time) representation.
    ///
    /// inResolution is relationship between "tick" and quarter note for saving to Standard MIDI File
    /// - pass in zero to use default - this will be the value that is currently set on the tempo track
    /// - see the comments for the set track property's time resolution
    ///
    /// The different Sequence types determine the kinds of files that can be created:
    ///
    /// Beats
    /// When saving a MIDI file, it saves a beats (PPQ) based axis
    ///
    /// Seconds
    /// When saving a MIDI file, it will save it as a SMPTE resolution - so you should specify this resolution
    /// when creating the MIDI file.
    /// If zero is specified, 25 fps and 40 ticks/frame is used (a time scale of a millisecond)
    ///
    /// Samples
    /// You cannot save to a MIDI file with this sequence type
    ///
    /// The complete meaning of the 16-bit "division" field in a MIDI File's MThd chunk.
    ///
    /// If it is positive, then a tick represents 1/D quarter notes.
    ///
    /// If it negative:
    ///
    /// bits 14-8 are a signed 7-bit number representing the SMPTE format:
    /// -24, -25, -29 (drop), -30
    /// bits 7-0 represents the number of ticks per SMPTE frame
    /// typical values: 4, 10, 80, 100
    ///
    /// You can obtain millisecond resolution by specifying 25 frames/sec and 40 divisions/frame.
    ///
    /// 30 fps with 80 bits (ticks) per frame: 0xE250  ((char)0xE2 == -30)
    ///
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `inFileRef`: the location of the file to create
    ///
    /// Parameter `inFileType`: the type of file to create
    ///
    /// Parameter `inFlags`: flags to control the file creation
    ///
    /// Parameter `inResolution`: the resolution (depending on file type and sequence type)
    ///
    /// # Safety
    ///
    /// `in_sequence` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MusicSequenceFileCreate(
        in_sequence: MusicSequence,
        in_file_ref: &CFURL,
        in_file_type: MusicSequenceFileTypeID,
        in_flags: MusicSequenceFileFlags,
        in_resolution: i16,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Create a data object from a sequence
    ///
    /// The same basic parameters apply to this as with the MusicSequenceFileCreate function. The difference
    /// being that that function will create a file on disk, whereas this one will create a CFData object
    /// that is a file in memory. The CFData object should be released by the caller.
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `inFileType`: the type of file to create
    ///
    /// Parameter `inFlags`: flags to control the file creation
    ///
    /// Parameter `inResolution`: the resolution (depending on file type and sequence type)
    ///
    /// Parameter `outData`: the resulting data object
    ///
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `out_data` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    pub fn MusicSequenceFileCreateData(
        in_sequence: MusicSequence,
        in_file_type: MusicSequenceFileTypeID,
        in_flags: MusicSequenceFileFlags,
        in_resolution: i16,
        out_data: NonNull<*const CFData>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Reverse in time all events in a sequence, including the tempo events
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// # Safety
    ///
    /// `in_sequence` must be a valid pointer.
    pub fn MusicSequenceReverse(in_sequence: MusicSequence) -> OSStatus;
}

extern "C-unwind" {
    /// Returns a seconds value that would correspond to the supplied beats
    ///
    /// Uses the sequence's tempo events
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `inBeats`: the beats
    ///
    /// Parameter `outSeconds`: the seconds (time from 0 beat)
    ///
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `out_seconds` must be a valid pointer.
    pub fn MusicSequenceGetSecondsForBeats(
        in_sequence: MusicSequence,
        in_beats: MusicTimeStamp,
        out_seconds: NonNull<f64>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Returns a beat value that would correspond to the supplied seconds from zero.
    ///
    /// Uses the sequence's tempo events
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `inSeconds`: the seconds
    ///
    /// Parameter `outBeats`: the corresponding beat
    ///
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `out_beats` must be a valid pointer.
    pub fn MusicSequenceGetBeatsForSeconds(
        in_sequence: MusicSequence,
        in_seconds: f64,
        out_beats: NonNull<MusicTimeStamp>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Establish a user callback for a sequence
    ///
    /// This call is used to register (or remove if inCallback is NULL) a callback
    /// that the MusicSequence will call for ANY UserEvents that are added to any of the
    /// tracks of the sequence.
    ///
    /// If there is a callback registered, then UserEvents will be chased when
    /// MusicPlayerSetTime is called. In that case the inStartSliceBeat and inEndSliceBeat
    /// will both be the same value and will be the beat that the player is chasing too.
    ///
    /// In normal cases, where the sequence data is being scheduled for playback, the
    /// following will apply:
    /// inStartSliceBeat
    /// <
    /// = inEventTime
    /// <
    /// inEndSliceBeat
    ///
    /// The only exception to this is if the track that owns the MusicEvent is looping.
    /// In this case the start beat will still be less than the end beat (so your callback
    /// can still determine that it is playing, and what beats are currently being scheduled),
    /// however, the inEventTime will be the original time-stamped time of the user event.
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `inCallback`: the callback
    ///
    /// Parameter `inClientData`: client (user supplied) data provided back to the callback when it is called by the sequence
    ///
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `in_callback` must be implemented correctly.
    /// - `in_client_data` must be a valid pointer or null.
    pub fn MusicSequenceSetUserCallback(
        in_sequence: MusicSequence,
        in_callback: MusicSequenceUserCallback,
        in_client_data: *mut c_void,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Convenience function to format a sequence's beat time to its bar-beat time
    ///
    /// The sequence's tempo track Time Sig events are used to
    /// to calculate the bar-beat representation. If there are no Time Sig events added to the sequence
    /// 4/4 is assumed. A Time Sig event is a MIDI Meta Event as specified for MIDI files.
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `inBeats`: the beat which should be represented by the bar-beat
    ///
    /// Parameter `inSubbeatDivisor`: The denominator of the fractional number of beats.
    ///
    /// Parameter `outBarBeatTime`: the formatted bar/beat time
    ///
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `out_bar_beat_time` must be a valid pointer.
    pub fn MusicSequenceBeatsToBarBeatTime(
        in_sequence: MusicSequence,
        in_beats: MusicTimeStamp,
        in_subbeat_divisor: u32,
        out_bar_beat_time: NonNull<CABarBeatTime>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Convenience function to format a bar-beat time to a sequence's beat time
    ///
    /// The sequence's tempo track Time Sig events are used to
    /// to calculate the bar-beat representation. If there are no Time Sig events added to the sequence
    /// 4/4 is assumed. A Time Sig event is a MIDI Meta Event as specified for MIDI files.
    ///
    /// Parameter `inSequence`: the sequence
    ///
    /// Parameter `inBarBeatTime`: the bar-beat time
    ///
    /// Parameter `outBeats`: the sequence's beat time for that bar-beat time
    ///
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `in_bar_beat_time` must be a valid pointer.
    /// - `out_beats` must be a valid pointer.
    pub fn MusicSequenceBarBeatTimeToBeats(
        in_sequence: MusicSequence,
        in_bar_beat_time: NonNull<CABarBeatTime>,
        out_beats: NonNull<MusicTimeStamp>,
    ) -> OSStatus;
}

/// Returns a dictionary containing meta-data derived from a sequence
///
/// The dictionary can contain one or more of the kAFInfoDictionary_*
/// keys specified in
/// <AudioToolbox
/// /AudioFile.h>
///
/// The caller should release the returned dictionary. If the call fails it will return NULL
///
///
/// Parameter `inSequence`: the sequence
///
/// Returns: a CFDictionary or NULL if the call fails.
///
/// # Safety
///
/// `in_sequence` must be a valid pointer.
#[cfg(feature = "objc2-core-foundation")]
#[inline]
pub unsafe extern "C-unwind" fn MusicSequenceGetInfoDictionary(
    in_sequence: MusicSequence,
) -> CFRetained<CFDictionary> {
    extern "C-unwind" {
        fn MusicSequenceGetInfoDictionary(
            in_sequence: MusicSequence,
        ) -> Option<NonNull<CFDictionary>>;
    }
    let ret = unsafe { MusicSequenceGetInfoDictionary(in_sequence) };
    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
    unsafe { CFRetained::retain(ret) }
}

extern "C-unwind" {
    /// Gets the sequence which the track is a member of
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `outSequence`: the track's sequence
    ///
    /// # Safety
    ///
    /// - `in_track` must be a valid pointer.
    /// - `out_sequence` must be a valid pointer.
    pub fn MusicTrackGetSequence(
        in_track: MusicTrack,
        out_sequence: NonNull<MusicSequence>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Sets the track's target to the specified AUNode
    ///
    /// The node must be a member of the graph that the track's sequence is using. When played, the track
    /// will send all of its events to that node.
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inNode`: the new node
    ///
    /// # Safety
    ///
    /// `in_track` must be a valid pointer.
    #[cfg(feature = "AUGraph")]
    pub fn MusicTrackSetDestNode(in_track: MusicTrack, in_node: AUNode) -> OSStatus;
}

extern "C-unwind" {
    /// Sets the track's target to the specified MIDI endpoint
    ///
    /// When played, the track will send all of its events to the specified MIDI Endpoint.
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inEndpoint`: the new MIDI endpoint
    ///
    /// # Safety
    ///
    /// `in_track` must be a valid pointer.
    #[cfg(feature = "objc2-core-midi")]
    pub fn MusicTrackSetDestMIDIEndpoint(
        in_track: MusicTrack,
        in_endpoint: MIDIEndpointRef,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Gets the track's target if it is an AUNode
    ///
    /// Returns kAudioToolboxErr_IllegalTrackDestination if the track's target is a MIDIEndpointRef
    /// and NOT an AUNode
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `outNode`: the node target for the track
    ///
    /// # Safety
    ///
    /// - `in_track` must be a valid pointer.
    /// - `out_node` must be a valid pointer.
    #[cfg(feature = "AUGraph")]
    pub fn MusicTrackGetDestNode(in_track: MusicTrack, out_node: NonNull<AUNode>) -> OSStatus;
}

extern "C-unwind" {
    /// Gets the track's target if it is a MIDI Endpoint
    ///
    /// Returns kAudioToolboxErr_IllegalTrackDestination if the track's target is an AUNode
    /// and NOT a MIDI Endpoint
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `outEndpoint`: the MIDI Endpoint target for the track
    ///
    /// # Safety
    ///
    /// - `in_track` must be a valid pointer.
    /// - `out_endpoint` must be a valid pointer.
    #[cfg(feature = "objc2-core-midi")]
    pub fn MusicTrackGetDestMIDIEndpoint(
        in_track: MusicTrack,
        out_endpoint: NonNull<MIDIEndpointRef>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Sets the specified property value
    ///
    /// Property values are always get and set by reference
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inPropertyID`: the property ID
    ///
    /// Parameter `inData`: the new property value
    ///
    /// Parameter `inLength`: the size of the property value being set
    ///
    /// # Safety
    ///
    /// - `in_track` must be a valid pointer.
    /// - `in_data` must be a valid pointer.
    pub fn MusicTrackSetProperty(
        in_track: MusicTrack,
        in_property_id: u32,
        in_data: NonNull<c_void>,
        in_length: u32,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Gets the specified property value
    ///
    /// If outData is NULL, then the size of the data will be passed back in ioLength
    /// This allows the client to allocate a buffer of the correct size (useful for variable
    /// length properties -- currently all properties have fixed size)
    /// Property values are always get and set by reference
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inPropertyID`: the property ID
    ///
    /// Parameter `outData`: if not NULL, points to data of size ioLength
    ///
    /// Parameter `ioLength`: on input the available size of outData, on output the size of the valid data that outData
    /// will then point too.
    ///
    /// # Safety
    ///
    /// - `in_track` must be a valid pointer.
    /// - `out_data` must be a valid pointer.
    /// - `io_length` must be a valid pointer.
    pub fn MusicTrackGetProperty(
        in_track: MusicTrack,
        in_property_id: u32,
        out_data: NonNull<c_void>,
        io_length: NonNull<u32>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Move events in a track
    ///
    /// Moves all of the events in the specified time range by the moveTime. MoveTime maybe negative to
    /// move events backwards (towards zero).
    ///
    /// All time ranges are [starttime
    /// <
    /// endtime]
    ///
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inStartTime`: the start time for the range of events
    ///
    /// Parameter `inEndTime`: the end time up to which will form the range of the events to move
    ///
    /// Parameter `inMoveTime`: amount of beats to move the selected events.
    ///
    /// # Safety
    ///
    /// `in_track` must be a valid pointer.
    pub fn MusicTrackMoveEvents(
        in_track: MusicTrack,
        in_start_time: MusicTimeStamp,
        in_end_time: MusicTimeStamp,
        in_move_time: MusicTimeStamp,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Removes all events within the specified range
    ///
    /// All time ranges are [starttime
    /// <
    /// endtime]
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inStartTime`: the start time for the range of events
    ///
    /// Parameter `inEndTime`: the end time up to which will form the range of the events to clear
    ///
    /// # Safety
    ///
    /// `in_track` must be a valid pointer.
    pub fn MusicTrackClear(
        in_track: MusicTrack,
        in_start_time: MusicTimeStamp,
        in_end_time: MusicTimeStamp,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Removes all the events within the specified range
    ///
    /// Events that fall past the specified range will be moved back by the specified range time.
    ///
    /// All time ranges are [starttime
    /// <
    /// endtime]
    ///
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inStartTime`: the start time for the range of events
    ///
    /// Parameter `inEndTime`: the end time up to which will form the range of the events to cut out
    ///
    /// # Safety
    ///
    /// `in_track` must be a valid pointer.
    pub fn MusicTrackCut(
        in_track: MusicTrack,
        in_start_time: MusicTimeStamp,
        in_end_time: MusicTimeStamp,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Copies events from one track and inserts them into another
    ///
    /// Copies all of the events with the specified time range of the source track. It then inserts
    /// those events into the destination track. All events at and after inDestInsertTime in inDestTrack
    /// are moved forward by the range's duration
    ///
    /// All time ranges are [starttime
    /// <
    /// endtime]
    ///
    ///
    /// Parameter `inSourceTrack`: the source track
    ///
    /// Parameter `inSourceStartTime`: the start time for the range of events
    ///
    /// Parameter `inSourceEndTime`: the end time up to which will form the range of the events to copy from the source track
    ///
    /// Parameter `inDestTrack`: the destination track to copy too
    ///
    /// Parameter `inDestInsertTime`: the time at which the copied events will be inserted.
    ///
    /// # Safety
    ///
    /// - `in_source_track` must be a valid pointer.
    /// - `in_dest_track` must be a valid pointer.
    pub fn MusicTrackCopyInsert(
        in_source_track: MusicTrack,
        in_source_start_time: MusicTimeStamp,
        in_source_end_time: MusicTimeStamp,
        in_dest_track: MusicTrack,
        in_dest_insert_time: MusicTimeStamp,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Copies events from one track and merges them into another
    ///
    /// Copies all of the events with the specified time range of the source track. It then merges
    /// those events into the destination track starting at inDestInsertTime.
    ///
    /// All time ranges are [starttime
    /// <
    /// endtime]
    ///
    ///
    /// Parameter `inSourceTrack`: the source track
    ///
    /// Parameter `inSourceStartTime`: the start time for the range of events
    ///
    /// Parameter `inSourceEndTime`: the end time up to which will form the range of the events to copy from the source track
    ///
    /// Parameter `inDestTrack`: the destination track to copy too
    ///
    /// Parameter `inDestInsertTime`: the time at which the copied events will be merged.
    ///
    /// # Safety
    ///
    /// - `in_source_track` must be a valid pointer.
    /// - `in_dest_track` must be a valid pointer.
    pub fn MusicTrackMerge(
        in_source_track: MusicTrack,
        in_source_start_time: MusicTimeStamp,
        in_source_end_time: MusicTimeStamp,
        in_dest_track: MusicTrack,
        in_dest_insert_time: MusicTimeStamp,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Adds a MIDINoteMessage event to a track
    ///
    /// The event is added at the specified time stamp. The time stamp should not be less than zero.
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inTimeStamp`: the time stamp
    ///
    /// Parameter `inMessage`: the event
    ///
    /// # Safety
    ///
    /// - `in_track` must be a valid pointer.
    /// - `in_message` must be a valid pointer.
    pub fn MusicTrackNewMIDINoteEvent(
        in_track: MusicTrack,
        in_time_stamp: MusicTimeStamp,
        in_message: NonNull<MIDINoteMessage>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Adds a MIDIChannelMessage event to a track
    ///
    /// The event is added at the specified time stamp. The time stamp should not be less than zero.
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inTimeStamp`: the time stamp
    ///
    /// Parameter `inMessage`: the event
    ///
    /// # Safety
    ///
    /// - `in_track` must be a valid pointer.
    /// - `in_message` must be a valid pointer.
    pub fn MusicTrackNewMIDIChannelEvent(
        in_track: MusicTrack,
        in_time_stamp: MusicTimeStamp,
        in_message: NonNull<MIDIChannelMessage>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Adds a MIDIRawData event to a track
    ///
    /// The event is added at the specified time stamp. The time stamp should not be less than zero.
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inTimeStamp`: the time stamp
    ///
    /// Parameter `inRawData`: the event
    ///
    /// # Safety
    ///
    /// - `in_track` must be a valid pointer.
    /// - `in_raw_data` must be a valid pointer.
    pub fn MusicTrackNewMIDIRawDataEvent(
        in_track: MusicTrack,
        in_time_stamp: MusicTimeStamp,
        in_raw_data: NonNull<MIDIRawData>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Adds a ExtendedNoteOnEvent to a track
    ///
    /// The event is added at the specified time stamp. The time stamp should not be less than zero.
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inTimeStamp`: the time stamp
    ///
    /// Parameter `inInfo`: the event
    ///
    /// # Safety
    ///
    /// - `in_track` must be a valid pointer.
    /// - `in_info` must be a valid pointer.
    #[cfg(all(feature = "AUComponent", feature = "MusicDevice"))]
    pub fn MusicTrackNewExtendedNoteEvent(
        in_track: MusicTrack,
        in_time_stamp: MusicTimeStamp,
        in_info: NonNull<ExtendedNoteOnEvent>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Adds a ParameterEvent to a track
    ///
    /// The event is added at the specified time stamp. The time stamp should not be less than zero.
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inTimeStamp`: the time stamp
    ///
    /// Parameter `inInfo`: the event
    ///
    /// # Safety
    ///
    /// - `in_track` must be a valid pointer.
    /// - `in_info` must be a valid pointer.
    #[cfg(feature = "AUComponent")]
    pub fn MusicTrackNewParameterEvent(
        in_track: MusicTrack,
        in_time_stamp: MusicTimeStamp,
        in_info: NonNull<ParameterEvent>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Adds a tempo event to a track
    ///
    /// The event is added at the specified time stamp. The time stamp should not be less than zero.
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inTimeStamp`: the time stamp
    ///
    /// Parameter `inBPM`: the event
    ///
    /// # Safety
    ///
    /// `in_track` must be a valid pointer.
    pub fn MusicTrackNewExtendedTempoEvent(
        in_track: MusicTrack,
        in_time_stamp: MusicTimeStamp,
        in_bpm: f64,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Adds a MIDIMetaEvent to a track
    ///
    /// The event is added at the specified time stamp. The time stamp should not be less than zero.
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inTimeStamp`: the time stamp
    ///
    /// Parameter `inMetaEvent`: the event
    ///
    /// # Safety
    ///
    /// - `in_track` must be a valid pointer.
    /// - `in_meta_event` must be a valid pointer.
    pub fn MusicTrackNewMetaEvent(
        in_track: MusicTrack,
        in_time_stamp: MusicTimeStamp,
        in_meta_event: NonNull<MIDIMetaEvent>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Adds a MusicEventUserData event to a track
    ///
    /// The event is added at the specified time stamp. The time stamp should not be less than zero.
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inTimeStamp`: the time stamp
    ///
    /// Parameter `inUserData`: the event
    ///
    /// # Safety
    ///
    /// - `in_track` must be a valid pointer.
    /// - `in_user_data` must be a valid pointer.
    pub fn MusicTrackNewUserEvent(
        in_track: MusicTrack,
        in_time_stamp: MusicTimeStamp,
        in_user_data: NonNull<MusicEventUserData>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Adds a AUPresetEvent to a track
    ///
    /// The event is added at the specified time stamp. The time stamp should not be less than zero.
    ///
    /// Parameter `inTrack`: the track
    ///
    /// Parameter `inTimeStamp`: the time stamp
    ///
    /// Parameter `inPresetEvent`: the event
    ///
    /// # Safety
    ///
    /// - `in_track` must be a valid pointer.
    /// - `in_preset_event` must be a valid pointer.
    #[cfg(all(feature = "AUComponent", feature = "objc2-core-foundation"))]
    pub fn MusicTrackNewAUPresetEvent(
        in_track: MusicTrack,
        in_time_stamp: MusicTimeStamp,
        in_preset_event: NonNull<AUPresetEvent>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Creates an iterator to iterator over a track's events
    ///
    /// The iterator should be considered invalid if a track is edited. In that case you should create a new
    /// iterator and seek it to the desired position.
    ///
    ///
    /// Parameter `inTrack`: the track upon which to iterate
    ///
    /// Parameter `outIterator`: the new iterator
    ///
    /// # Safety
    ///
    /// - `in_track` must be a valid pointer.
    /// - `out_iterator` must be a valid pointer.
    pub fn NewMusicEventIterator(
        in_track: MusicTrack,
        out_iterator: NonNull<MusicEventIterator>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Dispose an iterator
    ///
    /// Parameter `inIterator`: the iterator
    ///
    /// # Safety
    ///
    /// `in_iterator` must be a valid pointer.
    pub fn DisposeMusicEventIterator(in_iterator: MusicEventIterator) -> OSStatus;
}

extern "C-unwind" {
    /// Move the iterator to an event at the specified time
    ///
    /// If there is no event at the specified time, the iterator will point to the first event after
    /// that time.
    /// By specifying kMusicTimeStamp_EndOfTrack you will position the iterator to the end of track
    /// (which is pointing to the space just AFTER the last event). You can use MusicEventIteratorPreviousEvent
    /// to backup to the last event.
    /// By specifying 0, you will position the iterator at the first event
    ///
    /// Parameter `inIterator`: the iterator
    ///
    /// Parameter `inTimeStamp`: the time stamp to seek too
    ///
    /// # Safety
    ///
    /// `in_iterator` must be a valid pointer.
    pub fn MusicEventIteratorSeek(
        in_iterator: MusicEventIterator,
        in_time_stamp: MusicTimeStamp,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Move the iterator to the next event
    ///
    /// If the iterator was at the last event, then it will move past the last event and will no longer point
    /// to an event. You can use check MusicEventIteratorHasCurrentEvent to see if there is an event at the
    /// iterator's current position. See also MusicEventIteratorHasNextEvent.
    ///
    /// Typically this call is used to move the iterator forwards through the track's events.
    ///
    /// Parameter `inIterator`: the iterator
    ///
    /// # Safety
    ///
    /// `in_iterator` must be a valid pointer.
    pub fn MusicEventIteratorNextEvent(in_iterator: MusicEventIterator) -> OSStatus;
}

extern "C-unwind" {
    /// Move the iterator to the previous event
    ///
    /// If the iterator was at the first event, then it will leave the iterator unchanged and return an error.
    /// See also MusicEventIteratorHasPreviousEvent
    ///
    /// Typically this call is used to move the iterator backwards through the track's events.
    ///
    /// Parameter `inIterator`: the iterator
    ///
    /// # Safety
    ///
    /// `in_iterator` must be a valid pointer.
    pub fn MusicEventIteratorPreviousEvent(in_iterator: MusicEventIterator) -> OSStatus;
}

extern "C-unwind" {
    /// Retrieves the event data at the iterator.
    ///
    /// Retrieves the event and other information from the iterator's current position.
    ///
    /// If you do not want specific information (eg, the time stamp) pass in NULL for that parameter.
    ///
    ///
    /// Parameter `inIterator`: the iterator
    ///
    /// Parameter `outTimeStamp`: the time stamp of the event
    ///
    /// Parameter `outEventType`: one of kMusicEventType_XXX that indicates what kind of event type the iterator
    /// is currently pointing too
    ///
    /// Parameter `outEventData`: a reference to the event data. The type of data is described by the eventType. This data
    /// is read only and should not be edited in place.
    ///
    /// Parameter `outEventDataSize`: the size of the data referenced by outEventData
    ///
    /// # Safety
    ///
    /// - `in_iterator` must be a valid pointer.
    /// - `out_time_stamp` must be a valid pointer.
    /// - `out_event_type` must be a valid pointer.
    /// - `out_event_data` must be a valid pointer.
    /// - `out_event_data_size` must be a valid pointer.
    pub fn MusicEventIteratorGetEventInfo(
        in_iterator: MusicEventIterator,
        out_time_stamp: NonNull<MusicTimeStamp>,
        out_event_type: NonNull<MusicEventType>,
        out_event_data: NonNull<*const c_void>,
        out_event_data_size: NonNull<u32>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Changes the type or value of an event
    ///
    /// Allows you to change either the event type, or the values of the event data, that the iterator is
    /// currently pointing too. You cannot change the event's time (to do that you should use
    /// MusicEventIteratorSetEventTime).
    ///
    ///
    /// Parameter `inIterator`: the iterator
    ///
    /// Parameter `inEventType`: the new (or existing) type of the event you are changing
    ///
    /// Parameter `inEventData`: the new event data. The size and type of this event data must match the inEventType
    ///
    /// # Safety
    ///
    /// - `in_iterator` must be a valid pointer.
    /// - `in_event_data` must be a valid pointer.
    pub fn MusicEventIteratorSetEventInfo(
        in_iterator: MusicEventIterator,
        in_event_type: MusicEventType,
        in_event_data: NonNull<c_void>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Set a new time for an event
    ///
    /// The iterator will still be pointing to the same event, but as the event will have moved,
    /// it may or may not have a next or previous event now (depending of course on the time
    /// you moved it to).
    ///
    ///
    /// Parameter `inIterator`: the iterator
    ///
    /// Parameter `inTimeStamp`: the new time stamp of the event
    ///
    /// # Safety
    ///
    /// `in_iterator` must be a valid pointer.
    pub fn MusicEventIteratorSetEventTime(
        in_iterator: MusicEventIterator,
        in_time_stamp: MusicTimeStamp,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Deletes the event pointed to by the iterator
    ///
    /// The iterator will reference the next event after the event has been deleted.
    ///
    ///
    /// Parameter `inIterator`: the iterator
    ///
    /// # Safety
    ///
    /// `in_iterator` must be a valid pointer.
    pub fn MusicEventIteratorDeleteEvent(in_iterator: MusicEventIterator) -> OSStatus;
}

extern "C-unwind" {
    /// Does the track have an event previous to the event the iterator is pointing to?
    ///
    /// To use the iterator going backwards through a track:
    /// iter = New Iterator (points at first event)
    /// MusicEventIteratorSeek (iter, kMusicTimeStamp_EndOfTrack) // will point it past the last event
    /// bool hasPreviousEvent;
    /// MusicEventIteratorHasPreviousEvent (iter,
    /// &hasPreviousEvent
    /// )
    /// while (hasPreviousEvent) {
    /// MusicEventIteratorPreviousEvent (iter)
    /// //     do work... MusicEventIteratorGetEventInfo (iter, ...
    ///
    /// MusicEventIteratorHasPreviousEvent (iter,
    /// &hasPreviousEvent
    /// );
    /// }
    ///
    /// Parameter `inIterator`: the iterator
    ///
    /// Parameter `outHasPrevEvent`: true if there is a previous event, false if not
    ///
    /// # Safety
    ///
    /// - `in_iterator` must be a valid pointer.
    /// - `out_has_prev_event` must be a valid pointer.
    pub fn MusicEventIteratorHasPreviousEvent(
        in_iterator: MusicEventIterator,
        out_has_prev_event: NonNull<Boolean>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Does the track have an event past the event the iterator is pointing too?
    ///
    /// To use the iterator going forwards through a track:
    /// iter = New Iterator (points at first event)
    /// bool hasCurrentEvent;
    /// MusicEventIteratorHasCurrentEvent(iter,
    /// &hasCurrentEvent
    /// );
    /// while (hasCurrentEvent) {
    /// // do work... MusicEventIteratorGetEventInfo (iter, ...
    ///
    /// MusicEventIteratorNextEvent (iter)
    /// MusicEventIteratorHasCurrentEvent(iter,
    /// &hasCurrentEvent
    /// );
    /// }
    ///
    ///
    /// Parameter `inIterator`: the iterator
    ///
    /// Parameter `outHasNextEvent`: true if there is a next event, false if not
    ///
    /// # Safety
    ///
    /// - `in_iterator` must be a valid pointer.
    /// - `out_has_next_event` must be a valid pointer.
    pub fn MusicEventIteratorHasNextEvent(
        in_iterator: MusicEventIterator,
        out_has_next_event: NonNull<Boolean>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Is there an event at the iterator's current position?
    ///
    /// Parameter `inIterator`: the iterator
    ///
    /// Parameter `outHasCurEvent`: true if there is an event, false if not
    ///
    /// # Safety
    ///
    /// - `in_iterator` must be a valid pointer.
    /// - `out_has_cur_event` must be a valid pointer.
    pub fn MusicEventIteratorHasCurrentEvent(
        in_iterator: MusicEventIterator,
        out_has_cur_event: NonNull<Boolean>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// # Safety
    ///
    /// `in_sequence` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated = "no longer supported"]
    pub fn MusicSequenceLoadSMFDataWithFlags(
        in_sequence: MusicSequence,
        in_data: &CFData,
        in_flags: MusicSequenceLoadFlags,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// # Safety
    ///
    /// - `in_sequence` must be a valid pointer.
    /// - `out_data` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated = "no longer supported"]
    pub fn MusicSequenceSaveSMFData(
        in_sequence: MusicSequence,
        out_data: NonNull<*const CFData>,
        in_resolution: u16,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// # Safety
    ///
    /// - `in_source_track` must be a valid pointer.
    /// - `out_new_track` must be a valid pointer.
    #[deprecated = "no longer supported"]
    pub fn NewMusicTrackFrom(
        in_source_track: MusicTrack,
        in_source_start_time: MusicTimeStamp,
        in_source_end_time: MusicTimeStamp,
        out_new_track: NonNull<MusicTrack>,
    ) -> OSStatus;
}

/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusiceventtype_extendedcontrol?language=objc)
pub const kMusicEventType_ExtendedControl: c_uint = 2;

/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/extendedcontrolevent?language=objc)
#[cfg(all(feature = "AUComponent", feature = "MusicDevice"))]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ExtendedControlEvent {
    pub groupID: MusicDeviceGroupID,
    pub controlID: AudioUnitParameterID,
    pub value: AudioUnitParameterValue,
}

#[cfg(all(feature = "AUComponent", feature = "MusicDevice"))]
unsafe impl Encode for ExtendedControlEvent {
    const ENCODING: Encoding = Encoding::Struct(
        "ExtendedControlEvent",
        &[
            <MusicDeviceGroupID>::ENCODING,
            <AudioUnitParameterID>::ENCODING,
            <AudioUnitParameterValue>::ENCODING,
        ],
    );
}

#[cfg(all(feature = "AUComponent", feature = "MusicDevice"))]
unsafe impl RefEncode for ExtendedControlEvent {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern "C-unwind" {
    /// # Safety
    ///
    /// - `in_track` must be a valid pointer.
    /// - `in_info` must be a valid pointer.
    #[cfg(all(feature = "AUComponent", feature = "MusicDevice"))]
    #[deprecated = "no longer supported"]
    pub fn MusicTrackNewExtendedControlEvent(
        in_track: MusicTrack,
        in_time_stamp: MusicTimeStamp,
        in_info: NonNull<ExtendedControlEvent>,
    ) -> OSStatus;
}