diff --git a/Cog.help/Contents/Resources/English.lproj/Cog.helpindex b/Cog.help/Contents/Resources/English.lproj/Cog.helpindex
index 4f0e16eda..f61a7b5bf 100644
Binary files a/Cog.help/Contents/Resources/English.lproj/Cog.helpindex and b/Cog.help/Contents/Resources/English.lproj/Cog.helpindex differ
diff --git a/Cog.help/Contents/Resources/English.lproj/Cog.html b/Cog.help/Contents/Resources/English.lproj/Cog.html
index 4c623ca78..82ee5f174 100644
--- a/Cog.help/Contents/Resources/English.lproj/Cog.html
+++ b/Cog.help/Contents/Resources/English.lproj/Cog.html
@@ -62,6 +62,7 @@ td.icon { width: auto; }
Apple Lossless
WMA Standard, Pro, Lossless, and Voice
TrueAudio
+ MIDI Sequences
Sequenced Module formats (IT, XM, S3M, MOD, STM, PTM, MTM, 669, PSM, AM, J2B, DSM, AMF, OKT/OKTA, and UMX)
Emulated Console formats supported by the Game_Music_Emu library (AY, GBS, HES, KSS, NSF/NSFE, SAP, SGC, SPC, and VGM/VGZ)
Many Emulated Console formats utilizing the PSF format (PSF, PSF2, SSF, DSF, QSF, GSF, NCSF, 2SF, and their respective mini variants)
diff --git a/Cog.xcodeproj/project.pbxproj b/Cog.xcodeproj/project.pbxproj
index d3d3a08cc..69380b1e0 100644
--- a/Cog.xcodeproj/project.pbxproj
+++ b/Cog.xcodeproj/project.pbxproj
@@ -179,6 +179,7 @@
838491871808591F00E7332D /* NDHotKey.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8384917E1808585D00E7332D /* NDHotKey.framework */; };
838491881808593200E7332D /* NDHotKey.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8384917E1808585D00E7332D /* NDHotKey.framework */; };
8399D4E21805A55000B503B1 /* XmlContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = 8399D4E01805A55000B503B1 /* XmlContainer.m */; };
+ 83B06704180D579E008E3612 /* MIDI.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 83B066A1180D5669008E3612 /* MIDI.bundle */; };
83BCB8DE17FC971300760340 /* FFMPEG.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = B09E94350D747F7B0064F138 /* FFMPEG.bundle */; };
83E5E54C18087CA5001F3284 /* miniModeOffTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 83E5E54A18087CA5001F3284 /* miniModeOffTemplate.pdf */; };
83E5E54D18087CA5001F3284 /* miniModeOnTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 83E5E54B18087CA5001F3284 /* miniModeOnTemplate.pdf */; };
@@ -464,6 +465,20 @@
remoteGlobalIDString = 32F1615514E6BB3B00D6AB2F;
remoteInfo = NDHotKey;
};
+ 83B066A0180D5669008E3612 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 83B0669C180D5668008E3612 /* MIDI.xcodeproj */;
+ proxyType = 2;
+ remoteGlobalIDString = 83B06687180D5668008E3612;
+ remoteInfo = MIDI;
+ };
+ 83B06702180D5776008E3612 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 83B0669C180D5668008E3612 /* MIDI.xcodeproj */;
+ proxyType = 1;
+ remoteGlobalIDString = 83B06686180D5668008E3612;
+ remoteInfo = MIDI;
+ };
83BCB8D817FC96F800760340 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 8360EF0017F92B23005208A4 /* HighlyComplete.xcodeproj */;
@@ -531,6 +546,7 @@
dstPath = "";
dstSubfolderSpec = 13;
files = (
+ 83B06704180D579E008E3612 /* MIDI.bundle in CopyFiles */,
8375B36517FFEF130092A79F /* Opus.bundle in CopyFiles */,
8359009D17FF06570060F3ED /* ArchiveSource.bundle in CopyFiles */,
83BCB8DE17FC971300760340 /* FFMPEG.bundle in CopyFiles */,
@@ -816,6 +832,7 @@
838491791808585C00E7332D /* NDHotKey.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = NDHotKey.xcodeproj; path = Frameworks/NDHotKey/NDHotKey.xcodeproj; sourceTree = ""; };
8399D4E01805A55000B503B1 /* XmlContainer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XmlContainer.m; sourceTree = ""; };
8399D4E11805A55000B503B1 /* XmlContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XmlContainer.h; sourceTree = ""; };
+ 83B0669C180D5668008E3612 /* MIDI.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = MIDI.xcodeproj; path = Plugins/MIDI/MIDI.xcodeproj; sourceTree = ""; };
83E5E54A18087CA5001F3284 /* miniModeOffTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = miniModeOffTemplate.pdf; path = Images/miniModeOffTemplate.pdf; sourceTree = ""; };
83E5E54B18087CA5001F3284 /* miniModeOnTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = miniModeOnTemplate.pdf; path = Images/miniModeOnTemplate.pdf; sourceTree = ""; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; };
@@ -1119,6 +1136,7 @@
17C808660C3BD0F8005707C4 /* CoreAudio.xcodeproj */,
8359FF2C17FEF35C0060F3ED /* ArchiveSource.xcodeproj */,
8375B05117FFEA400092A79F /* Opus.xcodeproj */,
+ 83B0669C180D5668008E3612 /* MIDI.xcodeproj */,
);
name = PlugIns;
sourceTree = "";
@@ -1484,6 +1502,14 @@
name = Products;
sourceTree = "";
};
+ 83B0669D180D5668008E3612 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 83B066A1180D5669008E3612 /* MIDI.bundle */,
+ );
+ name = Products;
+ sourceTree = "";
+ };
8E07AAEA0AAC90DC00A4B32F /* Preferences */ = {
isa = PBXGroup;
children = (
@@ -1616,6 +1642,7 @@
buildRules = (
);
dependencies = (
+ 83B06703180D5776008E3612 /* PBXTargetDependency */,
838491861808591400E7332D /* PBXTargetDependency */,
8375B36217FFEF010092A79F /* PBXTargetDependency */,
8375B36417FFEF010092A79F /* PBXTargetDependency */,
@@ -1726,6 +1753,10 @@
ProductGroup = 8E8D40830CBB036600135C1B /* Products */;
ProjectRef = 8E8D40820CBB036600135C1B /* M3u.xcodeproj */;
},
+ {
+ ProductGroup = 83B0669D180D5668008E3612 /* Products */;
+ ProjectRef = 83B0669C180D5668008E3612 /* MIDI.xcodeproj */;
+ },
{
ProductGroup = 17C8089F0C3BD1AB005707C4 /* Products */;
ProjectRef = 17C8089E0C3BD1AB005707C4 /* Musepack.xcodeproj */;
@@ -1900,6 +1931,13 @@
remoteRef = 8384917D1808585D00E7332D /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
+ 83B066A1180D5669008E3612 /* MIDI.bundle */ = {
+ isa = PBXReferenceProxy;
+ fileType = wrapper.cfbundle;
+ path = MIDI.bundle;
+ remoteRef = 83B066A0180D5669008E3612 /* PBXContainerItemProxy */;
+ sourceTree = BUILT_PRODUCTS_DIR;
+ };
8E8D40870CBB036600135C1B /* M3u.bundle */ = {
isa = PBXReferenceProxy;
fileType = wrapper.cfbundle;
@@ -2213,6 +2251,11 @@
name = NDHotKey;
targetProxy = 838491851808591400E7332D /* PBXContainerItemProxy */;
};
+ 83B06703180D5776008E3612 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ name = MIDI;
+ targetProxy = 83B06702180D5776008E3612 /* PBXContainerItemProxy */;
+ };
83BCB8D917FC96F800760340 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
name = HighlyComplete;
diff --git a/Frameworks/midi_processing/midi_processing.xcodeproj/project.pbxproj b/Frameworks/midi_processing/midi_processing.xcodeproj/project.pbxproj
new file mode 100644
index 000000000..d663052c2
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing.xcodeproj/project.pbxproj
@@ -0,0 +1,342 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 83B066BA180D56B9008E3612 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 83B066B8180D56B9008E3612 /* InfoPlist.strings */; };
+ 83B066F1180D5724008E3612 /* midi_container.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83B066E3180D5724008E3612 /* midi_container.cpp */; };
+ 83B066F2180D5724008E3612 /* midi_container.h in Headers */ = {isa = PBXBuildFile; fileRef = 83B066E4180D5724008E3612 /* midi_container.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 83B066F3180D5724008E3612 /* midi_processor_gmf.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83B066E5180D5724008E3612 /* midi_processor_gmf.cpp */; };
+ 83B066F4180D5724008E3612 /* midi_processor_helpers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83B066E6180D5724008E3612 /* midi_processor_helpers.cpp */; };
+ 83B066F5180D5724008E3612 /* midi_processor_hmi.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83B066E7180D5724008E3612 /* midi_processor_hmi.cpp */; };
+ 83B066F6180D5724008E3612 /* midi_processor_hmp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83B066E8180D5724008E3612 /* midi_processor_hmp.cpp */; };
+ 83B066F7180D5724008E3612 /* midi_processor_lds.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83B066E9180D5724008E3612 /* midi_processor_lds.cpp */; };
+ 83B066F8180D5724008E3612 /* midi_processor_mids.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83B066EA180D5724008E3612 /* midi_processor_mids.cpp */; };
+ 83B066F9180D5724008E3612 /* midi_processor_mus.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83B066EB180D5724008E3612 /* midi_processor_mus.cpp */; };
+ 83B066FA180D5724008E3612 /* midi_processor_riff_midi.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83B066EC180D5724008E3612 /* midi_processor_riff_midi.cpp */; };
+ 83B066FB180D5724008E3612 /* midi_processor_standard_midi.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83B066ED180D5724008E3612 /* midi_processor_standard_midi.cpp */; };
+ 83B066FC180D5724008E3612 /* midi_processor_syx.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83B066EE180D5724008E3612 /* midi_processor_syx.cpp */; };
+ 83B066FD180D5724008E3612 /* midi_processor_xmi.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83B066EF180D5724008E3612 /* midi_processor_xmi.cpp */; };
+ 83B066FE180D5724008E3612 /* midi_processor.h in Headers */ = {isa = PBXBuildFile; fileRef = 83B066F0180D5724008E3612 /* midi_processor.h */; settings = {ATTRIBUTES = (Public, ); }; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ 83B066AC180D56B9008E3612 /* midi_processing.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = midi_processing.framework; sourceTree = BUILT_PRODUCTS_DIR; };
+ 83B066B7180D56B9008E3612 /* midi_processing-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "midi_processing-Info.plist"; sourceTree = ""; };
+ 83B066B9180D56B9008E3612 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; };
+ 83B066E3180D5724008E3612 /* midi_container.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = midi_container.cpp; sourceTree = ""; };
+ 83B066E4180D5724008E3612 /* midi_container.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = midi_container.h; sourceTree = ""; };
+ 83B066E5180D5724008E3612 /* midi_processor_gmf.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = midi_processor_gmf.cpp; sourceTree = ""; };
+ 83B066E6180D5724008E3612 /* midi_processor_helpers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = midi_processor_helpers.cpp; sourceTree = ""; };
+ 83B066E7180D5724008E3612 /* midi_processor_hmi.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = midi_processor_hmi.cpp; sourceTree = ""; };
+ 83B066E8180D5724008E3612 /* midi_processor_hmp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = midi_processor_hmp.cpp; sourceTree = ""; };
+ 83B066E9180D5724008E3612 /* midi_processor_lds.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = midi_processor_lds.cpp; sourceTree = ""; };
+ 83B066EA180D5724008E3612 /* midi_processor_mids.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = midi_processor_mids.cpp; sourceTree = ""; };
+ 83B066EB180D5724008E3612 /* midi_processor_mus.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = midi_processor_mus.cpp; sourceTree = ""; };
+ 83B066EC180D5724008E3612 /* midi_processor_riff_midi.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = midi_processor_riff_midi.cpp; sourceTree = ""; };
+ 83B066ED180D5724008E3612 /* midi_processor_standard_midi.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = midi_processor_standard_midi.cpp; sourceTree = ""; };
+ 83B066EE180D5724008E3612 /* midi_processor_syx.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = midi_processor_syx.cpp; sourceTree = ""; };
+ 83B066EF180D5724008E3612 /* midi_processor_xmi.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = midi_processor_xmi.cpp; sourceTree = ""; };
+ 83B066F0180D5724008E3612 /* midi_processor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = midi_processor.h; sourceTree = ""; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 83B066A8180D56B9008E3612 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 83B066A2180D56B9008E3612 = {
+ isa = PBXGroup;
+ children = (
+ 83B066B5180D56B9008E3612 /* midi_processing */,
+ 83B066AE180D56B9008E3612 /* Frameworks */,
+ 83B066AD180D56B9008E3612 /* Products */,
+ );
+ sourceTree = "";
+ };
+ 83B066AD180D56B9008E3612 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 83B066AC180D56B9008E3612 /* midi_processing.framework */,
+ );
+ name = Products;
+ sourceTree = "";
+ };
+ 83B066AE180D56B9008E3612 /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 83B066B1180D56B9008E3612 /* Other Frameworks */,
+ );
+ name = Frameworks;
+ sourceTree = "";
+ };
+ 83B066B1180D56B9008E3612 /* Other Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ );
+ name = "Other Frameworks";
+ sourceTree = "";
+ };
+ 83B066B5180D56B9008E3612 /* midi_processing */ = {
+ isa = PBXGroup;
+ children = (
+ 83B066E3180D5724008E3612 /* midi_container.cpp */,
+ 83B066E4180D5724008E3612 /* midi_container.h */,
+ 83B066E5180D5724008E3612 /* midi_processor_gmf.cpp */,
+ 83B066E6180D5724008E3612 /* midi_processor_helpers.cpp */,
+ 83B066E7180D5724008E3612 /* midi_processor_hmi.cpp */,
+ 83B066E8180D5724008E3612 /* midi_processor_hmp.cpp */,
+ 83B066E9180D5724008E3612 /* midi_processor_lds.cpp */,
+ 83B066EA180D5724008E3612 /* midi_processor_mids.cpp */,
+ 83B066EB180D5724008E3612 /* midi_processor_mus.cpp */,
+ 83B066EC180D5724008E3612 /* midi_processor_riff_midi.cpp */,
+ 83B066ED180D5724008E3612 /* midi_processor_standard_midi.cpp */,
+ 83B066EE180D5724008E3612 /* midi_processor_syx.cpp */,
+ 83B066EF180D5724008E3612 /* midi_processor_xmi.cpp */,
+ 83B066F0180D5724008E3612 /* midi_processor.h */,
+ 83B066B6180D56B9008E3612 /* Supporting Files */,
+ );
+ path = midi_processing;
+ sourceTree = "";
+ };
+ 83B066B6180D56B9008E3612 /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ 83B066B7180D56B9008E3612 /* midi_processing-Info.plist */,
+ 83B066B8180D56B9008E3612 /* InfoPlist.strings */,
+ );
+ name = "Supporting Files";
+ sourceTree = "";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXHeadersBuildPhase section */
+ 83B066A9180D56B9008E3612 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 83B066FE180D5724008E3612 /* midi_processor.h in Headers */,
+ 83B066F2180D5724008E3612 /* midi_container.h in Headers */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXHeadersBuildPhase section */
+
+/* Begin PBXNativeTarget section */
+ 83B066AB180D56B9008E3612 /* midi_processing */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 83B066D4180D56B9008E3612 /* Build configuration list for PBXNativeTarget "midi_processing" */;
+ buildPhases = (
+ 83B066A7180D56B9008E3612 /* Sources */,
+ 83B066A8180D56B9008E3612 /* Frameworks */,
+ 83B066A9180D56B9008E3612 /* Headers */,
+ 83B066AA180D56B9008E3612 /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = midi_processing;
+ productName = midi_processing;
+ productReference = 83B066AC180D56B9008E3612 /* midi_processing.framework */;
+ productType = "com.apple.product-type.framework";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 83B066A3180D56B9008E3612 /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0500;
+ ORGANIZATIONNAME = "Christopher Snowhill";
+ };
+ buildConfigurationList = 83B066A6180D56B9008E3612 /* Build configuration list for PBXProject "midi_processing" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ );
+ mainGroup = 83B066A2180D56B9008E3612;
+ productRefGroup = 83B066AD180D56B9008E3612 /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 83B066AB180D56B9008E3612 /* midi_processing */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ 83B066AA180D56B9008E3612 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 83B066BA180D56B9008E3612 /* InfoPlist.strings in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 83B066A7180D56B9008E3612 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 83B066F4180D5724008E3612 /* midi_processor_helpers.cpp in Sources */,
+ 83B066F3180D5724008E3612 /* midi_processor_gmf.cpp in Sources */,
+ 83B066FB180D5724008E3612 /* midi_processor_standard_midi.cpp in Sources */,
+ 83B066FC180D5724008E3612 /* midi_processor_syx.cpp in Sources */,
+ 83B066F5180D5724008E3612 /* midi_processor_hmi.cpp in Sources */,
+ 83B066F8180D5724008E3612 /* midi_processor_mids.cpp in Sources */,
+ 83B066F6180D5724008E3612 /* midi_processor_hmp.cpp in Sources */,
+ 83B066F9180D5724008E3612 /* midi_processor_mus.cpp in Sources */,
+ 83B066FA180D5724008E3612 /* midi_processor_riff_midi.cpp in Sources */,
+ 83B066F1180D5724008E3612 /* midi_container.cpp in Sources */,
+ 83B066FD180D5724008E3612 /* midi_processor_xmi.cpp in Sources */,
+ 83B066F7180D5724008E3612 /* midi_processor_lds.cpp in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+ 83B066B8180D56B9008E3612 /* InfoPlist.strings */ = {
+ isa = PBXVariantGroup;
+ children = (
+ 83B066B9180D56B9008E3612 /* en */,
+ );
+ name = InfoPlist.strings;
+ sourceTree = "";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ 83B066D2180D56B9008E3612 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = NO;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = macosx;
+ };
+ name = Debug;
+ };
+ 83B066D3180D56B9008E3612 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = YES;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ ENABLE_NS_ASSERTIONS = NO;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
+ SDKROOT = macosx;
+ };
+ name = Release;
+ };
+ 83B066D5180D56B9008E3612 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COMBINE_HIDPI_IMAGES = YES;
+ DYLIB_COMPATIBILITY_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 1;
+ FRAMEWORK_VERSION = A;
+ INFOPLIST_FILE = "midi_processing/midi_processing-Info.plist";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ WRAPPER_EXTENSION = framework;
+ };
+ name = Debug;
+ };
+ 83B066D6180D56B9008E3612 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COMBINE_HIDPI_IMAGES = YES;
+ DYLIB_COMPATIBILITY_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 1;
+ FRAMEWORK_VERSION = A;
+ INFOPLIST_FILE = "midi_processing/midi_processing-Info.plist";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ WRAPPER_EXTENSION = framework;
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 83B066A6180D56B9008E3612 /* Build configuration list for PBXProject "midi_processing" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 83B066D2180D56B9008E3612 /* Debug */,
+ 83B066D3180D56B9008E3612 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 83B066D4180D56B9008E3612 /* Build configuration list for PBXNativeTarget "midi_processing" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 83B066D5180D56B9008E3612 /* Debug */,
+ 83B066D6180D56B9008E3612 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 83B066A3180D56B9008E3612 /* Project object */;
+}
diff --git a/Frameworks/midi_processing/midi_processing/en.lproj/InfoPlist.strings b/Frameworks/midi_processing/midi_processing/en.lproj/InfoPlist.strings
new file mode 100644
index 000000000..477b28ff8
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/en.lproj/InfoPlist.strings
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
diff --git a/Frameworks/midi_processing/midi_processing/midi_container.cpp b/Frameworks/midi_processing/midi_processing/midi_container.cpp
new file mode 100644
index 000000000..a5912b141
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/midi_container.cpp
@@ -0,0 +1,1114 @@
+#include "midi_container.h"
+
+#include
+
+#include
+
+midi_event::midi_event( const midi_event & p_in )
+{
+ m_timestamp = p_in.m_timestamp;
+ m_channel = p_in.m_channel;
+ m_type = p_in.m_type;
+ m_data_count = p_in.m_data_count;
+ memcpy( m_data, p_in.m_data, m_data_count );
+ m_ext_data = p_in.m_ext_data;
+}
+
+midi_event::midi_event( unsigned long p_timestamp, event_type p_type, unsigned p_channel, const uint8_t * p_data, std::size_t p_data_count )
+{
+ m_timestamp = p_timestamp;
+ m_type = p_type;
+ m_channel = p_channel;
+ if ( p_data_count <= max_static_data_count )
+ {
+ m_data_count = p_data_count;
+ memcpy( m_data, p_data, p_data_count );
+ }
+ else
+ {
+ m_data_count = max_static_data_count;
+ memcpy( m_data, p_data, max_static_data_count );
+ m_ext_data.assign( p_data + max_static_data_count, p_data + p_data_count );
+ }
+}
+
+unsigned long midi_event::get_data_count() const
+{
+ return m_data_count + m_ext_data.size();
+}
+
+void midi_event::copy_data( uint8_t * p_out, unsigned long p_offset, unsigned long p_count ) const
+{
+ unsigned long max_count = m_data_count + m_ext_data.size() - p_offset;
+ p_count = std::min( p_count, max_count );
+ if ( p_offset < max_static_data_count )
+ {
+ unsigned long max_count = max_static_data_count - p_offset;
+ unsigned long count = std::min( max_count, p_count );
+ memcpy( p_out, m_data + p_offset, count );
+ p_offset -= count;
+ p_count -= count;
+ p_out += count;
+ }
+ if ( p_count ) memcpy( p_out, &m_ext_data[0], p_count );
+}
+
+midi_track::midi_track(const midi_track & p_in)
+{
+ m_events = p_in.m_events;
+}
+
+void midi_track::add_event( const midi_event & p_event )
+{
+ auto it = m_events.end();
+
+ if ( m_events.size() )
+ {
+ midi_event & event = *(it - 1);
+ if ( event.m_type == midi_event::extended && event.get_data_count() >= 2 &&
+ event.m_data[ 0 ] == 0xFF && event.m_data[ 1 ] == 0x2F )
+ {
+ --it;
+ if ( event.m_timestamp < p_event.m_timestamp )
+ {
+ event.m_timestamp = p_event.m_timestamp;
+ }
+ }
+
+ while ( it > m_events.begin() )
+ {
+ if ( (*( it - 1 )).m_timestamp <= p_event.m_timestamp ) break;
+ --it;
+ }
+ }
+
+ m_events.insert( it, p_event );
+}
+
+std::size_t midi_track::get_count() const
+{
+ return m_events.size();
+}
+
+const midi_event & midi_track::operator [] ( std::size_t p_index ) const
+{
+ return m_events[ p_index ];
+}
+
+void midi_track::remove_event( unsigned long index )
+{
+ m_events.erase( m_events.begin() + index );
+}
+
+tempo_entry::tempo_entry(unsigned long p_timestamp, unsigned p_tempo)
+{
+ m_timestamp = p_timestamp;
+ m_tempo = p_tempo;
+}
+
+void tempo_map::add_tempo( unsigned p_tempo, unsigned long p_timestamp )
+{
+ auto it = m_entries.end();
+
+ while ( it > m_entries.begin() )
+ {
+ if ( (*( it - 1 )).m_timestamp <= p_timestamp ) break;
+ --it;
+ }
+
+ if ( it > m_entries.begin() && (*( it - 1 )).m_timestamp == p_timestamp )
+ {
+ (*( it - 1 )).m_tempo = p_tempo;
+ }
+ else
+ {
+ m_entries.insert( it, tempo_entry( p_timestamp, p_tempo ) );
+ }
+}
+
+unsigned long tempo_map::timestamp_to_ms( unsigned long p_timestamp, unsigned p_dtx ) const
+{
+ unsigned long timestamp_ms = 0;
+ unsigned long timestamp = 0;
+ auto tempo_it = m_entries.begin();
+ unsigned current_tempo = 500000;
+
+ unsigned half_dtx = p_dtx * 500;
+ p_dtx = half_dtx * 2;
+
+ while ( tempo_it < m_entries.end() && timestamp + p_timestamp >= (*tempo_it).m_timestamp )
+ {
+ unsigned long delta = (*tempo_it).m_timestamp - timestamp;
+ timestamp_ms += ((uint64_t)current_tempo * (uint64_t)delta + half_dtx) / p_dtx;
+ current_tempo = (*tempo_it).m_tempo;
+ ++tempo_it;
+ timestamp += delta;
+ p_timestamp -= delta;
+ }
+
+ timestamp_ms += ((uint64_t)current_tempo * (uint64_t)p_timestamp + half_dtx) / p_dtx;
+
+ return timestamp_ms;
+}
+
+std::size_t tempo_map::get_count() const
+{
+ return m_entries.size();
+}
+
+const tempo_entry & tempo_map::operator [] ( std::size_t p_index ) const
+{
+ return m_entries[ p_index ];
+}
+
+system_exclusive_entry::system_exclusive_entry(const system_exclusive_entry & p_in)
+{
+ m_port = p_in.m_port;
+ m_offset = p_in.m_offset;
+ m_length = p_in.m_length;
+}
+
+system_exclusive_entry::system_exclusive_entry(std::size_t p_port, std::size_t p_offset, std::size_t p_length)
+{
+ m_port = p_port;
+ m_offset = p_offset;
+ m_length = p_length;
+}
+
+unsigned system_exclusive_table::add_entry( const uint8_t * p_data, std::size_t p_size, std::size_t p_port )
+{
+ for ( auto it = m_entries.begin(); it < m_entries.end(); ++it )
+ {
+ const system_exclusive_entry & entry = *it;
+ if ( p_port == entry.m_port && p_size == entry.m_length && !memcmp( p_data, &m_data[ entry.m_offset ], p_size ) )
+ return ((unsigned)(it - m_entries.begin()));
+ }
+ system_exclusive_entry entry( p_port, m_data.size(), p_size );
+ m_data.insert( m_data.end(), p_data, p_data + p_size );
+ m_entries.push_back( entry );
+ return ((unsigned)(m_entries.size() - 1));
+}
+
+void system_exclusive_table::get_entry( unsigned p_index, const uint8_t * & p_data, std::size_t & p_size, std::size_t & p_port )
+{
+ const system_exclusive_entry & entry = m_entries[ p_index ];
+ p_data = &m_data[ entry.m_offset ];
+ p_size = entry.m_length;
+ p_port = entry.m_port;
+}
+
+midi_stream_event::midi_stream_event(unsigned long p_timestamp, unsigned p_event)
+{
+ m_timestamp = p_timestamp;
+ m_event = p_event;
+}
+
+midi_meta_data_item::midi_meta_data_item(const midi_meta_data_item & p_in)
+{
+ m_timestamp = p_in.m_timestamp;
+ m_name = p_in.m_name;
+ m_value = p_in.m_value;
+}
+
+midi_meta_data_item::midi_meta_data_item(unsigned long p_timestamp, const char * p_name, const char * p_value)
+{
+ m_timestamp = p_timestamp;
+ m_name = p_name;
+ m_value = p_value;
+}
+
+void midi_meta_data::add_item( const midi_meta_data_item & p_item )
+{
+ m_data.push_back( p_item );
+}
+
+void midi_meta_data::append( const midi_meta_data & p_data )
+{
+ m_data.insert( m_data.end(), p_data.m_data.begin(), p_data.m_data.end() );
+}
+
+bool midi_meta_data::get_item( const char * p_name, midi_meta_data_item & p_out ) const
+{
+ for ( unsigned i = 0; i < m_data.size(); ++i )
+ {
+ const midi_meta_data_item & item = m_data[ i ];
+ if ( !strcasecmp( p_name, item.m_name.c_str() ) )
+ {
+ p_out = item;
+ return true;
+ }
+ }
+ return false;
+}
+
+std::size_t midi_meta_data::get_count() const
+{
+ return m_data.size();
+}
+
+const midi_meta_data_item & midi_meta_data::operator [] ( std::size_t p_index ) const
+{
+ return m_data[ p_index ];
+}
+
+void midi_container::encode_delta( std::vector & p_out, unsigned long delta )
+{
+ unsigned shift = 7 * 4;
+ while ( shift && !( delta >> shift ) )
+ {
+ shift -= 7;
+ }
+ while (shift > 0)
+ {
+ p_out.push_back( (unsigned char)( ( ( delta >> shift ) & 0x7F ) | 0x80 ) );
+ shift -= 7;
+ }
+ p_out.push_back( (unsigned char)( delta & 0x7F ) );
+}
+
+unsigned long midi_container::timestamp_to_ms( unsigned long p_timestamp, unsigned long p_subsong ) const
+{
+ unsigned long timestamp_ms = 0;
+ unsigned long timestamp = 0;
+ std::size_t tempo_index = 0;
+ unsigned current_tempo = 500000;
+
+ unsigned half_dtx = m_dtx * 500;
+ unsigned p_dtx = half_dtx * 2;
+
+ unsigned long subsong_count = m_tempo_map.size();
+
+ if ( p_subsong && subsong_count )
+ {
+ for ( unsigned long i = std::min( p_subsong, subsong_count ); --i; )
+ {
+ unsigned long count = m_tempo_map[ i ].get_count();
+ if ( count )
+ {
+ current_tempo = m_tempo_map[ i ][ count - 1 ].m_tempo;
+ break;
+ }
+ }
+ }
+
+ if ( p_subsong < subsong_count )
+ {
+ const tempo_map & m_entries = m_tempo_map[ p_subsong ];
+
+ std::size_t tempo_count = m_entries.get_count();
+
+ while ( tempo_index < tempo_count && timestamp + p_timestamp >= m_entries[ tempo_index ].m_timestamp )
+ {
+ unsigned long delta = m_entries[ tempo_index ].m_timestamp - timestamp;
+ timestamp_ms += ((uint64_t)current_tempo * (uint64_t)delta + half_dtx) / p_dtx;
+ current_tempo = m_entries[ tempo_index ].m_tempo;
+ ++tempo_index;
+ timestamp += delta;
+ p_timestamp -= delta;
+ }
+ }
+
+ timestamp_ms += ((uint64_t)current_tempo * (uint64_t)p_timestamp + half_dtx) / p_dtx;
+
+ return timestamp_ms;
+}
+
+void midi_container::initialize( unsigned p_form, unsigned p_dtx )
+{
+ m_form = p_form;
+ m_dtx = p_dtx;
+ if ( p_form != 2 )
+ {
+ m_channel_mask.resize( 1 );
+ m_channel_mask[ 0 ] = 0;
+ m_tempo_map.resize( 1 );
+ m_timestamp_end.resize( 1 );
+ m_timestamp_end[ 0 ] = 0;
+ m_timestamp_loop_start.resize( 1 );
+ m_timestamp_loop_end.resize( 1 );
+ }
+}
+
+void midi_container::add_track( const midi_track & p_track )
+{
+ unsigned i;
+ unsigned long port_number = 0;
+
+ std::vector data;
+ std::string device_name;
+
+ m_tracks.push_back( p_track );
+
+ for ( i = 0; i < p_track.get_count(); ++i )
+ {
+ const midi_event & event = p_track[ i ];
+ if ( event.m_type == midi_event::extended && event.get_data_count() >= 5 &&
+ event.m_data[ 0 ] == 0xFF && event.m_data[ 1 ] == 0x51 )
+ {
+ unsigned tempo = ( event.m_data[ 2 ] << 16 ) + ( event.m_data[ 3 ] << 8 ) + event.m_data[ 4 ];
+ if ( m_form != 2 ) m_tempo_map[ 0 ].add_tempo( tempo, event.m_timestamp );
+ else
+ {
+ m_tempo_map.resize( m_tracks.size() );
+ m_tempo_map[ m_tracks.size() - 1 ].add_tempo( tempo, event.m_timestamp );
+ }
+ }
+ else if ( event.m_type == midi_event::extended && event.get_data_count() >= 3 &&
+ event.m_data[ 0 ] == 0xFF )
+ {
+ if ( event.m_data[ 1 ] == 4 || event.m_data[1] == 9 )
+ {
+ unsigned long data_count = event.get_data_count() - 2;
+ data.resize( data_count );
+ event.copy_data( &data[0], 2, data_count );
+ device_name.assign( data.begin(), data.begin() + data_count );
+ std::transform( device_name.begin(), device_name.end(), device_name.begin(), ::tolower );
+ }
+ else if ( event.m_data[ 1 ] == 0x21 )
+ {
+ port_number = event.m_data[ 2 ];
+ limit_port_number( port_number );
+ device_name.clear();
+ }
+ }
+ else if ( event.m_type == midi_event::note_on || event.m_type == midi_event::note_off )
+ {
+ unsigned channel = event.m_channel;
+ if ( device_name.length() )
+ {
+ unsigned long i, j;
+ for ( i = 0, j = m_device_names[ channel ].size(); i < j; ++i )
+ {
+ if ( !strcmp( m_device_names[ channel ][ i ].c_str(), device_name.c_str() ) ) break;
+ }
+ if ( i < j ) port_number = i;
+ else
+ {
+ m_device_names[ channel ].push_back( device_name );
+ port_number = j;
+ }
+ device_name.clear();
+ limit_port_number( port_number );
+ }
+
+ channel += 16 * port_number;
+ channel %= 48;
+ if ( m_form != 2 ) m_channel_mask[ 0 ] |= 1 << channel;
+ else
+ {
+ m_channel_mask.resize( m_tracks.size(), 0 );
+ m_channel_mask[ m_tracks.size() - 1 ] |= 1 << channel;
+ }
+ }
+ }
+
+ if ( i && m_form != 2 && p_track[ i - 1 ].m_timestamp > m_timestamp_end[ 0 ] )
+ m_timestamp_end[ 0 ] = p_track[ i - 1 ].m_timestamp;
+ else if ( m_form == 2 )
+ {
+ if ( i )
+ m_timestamp_end.push_back( p_track[ i - 1 ].m_timestamp );
+ else
+ m_timestamp_end.push_back( (unsigned)0 );
+ }
+}
+
+void midi_container::add_track_event( std::size_t p_track_index, const midi_event & p_event )
+{
+ midi_track & track = m_tracks[ p_track_index ];
+
+ track.add_event( p_event );
+
+ if ( p_event.m_type == midi_event::extended && p_event.get_data_count() >= 5 &&
+ p_event.m_data[ 0 ] == 0xFF && p_event.m_data[ 1 ] == 0x51 )
+ {
+ unsigned tempo = ( p_event.m_data[ 2 ] << 16 ) + ( p_event.m_data[ 3 ] << 8 ) + p_event.m_data[ 4 ];
+ if ( m_form != 2 ) m_tempo_map[ 0 ].add_tempo( tempo, p_event.m_timestamp );
+ else
+ {
+ m_tempo_map.resize( m_tracks.size() );
+ m_tempo_map[ p_track_index ].add_tempo( tempo, p_event.m_timestamp );
+ }
+ }
+ else if ( p_event.m_type == midi_event::note_on || p_event.m_type == midi_event::note_off )
+ {
+ if ( m_form != 2 ) m_channel_mask[ 0 ] |= 1 << p_event.m_channel;
+ else
+ {
+ m_channel_mask.resize( m_tracks.size(), 0 );
+ m_channel_mask[ p_track_index ] |= 1 << p_event.m_channel;
+ }
+ }
+
+ if ( m_form != 2 && p_event.m_timestamp > m_timestamp_end[ 0 ] )
+ {
+ m_timestamp_end[ 0 ] = p_event.m_timestamp;
+ }
+ else if ( m_form == 2 && p_event.m_timestamp > m_timestamp_end[ p_track_index ] )
+ {
+ m_timestamp_end[ p_track_index ] = p_event.m_timestamp;
+ }
+}
+
+void midi_container::merge_tracks( const midi_container & p_source )
+{
+ for ( unsigned i = 0; i < p_source.m_tracks.size(); i++ )
+ {
+ add_track( p_source.m_tracks[ i ] );
+ }
+}
+
+void midi_container::set_track_count( unsigned count )
+{
+ m_tracks.resize( count );
+}
+
+void midi_container::set_extra_meta_data( const midi_meta_data & p_data )
+{
+ m_extra_meta_data = p_data;
+}
+
+void midi_container::apply_hackfix( unsigned hack )
+{
+ switch (hack)
+ {
+ case 0:
+ for (unsigned i = 0; i < m_tracks.size(); ++i)
+ {
+ midi_track & t = m_tracks[ i ];
+ for ( unsigned i = 0; i < t.get_count(); )
+ {
+ if ( t[ i ].m_type != midi_event::extended &&
+ t[ i ].m_channel == 16 )
+ {
+ t.remove_event( i );
+ }
+ else
+ {
+ ++i;
+ }
+ }
+ }
+ break;
+
+ case 1:
+ for (unsigned i = 0; i < m_tracks.size(); ++i)
+ {
+ midi_track & t = m_tracks[ i ];
+ for ( unsigned i = 0; i < t.get_count(); )
+ {
+ if ( t[ i ].m_type != midi_event::extended &&
+ ( t[ i ].m_channel - 10 < 6 ) )
+ {
+ t.remove_event( i );
+ }
+ else
+ {
+ ++i;
+ }
+ }
+ }
+ break;
+ }
+}
+
+void midi_container::serialize_as_stream( unsigned long subsong, std::vector & p_stream, system_exclusive_table & p_system_exclusive, unsigned clean_flags ) const
+{
+ std::vector data;
+ std::vector track_positions;
+ std::vector port_numbers;
+ std::vector device_names;
+ std::size_t track_count = m_tracks.size();
+
+ track_positions.resize( track_count, 0 );
+ port_numbers.resize( track_count, 0 );
+ device_names.resize( track_count );
+
+ bool clean_emidi = !!( clean_flags & clean_flag_emidi );
+ bool clean_instruments = !!( clean_flags & clean_flag_instruments );
+ bool clean_banks = !!( clean_flags & clean_flag_banks );
+
+ if ( clean_emidi )
+ {
+ for ( unsigned i = 0; i < track_count; ++i )
+ {
+ bool skip_track = false;
+ const midi_track & track = m_tracks[ i ];
+ for ( unsigned j = 0; j < track.get_count(); ++j )
+ {
+ const midi_event & event = track[ j ];
+ if ( event.m_type == midi_event::control_change &&
+ ( event.m_data[ 0 ] == 110 || event.m_data[ 0 ] == 111 ) )
+ {
+ if ( event.m_data[ 0 ] == 110 )
+ {
+ if ( event.m_data[ 1 ] != 0 && event.m_data[ 1 ] != 1 && event.m_data[ 1 ] != 127 )
+ {
+ skip_track = true;
+ break;
+ }
+ }
+ else
+ {
+ if ( event.m_data[ 1 ] == 0 || event.m_data[ 1 ] == 1 )
+ {
+ skip_track = true;
+ break;
+ }
+ }
+ }
+ }
+ if ( skip_track )
+ {
+ track_positions[ i ] = track.get_count();
+ }
+ }
+ }
+
+ if ( m_form == 2 )
+ {
+ for ( unsigned long i = 0; i < track_count; ++i )
+ {
+ if ( i != subsong ) track_positions[ i ] = m_tracks[ i ].get_count();
+ }
+ }
+
+ for (;;)
+ {
+ unsigned long next_timestamp = ~0UL;
+ std::size_t next_track = 0;
+ for ( unsigned i = 0; i < track_count; ++i )
+ {
+ if ( track_positions[ i ] >= m_tracks[ i ].get_count() ) continue;
+ if ( m_tracks[ i ][ track_positions[ i ] ].m_timestamp < next_timestamp )
+ {
+ next_timestamp = m_tracks[ i ][ track_positions[ i ] ].m_timestamp;
+ next_track = i;
+ }
+ }
+ if ( next_timestamp == ~0UL ) break;
+
+ bool filtered = false;
+
+ if ( clean_instruments || clean_banks )
+ {
+ const midi_event & event = m_tracks[ next_track ][ track_positions[ next_track ] ];
+ if ( clean_instruments && event.m_type == midi_event::program_change ) filtered = true;
+ else if ( clean_banks && event.m_type == midi_event::control_change &&
+ ( event.m_data[ 0 ] == 0x00 || event.m_data[ 0 ] == 0x20 ) ) filtered = true;
+ }
+
+ if ( !filtered )
+ {
+ unsigned long tempo_track = 0;
+ if ( m_form == 2 && subsong ) tempo_track = subsong;
+
+ const midi_event & event = m_tracks[ next_track ][ track_positions[ next_track ] ];
+ unsigned long timestamp_ms = timestamp_to_ms( event.m_timestamp, tempo_track );
+ if ( event.m_type != midi_event::extended )
+ {
+ if ( device_names[ next_track ].length() )
+ {
+ unsigned long i, j;
+ for ( i = 0, j = m_device_names[ event.m_channel ].size(); i < j; ++i )
+ {
+ if ( !strcmp( m_device_names[ event.m_channel ][ i ].c_str(), device_names[ next_track ].c_str() ) ) break;
+ }
+ port_numbers[ next_track ] = i;
+ device_names[ next_track ].clear();
+ limit_port_number( port_numbers[ next_track ] );
+ }
+
+ uint32_t event_code = ( ( event.m_type + 8 ) << 4 ) + event.m_channel;
+ if ( event.m_data_count >= 1 ) event_code += event.m_data[ 0 ] << 8;
+ if ( event.m_data_count >= 2 ) event_code += event.m_data[ 1 ] << 16;
+ event_code += port_numbers[ next_track ] << 24;
+ p_stream.push_back( midi_stream_event( timestamp_ms, event_code ) );
+ }
+ else
+ {
+ std::size_t data_count = event.get_data_count();
+ if ( data_count >= 3 && event.m_data[ 0 ] == 0xF0 )
+ {
+ if ( device_names[ next_track ].length() )
+ {
+ unsigned long i, j;
+ for ( i = 0, j = m_device_names[ event.m_channel ].size(); i < j; ++i )
+ {
+ if ( !strcmp( m_device_names[ event.m_channel ][ i ].c_str(), device_names[ next_track ].c_str() ) ) break;
+ }
+ port_numbers[ next_track ] = i;
+ device_names[ next_track ].clear();
+ limit_port_number( port_numbers[ next_track ] );
+ }
+
+ data.resize( data_count );
+ event.copy_data( &data[0], 0, data_count );
+ if ( data[ data_count - 1 ] == 0xF7 )
+ {
+ uint32_t system_exclusive_index = p_system_exclusive.add_entry( &data[0], data_count, port_numbers[ next_track ] );
+ p_stream.push_back( midi_stream_event( timestamp_ms, system_exclusive_index | 0x80000000 ) );
+ }
+ }
+ else if ( data_count >= 3 && event.m_data[ 0 ] == 0xFF )
+ {
+ if ( event.m_data[ 1 ] == 4 || event.m_data[ 1 ] == 9 )
+ {
+ unsigned long data_count = event.get_data_count() - 2;
+ data.resize( data_count );
+ event.copy_data( &data[0], 2, data_count );
+ device_names[ next_track ].clear();
+ device_names[ next_track ].assign( data.begin(), data.begin() + data_count );
+ std::transform( device_names[ next_track ].begin(), device_names[ next_track ].end(), device_names[ next_track ].begin(), ::tolower );
+ }
+ else if ( event.m_data[ 1 ] == 0x21 )
+ {
+ port_numbers[ next_track ] = event.m_data[ 2 ];
+ device_names[ next_track ].clear();
+ limit_port_number( port_numbers[ next_track ] );
+ }
+ }
+ }
+ }
+
+ track_positions[ next_track ]++;
+ }
+}
+
+void midi_container::serialize_as_standard_midi_file( std::vector & p_midi_file ) const
+{
+ if ( !m_tracks.size() ) return;
+
+ std::vector data;
+
+ const char signature[] = "MThd";
+ p_midi_file.insert( p_midi_file.end(), signature, signature + 4 );
+ p_midi_file.push_back( 0 );
+ p_midi_file.push_back( 0 );
+ p_midi_file.push_back( 0 );
+ p_midi_file.push_back( 6 );
+ p_midi_file.push_back( 0 );
+ p_midi_file.push_back( m_form );
+ p_midi_file.push_back( (m_tracks.size() >> 8) );
+ p_midi_file.push_back( m_tracks.size() );
+ p_midi_file.push_back( (m_dtx >> 8) );
+ p_midi_file.push_back( m_dtx );
+
+ for ( unsigned i = 0; i < m_tracks.size(); ++i )
+ {
+ const midi_track & track = m_tracks[ i ];
+ unsigned long last_timestamp = 0;
+ unsigned char last_event_code = 0xFF;
+ std::size_t length_offset;
+
+ const char signature[] = "MTrk";
+ p_midi_file.insert( p_midi_file.end(), signature, signature + 4 );
+
+ length_offset = p_midi_file.size();
+ p_midi_file.push_back( 0 );
+ p_midi_file.push_back( 0 );
+ p_midi_file.push_back( 0 );
+ p_midi_file.push_back( 0 );
+
+ for ( unsigned j = 0; j < track.get_count(); ++j )
+ {
+ const midi_event & event = track[ j ];
+ encode_delta( p_midi_file, event.m_timestamp - last_timestamp );
+ last_timestamp = event.m_timestamp;
+ if ( event.m_type != midi_event::extended )
+ {
+ const unsigned char event_code = ( ( event.m_type + 8 ) << 4 ) + event.m_channel;
+ if ( event_code != last_event_code )
+ {
+ p_midi_file.push_back( event_code );
+ last_event_code = event_code;
+ }
+ p_midi_file.insert( p_midi_file.end(), event.m_data, event.m_data + event.m_data_count );
+ }
+ else
+ {
+ std::size_t data_count = event.get_data_count();
+ if ( data_count >= 1 )
+ {
+ if ( event.m_data[ 0 ] == 0xF0 )
+ {
+ --data_count;
+ p_midi_file.push_back( 0xF0 );
+ encode_delta( p_midi_file, data_count );
+ if ( data_count )
+ {
+ data.resize( data_count );
+ event.copy_data( &data[0], 1, data_count );
+ p_midi_file.insert( p_midi_file.end(), data.begin(), data.begin() + data_count );
+ }
+ }
+ else if ( event.m_data[ 0 ] == 0xFF && data_count >= 2 )
+ {
+ data_count -= 2;
+ p_midi_file.push_back( 0xFF );
+ p_midi_file.push_back( event.m_data[ 1 ] );
+ encode_delta( p_midi_file, data_count );
+ if ( data_count )
+ {
+ data.resize( data_count );
+ event.copy_data( &data[0], 2, data_count );
+ p_midi_file.insert( p_midi_file.end(), data.begin(), data.begin() + data_count );
+ }
+ }
+ }
+ }
+ }
+
+ std::size_t track_length = p_midi_file.size() - length_offset - 4;
+ p_midi_file[ length_offset + 0 ] = (unsigned char)( track_length >> 24 );
+ p_midi_file[ length_offset + 1 ] = (unsigned char)( track_length >> 16 );
+ p_midi_file[ length_offset + 2 ] = (unsigned char)( track_length >> 8 );
+ p_midi_file[ length_offset + 3 ] = (unsigned char)track_length;
+ }
+}
+
+void midi_container::promote_to_type1()
+{
+ if ( m_form == 0 && m_tracks.size() <= 2 )
+ {
+ bool meter_track_present = false;
+ midi_track new_tracks[17];
+ midi_track original_data_track = m_tracks[ m_tracks.size() - 1 ];
+ if ( m_tracks.size() > 1 )
+ {
+ new_tracks[0] = m_tracks[0];
+ meter_track_present = true;
+ }
+
+ m_tracks.resize( 0 );
+
+ for ( std::size_t i = 0; i < original_data_track.get_count(); ++i )
+ {
+ const midi_event & event = original_data_track[ i ];
+
+ if ( event.m_type != midi_event::extended )
+ {
+ new_tracks[ 1 + event.m_channel ].add_event( event );
+ }
+ else
+ {
+ if ( event.m_data[0] != 0xFF || event.get_data_count() < 2 || event.m_data[1] != 0x2F )
+ {
+ new_tracks[ 0 ].add_event( event );
+ }
+ else
+ {
+ if ( !meter_track_present )
+ new_tracks[ 0 ].add_event( event );
+ for ( std::size_t j = 1; j < 17; ++j )
+ {
+ new_tracks[ j ].add_event( event );
+ }
+ }
+ }
+ }
+
+ for ( std::size_t i = 0; i < 17; ++i )
+ {
+ if ( new_tracks[ i ].get_count() > 1 )
+ add_track( new_tracks[ i ] );
+ }
+
+ m_form = 1;
+ }
+}
+
+unsigned long midi_container::get_subsong_count() const
+{
+ unsigned long subsong_count = 0;
+ for ( unsigned i = 0; i < m_channel_mask.size(); ++i )
+ {
+ if ( m_channel_mask[ i ] ) ++subsong_count;
+ }
+ return subsong_count;
+}
+
+unsigned long midi_container::get_subsong( unsigned long p_index ) const
+{
+ for ( unsigned i = 0; i < m_channel_mask.size(); ++i )
+ {
+ if ( m_channel_mask[ i ] )
+ {
+ if ( p_index ) --p_index;
+ else return i;
+ }
+ }
+ return 0;
+}
+
+unsigned long midi_container::get_timestamp_end(unsigned long subsong, bool ms /* = false */) const
+{
+ unsigned long tempo_track = 0;
+ unsigned long timestamp = m_timestamp_end[ 0 ];
+ if ( m_form == 2 && subsong )
+ {
+ tempo_track = subsong;
+ timestamp = m_timestamp_end[ subsong ];
+ }
+ if ( !ms ) return timestamp;
+ else return timestamp_to_ms( timestamp, tempo_track );
+}
+
+unsigned midi_container::get_format() const
+{
+ return m_form;
+}
+
+unsigned midi_container::get_track_count() const
+{
+ return (unsigned) m_tracks.size();
+}
+
+unsigned midi_container::get_channel_count( unsigned long subsong ) const
+{
+ unsigned count = 0;
+ uint64_t j = 1;
+ for (unsigned i = 0; i < 48; ++i, j <<= 1)
+ {
+ if ( m_channel_mask[ subsong ] & j ) ++count;
+ }
+ return count;
+}
+
+unsigned long midi_container::get_timestamp_loop_start( unsigned long subsong, bool ms /* = false */ ) const
+{
+ unsigned long tempo_track = 0;
+ unsigned long timestamp = m_timestamp_loop_start[ 0 ];
+ if ( m_form == 2 && subsong )
+ {
+ tempo_track = subsong;
+ timestamp = m_timestamp_loop_start[ subsong ];
+ }
+ if ( !ms ) return timestamp;
+ else if ( timestamp != ~0UL ) return timestamp_to_ms( timestamp, tempo_track );
+ else return ~0UL;
+}
+
+unsigned long midi_container::get_timestamp_loop_end( unsigned long subsong, bool ms /* = false */ ) const
+{
+ unsigned long tempo_track = 0;
+ unsigned long timestamp = m_timestamp_loop_end[ 0 ];
+ if ( m_form == 2 && subsong )
+ {
+ tempo_track = subsong;
+ timestamp = m_timestamp_loop_end[ subsong ];
+ }
+ if ( !ms ) return timestamp;
+ else if ( timestamp != ~0UL ) return timestamp_to_ms( timestamp, tempo_track );
+ else return ~0UL;
+}
+
+/* TODO: Use iconv or libintl or something to probe for code pages and convert some mess to UTF-8 */
+static void convert_mess_to_utf8( const char * p_src, std::size_t p_src_len, std::string & p_dst )
+{
+ p_dst.assign( p_src, p_src + p_src_len );
+}
+
+void midi_container::get_meta_data( unsigned long subsong, midi_meta_data & p_out )
+{
+ char temp[32];
+ std::string convert;
+
+ std::vector data;
+
+ bool type_found = false;
+ bool type_non_gm_found = false;
+
+ for ( unsigned long i = 0; i < m_tracks.size(); ++i )
+ {
+ if ( m_form == 2 && i != subsong ) continue;
+
+ unsigned long tempo_track = 0;
+ if ( m_form == 2 ) tempo_track = i;
+
+ const midi_track & track = m_tracks[ i ];
+ for ( unsigned j = 0; j < track.get_count(); ++j )
+ {
+ const midi_event & event = track[ j ];
+ if ( event.m_type == midi_event::extended )
+ {
+ std::size_t data_count = event.get_data_count();
+ if ( !type_non_gm_found && data_count >= 1 && event.m_data[ 0 ] == 0xF0 )
+ {
+ unsigned char test = 0;
+ unsigned char test2 = 0;
+ if ( data_count > 1 ) test = event.m_data[ 1 ];
+ if ( data_count > 3 ) test2 = event.m_data[ 3 ];
+
+ const char * type = NULL;
+
+ switch( test )
+ {
+ case 0x7E:
+ type_found = true;
+ break;
+ case 0x43:
+ type = "XG";
+ break;
+ case 0x42:
+ type = "X5";
+ break;
+ case 0x41:
+ if ( test2 == 0x42 ) type = "GS";
+ else if ( test2 == 0x16 ) type = "MT-32";
+ else if ( test2 == 0x14 ) type = "D-50";
+ }
+
+ if ( type )
+ {
+ type_found = true;
+ type_non_gm_found = true;
+ p_out.add_item( midi_meta_data_item( timestamp_to_ms( event.m_timestamp, tempo_track ), "type", type ) );
+ }
+ }
+ else if ( data_count >= 2 && event.m_data[ 0 ] == 0xFF )
+ {
+ data_count -= 2;
+ switch ( event.m_data[ 1 ] )
+ {
+ case 6:
+ data.resize( data_count );
+ event.copy_data( &data[0], 2, data_count );
+ convert_mess_to_utf8( ( const char * ) &data[0], data_count, convert );
+ p_out.add_item( midi_meta_data_item( timestamp_to_ms( event.m_timestamp, tempo_track ), "track_marker", convert.c_str() ) );
+ break;
+
+ case 2:
+ data.resize( data_count );
+ event.copy_data( &data[0], 2, data_count );
+ convert_mess_to_utf8( ( const char * ) &data[0], data_count, convert );
+ p_out.add_item( midi_meta_data_item( timestamp_to_ms( event.m_timestamp, tempo_track ), "copyright", convert.c_str() ) );
+ break;
+
+ case 1:
+ data.resize( data_count );
+ event.copy_data( &data[0], 2, data_count );
+ convert_mess_to_utf8( ( const char * ) &data[0], data_count, convert );
+ snprintf(temp, 31, "track_text_%02lu", i);
+ p_out.add_item( midi_meta_data_item( timestamp_to_ms( event.m_timestamp, tempo_track ), temp, convert.c_str() ) );
+ break;
+
+ case 3:
+ case 4:
+ data.resize( data_count );
+ event.copy_data( &data[0], 2, data_count );
+ convert_mess_to_utf8( ( const char * ) &data[0], data_count, convert );
+ snprintf(temp, 31, "track_name_%02lu", i);
+ p_out.add_item( midi_meta_data_item( timestamp_to_ms( event.m_timestamp, tempo_track ), temp, convert.c_str() ) );
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if ( type_found && !type_non_gm_found )
+ {
+ p_out.add_item( midi_meta_data_item( 0, "type", "GM" ) );
+ }
+
+ p_out.append( m_extra_meta_data );
+}
+
+void midi_container::scan_for_loops( bool p_xmi_loops, bool p_marker_loops )
+{
+ std::vector data;
+
+ unsigned long subsong_count = m_form == 2 ? m_tracks.size() : 1;
+
+ m_timestamp_loop_start.resize( subsong_count );
+ m_timestamp_loop_end.resize( subsong_count );
+
+ for ( unsigned long i = 0; i < subsong_count; ++i )
+ {
+ m_timestamp_loop_start[ i ] = ~0UL;
+ m_timestamp_loop_end[ i ] = ~0UL;
+ }
+
+ if ( p_xmi_loops )
+ {
+ for ( unsigned long i = 0; i < m_tracks.size(); ++i )
+ {
+ unsigned long subsong = 0;
+ if ( m_form == 2 ) subsong = i;
+
+ const midi_track & track = m_tracks[ i ];
+ for ( unsigned long j = 0; j < track.get_count(); ++j )
+ {
+ const midi_event & event = track[ j ];
+ if ( event.m_type == midi_event::control_change &&
+ ( event.m_data[ 0 ] == 0x74 || event.m_data[ 0 ] == 0x75 ) )
+ {
+ if ( event.m_data[ 0 ] == 0x74 )
+ {
+ if ( m_timestamp_loop_start[ subsong ] == ~0u || m_timestamp_loop_start[ subsong ] > event.m_timestamp )
+ {
+ m_timestamp_loop_start[ subsong ] = event.m_timestamp;
+ }
+ }
+ else
+ {
+ if ( m_timestamp_loop_end[ subsong ] == ~0u || m_timestamp_loop_end[ subsong ] < event.m_timestamp )
+ {
+ m_timestamp_loop_end[ subsong ] = event.m_timestamp;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if ( p_marker_loops )
+ {
+ for ( unsigned long i = 0; i < m_tracks.size(); ++i )
+ {
+ unsigned long subsong = 0;
+ if ( m_form == 2 ) subsong = i;
+
+ const midi_track & track = m_tracks[ i ];
+ for ( unsigned long j = 0; j < track.get_count(); ++j )
+ {
+ const midi_event & event = track[ j ];
+ if ( event.m_type == midi_event::extended &&
+ event.get_data_count() >= 9 &&
+ event.m_data[ 0 ] == 0xFF && event.m_data[ 1 ] == 0x06 )
+ {
+ unsigned long data_count = event.get_data_count() - 2;
+ data.resize( data_count );
+ event.copy_data( &data[0], 2, data_count );
+
+ if ( data_count == 9 && !strncasecmp( (const char *) &data[0], "loopStart", 9 ) )
+ {
+ if ( m_timestamp_loop_start[ subsong ] == ~0u || m_timestamp_loop_start[ subsong ] > event.m_timestamp )
+ {
+ m_timestamp_loop_start[ subsong ] = event.m_timestamp;
+ }
+ }
+ else if ( data_count == 7 && !strncasecmp( (const char *) &data[0], "loopEnd", 7 ) )
+ {
+ if ( m_timestamp_loop_end[ subsong ] == ~0u || m_timestamp_loop_end[ subsong ] < event.m_timestamp )
+ {
+ m_timestamp_loop_end[ subsong ] = event.m_timestamp;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Sanity
+
+ for ( unsigned long i = 0; i < subsong_count; ++i )
+ {
+ if ( m_timestamp_loop_start[ i ] != ~0UL && m_timestamp_loop_start[ i ] == m_timestamp_loop_end[ i ] )
+ {
+ m_timestamp_loop_start[ i ] = ~0UL;
+ m_timestamp_loop_end[ i ] = ~0UL;
+ }
+ }
+}
diff --git a/Frameworks/midi_processing/midi_processing/midi_container.h b/Frameworks/midi_processing/midi_processing/midi_container.h
new file mode 100644
index 000000000..a44bd0ab1
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/midi_container.h
@@ -0,0 +1,244 @@
+#ifndef _MIDI_CONTAINER_H_
+#define _MIDI_CONTAINER_H_
+
+#include
+#include
+#include
+
+struct midi_event
+{
+ enum
+ {
+ max_static_data_count = 16
+ };
+
+ enum event_type
+ {
+ note_off = 0,
+ note_on,
+ polyphonic_aftertouch,
+ control_change,
+ program_change,
+ channel_aftertouch,
+ pitch_wheel,
+ extended
+ };
+
+ unsigned long m_timestamp;
+
+ event_type m_type;
+ unsigned m_channel;
+ unsigned long m_data_count;
+ uint8_t m_data[max_static_data_count];
+ std::vector m_ext_data;
+
+ midi_event() : m_timestamp(0), m_type(note_off), m_channel(0), m_data_count(0) { }
+ midi_event( const midi_event & p_in );
+ midi_event( unsigned long p_timestamp, event_type p_type, unsigned p_channel, const uint8_t * p_data, std::size_t p_data_count );
+
+ unsigned long get_data_count() const;
+ void copy_data( uint8_t * p_out, unsigned long p_offset, unsigned long p_count ) const;
+};
+
+class midi_track
+{
+ std::vector m_events;
+
+public:
+ midi_track() { }
+ midi_track(const midi_track & p_in);
+
+ void add_event( const midi_event & p_event );
+ std::size_t get_count() const;
+ const midi_event & operator [] ( std::size_t p_index ) const;
+
+ void remove_event( unsigned long index );
+};
+
+struct tempo_entry
+{
+ unsigned long m_timestamp;
+ unsigned m_tempo;
+
+ tempo_entry() : m_timestamp(0), m_tempo(0) { }
+ tempo_entry(unsigned long p_timestamp, unsigned p_tempo);
+};
+
+class tempo_map
+{
+ std::vector m_entries;
+
+public:
+ void add_tempo( unsigned p_tempo, unsigned long p_timestamp );
+ unsigned long timestamp_to_ms( unsigned long p_timestamp, unsigned p_dtx ) const;
+
+ std::size_t get_count() const;
+ const tempo_entry & operator [] ( std::size_t p_index ) const;
+};
+
+struct system_exclusive_entry
+{
+ std::size_t m_port;
+ std::size_t m_offset;
+ std::size_t m_length;
+ system_exclusive_entry() : m_port(0), m_offset(0), m_length(0) { }
+ system_exclusive_entry(const system_exclusive_entry & p_in);
+ system_exclusive_entry(std::size_t p_port, std::size_t p_offset, std::size_t p_length);
+};
+
+class system_exclusive_table
+{
+ std::vector m_data;
+ std::vector m_entries;
+
+public:
+ unsigned add_entry( const uint8_t * p_data, std::size_t p_size, std::size_t p_port );
+ void get_entry( unsigned p_index, const uint8_t * & p_data, std::size_t & p_size, std::size_t & p_port );
+};
+
+struct midi_stream_event
+{
+ unsigned long m_timestamp;
+ uint32_t m_event;
+
+ midi_stream_event() : m_timestamp(0), m_event(0) { }
+ midi_stream_event(unsigned long p_timestamp, uint32_t p_event);
+};
+
+struct midi_meta_data_item
+{
+ unsigned long m_timestamp;
+ std::string m_name;
+ std::string m_value;
+
+ midi_meta_data_item() : m_timestamp(0) { }
+ midi_meta_data_item(const midi_meta_data_item & p_in);
+ midi_meta_data_item(unsigned long p_timestamp, const char * p_name, const char * p_value);
+};
+
+class midi_meta_data
+{
+ std::vector m_data;
+
+public:
+ midi_meta_data() { }
+
+ void add_item( const midi_meta_data_item & p_item );
+
+ void append( const midi_meta_data & p_data );
+
+ bool get_item( const char * p_name, midi_meta_data_item & p_out ) const;
+
+ std::size_t get_count() const;
+
+ const midi_meta_data_item & operator [] ( std::size_t p_index ) const;
+};
+
+class midi_container
+{
+public:
+ enum
+ {
+ clean_flag_emidi = 1 << 0,
+ clean_flag_instruments = 1 << 1,
+ clean_flag_banks = 1 << 2,
+ };
+
+private:
+ unsigned m_form;
+ unsigned m_dtx;
+ std::vector m_channel_mask;
+ std::vector m_tempo_map;
+ std::vector m_tracks;
+
+ std::vector m_port_numbers;
+
+ std::vector< std::vector< std::string > > m_device_names;
+
+ midi_meta_data m_extra_meta_data;
+
+ std::vector m_timestamp_end;
+
+ std::vector m_timestamp_loop_start;
+ std::vector m_timestamp_loop_end;
+
+ unsigned long timestamp_to_ms( unsigned long p_timestamp, unsigned long p_subsong ) const;
+
+ /*
+ * Normalize port numbers properly
+ */
+ template void limit_port_number(T & number)
+ {
+ for ( unsigned i = 0; i < m_port_numbers.size(); i++ )
+ {
+ if ( m_port_numbers[ i ] == number )
+ {
+ number = i;
+ return;
+ }
+ }
+ m_port_numbers.push_back( number );
+ number = m_port_numbers.size() - 1;
+ }
+
+ template void limit_port_number(T & number) const
+ {
+ for ( unsigned i = 0; i < m_port_numbers.size(); i++ )
+ {
+ if ( m_port_numbers[ i ] == number )
+ {
+ number = i;
+ return;
+ }
+ }
+ }
+
+public:
+ midi_container() { m_device_names.resize( 16 ); }
+
+ void initialize( unsigned p_form, unsigned p_dtx );
+
+ void add_track( const midi_track & p_track );
+
+ void add_track_event( std::size_t p_track_index, const midi_event & p_event );
+
+ /*
+ * These functions are really only designed to merge and later remove System Exclusive message dumps
+ */
+ void merge_tracks( const midi_container & p_source );
+ void set_track_count( unsigned count );
+ void set_extra_meta_data( const midi_meta_data & p_data );
+
+ /*
+ * Blah.
+ * Hack 0: Remove channel 16
+ * Hack 1: Remove channels 11-16
+ */
+ void apply_hackfix( unsigned hack );
+
+ void serialize_as_stream( unsigned long subsong, std::vector & p_stream, system_exclusive_table & p_system_exclusive, unsigned clean_flags ) const;
+
+ void serialize_as_standard_midi_file( std::vector & p_midi_file ) const;
+
+ void promote_to_type1();
+
+ unsigned long get_subsong_count() const;
+ unsigned long get_subsong( unsigned long p_index ) const;
+
+ unsigned long get_timestamp_end(unsigned long subsong, bool ms = false) const;
+
+ unsigned get_format() const;
+ unsigned get_track_count() const;
+ unsigned get_channel_count(unsigned long subsong) const;
+
+ unsigned long get_timestamp_loop_start(unsigned long subsong, bool ms = false) const;
+ unsigned long get_timestamp_loop_end(unsigned long subsong, bool ms = false) const;
+
+ void get_meta_data( unsigned long subsong, midi_meta_data & p_out );
+
+ void scan_for_loops( bool p_xmi_loops, bool p_marker_loops );
+
+ static void encode_delta( std::vector & p_out, unsigned long delta );
+};
+
+#endif
diff --git a/Frameworks/midi_processing/midi_processing/midi_processing-Info.plist b/Frameworks/midi_processing/midi_processing/midi_processing-Info.plist
new file mode 100644
index 000000000..02c2a8310
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/midi_processing-Info.plist
@@ -0,0 +1,30 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ English
+ CFBundleExecutable
+ ${EXECUTABLE_NAME}
+ CFBundleIconFile
+
+ CFBundleIdentifier
+ NoWork-Inc.${PRODUCT_NAME:rfc1034identifier}
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundleName
+ ${PRODUCT_NAME}
+ CFBundlePackageType
+ FMWK
+ CFBundleShortVersionString
+ 1.0
+ CFBundleSignature
+ ????
+ CFBundleVersion
+ 1
+ NSHumanReadableCopyright
+ Copyright © 2013 Christopher Snowhill. All rights reserved.
+ NSPrincipalClass
+
+
+
diff --git a/Frameworks/midi_processing/midi_processing/midi_processor.h b/Frameworks/midi_processing/midi_processing/midi_processor.h
new file mode 100644
index 000000000..20c289901
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/midi_processor.h
@@ -0,0 +1,61 @@
+#ifndef _MIDI_PROCESSORS_H_
+#define _MIDI_PROCESSORS_H_
+
+#include "midi_container.h"
+
+#ifndef _countof
+template
+char ( &_ArraySizeHelper( T (&array)[N] ))[N];
+#define _countof( array ) (sizeof( _ArraySizeHelper( array ) ))
+#endif
+
+class midi_processor
+{
+ static const uint8_t end_of_track[2];
+ static const uint8_t loop_start[11];
+ static const uint8_t loop_end[9];
+
+ static const uint8_t hmp_default_tempo[5];
+
+ static const uint8_t xmi_default_tempo[5];
+
+ static const uint8_t mus_default_tempo[5];
+ static const uint8_t mus_controllers[15];
+
+ static const uint8_t lds_default_tempo[5];
+
+ static int decode_delta( std::vector::const_iterator & it );
+ static unsigned decode_hmp_delta( std::vector::const_iterator & it );
+ static unsigned decode_xmi_delta( std::vector::const_iterator & it, std::vector::const_iterator end );
+
+ static bool is_standard_midi( std::vector const& p_file );
+ static bool is_riff_midi( std::vector const& p_file );
+ static bool is_hmp( std::vector const& p_file );
+ static bool is_hmi( std::vector const& p_file );
+ static bool is_xmi( std::vector const& p_file );
+ static bool is_mus( std::vector const& p_file );
+ static bool is_mids( std::vector const& p_file );
+ static bool is_lds( std::vector const& p_file, const char * p_extension );
+ static bool is_gmf( std::vector const& p_file );
+ static bool is_syx( std::vector const& p_file );
+
+ static bool process_standard_midi_track( std::vector::const_iterator & it, std::vector::const_iterator end, midi_container & p_out, bool needs_end_marker );
+
+ static bool process_standard_midi( std::vector const& p_file, midi_container & p_out );
+ static bool process_riff_midi( std::vector const& p_file, midi_container & p_out );
+ static bool process_hmp( std::vector const& p_file, midi_container & p_out );
+ static bool process_hmi( std::vector const& p_file, midi_container & p_out );
+ static bool process_xmi( std::vector const& p_file, midi_container & p_out );
+ static bool process_mus( std::vector const& p_file, midi_container & p_out );
+ static bool process_mids( std::vector const& p_file, midi_container & p_out );
+ static bool process_lds( std::vector const& p_file, midi_container & p_out );
+ static bool process_gmf( std::vector const& p_file, midi_container & p_out );
+ static bool process_syx( std::vector const& p_file, midi_container & p_out );
+
+public:
+ static bool process_file( std::vector const& p_file, const char * p_extension, midi_container & p_out );
+
+ static bool process_syx_file( std::vector const& p_file, midi_container & p_out );
+};
+
+#endif
diff --git a/Frameworks/midi_processing/midi_processing/midi_processor_gmf.cpp b/Frameworks/midi_processing/midi_processing/midi_processor_gmf.cpp
new file mode 100644
index 000000000..b8fdc8899
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/midi_processor_gmf.cpp
@@ -0,0 +1,52 @@
+#include "midi_processor.h"
+
+bool midi_processor::is_gmf( std::vector const& p_file )
+{
+ if ( p_file.size() < 32 ) return false;
+ if ( p_file[ 0 ] != 'G' || p_file[ 1 ] != 'M' || p_file[ 2 ] != 'F' || p_file[ 3 ] != 1 ) return false;
+ return true;
+}
+
+bool midi_processor::process_gmf( std::vector const& p_file, midi_container & p_out )
+{
+ uint8_t buffer[10];
+
+ p_out.initialize( 0, 0xC0 );
+
+ uint16_t tempo = ( p_file[ 4 ] << 8 ) | p_file[ 5 ];
+ uint32_t tempo_scaled = tempo * 100000;
+
+ midi_track track;
+
+ buffer[0] = 0xFF;
+ buffer[1] = 0x51;
+ buffer[2] = tempo_scaled >> 16;
+ buffer[3] = tempo_scaled >> 8;
+ buffer[4] = tempo_scaled;
+
+ track.add_event( midi_event( 0, midi_event::extended, 0, buffer, 5 ) );
+
+ buffer[0] = 0xF0;
+ buffer[1] = 0x41;
+ buffer[2] = 0x10;
+ buffer[3] = 0x16;
+ buffer[4] = 0x12;
+ buffer[5] = 0x7F;
+ buffer[6] = 0x00;
+ buffer[7] = 0x00;
+ buffer[8] = 0x01;
+ buffer[9] = 0xF7;
+
+ track.add_event( midi_event( 0, midi_event::extended, 0, buffer, 10 ) );
+
+ buffer[0] = 0xFF;
+ buffer[1] = 0x2F;
+
+ track.add_event( midi_event( 0, midi_event::extended, 0, buffer, 2 ) );
+
+ p_out.add_track( track );
+
+ std::vector::const_iterator it = p_file.begin() + 7;
+
+ return process_standard_midi_track( it, p_file.end(), p_out, false );
+}
diff --git a/Frameworks/midi_processing/midi_processing/midi_processor_helpers.cpp b/Frameworks/midi_processing/midi_processing/midi_processor_helpers.cpp
new file mode 100644
index 000000000..0fec3bee5
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/midi_processor_helpers.cpp
@@ -0,0 +1,68 @@
+#include "midi_processor.h"
+
+const uint8_t midi_processor::end_of_track[2] = {0xFF, 0x2F};
+const uint8_t midi_processor::loop_start[11] = {0xFF, 0x06, 'l', 'o', 'o', 'p', 'S', 't', 'a', 'r', 't'};
+const uint8_t midi_processor::loop_end[9] = {0xFF, 0x06, 'l', 'o', 'o', 'p', 'E', 'n', 'd'};
+
+int midi_processor::decode_delta( std::vector::const_iterator & it )
+{
+ int delta = 0;
+ unsigned char byte;
+ do
+ {
+ byte = *it++;
+ delta = ( delta << 7 ) + ( byte & 0x7F );
+ }
+ while ( byte & 0x80 );
+ return delta;
+}
+
+bool midi_processor::process_file( std::vector const& p_file, const char * p_extension, midi_container & p_out )
+{
+ if ( is_standard_midi( p_file ) )
+ {
+ return process_standard_midi( p_file, p_out );
+ }
+ else if ( is_riff_midi( p_file ) )
+ {
+ return process_riff_midi( p_file, p_out );
+ }
+ else if ( is_hmp( p_file ) )
+ {
+ return process_hmp( p_file, p_out );
+ }
+ else if ( is_hmi( p_file ) )
+ {
+ return process_hmi( p_file, p_out );
+ }
+ else if ( is_xmi( p_file ) )
+ {
+ return process_xmi( p_file, p_out );
+ }
+ else if ( is_mus( p_file ) )
+ {
+ return process_mus( p_file, p_out );
+ }
+ else if ( is_mids( p_file ) )
+ {
+ return process_mids( p_file, p_out );
+ }
+ else if ( is_lds( p_file, p_extension ) )
+ {
+ return process_lds( p_file, p_out );
+ }
+ else if ( is_gmf( p_file ) )
+ {
+ return process_gmf( p_file, p_out );
+ }
+ else return false;
+}
+
+bool midi_processor::process_syx_file( std::vector const& p_file, midi_container & p_out )
+{
+ if ( is_syx( p_file ) )
+ {
+ return process_syx( p_file, p_out );
+ }
+ else return false;
+}
diff --git a/Frameworks/midi_processing/midi_processing/midi_processor_hmi.cpp b/Frameworks/midi_processing/midi_processing/midi_processor_hmi.cpp
new file mode 100644
index 000000000..9581f016b
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/midi_processor_hmi.cpp
@@ -0,0 +1,209 @@
+#include "midi_processor.h"
+
+bool midi_processor::is_hmi( std::vector const& p_file )
+{
+ if ( p_file.size() < 12 ) return false;
+ if ( p_file[ 0 ] != 'H' || p_file[ 1 ] != 'M' || p_file[ 2 ] != 'I' || p_file[ 3 ] != '-' ||
+ p_file[ 4 ] != 'M' || p_file[ 5 ] != 'I' || p_file[ 6 ] != 'D' || p_file[ 7 ] != 'I' ||
+ p_file[ 8 ] != 'S' || p_file[ 9 ] != 'O' || p_file[ 10 ] != 'N' || p_file[ 11 ] != 'G' ) return false;
+ return true;
+}
+
+bool midi_processor::process_hmi( std::vector const& p_file, midi_container & p_out )
+{
+ std::vector buffer;
+
+ std::vector::const_iterator it = p_file.begin() + 0xE4;
+
+ uint32_t track_count = it[ 0 ] | ( it[ 1 ] << 8 ) | ( it[ 2 ] << 16 ) | ( it[ 3 ] << 24 );
+ uint32_t track_table_offset = it[ 4 ] | ( it[ 5 ] << 8 ) | ( it[ 6 ] << 16 ) | ( it[ 7 ] << 24 );
+
+ it = p_file.begin() + track_table_offset;
+
+ std::vector track_offsets;
+ track_offsets.resize( track_count );
+
+ for ( unsigned i = 0; i < track_count; ++i )
+ {
+ track_offsets[ i ] = it[ 0 ] | ( it[ 1 ] << 8 ) | ( it[ 2 ] << 16 ) | ( it[ 3 ] << 24 );
+ it += 4;
+ }
+
+ p_out.initialize( 1, 0xC0 );
+
+ {
+ midi_track track;
+ track.add_event( midi_event( 0, midi_event::extended, 0, hmp_default_tempo, _countof( hmp_default_tempo ) ) );
+ track.add_event( midi_event( 0, midi_event::extended, 0, end_of_track, _countof( end_of_track ) ) );
+ p_out.add_track( track );
+ }
+
+ for ( unsigned i = 0; i < track_count; ++i )
+ {
+ unsigned track_offset = track_offsets[ i ];
+ unsigned long track_length;
+ if ( i + 1 < track_count )
+ {
+ track_length = track_offsets[ i + 1 ] - track_offset;
+ }
+ else
+ {
+ track_length = p_file.size() - track_offset;
+ }
+ std::vector::const_iterator track_body = p_file.begin() + track_offset;
+ std::vector::const_iterator track_end = track_body + track_length;
+
+ if ( track_length < 13 ) return false;
+ if ( track_body[ 0 ] != 'H' || track_body[ 1 ] != 'M' || track_body[ 2 ] != 'I' || track_body[ 3 ] != '-' ||
+ track_body[ 4 ] != 'M' || track_body[ 5 ] != 'I' || track_body[ 6 ] != 'D' || track_body[ 7 ] != 'I' ||
+ track_body[ 8 ] != 'T' || track_body[ 9 ] != 'R' || track_body[ 10 ] != 'A' || track_body[ 11 ] != 'C' ||
+ track_body[ 12 ] != 'K' ) return false;
+
+ midi_track track;
+ unsigned current_timestamp = 0;
+ unsigned char last_event_code = 0xFF;
+
+ unsigned last_event_timestamp = 0;
+
+ if ( track_length < 0x4B + 4 ) return false;
+
+ uint32_t meta_offset = track_body[ 0x4B ] | ( track_body[ 0x4C ] << 8 ) | ( track_body[ 0x4D ] << 16 ) | ( track_body[ 0x4E ] << 24 );
+ if ( meta_offset && meta_offset + 1 < track_length )
+ {
+ buffer.resize( 2 );
+ std::copy( track_body + meta_offset, track_body + meta_offset + 2, buffer.begin() );
+ unsigned meta_size = buffer[ 1 ];
+ if ( meta_offset + 2 + meta_size > track_length ) return false;
+ buffer.resize( meta_size + 2 );
+ std::copy( track_body + meta_offset + 2, track_body + meta_offset + 2 + meta_size, buffer.begin() + 2 );
+ while ( meta_size > 0 && buffer[ meta_size + 1 ] == ' ' ) --meta_size;
+ if ( meta_size > 0 )
+ {
+ buffer[ 0 ] = 0xFF;
+ buffer[ 1 ] = 0x01;
+ track.add_event( midi_event( 0, midi_event::extended, 0, &buffer[0], meta_size + 2 ) );
+ }
+ }
+
+ if ( track_length < 0x57 + 4 ) return false;
+
+ uint32_t track_data_offset = track_body[ 0x57 ] | ( track_body[ 0x58 ] << 8 ) | ( track_body[ 0x59 ] << 16 ) | ( track_body[ 0x5A ] << 24 );
+
+ it = track_body + track_data_offset;
+
+ buffer.resize( 3 );
+
+ while ( it < track_end )
+ {
+ int delta = decode_delta( it );
+ if ( delta > 0xFFFF || delta < 0 )
+ {
+ current_timestamp = last_event_timestamp;
+ /*console::formatter() << "[foo_midi] Large HMI delta detected, shunting.";*/
+ }
+ else
+ {
+ current_timestamp += delta;
+ if ( current_timestamp > last_event_timestamp )
+ {
+ last_event_timestamp = current_timestamp;
+ }
+ }
+
+ buffer[ 0 ] = *it++;
+ if ( buffer[ 0 ] == 0xFF )
+ {
+ last_event_code = 0xFF;
+ buffer[ 1 ] = *it++;
+ int meta_count = decode_delta( it );
+ if ( meta_count < 0 ) return false; /*throw exception_io_data( "Invalid HMI meta message" );*/
+ buffer.resize( meta_count + 2 );
+ std::copy( it, it + meta_count, buffer.begin() + 2 );
+ it += meta_count;
+ if ( buffer[ 1 ] == 0x2F && last_event_timestamp > current_timestamp )
+ {
+ current_timestamp = last_event_timestamp;
+ }
+ track.add_event( midi_event( current_timestamp, midi_event::extended, 0, &buffer[0], meta_count + 2 ) );
+ if ( buffer[ 1 ] == 0x2F ) break;
+ }
+ else if ( buffer[ 0 ] == 0xF0 )
+ {
+ last_event_code = 0xFF;
+ int system_exclusive_count = decode_delta( it );
+ if ( system_exclusive_count < 0 ) return false; /*throw exception_io_data( "Invalid HMI System Exclusive message" );*/
+ buffer.resize( system_exclusive_count + 1 );
+ std::copy( it, it + system_exclusive_count, buffer.begin() + 1 );
+ it += system_exclusive_count;
+ track.add_event( midi_event( current_timestamp, midi_event::extended, 0, &buffer[0], system_exclusive_count + 1 ) );
+ }
+ else if ( buffer[ 0 ] == 0xFE )
+ {
+ last_event_code = 0xFF;
+ buffer[ 1 ] = *it++;
+ if ( buffer[ 1 ] == 0x10 )
+ {
+ it += 2;
+ buffer[ 2 ] = *it++;
+ it += buffer[ 2 ] + 4;
+ }
+ else if ( buffer[ 1 ] == 0x12 )
+ {
+ it += 2;
+ }
+ else if ( buffer[ 1 ] == 0x13 )
+ {
+ it += 10;
+ }
+ else if ( buffer[ 1 ] == 0x14 )
+ {
+ it += 2;
+ p_out.add_track_event( 0, midi_event( current_timestamp, midi_event::extended, 0, loop_start, _countof( loop_start ) ) );
+ }
+ else if ( buffer[ 1 ] == 0x15 )
+ {
+ it += 6;
+ p_out.add_track_event( 0, midi_event( current_timestamp, midi_event::extended, 0, loop_end, _countof( loop_end ) ) );
+ }
+ else return false; /*throw exception_io_data( "Unexpected HMI meta event" );*/
+ }
+ else if ( buffer[ 0 ] <= 0xEF )
+ {
+ unsigned bytes_read = 1;
+ if ( buffer[ 0 ] >= 0x80 )
+ {
+ buffer[ 1 ] = *it++;
+ last_event_code = buffer[ 0 ];
+ }
+ else
+ {
+ if ( last_event_code == 0xFF ) return false; /*throw exception_io_data( "HMI used shortened event after Meta or SysEx message" );*/
+ buffer[ 1 ] = buffer[ 0 ];
+ buffer[ 0 ] = last_event_code;
+ }
+ midi_event::event_type type = (midi_event::event_type)( ( buffer[ 0 ] >> 4 ) - 8 );
+ unsigned channel = buffer[ 0 ] & 0x0F;
+ if ( type != midi_event::program_change && type != midi_event::channel_aftertouch )
+ {
+ buffer[ 2 ] = *it++;
+ bytes_read = 2;
+ }
+ track.add_event( midi_event( current_timestamp, type, channel, &buffer[ 1 ], bytes_read ) );
+ if ( type == midi_event::note_on )
+ {
+ buffer[ 2 ] = 0x00;
+ int note_length = decode_delta( it );
+ if ( note_length < 0 ) return false; /*throw exception_io_data( "Invalid HMI note message" );*/
+ unsigned note_end_timestamp = current_timestamp + note_length;
+ if ( note_end_timestamp > last_event_timestamp ) last_event_timestamp = note_end_timestamp;
+ track.add_event( midi_event( note_end_timestamp, midi_event::note_on, channel, &buffer[1], bytes_read ) );
+ }
+ }
+ else return false; /*throw exception_io_data( "Unexpected HMI status code" );*/
+ }
+
+ p_out.add_track( track );
+ }
+
+ return true;
+}
diff --git a/Frameworks/midi_processing/midi_processing/midi_processor_hmp.cpp b/Frameworks/midi_processing/midi_processing/midi_processor_hmp.cpp
new file mode 100644
index 000000000..6e0ec068c
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/midi_processor_hmp.cpp
@@ -0,0 +1,147 @@
+#include "midi_processor.h"
+
+const uint8_t midi_processor::hmp_default_tempo[5] = {0xFF, 0x51, 0x18, 0x80, 0x00};
+
+bool midi_processor::is_hmp( std::vector const& p_file )
+{
+ if ( p_file.size() < 8 ) return false;
+ if ( p_file[ 0 ] != 'H' || p_file[ 1 ] != 'M' || p_file[ 2 ] != 'I' || p_file[ 3 ] != 'M' ||
+ p_file[ 4 ] != 'I' || p_file[ 5 ] != 'D' || p_file[ 6 ] != 'I' ||
+ ( p_file[ 7 ] != 'P' && p_file[ 7 ] != 'R' ) ) return false;
+ return true;
+}
+
+unsigned midi_processor::decode_hmp_delta( std::vector::const_iterator & it )
+{
+ unsigned delta = 0;
+ unsigned shift = 0;
+ unsigned char byte;
+ do
+ {
+ byte = *it++;
+ delta = delta + ( ( byte & 0x7F ) << shift );
+ shift += 7;
+ }
+ while ( !( byte & 0x80 ) );
+ return delta;
+}
+
+bool midi_processor::process_hmp( std::vector const& p_file, midi_container & p_out )
+{
+ bool is_funky = p_file[ 7 ] == 'R';
+
+ uint8_t track_count_8;
+ uint16_t dtx = 0xC0;
+
+ std::vector::const_iterator it = p_file.begin() + ( is_funky ? 0x1A : 0x30 );
+
+ track_count_8 = *it;
+
+ if ( is_funky )
+ {
+ dtx = ( p_file[ 0x4C ] << 16 ) | p_file[ 0x4D ];
+ }
+
+ p_out.initialize( 1, dtx );
+
+ {
+ midi_track track;
+ track.add_event( midi_event( 0, midi_event::extended, 0, hmp_default_tempo, _countof( hmp_default_tempo ) ) );
+ track.add_event( midi_event( 0, midi_event::extended, 0, end_of_track, _countof( end_of_track ) ) );
+ p_out.add_track( track );
+ }
+
+ uint8_t buffer[ 4 ];
+
+ buffer[ 0 ] = *it++;
+
+ while ( it < p_file.end() )
+ {
+ if ( buffer[ 0 ] != 0xFF )
+ {
+ buffer[ 0 ] = *it++;
+ continue;
+ }
+ buffer[ 1 ] = *it++;
+ if ( buffer[ 1 ] != 0x2F )
+ {
+ buffer[ 0 ] = buffer[ 1 ];
+ continue;
+ }
+ break;
+ }
+
+ it += ( is_funky ? 3 : 5 );
+
+ unsigned track_count = track_count_8;
+
+ for ( unsigned i = 1; i < track_count; ++i )
+ {
+ uint16_t track_size_16;
+ uint32_t track_size_32;
+
+ if ( is_funky )
+ {
+ track_size_16 = it[ 0 ] | ( it[ 1 ] << 8 );
+ it += 2;
+ track_size_32 = track_size_16 - 4;
+ if ( p_file.end() - it < track_size_32 + 2 ) break;
+ it += 2;
+ }
+ else
+ {
+ track_size_32 = it[ 0 ] | ( it[ 1 ] << 8 ) | ( it[ 2 ] << 16 ) | ( it[ 3 ] << 24 );
+ it += 4;
+ track_size_32 -= 12;
+ if ( p_file.end() - it < track_size_32 + 8 ) break;
+ it += 4;
+ }
+
+ midi_track track;
+
+ unsigned current_timestamp = 0;
+
+ std::vector buffer;
+ buffer.resize( 3 );
+
+ std::vector::const_iterator track_end = it + track_size_32;
+
+ while ( it < track_end )
+ {
+ unsigned delta = decode_hmp_delta( it );
+ current_timestamp += delta;
+ buffer[ 0 ] = *it++;
+ if ( buffer[ 0 ] == 0xFF )
+ {
+ buffer[ 1 ] = *it++;
+ int meta_count = decode_delta( it );
+ if ( meta_count < 0 ) return false; /*throw exception_io_data( "Invalid HMP meta message" );*/
+ buffer.resize( meta_count + 2 );
+ std::copy( it, it + meta_count, buffer.begin() + 2 );
+ it += meta_count;
+ track.add_event( midi_event( current_timestamp, midi_event::extended, 0, &buffer[0], meta_count + 2 ) );
+ if ( buffer[ 1 ] == 0x2F ) break;
+ }
+ else if ( buffer[ 0 ] >= 0x80 && buffer[ 0 ] <= 0xEF )
+ {
+ unsigned bytes_read = 2;
+ switch ( buffer[ 0 ] & 0xF0 )
+ {
+ case 0xC0:
+ case 0xD0:
+ bytes_read = 1;
+ }
+ std::copy( it, it + bytes_read, buffer.begin() + 1 );
+ it += bytes_read;
+ track.add_event( midi_event( current_timestamp, (midi_event::event_type)( ( buffer[ 0 ] >> 4 ) - 8 ), buffer[ 0 ] & 0x0F, &buffer[1], bytes_read ) );
+ }
+ else return false; /*throw exception_io_data( "Unexpected status code in HMP track" );*/
+ }
+
+ it = track_end + ( is_funky ? 0 : 4 );
+
+ p_out.add_track( track );
+ }
+
+ return true;
+}
diff --git a/Frameworks/midi_processing/midi_processing/midi_processor_lds.cpp b/Frameworks/midi_processing/midi_processing/midi_processor_lds.cpp
new file mode 100644
index 000000000..050ab5f2b
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/midi_processor_lds.cpp
@@ -0,0 +1,1038 @@
+#include "midi_processor.h"
+
+#include
+
+const uint8_t midi_processor::lds_default_tempo[5] = { 0xFF, 0x51, 0x07, 0xA1, 0x20 };
+
+#define ENABLE_WHEEL
+//#define ENABLE_VIB
+//#define ENABLE_ARP
+//#define ENABLE_TREM
+
+#ifdef ENABLE_WHEEL
+#define WHEEL_RANGE_HIGH 12
+#define WHEEL_RANGE_LOW 0
+#define WHEEL_SCALE(x) ((x) * 512 / WHEEL_RANGE_HIGH)
+#define WHEEL_SCALE_LOW(x) (WHEEL_SCALE(x) & 127)
+#define WHEEL_SCALE_HIGH(x) (((WHEEL_SCALE(x) >> 7) + 64) & 127)
+#endif
+
+#ifdef ENABLE_VIB
+// Vibrato (sine) table
+static const unsigned char vibtab[] = {
+ 0, 13, 25, 37, 50, 62, 74, 86, 98, 109, 120, 131, 142, 152, 162,
+ 171, 180, 189, 197, 205, 212, 219, 225, 231, 236, 240, 244, 247,
+ 250, 252, 254, 255, 255, 255, 254, 252, 250, 247, 244, 240, 236,
+ 231, 225, 219, 212, 205, 197, 189, 180, 171, 162, 152, 142, 131,
+ 120, 109, 98, 86, 74, 62, 50, 37, 25, 13
+};
+#endif
+
+#ifdef ENABLE_TREM
+// Tremolo (sine * sine) table
+static const unsigned char tremtab[] = {
+ 0, 0, 1, 1, 2, 4, 5, 7, 10, 12, 15, 18, 21, 25, 29, 33, 37, 42, 47,
+ 52, 57, 62, 67, 73, 79, 85, 90, 97, 103, 109, 115, 121, 128, 134,
+ 140, 146, 152, 158, 165, 170, 176, 182, 188, 193, 198, 203, 208,
+ 213, 218, 222, 226, 230, 234, 237, 240, 243, 245, 248, 250, 251,
+ 253, 254, 254, 255, 255, 255, 254, 254, 253, 251, 250, 248, 245,
+ 243, 240, 237, 234, 230, 226, 222, 218, 213, 208, 203, 198, 193,
+ 188, 182, 176, 170, 165, 158, 152, 146, 140, 134, 127, 121, 115,
+ 109, 103, 97, 90, 85, 79, 73, 67, 62, 57, 52, 47, 42, 37, 33, 29,
+ 25, 21, 18, 15, 12, 10, 7, 5, 4, 2, 1, 1, 0
+};
+#endif
+
+bool midi_processor::is_lds( std::vector const& p_file, const char * p_extension )
+{
+ if ( strcasecmp( p_extension, "LDS" ) ) return false;
+ if ( p_file.size() < 1 ) return false;
+ if ( p_file[ 0 ] > 2 ) return false;
+ return true;
+}
+
+struct sound_patch
+{
+ // skip 11 bytes worth of Adlib crap
+ uint8_t keyoff;
+#ifdef ENABLE_WHEEL
+ uint8_t portamento;
+ int8_t glide;
+#endif
+ // skip 1 byte
+#ifdef ENABLE_VIB
+ uint8_t vibrato;
+ uint8_t vibrato_delay;
+#endif
+#ifdef ENABLE_TREM
+ uint8_t modulator_tremolo;
+ uint8_t carrier_tremolo;
+ uint8_t tremolo_delay;
+#endif
+#ifdef ENABLE_ARP
+ uint8_t arpeggio;
+ int8_t arpeggio_table[12];
+#endif
+ // skip 4 bytes worth of digital instrument crap
+ // skip 3 more bytes worth of Adlib crap that isn't even used
+ uint8_t midi_instrument;
+ uint8_t midi_velocity;
+ uint8_t midi_key;
+ int8_t midi_transpose;
+ // skip 2 bytes worth of MIDI dummy fields or whatever
+};
+
+struct channel_state {
+#ifdef ENABLE_WHEEL
+ int16_t gototune, lasttune;
+#endif
+ uint16_t packpos;
+ int8_t finetune;
+#ifdef ENABLE_WHEEL
+ uint8_t glideto, portspeed;
+#endif
+ uint8_t nextvol, volmod, volcar,
+ keycount, packwait;
+#ifdef ENABLE_VIB
+ uint8_t vibwait, vibspeed, vibrate, vibcount;
+#endif
+#ifdef ENABLE_TREM
+ uint8_t trmstay, trmwait, trmspeed, trmrate, trmcount,
+ trcwait, trcspeed, trcrate, trccount;
+#endif
+#ifdef ENABLE_ARP
+ uint8_t arp_count, arp_size, arp_speed, arp_pos;
+ int8_t arp_tab[12];
+#endif
+
+ struct {
+ uint8_t chandelay, sound;
+ uint16_t high;
+ } chancheat;
+};
+
+void playsound( uint8_t current_instrument[], std::vector const& patches, uint8_t last_note[], uint8_t last_channel[], uint8_t last_instrument[], uint8_t last_volume[], uint8_t last_sent_volume[],
+#ifdef ENABLE_WHEEL
+ int16_t last_pitch_wheel[],
+#endif
+ channel_state * c, uint8_t allvolume, unsigned current_timestamp, unsigned sound, unsigned chan, unsigned high, midi_track & track )
+{
+ uint8_t buffer[ 2 ];
+ current_instrument[ chan ] = sound;
+ if ( sound >= patches.size() ) return;
+ const sound_patch & patch = patches[ current_instrument[ chan ] ];
+ unsigned channel = ( patch.midi_instrument >= 0x80 ) ? 9 : ( chan == 9 ) ? 10 : chan;
+ unsigned saved_last_note = last_note[ chan ];
+ unsigned note;
+
+ if ( channel != 9 )
+ {
+ // set fine tune
+ high += c->finetune;
+
+ // arpeggio handling
+#ifdef ENABLE_ARP
+ if(patch.arpeggio)
+ {
+ short arpcalc = patch.arpeggio_table[0] << 4;
+
+ high += arpcalc;
+ }
+#endif
+
+ // and MIDI transpose
+ high = (int)high + ( patch.midi_transpose << 4 );
+
+ note = high
+#ifdef ENABLE_WHEEL
+ - c->lasttune
+#endif
+ ;
+
+ // glide handling
+#ifdef ENABLE_WHEEL
+ if(c->glideto != 0)
+ {
+ c->gototune = note - ( last_note[ chan ] << 4 ) + c->lasttune;
+ c->portspeed = c->glideto;
+ c->glideto = c->finetune = 0;
+ return;
+ }
+#endif
+
+ if ( patch.midi_instrument != last_instrument[ chan ] )
+ {
+ buffer[ 0 ] = patch.midi_instrument;
+ track.add_event( midi_event( current_timestamp, midi_event::program_change, channel, buffer, 1 ) );
+ last_instrument[ chan ] = patch.midi_instrument;
+ }
+ }
+ else
+ {
+ note = ( patch.midi_instrument & 0x7F ) << 4;
+ }
+
+ unsigned volume = 127;
+
+ if ( c->nextvol )
+ {
+ volume = ( c->nextvol & 0x3F ) * 127 / 63;
+ last_volume[ chan ] = volume;
+ }
+
+ if ( allvolume )
+ {
+ volume = volume * allvolume / 255;
+ }
+
+ if ( volume != last_sent_volume[ channel ] )
+ {
+ buffer[ 0 ] = 7;
+ buffer[ 1 ] = volume;
+ track.add_event( midi_event( current_timestamp, midi_event::control_change, last_channel[ chan ], buffer, 2 ) );
+ last_sent_volume[ channel ] = volume;
+ }
+
+ if ( saved_last_note != 0xFF )
+ {
+ buffer[ 0 ] = saved_last_note;
+ buffer[ 1 ] = 127;
+ track.add_event( midi_event( current_timestamp, midi_event::note_off, last_channel[ chan ], buffer, 2 ) );
+ last_note[ chan ] = 0xFF;
+#ifdef ENABLE_WHEEL
+ if ( channel != 9 )
+ {
+ note += c->lasttune;
+ c->lasttune = 0;
+ if ( last_pitch_wheel[ channel ] != 0 )
+ {
+ buffer[ 0 ] = 0;
+ buffer[ 1 ] = 64;
+ track.add_event( midi_event( current_timestamp, midi_event::pitch_wheel, last_channel[ chan ], buffer, 2 ) );
+ last_pitch_wheel[ channel ] = 0;
+ }
+ }
+#endif
+ }
+#ifdef ENABLE_WHEEL
+ if ( c->lasttune != last_pitch_wheel[ channel ] )
+ {
+ buffer[ 0 ] = WHEEL_SCALE_LOW( c->lasttune );
+ buffer[ 1 ] = WHEEL_SCALE_HIGH( c->lasttune );
+ track.add_event( midi_event( current_timestamp, midi_event::pitch_wheel, channel, buffer, 2 ) );
+ last_pitch_wheel[ channel ] = c->lasttune;
+ }
+ if( !patch.glide || last_note[ chan ] == 0xFF )
+#endif
+ {
+#ifdef ENABLE_WHEEL
+ if( !patch.portamento || last_note[ chan ] == 0xFF )
+#endif
+ {
+ buffer[ 0 ] = note >> 4;
+ buffer[ 1 ] = patch.midi_velocity;
+ track.add_event( midi_event( current_timestamp, midi_event::note_on, channel, buffer, 2 ) );
+ last_note[ chan ] = note >> 4;
+ last_channel[ chan ] = channel;
+#ifdef ENABLE_WHEEL
+ c->gototune = c->lasttune;
+#endif
+ }
+#ifdef ENABLE_WHEEL
+ else
+ {
+ c->gototune = note - ( last_note[ chan ] << 4 ) + c->lasttune;
+ c->portspeed = patch.portamento;
+ buffer[ 0 ] = last_note[ chan ] = saved_last_note;
+ buffer[ 1 ] = patch.midi_velocity;
+ track.add_event( midi_event( current_timestamp, midi_event::note_on, channel, buffer, 2 ) );
+ }
+#endif
+ }
+#ifdef ENABLE_WHEEL
+ else
+ {
+ buffer[ 0 ] = note >> 4;
+ buffer[ 1 ] = patch.midi_velocity;
+ track.add_event( midi_event( current_timestamp, midi_event::note_on, channel, buffer, 2 ) );
+ last_note[ chan ] = note >> 4;
+ last_channel[ chan ] = channel;
+ c->gototune = patch.glide;
+ c->portspeed = patch.portamento;
+ }
+#endif
+
+#ifdef ENABLE_VIB
+ if(!patch.vibrato)
+ {
+ c->vibwait = c->vibspeed = c->vibrate = 0;
+ }
+ else
+ {
+ c->vibwait = patch.vibrato_delay;
+ // PASCAL: c->vibspeed = ((i->vibrato >> 4) & 15) + 1;
+ c->vibspeed = (patch.vibrato >> 4) + 2;
+ c->vibrate = (patch.vibrato & 15) + 1;
+ }
+#endif
+
+#ifdef ENABLE_TREM
+ if(!(c->trmstay & 0xf0))
+ {
+ c->trmwait = (patch.tremolo_delay & 0xf0) >> 3;
+ // PASCAL: c->trmspeed = (i->mod_trem >> 4) & 15;
+ c->trmspeed = patch.modulator_tremolo >> 4;
+ c->trmrate = patch.modulator_tremolo & 15;
+ c->trmcount = 0;
+ }
+
+ if(!(c->trmstay & 0x0f))
+ {
+ c->trcwait = (patch.tremolo_delay & 15) << 1;
+ // PASCAL: c->trcspeed = (i->car_trem >> 4) & 15;
+ c->trcspeed = patch.carrier_tremolo >> 4;
+ c->trcrate = patch.carrier_tremolo & 15;
+ c->trccount = 0;
+ }
+#endif
+
+#ifdef ENABLE_ARP
+ c->arp_size = patch.arpeggio & 15;
+ c->arp_speed = patch.arpeggio >> 4;
+ memcpy(c->arp_tab, patch.arpeggio_table, 12);
+ c->arp_pos = c->arp_count = 0;
+#endif
+#ifdef ENABLE_VIB
+ c->vibcount = 0;
+#endif
+#ifdef ENABLE_WHEEL
+ c->glideto = 0;
+#endif
+ c->keycount = patch.keyoff;
+ c->nextvol = c->finetune = 0;
+}
+
+bool midi_processor::process_lds( std::vector const& p_file, midi_container & p_out )
+{
+ struct position_data
+ {
+ uint16_t pattern_number;
+ uint8_t transpose;
+ };
+
+ uint8_t mode;
+ /*uint16_t speed;*/
+ uint8_t tempo;
+ uint8_t pattern_length;
+ uint8_t channel_delay[ 9 ];
+ /*uint8_t register_bd;*/
+ uint16_t patch_count;
+ std::vector patches;
+ uint16_t position_count;
+ std::vector positions;
+ std::size_t pattern_count;
+ std::vector patterns;
+
+ std::vector::const_iterator it = p_file.begin();
+
+ mode = *it++;
+ if ( mode > 2 ) return false; /*throw exception_io_data( "Invalid LDS mode" );*/
+ /*speed = it[ 0 ] | ( it[ 1 ] << 8 );*/
+ tempo = it[ 2 ];
+ pattern_length = it[ 3 ];
+ it += 4;
+ for ( unsigned i = 0; i < 9; ++i )
+ channel_delay[ i ] = *it++;
+ /*register_bd = *it++;*/ it++;
+
+ patch_count = it[ 0 ] | ( it[ 1 ] << 8 );
+ it += 2;
+ patches.resize( patch_count );
+ for ( unsigned i = 0; i < patch_count; ++i )
+ {
+ sound_patch & patch = patches[ i ];
+ it += 11;
+ patch.keyoff = *it++;
+#ifdef ENABLE_WHEEL
+ patch.portamento = *it++;
+ patch.glide = *it++;
+ it++;
+#else
+ it += 3;
+#endif
+#ifdef ENABLE_VIB
+ patch.vibrato = *it++;
+ patch.vibrato_delay = *it++;
+#else
+ it += 2;
+#endif
+#ifdef ENABLE_TREM
+ patch.modulator_tremolo = *it++;
+ patch.carrier_tremolo = *it++;
+ patch.tremolo_delay = *it++;
+#else
+ it += 3;
+#endif
+#ifdef ENABLE_ARP
+ patch.arpeggio = *it++;
+ for ( unsigned j = 0; j < 12; ++j )
+ patch.arpeggio_table[ j ] = *it++;
+ it += 7;
+#else
+ it += 20;
+#endif
+ patch.midi_instrument = *it++;
+ patch.midi_velocity = *it++;
+ patch.midi_key = *it++;
+ patch.midi_transpose = *it++;
+ it += 2;
+
+#ifdef ENABLE_WHEEL
+ // hax
+ if ( patch.midi_instrument >= 0x80 )
+ {
+ patch.glide = 0;
+ }
+#endif
+ }
+
+ position_count = it[ 0 ] | ( it[ 1 ] << 8 );
+ it += 2;
+ positions.resize( 9 * position_count );
+ for ( unsigned i = 0; i < position_count; ++i )
+ {
+ for ( unsigned j = 0; j < 9; ++j )
+ {
+ position_data & position = positions[ i * 9 + j ];
+ position.pattern_number = it[ 0 ] | ( it[ 1 ] << 8 );
+ if ( position.pattern_number & 1 ) return false; /*throw exception_io_data( "Odd LDS pattern number" );*/
+ position.pattern_number >>= 1;
+ position.transpose = it[ 2 ];
+ it += 3;
+ }
+ }
+
+ it += 2;
+
+ pattern_count = ( p_file.end() - it ) / 2;
+ patterns.resize( pattern_count );
+ for ( unsigned i = 0; i < pattern_count; ++i )
+ {
+ patterns[ i ] = it[ 0 ] | ( it[ 1 ] << 8 );
+ it += 2;
+ }
+
+ uint8_t /*jumping,*/ fadeonoff, allvolume, hardfade, tempo_now, pattplay;
+ uint16_t posplay, jumppos;
+ uint32_t mainvolume;
+ std::vector channel;
+ channel.resize( 9 );
+ std::vector position_timestamps;
+ position_timestamps.resize( position_count, ~0u );
+
+ uint8_t current_instrument[9] = { 0 };
+
+ uint8_t last_channel[9];
+ uint8_t last_instrument[9];
+ uint8_t last_note[9];
+ uint8_t last_volume[9];
+ uint8_t last_sent_volume[11];
+#ifdef ENABLE_WHEEL
+ int16_t last_pitch_wheel[11];
+#endif
+ uint8_t ticks_without_notes[11];
+
+ memset( last_channel, 0, sizeof( last_channel ) );
+ memset( last_instrument, 0xFF, sizeof( last_instrument ) );
+ memset( last_note, 0xFF, sizeof( last_note ) );
+ memset( last_volume, 127, sizeof( last_volume ) );
+ memset( last_sent_volume, 127, sizeof( last_sent_volume ) );
+#ifdef ENABLE_WHEEL
+ memset( last_pitch_wheel, 0, sizeof( last_pitch_wheel ) );
+#endif
+ memset( ticks_without_notes, 0, sizeof( ticks_without_notes ) );
+
+ unsigned current_timestamp = 0;
+
+ uint8_t buffer[ 2 ];
+
+ p_out.initialize( 1, 35 );
+
+ {
+ midi_track track;
+ track.add_event( midi_event( 0, midi_event::extended, 0, lds_default_tempo, _countof( lds_default_tempo ) ) );
+ for ( unsigned i = 0; i < 11; ++i )
+ {
+ buffer[ 0 ] = 120;
+ buffer[ 1 ] = 0;
+ track.add_event( midi_event( 0, midi_event::control_change, i, buffer, 2 ) );
+ buffer[ 0 ] = 121;
+ track.add_event( midi_event( 0, midi_event::control_change, i, buffer, 2 ) );
+#ifdef ENABLE_WHEEL
+ buffer[ 0 ] = 0x65;
+ track.add_event( midi_event( 0, midi_event::control_change, i, buffer, 2 ) );
+ buffer[ 0 ] = 0x64;
+ track.add_event( midi_event( 0, midi_event::control_change, i, buffer, 2 ) );
+ buffer[ 0 ] = 0x06;
+ buffer[ 1 ] = WHEEL_RANGE_HIGH;
+ track.add_event( midi_event( 0, midi_event::control_change, i, buffer, 2 ) );
+ buffer[ 0 ] = 0x26;
+ buffer[ 1 ] = WHEEL_RANGE_LOW;
+ track.add_event( midi_event( 0, midi_event::control_change, i, buffer, 2 ) );
+ buffer[ 0 ] = 0;
+ buffer[ 1 ] = 64;
+ track.add_event( midi_event( 0, midi_event::pitch_wheel, i, buffer, 2 ) );
+#endif
+ }
+ track.add_event( midi_event( 0, midi_event::extended, 0, end_of_track, _countof( end_of_track ) ) );
+ p_out.add_track( track );
+ }
+
+ std::vector tracks;
+ {
+ midi_track track;
+ track.add_event( midi_event( 0, midi_event::extended, 0, end_of_track, _countof( end_of_track ) ) );
+ tracks.resize( 10, track );
+ }
+
+ tempo_now = 3;
+ /*jumping = 0;*/
+ fadeonoff = 0;
+ allvolume = 0;
+ hardfade = 0;
+ pattplay = 0;
+ posplay = 0;
+ jumppos = 0;
+ mainvolume = 0;
+ memset( &channel[0], 0, sizeof( channel_state ) * 9 );
+
+ const uint16_t maxsound = 0x3F;
+ const uint16_t maxpos = 0xFF;
+
+ bool playing = true;
+ while ( playing )
+ {
+ uint16_t chan;
+#ifdef ENABLE_VIB
+ uint16_t wibc;
+#endif
+#if defined(ENABLE_VIB) || defined(ENABLE_ARP)
+ int16_t tune;
+#endif
+#ifdef ENABLE_ARP
+ int16_t arpreg;
+#endif
+#ifdef ENABLE_TREM
+ uint16_t tremc;
+#endif
+ bool vbreak;
+ unsigned i;
+ channel_state * c;
+
+ if(fadeonoff)
+ {
+ if(fadeonoff <= 128)
+ {
+ if(allvolume > fadeonoff || allvolume == 0)
+ {
+ allvolume -= fadeonoff;
+ }
+ else
+ {
+ allvolume = 1;
+ fadeonoff = 0;
+ if(hardfade != 0)
+ {
+ playing = false;
+ hardfade = 0;
+ for(i = 0; i < 9; i++)
+ channel[i].keycount = 1;
+ }
+ }
+ }
+ else if(((allvolume + (0x100 - fadeonoff)) & 0xff) <= mainvolume)
+ {
+ allvolume += 0x100 - fadeonoff;
+ }
+ else
+ {
+ allvolume = mainvolume;
+ fadeonoff = 0;
+ }
+ }
+
+ // handle channel delay
+ for(chan = 0; chan < 9; ++chan)
+ {
+ channel_state * c = &channel[chan];
+ if(c->chancheat.chandelay)
+ {
+ if(!(--c->chancheat.chandelay))
+ {
+ playsound( current_instrument, patches, last_note, last_channel, last_instrument, last_volume, last_sent_volume,
+#ifdef ENABLE_WHEEL
+ last_pitch_wheel,
+#endif
+ c, allvolume, current_timestamp, c->chancheat.sound, chan, c->chancheat.high, tracks[ chan ] );
+ ticks_without_notes[ last_channel[ chan ] ] = 0;
+ }
+ }
+ }
+
+ // handle notes
+ if(!tempo_now)
+ {
+ if ( pattplay == 0 && position_timestamps[ posplay ] == ~0u )
+ {
+ position_timestamps[ posplay ] = current_timestamp;
+ }
+
+ vbreak = false;
+ for(unsigned chan = 0; chan < 9; chan++)
+ {
+ channel_state * c = &channel[chan];
+ if(!c->packwait)
+ {
+ unsigned short patnum = positions[posplay * 9 + chan].pattern_number;
+ unsigned char transpose = positions[posplay * 9 + chan].transpose;
+
+ if ( patnum + c->packpos >= patterns.size() ) return false; /*throw exception_io_data( "Invalid LDS pattern number" );*/
+
+ unsigned comword = patterns[patnum + c->packpos];
+ unsigned comhi = comword >> 8;
+ unsigned comlo = comword & 0xff;
+ if(comword)
+ {
+ if(comhi == 0x80)
+ {
+ c->packwait = comlo;
+ }
+ else if(comhi >= 0x80)
+ {
+ switch(comhi) {
+ case 0xff:
+ {
+ unsigned volume = ( comlo & 0x3F ) * 127 / 63;
+ last_volume[ chan ] = volume;
+ if ( volume != last_sent_volume[ last_channel[ chan ] ] )
+ {
+ buffer[ 0 ] = 7;
+ buffer[ 1 ] = volume;
+ tracks[ chan ].add_event( midi_event( current_timestamp, midi_event::control_change, last_channel[ chan ], buffer, 2 ) );
+ last_sent_volume[ last_channel [ chan ] ] = volume;
+ }
+ }
+ break;
+ case 0xfe:
+ tempo = comword & 0x3f;
+ break;
+ case 0xfd:
+ c->nextvol = comlo;
+ break;
+ case 0xfc:
+ playing = false;
+ // in real player there's also full keyoff here, but we don't need it
+ break;
+ case 0xfb:
+ c->keycount = 1;
+ break;
+ case 0xfa:
+ vbreak = true;
+ jumppos = (posplay + 1) & maxpos;
+ break;
+ case 0xf9:
+ vbreak = true;
+ jumppos = comlo & maxpos;
+ /*jumping = 1;*/
+ if(jumppos <= posplay)
+ {
+ p_out.add_track_event( 0, midi_event( position_timestamps[ jumppos ], midi_event::extended, 0, loop_start, _countof( loop_start ) ) );
+ p_out.add_track_event( 0, midi_event( current_timestamp + tempo - 1, midi_event::extended, 0, loop_end, _countof( loop_end ) ) );
+ playing = false;
+ }
+ break;
+ case 0xf8:
+#ifdef ENABLE_WHEEL
+ c->lasttune = 0;
+#endif
+ break;
+ case 0xf7:
+#ifdef ENABLE_VIB
+ c->vibwait = 0;
+ // PASCAL: c->vibspeed = ((comlo >> 4) & 15) + 2;
+ c->vibspeed = (comlo >> 4) + 2;
+ c->vibrate = (comlo & 15) + 1;
+#endif
+ break;
+ case 0xf6:
+#ifdef ENABLE_WHEEL
+ c->glideto = comlo;
+#endif
+ break;
+ case 0xf5:
+ c->finetune = comlo;
+ break;
+ case 0xf4:
+ if(!hardfade) {
+ allvolume = mainvolume = comlo;
+ fadeonoff = 0;
+ }
+ break;
+ case 0xf3:
+ if(!hardfade) fadeonoff = comlo;
+ break;
+ case 0xf2:
+#ifdef ENABLE_TREM
+ c->trmstay = comlo;
+#endif
+ break;
+ case 0xf1:
+ buffer[ 0 ] = 10;
+ buffer[ 1 ] = ( comlo & 0x3F ) * 127 / 63;
+ tracks[ chan ].add_event( midi_event( current_timestamp, midi_event::control_change, last_channel[ chan ], buffer, 2 ) );
+ break;
+ case 0xf0:
+ buffer[ 0 ] = comlo & 0x7F;
+ tracks[ chan ].add_event( midi_event( current_timestamp, midi_event::program_change, last_channel[ chan ], buffer, 1 ) );
+ break;
+ default:
+#ifdef ENABLE_WHEEL
+ if(comhi < 0xa0)
+ c->glideto = comhi & 0x1f;
+#endif
+ break;
+ }
+ }
+ else
+ {
+ unsigned char sound;
+ unsigned short high;
+ signed char transp = transpose << 1;
+ transp >>= 1;
+
+ if(transpose & 128) {
+ sound = (comlo + transp) & maxsound;
+ high = comhi << 4;
+ } else {
+ sound = comlo & maxsound;
+ high = (comhi + transp) << 4;
+ }
+
+ /*
+ PASCAL:
+ sound = comlo & maxsound;
+ high = (comhi + (((transpose + 0x24) & 0xff) - 0x24)) << 4;
+ */
+
+ if( !channel_delay[ chan ] )
+ {
+ playsound( current_instrument, patches, last_note, last_channel, last_instrument, last_volume, last_sent_volume,
+#ifdef ENABLE_WHEEL
+ last_pitch_wheel,
+#endif
+ c, allvolume, current_timestamp, sound, chan, high, tracks[ chan ] );
+ ticks_without_notes[ last_channel[ chan ] ] = 0;
+ }
+ else
+ {
+ c->chancheat.chandelay = channel_delay[chan];
+ c->chancheat.sound = sound;
+ c->chancheat.high = high;
+ }
+ }
+ }
+ c->packpos++;
+ }
+ else
+ {
+ c->packwait--;
+ }
+ }
+
+ tempo_now = tempo;
+ /*
+ The continue table is updated here, but this is only used in the
+ original player, which can be paused in the middle of a song and then
+ unpaused. Since AdPlug does all this for us automatically, we don't
+ have a continue table here. The continue table update code is noted
+ here for reference only.
+
+ if(!pattplay) {
+ conttab[speed & maxcont].position = posplay & 0xff;
+ conttab[speed & maxcont].tempo = tempo;
+ }
+ */
+ pattplay++;
+ if(vbreak)
+ {
+ pattplay = 0;
+ for(i = 0; i < 9; i++) channel[i].packpos = channel[i].packwait = 0;
+ posplay = jumppos;
+ if ( posplay >= position_count ) return false; /*throw exception_io_data( "Invalid LDS position jump" );*/
+ }
+ else if(pattplay >= pattern_length)
+ {
+ pattplay = 0;
+ for(i = 0; i < 9; i++) channel[i].packpos = channel[i].packwait = 0;
+ posplay = (posplay + 1) & maxpos;
+ if ( posplay >= position_count ) playing = false; //throw exception_io_data( "LDS reached the end without a loop or end command" );
+ }
+ }
+ else
+ {
+ tempo_now--;
+ }
+
+ // make effects
+ for(chan = 0; chan < 9; ++chan)
+ {
+ c = &channel[chan];
+ if(c->keycount > 0)
+ {
+ if( c->keycount == 1 && last_note[ chan ] != 0xFF )
+ {
+ buffer[ 0 ] = last_note[ chan ];
+ buffer[ 1 ] = 127;
+ tracks[ chan ].add_event( midi_event( current_timestamp, midi_event::note_off, last_channel[ chan ], buffer, 2 ) );
+ last_note[ chan ] = 0xFF;
+#ifdef ENABLE_WHEEL
+ if ( 0 != last_pitch_wheel[ last_channel[ chan ] ] )
+ {
+ buffer[ 0 ] = 0;
+ buffer[ 1 ] = 64;
+ tracks[ chan ].add_event( midi_event( current_timestamp, midi_event::pitch_wheel, last_channel[ chan ], buffer, 2 ) );
+ last_pitch_wheel[ last_channel[ chan ] ] = 0;
+ c->lasttune = 0;
+ c->gototune = 0;
+ }
+#endif
+ }
+ c->keycount--;
+ }
+
+#ifdef ENABLE_ARP
+ // arpeggio
+ if(c->arp_size == 0)
+ {
+ arpreg = 0;
+ }
+ else
+ {
+ arpreg = c->arp_tab[c->arp_pos] << 4;
+ if(arpreg == -0x800)
+ {
+ if(c->arp_pos > 0) c->arp_tab[0] = c->arp_tab[c->arp_pos - 1];
+ c->arp_size = 1; c->arp_pos = 0;
+ arpreg = c->arp_tab[0] << 4;
+ }
+
+ if(c->arp_count == c->arp_speed) {
+ c->arp_pos++;
+ if(c->arp_pos >= c->arp_size) c->arp_pos = 0;
+ c->arp_count = 0;
+ }
+ else
+ {
+ c->arp_count++;
+ }
+ }
+#endif
+
+#ifdef ENABLE_WHEEL
+ // glide & portamento
+ if(c->lasttune != c->gototune)
+ {
+ if(c->lasttune > c->gototune)
+ {
+ if(c->lasttune - c->gototune < c->portspeed)
+ {
+ c->lasttune = c->gototune;
+ }
+ else
+ {
+ c->lasttune -= c->portspeed;
+ }
+ }
+ else
+ {
+ if(c->gototune - c->lasttune < c->portspeed)
+ {
+ c->lasttune = c->gototune;
+ }
+ else
+ {
+ c->lasttune += c->portspeed;
+ }
+ }
+
+#ifdef ENABLE_ARP
+ arpreg +=
+#else
+ int16_t arpreg =
+#endif
+ c->lasttune;
+
+ if ( arpreg != last_pitch_wheel[ last_channel[ chan ] ] )
+ {
+ buffer[ 0 ] = WHEEL_SCALE_LOW( arpreg );
+ buffer[ 1 ] = WHEEL_SCALE_HIGH( arpreg );
+ tracks[ chan ].add_event( midi_event( current_timestamp, midi_event::pitch_wheel, last_channel[ chan ], buffer, 2 ) );
+ last_pitch_wheel[ last_channel[ chan ] ] = arpreg;
+ }
+ } else
+ {
+#ifdef ENABLE_VIB
+ // vibrato
+ if(!c->vibwait)
+ {
+ if(c->vibrate)
+ {
+ wibc = vibtab[c->vibcount & 0x3f] * c->vibrate;
+
+ if((c->vibcount & 0x40) == 0)
+ tune = c->lasttune + (wibc >> 8);
+ else
+ tune = c->lasttune - (wibc >> 8);
+
+#ifdef ENABLE_ARP
+ tune += arpreg;
+#endif
+
+ if ( tune != last_pitch_wheel[ last_channel[ chan ] ] )
+ {
+ buffer[ 0 ] = WHEEL_SCALE_LOW( tune );
+ buffer[ 1 ] = WHEEL_SCALE_HIGH( tune );
+ tracks[ chan ].add_event( midi_event( current_timestamp, midi_event::pitch_wheel, last_channel[ chan ], buffer, 2 ) );
+ last_pitch_wheel[ last_channel[ chan ] ] = tune;
+ }
+
+ c->vibcount += c->vibspeed;
+ }
+#ifdef ENABLE_ARP
+ else if(c->arp_size != 0)
+ { // no vibrato, just arpeggio
+ tune = c->lasttune + arpreg;
+
+ if ( tune != last_pitch_wheel[ last_channel[ chan ] ] )
+ {
+ buffer[ 0 ] = WHEEL_SCALE_LOW( tune );
+ buffer[ 1 ] = WHEEL_SCALE_HIGH( tune );
+ tracks[ chan ].add_event( midi_event( current_timestamp, midi_event::pitch_wheel, last_channel[ chan ], buffer, 2 ) );
+ last_pitch_wheel[ last_channel[ chan ] ] = tune;
+ }
+ }
+#endif
+ }
+#ifdef ENABLE_ARP
+ else
+#endif
+#endif
+#ifdef ENABLE_ARP
+ { // no vibrato, just arpeggio
+#ifdef ENABLE_VIB
+ c->vibwait--;
+#endif
+
+ if(c->arp_size != 0)
+ {
+ tune = c->lasttune + arpreg;
+
+ if ( tune != last_pitch_wheel[ last_channel[ chan ] ] )
+ {
+ buffer[ 0 ] = WHEEL_SCALE_LOW( tune );
+ buffer[ 1 ] = WHEEL_SCALE_HIGH( tune );
+ tracks[ chan ].add_event( midi_event( current_timestamp, midi_event::pitch_wheel, last_channel[ chan ], buffer, 2 ) );
+ last_pitch_wheel[ last_channel[ chan ] ] = tune;
+ }
+ }
+ }
+#endif
+ }
+#endif
+
+#ifdef ENABLE_TREM
+ unsigned volume = last_volume[ chan ];
+
+ // tremolo (modulator)
+ if(!c->trmwait)
+ {
+ if(c->trmrate)
+ {
+ tremc = tremtab[c->trmcount & 0x7f] * c->trmrate;
+ if((tremc >> 7) <= volume)
+ volume = volume - (tremc >> 7);
+ else
+ volume = 0;
+
+ c->trmcount += c->trmspeed;
+ }
+ }
+ else
+ {
+ c->trmwait--;
+ }
+
+ // tremolo (carrier)
+ if(!c->trcwait)
+ {
+ if(c->trcrate)
+ {
+ tremc = tremtab[c->trccount & 0x7f] * c->trcrate;
+ if((tremc >> 7) <= volume)
+ volume = volume - (tremc >> 8);
+ else
+ volume = 0;
+ }
+ }
+ else
+ {
+ c->trcwait--;
+ }
+
+ if ( allvolume )
+ {
+ volume = volume * allvolume / 255;
+ }
+
+ if ( volume != last_sent_volume[ last_channel[ chan ] ] )
+ {
+ buffer[ 0 ] = 7;
+ buffer[ 1 ] = volume;
+ tracks[ chan ].add_event( midi_event( current_timestamp, midi_event::control_change, last_channel[ chan ], buffer, 2 ) );
+ last_sent_volume[ last_channel[ chan ] ] = volume;
+ }
+#endif
+
+ }
+
+ ++current_timestamp;
+ }
+
+ --current_timestamp;
+
+ for ( unsigned i = 0; i < 9; ++i )
+ {
+ midi_track & track = tracks[ i ];
+ unsigned long count = track.get_count();
+ if ( count > 1 )
+ {
+ if ( last_note[ i ] != 0xFF )
+ {
+ buffer[ 0 ] = last_note[ i ];
+ buffer[ 1 ] = 127;
+ track.add_event( midi_event( current_timestamp + channel[ i ].keycount, midi_event::note_off, last_channel[ i ], buffer, 2 ) );
+#ifdef ENABLE_WHEEL
+ if ( last_pitch_wheel[ last_channel[ i ] ] != 0 )
+ {
+ buffer[ 0 ] = 0;
+ buffer[ 1 ] = 0x40;
+ track.add_event( midi_event( current_timestamp + channel[ i ].keycount, midi_event::pitch_wheel, last_channel[ i ], buffer, 2 ) );
+ }
+#endif
+ }
+ p_out.add_track( track );
+ }
+ }
+
+ return true;
+}
diff --git a/Frameworks/midi_processing/midi_processing/midi_processor_mids.cpp b/Frameworks/midi_processing/midi_processing/midi_processor_mids.cpp
new file mode 100644
index 000000000..3807a3f4b
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/midi_processor_mids.cpp
@@ -0,0 +1,120 @@
+#include "midi_processor.h"
+
+bool midi_processor::is_mids( std::vector const& p_file )
+{
+ if ( p_file.size() < 8 ) return false;
+ if ( p_file[ 0 ] != 'R' || p_file[ 1 ] != 'I' || p_file[ 2 ] != 'F' || p_file[ 3 ] != 'F' ) return false;
+ uint32_t size = p_file[ 4 ] | ( p_file[ 5 ] << 8 ) | ( p_file[ 6 ] << 16 ) | ( p_file[ 7 ] << 24 );
+ if ( size < 8 || ( p_file.size() < size + 8 ) ) return false;
+ if ( p_file[ 8 ] != 'M' || p_file[ 9 ] != 'I' || p_file[ 10 ] != 'D' || p_file[ 11 ] != 'S' ||
+ p_file[ 12 ] != 'f' || p_file[ 13 ] != 'm' || p_file[ 14 ] != 't' || p_file[ 15 ] != ' ' ) return false;
+ return true;
+}
+
+bool midi_processor::process_mids( std::vector const& p_file, midi_container & p_out )
+{
+ std::vector::const_iterator it = p_file.begin() + 16;
+
+ uint32_t fmt_size = it[ 0 ] | ( it[ 1 ] << 8 ) | ( it[ 2 ] << 16 ) | ( it[ 3 ] << 24 );
+ it += 4;
+
+ uint32_t time_format = 1;
+ /*uint32_t max_buffer = 0;*/
+ uint32_t flags = 0;
+
+ if ( fmt_size >= 4 )
+ {
+ time_format = it[ 0 ] | ( it[ 1 ] << 8 ) | ( it[ 2 ] << 16 ) | ( it[ 3 ] << 24 );
+ it += 4;
+ fmt_size -= 4;
+ }
+ if ( fmt_size >= 4 )
+ {
+ /*max_buffer = it[ 0 ] | ( it[ 1 ] << 8 ) | ( it[ 2 ] << 16 ) | ( it[ 3 ] << 24 );*/
+ it += 4;
+ fmt_size -= 4;
+ }
+ if ( fmt_size >= 4 )
+ {
+ flags = it[ 0 ] | ( it[ 1 ] << 8 ) | ( it[ 2 ] << 16 ) | ( it[ 3 ] << 24 );
+ it += 4;
+ fmt_size -= 4;
+ }
+
+ it += fmt_size;
+ if ( fmt_size & 1 ) ++it;
+
+ p_out.initialize( 0, time_format );
+
+ if ( it[ 0 ] != 'd' || it[ 1 ] != 'a' || it[ 2 ] != 't' || it[ 3 ] != 'a' ) return false; /*throw exception_io_data( "MIDS missing RIFF data chunk" );*/
+
+ it += 4;
+
+ {
+ midi_track track;
+ track.add_event( midi_event( 0, midi_event::extended, 0, end_of_track, _countof( end_of_track ) ) );
+ p_out.add_track( track );
+ }
+
+ uint32_t data_size = it[ 0 ] | ( it[ 1 ] << 8 ) | ( it[ 2 ] << 16 ) | ( it[ 3 ] << 24 );
+ it += 4;
+
+ std::vector::const_iterator body_end = it + data_size;
+
+ uint32_t segment_count = it[ 0 ] | ( it[ 1 ] << 8 ) | ( it[ 2 ] << 16 ) | ( it[ 3 ] << 24 );
+ it += 4;
+
+ bool is_eight_byte = !!(flags & 1);
+
+ midi_track track;
+
+ unsigned current_timestamp = 0;
+
+ for ( unsigned i = 0; i < segment_count; ++i )
+ {
+ it += 4;
+ uint32_t segment_size = it[ 0 ] | ( it[ 1 ] << 8 ) | ( it[ 2 ] << 16 ) | ( it[ 3 ] << 24 );
+ it += 4;
+ std::vector::const_iterator segment_end = it + segment_size;
+ while ( it < segment_end && it < body_end )
+ {
+ uint32_t delta = it[ 0 ] | ( it[ 1 ] << 8 ) | ( it[ 2 ] << 16 ) | ( it[ 3 ] << 24 );
+ it += 4;
+ uint32_t event;
+ current_timestamp += delta;
+ if ( !is_eight_byte ) it += 4;
+ event = it[ 0 ] | ( it[ 1 ] << 8 ) | ( it[ 2 ] << 16 ) | ( it[ 3 ] << 24 );
+ it += 4;
+ if ( event >> 24 == 0x01 )
+ {
+ uint8_t buffer[ 5 ] = { 0xFF, 0x51 };
+ buffer[ 2 ] = (uint8_t)( event >> 16 );
+ buffer[ 3 ] = (uint8_t)( event >> 8 );
+ buffer[ 4 ] = (uint8_t)event;
+ p_out.add_track_event( 0, midi_event( current_timestamp, midi_event::extended, 0, buffer, sizeof( buffer ) ) );
+ }
+ else if ( !( event >> 24 ) )
+ {
+ unsigned event_code = ( event & 0xF0 ) >> 4;
+ if ( event_code >= 0x8 && event_code <= 0xE )
+ {
+ unsigned bytes_to_write = 1;
+ uint8_t buffer[2];
+ buffer[ 0 ] = (uint8_t)( event >> 8 );
+ if ( event_code != 0xC && event_code != 0xD )
+ {
+ buffer[ 1 ] = (uint8_t)( event >> 16 );
+ bytes_to_write = 2;
+ }
+ track.add_event( midi_event( current_timestamp, (midi_event::event_type)( event_code - 8 ), event & 0x0F, buffer, bytes_to_write ) );
+ }
+ }
+ }
+ }
+
+ track.add_event( midi_event( current_timestamp, midi_event::extended, 0, end_of_track, _countof( end_of_track ) ) );
+
+ p_out.add_track( track );
+
+ return true;
+}
diff --git a/Frameworks/midi_processing/midi_processing/midi_processor_mus.cpp b/Frameworks/midi_processing/midi_processing/midi_processor_mus.cpp
new file mode 100644
index 000000000..d65385a20
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/midi_processor_mus.cpp
@@ -0,0 +1,140 @@
+#include "midi_processor.h"
+
+const uint8_t midi_processor::mus_default_tempo[5] = {0xFF, 0x51, 0x09, 0xA3, 0x1A};
+
+const uint8_t midi_processor::mus_controllers[15] = {0,0,1,7,10,11,91,93,64,67,120,123,126,127,121};
+
+bool midi_processor::is_mus( std::vector const& p_file )
+{
+ if ( p_file.size() < 0x20 ) return false;
+ if ( p_file[ 0 ] != 'M' || p_file[ 1 ] != 'U' || p_file[ 2 ] != 'S' || p_file[ 3 ] != 0x1A ) return false;
+ uint16_t length = p_file[ 4 ] | ( p_file[ 5 ] << 8 );
+ uint16_t offset = p_file[ 6 ] | ( p_file[ 7 ] << 8 );
+ uint16_t instrument_count = p_file[ 12 ] | ( p_file[ 13 ] << 8 );
+ if ( offset >= 16 + instrument_count * 2 && offset < 16 + instrument_count * 4 && offset + length <= p_file.size() ) return true;
+ return false;
+}
+
+bool midi_processor::process_mus( std::vector const& p_file, midi_container & p_out )
+{
+ uint16_t length = p_file[ 4 ] | ( p_file[ 5 ] << 8 );
+ uint16_t offset = p_file[ 6 ] | ( p_file[ 7 ] << 8 );
+
+ p_out.initialize( 0, 0x59 );
+
+ {
+ midi_track track;
+ track.add_event( midi_event( 0, midi_event::extended, 0, mus_default_tempo, _countof( mus_default_tempo ) ) );
+ track.add_event( midi_event( 0, midi_event::extended, 0, end_of_track, _countof( end_of_track ) ) );
+ p_out.add_track( track );
+ }
+
+ midi_track track;
+
+ unsigned current_timestamp = 0;
+
+ uint8_t velocity_levels[ 16 ] = { 0 };
+
+ std::vector::const_iterator it = p_file.begin() + offset, end = p_file.begin() + offset + length;
+
+ uint8_t buffer[ 4 ];
+
+ while ( it < end )
+ {
+ buffer[ 0 ] = *it++;
+ if ( buffer[ 0 ] == 0x60 ) break;
+
+ midi_event::event_type type;
+
+ unsigned bytes_to_write;
+
+ unsigned channel = buffer[ 0 ] & 0x0F;
+ if ( channel == 0x0F ) channel = 9;
+ else if ( channel >= 9 ) ++channel;
+
+ switch ( buffer[ 0 ] & 0x70 )
+ {
+ case 0x00:
+ type = midi_event::note_on;
+ buffer[ 1 ] = *it++;
+ buffer[ 2 ] = 0;
+ bytes_to_write = 2;
+ break;
+
+ case 0x10:
+ type = midi_event::note_on;
+ buffer[ 1 ] = *it++;
+ if ( buffer[ 1 ] & 0x80 )
+ {
+ buffer[ 2 ] = *it++;
+ velocity_levels[ channel ] = buffer[ 2 ];
+ buffer[ 1 ] &= 0x7F;
+ }
+ else
+ {
+ buffer[ 2 ] = velocity_levels[ channel ];
+ }
+ bytes_to_write = 2;
+ break;
+
+ case 0x20:
+ type = midi_event::pitch_wheel;
+ buffer[ 1 ] = *it++;
+ buffer[ 2 ] = buffer[ 1 ] >> 1;
+ buffer[ 1 ] <<= 7;
+ bytes_to_write = 2;
+ break;
+
+ case 0x30:
+ type = midi_event::control_change;
+ buffer[ 1 ] = *it++;
+ if ( buffer[ 1 ] >= 10 && buffer[ 1 ] <= 14 )
+ {
+ buffer[ 1 ] = mus_controllers[ buffer[ 1 ] ];
+ buffer[ 2 ] = 1;
+ bytes_to_write = 2;
+ }
+ else return false; /*throw exception_io_data( "Unhandled MUS system event" );*/
+ break;
+
+ case 0x40:
+ buffer[ 1 ] = *it++;
+ if ( buffer[ 1 ] )
+ {
+ if ( buffer[ 1 ] < 10 )
+ {
+ type = midi_event::control_change;
+ buffer[ 1 ] = mus_controllers[ buffer[ 1 ] ];
+ buffer[ 2 ] = *it++;
+ bytes_to_write = 2;
+ }
+ else return false; /*throw exception_io_data( "Invalid MUS controller change event" );*/
+ }
+ else
+ {
+ type = midi_event::program_change;
+ buffer[ 1 ] = *it++;
+ bytes_to_write = 1;
+ }
+ break;
+
+ default:
+ return false; /*throw exception_io_data( "Invalid MUS status code" );*/
+ }
+
+ track.add_event( midi_event( current_timestamp, type, channel, buffer + 1, bytes_to_write ) );
+
+ if ( buffer[ 0 ] & 0x80 )
+ {
+ int delta = decode_delta( it );
+ if ( delta < 0 ) return false; /*throw exception_io_data( "Invalid MUS delta" );*/
+ current_timestamp += delta;
+ }
+ }
+
+ track.add_event( midi_event( current_timestamp, midi_event::extended, 0, end_of_track, _countof( end_of_track ) ) );
+
+ p_out.add_track( track );
+
+ return true;
+}
diff --git a/Frameworks/midi_processing/midi_processing/midi_processor_riff_midi.cpp b/Frameworks/midi_processing/midi_processing/midi_processor_riff_midi.cpp
new file mode 100644
index 000000000..1670512b9
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/midi_processor_riff_midi.cpp
@@ -0,0 +1,134 @@
+#include "midi_processor.h"
+
+#include
+
+bool midi_processor::is_riff_midi( std::vector const& p_file )
+{
+ if ( p_file.size() < 20 ) return false;
+ if ( p_file[ 0 ] != 'R' || p_file[ 1 ] != 'I' || p_file[ 2 ] != 'F' || p_file[ 3 ] != 'F' ) return false;
+ uint32_t riff_size = p_file[ 4 ] | ( p_file[ 5 ] << 8 ) | ( p_file[ 6 ] << 16 ) | ( p_file[ 7 ] << 24 );
+ if ( riff_size < 12 || ( p_file.size() < riff_size + 8 ) ) return false;
+ if ( p_file[ 8 ] != 'R' || p_file[ 9 ] != 'M' || p_file[ 10 ] != 'I' || p_file[ 11 ] != 'D' ||
+ p_file[ 12 ] != 'd' || p_file[ 13 ] != 'a' || p_file[ 14 ] != 't' || p_file[ 15 ] != 'a' ) return false;
+ uint32_t data_size = p_file[ 16 ] | ( p_file[ 17 ] << 8 ) | ( p_file[ 18 ] << 16 ) | ( p_file[ 19 ] << 24 );
+ if ( data_size < 18 || p_file.size() < data_size + 20 || riff_size < data_size + 12 ) return false;
+ std::vector test;
+ test.assign( p_file.begin() + 20, p_file.begin() + 20 + 18 );
+ return is_standard_midi( test );
+}
+
+static const char * riff_tag_mappings[][2] =
+{
+ { "IALB", "album" },
+ { "IARL", "archival_location" },
+ { "IART", "artist" },
+ { "ITRK", "tracknumber" },
+ { "ICMS", "commissioned" },
+ { "ICMP", "composer" },
+ { "ICMT", "comment" },
+ { "ICOP", "copyright" },
+ { "ICRD", "creation_date" },
+ { "IENG", "engineer" },
+ { "IGNR", "genre" },
+ { "IKEY", "keywords" },
+ { "IMED", "medium" },
+ { "INAM", "title" },
+ { "IPRD", "product" },
+ { "ISBJ", "subject" },
+ { "ISFT", "software" },
+ { "ISRC", "source" },
+ { "ISRF", "source_form" },
+ { "ITCH", "technician" }
+};
+
+bool midi_processor::process_riff_midi( std::vector const& p_file, midi_container & p_out )
+{
+ uint32_t file_size = p_file[ 4 ] | ( p_file[ 5 ] << 8 ) | ( p_file[ 6 ] << 16 ) | ( p_file[ 7 ] << 24 );
+
+ std::vector::const_iterator it = p_file.begin() + 12;
+
+ std::vector::const_iterator body_end = p_file.begin() + 8 + file_size;
+
+ bool found_data = false;
+ bool found_info = false;
+
+ midi_meta_data meta_data;
+
+ std::vector extra_buffer;
+
+ while ( it < body_end )
+ {
+ uint32_t chunk_size = it[ 4 ] | ( it[ 5 ] << 8 ) | ( it[ 6 ] << 16 ) | ( it[ 7 ] << 24 );
+ if ( it[ 0 ] == 'd' && it[ 1 ] == 'a' && it[ 2 ] == 't' && it[ 3 ] == 'a' )
+ {
+ if ( !found_data )
+ {
+ std::vector midi_file;
+ midi_file.assign( it + 8, it + 8 + chunk_size );
+ if ( !process_standard_midi( midi_file, p_out ) ) return false;
+ found_data = true;
+ }
+ else return false; /*throw exception_io_data( "Multiple RIFF data chunks found" );*/
+ it += 8 + chunk_size;
+ if ( chunk_size & 1 && it < body_end ) ++it;
+ }
+ else if ( it[ 0 ] == 'D' && it[ 1 ] == 'I' && it[ 2 ] == 'S' && it[ 3 ] == 'P' )
+ {
+ uint32_t type = it[ 8 ] | ( it[ 9 ] << 8 ) | ( it[ 10 ] << 16 ) | ( it[ 11 ] << 24 );
+ if ( type == 1 )
+ {
+ extra_buffer.resize( chunk_size - 4 );
+ std::copy( it + 12, it + 8 + chunk_size, extra_buffer.begin() );
+ meta_data.add_item( midi_meta_data_item( 0, "display_name", (const char *) &extra_buffer[0] ) );
+ }
+ it += 8 + chunk_size;
+ if ( chunk_size & 1 && it < body_end ) ++it;
+ }
+ else if ( it[ 0 ] == 'L' && it[ 1 ] == 'I' && it[ 2 ] == 'S' && it[ 3 ] == 'T' )
+ {
+ std::vector::const_iterator chunk_end = it + 8 + chunk_size;
+ if ( it[ 8 ] == 'I' && it[ 9 ] == 'N' && it[ 10 ] == 'F' && it[ 11 ] == 'O' )
+ {
+ if ( !found_info )
+ {
+ it += 12;
+ while ( it < chunk_end )
+ {
+ uint32_t field_size = it[ 4 ] | ( it[ 5 ] << 8 ) | ( it[ 6 ] << 16 ) | ( it[ 7 ] << 24 );
+ std::string field;
+ field.assign( it, it + 4 );
+ for ( unsigned i = 0; i < _countof(riff_tag_mappings); ++i )
+ {
+ if ( !memcmp( &it[0], riff_tag_mappings[ i ][ 0 ], 4 ) )
+ {
+ field = riff_tag_mappings[ i ][ 1 ];
+ break;
+ }
+ }
+ extra_buffer.resize( field_size );
+ std::copy( it + 8, it + 8 + field_size, extra_buffer.begin() );
+ it += 8 + field_size;
+ meta_data.add_item( midi_meta_data_item( 0, field.c_str(), ( const char * ) &extra_buffer[0] ) );
+ if ( field_size & 1 && it < chunk_end ) ++it;
+ }
+ found_info = true;
+ }
+ else return false; /*throw exception_io_data( "Multiple RIFF LIST INFO chunks found" );*/
+ }
+ else return false; /* unknown LIST chunk */
+ it = chunk_end;
+ if ( chunk_size & 1 && it < body_end ) ++it;
+ }
+ else
+ {
+ it += chunk_size;
+ if ( chunk_size & 1 && it < body_end ) ++it;
+ }
+
+ if ( found_data && found_info ) break;
+ }
+
+ p_out.set_extra_meta_data( meta_data );
+
+ return true;
+}
diff --git a/Frameworks/midi_processing/midi_processing/midi_processor_standard_midi.cpp b/Frameworks/midi_processing/midi_processing/midi_processor_standard_midi.cpp
new file mode 100644
index 000000000..084da5066
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/midi_processor_standard_midi.cpp
@@ -0,0 +1,148 @@
+#include "midi_processor.h"
+
+bool midi_processor::is_standard_midi( std::vector const& p_file )
+{
+ if ( p_file.size() < 18 ) return false;
+ if ( p_file[ 0 ] != 'M' || p_file[ 1 ] != 'T' || p_file[ 2 ] != 'h' || p_file[ 3 ] != 'd') return false;
+ if ( p_file[ 4 ] != 0 || p_file[ 5 ] != 0 || p_file[ 6 ] != 0 || p_file[ 7 ] != 6 ) return false;
+ if ( p_file[ 14 ] != 'M' || p_file[ 15 ] != 'T' || p_file[ 16 ] != 'r' || p_file[ 17 ] != 'k' ) return false;
+ return true;
+}
+
+bool midi_processor::process_standard_midi_track( std::vector::const_iterator & it, std::vector::const_iterator end, midi_container & p_out, bool needs_end_marker )
+{
+ midi_track track;
+ unsigned current_timestamp = 0;
+ unsigned char last_event_code = 0xFF;
+
+ std::vector buffer;
+ buffer.resize( 3 );
+
+ for (;;)
+ {
+ if ( !needs_end_marker && it >= end ) break;
+ int delta = decode_delta( it );
+ if ( !needs_end_marker && it >= end ) break;
+
+ if ( delta < 0 )
+ {
+ /*"MIDI processor encountered negative delta: " << delta << "; flipping sign.";*/
+ delta = -delta;
+ }
+
+ current_timestamp += delta;
+ unsigned char event_code = *it++;
+ unsigned data_bytes_read = 0;
+ if ( event_code < 0x80 )
+ {
+ if ( last_event_code == 0xFF ) return false; /*throw exception_io_data("First MIDI track event short encoded");*/
+ buffer[ data_bytes_read++ ] = event_code;
+ event_code = last_event_code;
+ }
+ if ( event_code < 0xF0 )
+ {
+ last_event_code = event_code;
+ if ( !needs_end_marker && ( event_code & 0xF0 ) == 0xE0 ) continue;
+ if ( data_bytes_read < 1 )
+ {
+ buffer[ 0 ] = *it++;
+ ++data_bytes_read;
+ }
+ switch ( event_code & 0xF0 )
+ {
+ case 0xC0:
+ case 0xD0:
+ break;
+ default:
+ buffer[ data_bytes_read ] = *it++;
+ ++data_bytes_read;
+ }
+ track.add_event( midi_event( current_timestamp, (midi_event::event_type)(( event_code >> 4 ) - 8), event_code & 0x0F, &buffer[0], data_bytes_read ) );
+ }
+ else if ( event_code == 0xF0 )
+ {
+ int data_count = decode_delta( it );
+ if ( data_count < 0 ) return false; /*throw exception_io_data( "Invalid System Exclusive message" );*/
+ buffer.resize( data_count + 1 );
+ buffer[ 0 ] = 0xF0;
+ std::copy( it, it + data_count, buffer.begin() + 1 );
+ it += data_count;
+ track.add_event( midi_event( current_timestamp, midi_event::extended, 0, &buffer[0], data_count + 1 ) );
+ }
+ else if ( event_code == 0xFF )
+ {
+ unsigned char meta_type = *it++;
+ int data_count = decode_delta( it );
+ if ( data_count < 0 ) return false; /*throw exception_io_data( "Invalid meta message" );*/
+ buffer.resize( data_count + 2 );
+ buffer[ 0 ] = 0xFF;
+ buffer[ 1 ] = meta_type;
+ std::copy( it, it + data_count, buffer.begin() + 2 );
+ it += data_count;
+ track.add_event( midi_event( current_timestamp, midi_event::extended, 0, &buffer[0], data_count + 2 ) );
+
+ if ( meta_type == 0x2F )
+ {
+ needs_end_marker = true;
+ break;
+ }
+ }
+ else if ( event_code == 0xFB || event_code == 0xFC )
+ {
+ /*console::formatter() << "MIDI " << ( ( event_code == 0xFC ) ? "stop" : "start" ) << " status code ignored";*/
+ }
+ else return false; /*throw exception_io_data("Unhandled MIDI status code");*/
+ }
+
+ if ( !needs_end_marker )
+ {
+ buffer[ 0 ] = 0xFF;
+ buffer[ 1 ] = 0x2F;
+ track.add_event( midi_event( current_timestamp, midi_event::extended, 0, &buffer[0], 2 ) );
+ }
+
+ p_out.add_track( track );
+
+ return true;
+}
+
+bool midi_processor::process_standard_midi( std::vector const& p_file, midi_container & p_out )
+{
+ if ( p_file[ 0 ] != 'M' || p_file[ 1 ] != 'T' || p_file[ 2 ] != 'h' || p_file[ 3 ] != 'd' ) return false;
+ if ( p_file[ 4 ] != 0 || p_file[ 5 ] != 0 || p_file[ 6 ] != 0 || p_file[ 7 ] != 6 ) return false; /*throw exception_io_data("Bad MIDI header size");*/
+
+ std::vector::const_iterator it = p_file.begin() + 8;
+
+ uint16_t form = ( it[0] << 8 ) | it[1];
+ if ( form > 2 ) return false;
+
+ uint16_t track_count_16 = ( it[2] << 8 ) | it[3];
+ uint16_t dtx = ( it[4] << 8 ) | it[5];
+
+ it += 6;
+
+ std::size_t track_count = track_count_16;
+
+ p_out.initialize( form, dtx );
+
+ for ( std::size_t i = 0; i < track_count; ++i )
+ {
+ if ( it[0] != 'M' || it[1] != 'T' || it[2] != 'r' || it[3] != 'k' ) return false;
+
+ uint32_t track_size = ( it[4] << 24 ) | ( it[5] << 16 ) | ( it[6] << 8 ) | it[7];
+
+ it += 8;
+
+ intptr_t track_data_offset = it - p_file.begin();
+
+ if ( !process_standard_midi_track( it, it + track_size, p_out, true ) ) return false;
+
+ track_data_offset += track_size;
+ if ( it - p_file.begin() != track_data_offset )
+ {
+ it = p_file.begin() + track_data_offset;
+ }
+ }
+
+ return true;
+}
diff --git a/Frameworks/midi_processing/midi_processing/midi_processor_syx.cpp b/Frameworks/midi_processing/midi_processing/midi_processor_syx.cpp
new file mode 100644
index 000000000..5e99bf626
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/midi_processor_syx.cpp
@@ -0,0 +1,35 @@
+#include "midi_processor.h"
+
+bool midi_processor::is_syx( std::vector const& p_file )
+{
+ if ( p_file.size() < 2 ) return false;
+ if ( p_file[ 0 ] != 0xF0 || p_file[ p_file.size() - 1 ] != 0xF7 ) return false;
+ return true;
+}
+
+bool midi_processor::process_syx( std::vector const& p_file, midi_container & p_out )
+{
+ const size_t size = p_file.size();
+ size_t ptr = 0;
+
+ p_out.initialize( 0, 1 );
+
+ midi_track track;
+
+ while ( ptr < size )
+ {
+ size_t msg_length = 1;
+
+ if ( p_file[ptr] != 0xF0 ) return false;
+
+ while ( p_file[ptr + msg_length++] != 0xF7 );
+
+ track.add_event( midi_event( 0, midi_event::extended, 0, &p_file[ptr], msg_length ) );
+
+ ptr += msg_length;
+ }
+
+ p_out.add_track( track );
+
+ return true;
+}
diff --git a/Frameworks/midi_processing/midi_processing/midi_processor_xmi.cpp b/Frameworks/midi_processing/midi_processing/midi_processor_xmi.cpp
new file mode 100644
index 000000000..6cb4c7daa
--- /dev/null
+++ b/Frameworks/midi_processing/midi_processing/midi_processor_xmi.cpp
@@ -0,0 +1,277 @@
+#include "midi_processor.h"
+
+#include
+
+bool midi_processor::is_xmi( std::vector const& p_file )
+{
+ if ( p_file.size() < 0x22 ) return false;
+ if ( p_file[ 0 ] != 'F' || p_file[ 1 ] != 'O' || p_file[ 2 ] != 'R' || p_file[ 3 ] != 'M' ||
+ p_file[ 8 ] != 'X' || p_file[ 9 ] != 'D' || p_file[ 10 ] != 'I' || p_file[ 11 ] != 'R' ||
+ p_file[ 0x1E ] != 'X' || p_file[ 0x1F ] != 'M' || p_file[ 0x20 ] != 'I' || p_file[ 0x21 ] != 'D' ) return false;
+ return true;
+}
+
+const uint8_t midi_processor::xmi_default_tempo[5] = {0xFF, 0x51, 0x07, 0xA1, 0x20};
+
+unsigned midi_processor::decode_xmi_delta( std::vector::const_iterator & it, std::vector::const_iterator end )
+{
+ unsigned delta = 0;
+ uint8_t byte = *it++;
+ if ( !( byte & 0x80 ) )
+ {
+ do
+ {
+ delta += byte;
+ byte = *it++;
+ }
+ while ( !( byte & 0x80 ) && it < end );
+ }
+ --it;
+ return delta;
+}
+
+struct iff_chunk
+{
+ uint8_t m_id[4];
+ uint8_t m_type[4];
+ std::vector m_data;
+ std::vector m_sub_chunks;
+
+ iff_chunk()
+ {
+ memset( m_id, 0, sizeof( m_id ) );
+ memset( m_type, 0, sizeof( m_type ) );
+ }
+
+ iff_chunk( const iff_chunk & p_in )
+ {
+ memcpy( m_id, p_in.m_id, sizeof( m_id ) );
+ memcpy( m_type, p_in.m_type, sizeof( m_type ) );
+ m_data = p_in.m_data;
+ m_sub_chunks = p_in.m_sub_chunks;
+ }
+
+ const iff_chunk & find_sub_chunk( const char * p_id, unsigned index = 0 ) const
+ {
+ for ( std::size_t i = 0; i < m_sub_chunks.size(); ++i )
+ {
+ if ( !memcmp( p_id, m_sub_chunks[ i ].m_id, 4 ) )
+ {
+ if ( index ) --index;
+ if ( !index ) return m_sub_chunks[ i ];
+ }
+ }
+ /*throw exception_io_data( pfc::string_formatter() << "Missing IFF chunk: " << p_id );*/
+ return *this;
+ }
+
+ unsigned get_chunk_count( const char * p_id ) const
+ {
+ unsigned chunk_count = 0;
+ for ( std::size_t i = 0; i < m_sub_chunks.size(); ++i )
+ {
+ if ( !memcmp( p_id, m_sub_chunks[ i ].m_id, 4 ) )
+ {
+ ++chunk_count;
+ }
+ }
+ return chunk_count;
+ }
+};
+
+struct iff_stream
+{
+ std::vector m_chunks;
+
+ iff_chunk fail;
+
+ const iff_chunk & find_chunk( const char * p_id ) const
+ {
+ for ( std::size_t i = 0; i < m_chunks.size(); ++i )
+ {
+ if ( !memcmp( p_id, m_chunks[ i ].m_id, 4 ) )
+ {
+ return m_chunks[ i ];
+ }
+ }
+ /*throw exception_io_data( pfc::string_formatter() << "Missing IFF chunk: " << p_id );*/
+ return fail;
+ }
+};
+
+static bool read_iff_chunk( std::vector::const_iterator & it, std::vector::const_iterator end, iff_chunk & p_out, bool first_chunk )
+{
+ std::copy( it, it + 4, p_out.m_id );
+ it += 4;
+ uint32_t chunk_size = ( it[ 0 ] << 24 ) | ( it[ 1 ] << 16 ) | ( it[ 2 ] << 8 ) | it[ 3 ];
+ it += 4;
+ bool is_cat_chunk = !memcmp( p_out.m_id, "CAT ", 4 );
+ bool is_form_chunk = !memcmp( p_out.m_id, "FORM", 4 );
+ std::size_t chunk_size_limit = end - it;
+ if ( chunk_size > chunk_size_limit ) chunk_size = (uint32_t) chunk_size_limit;
+ if ( ( first_chunk && is_form_chunk ) || ( !first_chunk && is_cat_chunk ) )
+ {
+ std::vector::const_iterator chunk_end = it + chunk_size;
+ std::copy( it, it + 4, p_out.m_type );
+ it += 4;
+ while ( it < chunk_end )
+ {
+ iff_chunk chunk;
+ if ( !read_iff_chunk( it, chunk_end, chunk, is_cat_chunk ) ) return false;
+ p_out.m_sub_chunks.push_back( chunk );
+ }
+ it = chunk_end;
+ if ( chunk_size & 1 && it < end ) ++it;
+ }
+ else if ( !is_form_chunk && !is_cat_chunk )
+ {
+ p_out.m_data.assign( it, it + chunk_size );
+ it += chunk_size;
+ if ( chunk_size & 1 && it < end ) ++it;
+ }
+ else
+ {
+ /*if ( first_chunk ) throw exception_io_data( pfc::string_formatter() << "Found " << pfc::string8( (const char *)p_out.m_id, 4 ) << " chunk instead of FORM" );
+ else throw exception_io_data( "Found multiple FORM chunks" );*/
+ return false;
+ }
+ return true;
+}
+
+static bool read_iff_stream( std::vector const& p_file, iff_stream & p_out )
+{
+ std::vector::const_iterator it = p_file.begin(), end = p_file.end();
+ bool first_chunk = true;
+ while ( it < end )
+ {
+ iff_chunk chunk;
+ if ( !read_iff_chunk( it, end, chunk, first_chunk ) ) return false;
+ p_out.m_chunks.push_back( chunk );
+ first_chunk = false;
+ }
+ return true;
+}
+
+bool midi_processor::process_xmi( std::vector const& p_file, midi_container & p_out )
+{
+ iff_stream xmi_file;
+ if ( !read_iff_stream( p_file, xmi_file ) ) return false;
+
+ const iff_chunk & form_chunk = xmi_file.find_chunk( "FORM" );
+ if ( memcmp( form_chunk.m_type, "XDIR", 4 ) ) return false; /*throw exception_io_data( "XMI IFF not XDIR type" );*/
+
+ const iff_chunk & cat_chunk = xmi_file.find_chunk( "CAT " );
+ if ( memcmp( cat_chunk.m_type, "XMID", 4 ) ) return false; /*throw exception_io_data( "XMI CAT chunk not XMID type" );*/
+
+ unsigned track_count = cat_chunk.get_chunk_count( "FORM" );
+
+ p_out.initialize( track_count > 1 ? 2 : 0, 60 );
+
+ for ( unsigned i = 0; i < track_count; ++i )
+ {
+ const iff_chunk & xmid_form_chunk = cat_chunk.find_sub_chunk( "FORM", i );
+ if ( memcmp( xmid_form_chunk.m_type, "XMID", 4 ) ) return false; /*throw exception_io_data( "XMI nested FORM chunk not XMID type" );*/
+
+ const iff_chunk & event_chunk = xmid_form_chunk.find_sub_chunk( "EVNT" );
+ if ( memcmp( event_chunk.m_id, "EVNT", 4 ) ) return false; /* EVNT chunk not found */
+ std::vector const& event_body = event_chunk.m_data;
+
+ midi_track track;
+
+ bool initial_tempo = false;
+
+ unsigned current_timestamp = 0;
+
+ unsigned last_event_timestamp = 0;
+
+ std::vector buffer;
+ buffer.resize( 3 );
+
+ std::vector::const_iterator it = event_body.begin(), end = event_body.end();
+
+ while ( it < end )
+ {
+ unsigned delta = decode_xmi_delta( it, end );
+ current_timestamp += delta;
+
+ if ( current_timestamp > last_event_timestamp )
+ {
+ last_event_timestamp = current_timestamp;
+ }
+
+ buffer[ 0 ] = *it++;
+ if ( buffer[ 0 ] == 0xFF )
+ {
+ buffer[ 1 ] = *it++;
+ int meta_count;
+ if ( buffer[ 1 ] == 0x2F )
+ {
+ meta_count = 0;
+ }
+ else
+ {
+ meta_count = decode_delta( it );
+ if ( meta_count < 0 ) return false; /*throw exception_io_data( "Invalid XMI meta message" );*/
+ buffer.resize( meta_count + 2 );
+ std::copy( it, it + meta_count, buffer.begin() + 2 );
+ it += meta_count;
+ }
+ if ( buffer[ 1 ] == 0x2F && current_timestamp < last_event_timestamp )
+ {
+ current_timestamp = last_event_timestamp;
+ }
+ if ( buffer[ 1 ] == 0x51 && meta_count == 3 )
+ {
+ unsigned tempo = buffer[ 2 ] * 0x10000 + buffer[ 3 ] * 0x100 + buffer[ 4 ];
+ unsigned ppqn = ( tempo * 3 ) / 25000;
+ tempo = tempo * 60 / ppqn;
+ buffer[ 2 ] = tempo / 0x10000;
+ buffer[ 3 ] = tempo / 0x100;
+ buffer[ 4 ] = tempo;
+ if ( current_timestamp == 0 ) initial_tempo = true;
+ }
+ track.add_event( midi_event( current_timestamp, midi_event::extended, 0, &buffer[0], meta_count + 2 ) );
+ if ( buffer[ 1 ] == 0x2F ) break;
+ }
+ else if ( buffer[ 0 ] == 0xF0 )
+ {
+ int system_exclusive_count = decode_delta( it );
+ if ( system_exclusive_count < 0 ) return false; /*throw exception_io_data( "Invalid XMI System Exclusive message" );*/
+ buffer.resize( system_exclusive_count + 1 );
+ std::copy( it, it + system_exclusive_count, buffer.begin() + 1 );
+ it += system_exclusive_count;
+ track.add_event( midi_event( current_timestamp, midi_event::extended, 0, &buffer[0], system_exclusive_count + 1 ) );
+ }
+ else if ( buffer[ 0 ] >= 0x80 && buffer[ 0 ] <= 0xEF )
+ {
+ unsigned bytes_read = 1;
+ buffer[ 1 ] = *it++;
+ midi_event::event_type type = (midi_event::event_type)( ( buffer[ 0 ] >> 4 ) - 8 );
+ unsigned channel = buffer[ 0 ] & 0x0F;
+ if ( type != midi_event::program_change && type != midi_event::channel_aftertouch )
+ {
+ buffer[ 2 ] = *it++;
+ bytes_read = 2;
+ }
+ track.add_event( midi_event( current_timestamp, type, channel, &buffer[1], bytes_read ) );
+ if ( type == midi_event::note_on )
+ {
+ buffer[ 2 ] = 0x00;
+ int note_length = decode_delta( it );
+ if ( note_length < 0 ) return false; /*throw exception_io_data( "Invalid XMI note message" );*/
+ unsigned note_end_timestamp = current_timestamp + note_length;
+ if ( note_end_timestamp > last_event_timestamp ) last_event_timestamp = note_end_timestamp;
+ track.add_event( midi_event( note_end_timestamp, type, channel, &buffer[1], bytes_read ) );
+ }
+ }
+ else return false; /*throw exception_io_data( "Unexpected XMI status code" );*/
+ }
+
+ if ( !initial_tempo )
+ track.add_event( midi_event( 0, midi_event::extended, 0, xmi_default_tempo, _countof( xmi_default_tempo ) ) );
+
+ p_out.add_track( track );
+ }
+
+ return true;
+}
diff --git a/Info.plist b/Info.plist
index a2e0d1a63..acff25bbb 100644
--- a/Info.plist
+++ b/Info.plist
@@ -22,6 +22,30 @@
CFBundleTypeRole
None
+
+ CFBundleTypeExtensions
+
+ lds
+ xmi
+ mus
+ hmp
+ hmi
+ mds
+ mids
+ rmi
+ kar
+ midi
+ mid
+
+ LSTypeIsPackage
+
+ CFBundleTypeRole
+ Viewer
+ CFBundleTypeIconFile
+ song.icns
+ CFBundleTypeName
+ MIDI Audio File
+
CFBundleTypeExtensions
diff --git a/Plugins/MIDI/MIDI.xcodeproj/project.pbxproj b/Plugins/MIDI/MIDI.xcodeproj/project.pbxproj
new file mode 100644
index 000000000..dc2247dc4
--- /dev/null
+++ b/Plugins/MIDI/MIDI.xcodeproj/project.pbxproj
@@ -0,0 +1,412 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 83B0668B180D5668008E3612 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 83B0668A180D5668008E3612 /* Cocoa.framework */; };
+ 83B06695180D5668008E3612 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 83B06693180D5668008E3612 /* InfoPlist.strings */; };
+ 83B06701180D5747008E3612 /* midi_processing.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 83B066E0180D56BA008E3612 /* midi_processing.framework */; };
+ 83B06709180D64DA008E3612 /* MIDIPlayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83B06708180D64DA008E3612 /* MIDIPlayer.cpp */; };
+ 83B0670C180D6665008E3612 /* BMPlayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83B0670A180D6665008E3612 /* BMPlayer.cpp */; };
+ 83B0670F180D6F7F008E3612 /* libbass.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 83B0670D180D6F7F008E3612 /* libbass.dylib */; };
+ 83B06710180D6F7F008E3612 /* libbassmidi.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 83B0670E180D6F7F008E3612 /* libbassmidi.dylib */; };
+ 83B06712180D6FAA008E3612 /* libbass.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = 83B0670D180D6F7F008E3612 /* libbass.dylib */; };
+ 83B06713180D6FAA008E3612 /* libbassmidi.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = 83B0670E180D6F7F008E3612 /* libbassmidi.dylib */; };
+ 83B0671C180D6FD8008E3612 /* libbass_mpc.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = 83B06714180D6FC8008E3612 /* libbass_mpc.dylib */; };
+ 83B0671D180D6FD8008E3612 /* libbassflac.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = 83B06715180D6FC8008E3612 /* libbassflac.dylib */; };
+ 83B0671E180D6FD8008E3612 /* libbassopus.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = 83B06716180D6FC8008E3612 /* libbassopus.dylib */; };
+ 83B0671F180D6FD8008E3612 /* libbasswv.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = 83B06717180D6FC8008E3612 /* libbasswv.dylib */; };
+ 83B06722180D70FE008E3612 /* MIDIDecoder.mm in Sources */ = {isa = PBXBuildFile; fileRef = 83B06721180D70FE008E3612 /* MIDIDecoder.mm */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXContainerItemProxy section */
+ 83B066DF180D56BA008E3612 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 83B066DA180D56B9008E3612 /* midi_processing.xcodeproj */;
+ proxyType = 2;
+ remoteGlobalIDString = 83B066AC180D56B9008E3612;
+ remoteInfo = midi_processing;
+ };
+ 83B066FF180D573D008E3612 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 83B066DA180D56B9008E3612 /* midi_processing.xcodeproj */;
+ proxyType = 1;
+ remoteGlobalIDString = 83B066AB180D56B9008E3612;
+ remoteInfo = midi_processing;
+ };
+/* End PBXContainerItemProxy section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+ 83B06711180D6F87008E3612 /* CopyFiles */ = {
+ isa = PBXCopyFilesBuildPhase;
+ buildActionMask = 2147483647;
+ dstPath = "";
+ dstSubfolderSpec = 6;
+ files = (
+ 83B0671C180D6FD8008E3612 /* libbass_mpc.dylib in CopyFiles */,
+ 83B0671D180D6FD8008E3612 /* libbassflac.dylib in CopyFiles */,
+ 83B0671E180D6FD8008E3612 /* libbassopus.dylib in CopyFiles */,
+ 83B0671F180D6FD8008E3612 /* libbasswv.dylib in CopyFiles */,
+ 83B06712180D6FAA008E3612 /* libbass.dylib in CopyFiles */,
+ 83B06713180D6FAA008E3612 /* libbassmidi.dylib in CopyFiles */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+ 83B06687180D5668008E3612 /* MIDI.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MIDI.bundle; sourceTree = BUILT_PRODUCTS_DIR; };
+ 83B0668A180D5668008E3612 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
+ 83B0668D180D5668008E3612 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ 83B0668E180D5668008E3612 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
+ 83B0668F180D5668008E3612 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
+ 83B06692180D5668008E3612 /* MIDI-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "MIDI-Info.plist"; sourceTree = ""; };
+ 83B06694180D5668008E3612 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; };
+ 83B06696180D5668008E3612 /* MIDI-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MIDI-Prefix.pch"; sourceTree = ""; };
+ 83B066DA180D56B9008E3612 /* midi_processing.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = midi_processing.xcodeproj; path = ../../Frameworks/midi_processing/midi_processing.xcodeproj; sourceTree = ""; };
+ 83B06706180D6471008E3612 /* MIDIPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MIDIPlayer.h; sourceTree = ""; };
+ 83B06708180D64DA008E3612 /* MIDIPlayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MIDIPlayer.cpp; sourceTree = ""; };
+ 83B0670A180D6665008E3612 /* BMPlayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BMPlayer.cpp; sourceTree = ""; };
+ 83B0670B180D6665008E3612 /* BMPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BMPlayer.h; sourceTree = ""; };
+ 83B0670D180D6F7F008E3612 /* libbass.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libbass.dylib; path = ../../ThirdParty/BASS/libbass.dylib; sourceTree = ""; };
+ 83B0670E180D6F7F008E3612 /* libbassmidi.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libbassmidi.dylib; path = ../../ThirdParty/BASS/libbassmidi.dylib; sourceTree = ""; };
+ 83B06714180D6FC8008E3612 /* libbass_mpc.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libbass_mpc.dylib; path = ../../ThirdParty/BASS/libbass_mpc.dylib; sourceTree = ""; };
+ 83B06715180D6FC8008E3612 /* libbassflac.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libbassflac.dylib; path = ../../ThirdParty/BASS/libbassflac.dylib; sourceTree = ""; };
+ 83B06716180D6FC8008E3612 /* libbassopus.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libbassopus.dylib; path = ../../ThirdParty/BASS/libbassopus.dylib; sourceTree = ""; };
+ 83B06717180D6FC8008E3612 /* libbasswv.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libbasswv.dylib; path = ../../ThirdParty/BASS/libbasswv.dylib; sourceTree = ""; };
+ 83B06720180D70FE008E3612 /* MIDIDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MIDIDecoder.h; sourceTree = ""; };
+ 83B06721180D70FE008E3612 /* MIDIDecoder.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MIDIDecoder.mm; sourceTree = ""; };
+ 83B06723180D714F008E3612 /* Plugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Plugin.h; path = ../../../Audio/Plugin.h; sourceTree = ""; };
+ 83B06724180D792E008E3612 /* Logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Logging.h; path = ../../../Utils/Logging.h; sourceTree = ""; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 83B06684180D5668008E3612 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 83B0670F180D6F7F008E3612 /* libbass.dylib in Frameworks */,
+ 83B06701180D5747008E3612 /* midi_processing.framework in Frameworks */,
+ 83B06710180D6F7F008E3612 /* libbassmidi.dylib in Frameworks */,
+ 83B0668B180D5668008E3612 /* Cocoa.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 83B0667E180D5668008E3612 = {
+ isa = PBXGroup;
+ children = (
+ 83B06690180D5668008E3612 /* MIDI */,
+ 83B06689180D5668008E3612 /* Frameworks */,
+ 83B06688180D5668008E3612 /* Products */,
+ );
+ sourceTree = "";
+ };
+ 83B06688180D5668008E3612 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 83B06687180D5668008E3612 /* MIDI.bundle */,
+ );
+ name = Products;
+ sourceTree = "";
+ };
+ 83B06689180D5668008E3612 /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 83B06714180D6FC8008E3612 /* libbass_mpc.dylib */,
+ 83B06715180D6FC8008E3612 /* libbassflac.dylib */,
+ 83B06716180D6FC8008E3612 /* libbassopus.dylib */,
+ 83B06717180D6FC8008E3612 /* libbasswv.dylib */,
+ 83B0670D180D6F7F008E3612 /* libbass.dylib */,
+ 83B0670E180D6F7F008E3612 /* libbassmidi.dylib */,
+ 83B0668A180D5668008E3612 /* Cocoa.framework */,
+ 83B0668C180D5668008E3612 /* Other Frameworks */,
+ 83B066DA180D56B9008E3612 /* midi_processing.xcodeproj */,
+ );
+ name = Frameworks;
+ sourceTree = "";
+ };
+ 83B0668C180D5668008E3612 /* Other Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 83B0668D180D5668008E3612 /* Foundation.framework */,
+ 83B0668E180D5668008E3612 /* CoreData.framework */,
+ 83B0668F180D5668008E3612 /* AppKit.framework */,
+ );
+ name = "Other Frameworks";
+ sourceTree = "";
+ };
+ 83B06690180D5668008E3612 /* MIDI */ = {
+ isa = PBXGroup;
+ children = (
+ 83B06724180D792E008E3612 /* Logging.h */,
+ 83B06723180D714F008E3612 /* Plugin.h */,
+ 83B06720180D70FE008E3612 /* MIDIDecoder.h */,
+ 83B06721180D70FE008E3612 /* MIDIDecoder.mm */,
+ 83B0670A180D6665008E3612 /* BMPlayer.cpp */,
+ 83B0670B180D6665008E3612 /* BMPlayer.h */,
+ 83B06708180D64DA008E3612 /* MIDIPlayer.cpp */,
+ 83B06706180D6471008E3612 /* MIDIPlayer.h */,
+ 83B06691180D5668008E3612 /* Supporting Files */,
+ );
+ path = MIDI;
+ sourceTree = "";
+ };
+ 83B06691180D5668008E3612 /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ 83B06692180D5668008E3612 /* MIDI-Info.plist */,
+ 83B06693180D5668008E3612 /* InfoPlist.strings */,
+ 83B06696180D5668008E3612 /* MIDI-Prefix.pch */,
+ );
+ name = "Supporting Files";
+ sourceTree = "";
+ };
+ 83B066DB180D56B9008E3612 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 83B066E0180D56BA008E3612 /* midi_processing.framework */,
+ );
+ name = Products;
+ sourceTree = "";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ 83B06686180D5668008E3612 /* MIDI */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 83B06699180D5668008E3612 /* Build configuration list for PBXNativeTarget "MIDI" */;
+ buildPhases = (
+ 83B06683180D5668008E3612 /* Sources */,
+ 83B06684180D5668008E3612 /* Frameworks */,
+ 83B06685180D5668008E3612 /* Resources */,
+ 83B06711180D6F87008E3612 /* CopyFiles */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ 83B06700180D573D008E3612 /* PBXTargetDependency */,
+ );
+ name = MIDI;
+ productName = MIDI;
+ productReference = 83B06687180D5668008E3612 /* MIDI.bundle */;
+ productType = "com.apple.product-type.bundle";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 83B0667F180D5668008E3612 /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0500;
+ ORGANIZATIONNAME = "Christopher Snowhill";
+ };
+ buildConfigurationList = 83B06682180D5668008E3612 /* Build configuration list for PBXProject "MIDI" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ );
+ mainGroup = 83B0667E180D5668008E3612;
+ productRefGroup = 83B06688180D5668008E3612 /* Products */;
+ projectDirPath = "";
+ projectReferences = (
+ {
+ ProductGroup = 83B066DB180D56B9008E3612 /* Products */;
+ ProjectRef = 83B066DA180D56B9008E3612 /* midi_processing.xcodeproj */;
+ },
+ );
+ projectRoot = "";
+ targets = (
+ 83B06686180D5668008E3612 /* MIDI */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXReferenceProxy section */
+ 83B066E0180D56BA008E3612 /* midi_processing.framework */ = {
+ isa = PBXReferenceProxy;
+ fileType = wrapper.framework;
+ path = midi_processing.framework;
+ remoteRef = 83B066DF180D56BA008E3612 /* PBXContainerItemProxy */;
+ sourceTree = BUILT_PRODUCTS_DIR;
+ };
+/* End PBXReferenceProxy section */
+
+/* Begin PBXResourcesBuildPhase section */
+ 83B06685180D5668008E3612 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 83B06695180D5668008E3612 /* InfoPlist.strings in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 83B06683180D5668008E3612 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 83B06709180D64DA008E3612 /* MIDIPlayer.cpp in Sources */,
+ 83B06722180D70FE008E3612 /* MIDIDecoder.mm in Sources */,
+ 83B0670C180D6665008E3612 /* BMPlayer.cpp in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXTargetDependency section */
+ 83B06700180D573D008E3612 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ name = midi_processing;
+ targetProxy = 83B066FF180D573D008E3612 /* PBXContainerItemProxy */;
+ };
+/* End PBXTargetDependency section */
+
+/* Begin PBXVariantGroup section */
+ 83B06693180D5668008E3612 /* InfoPlist.strings */ = {
+ isa = PBXVariantGroup;
+ children = (
+ 83B06694180D5668008E3612 /* en */,
+ );
+ name = InfoPlist.strings;
+ sourceTree = "";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ 83B06697180D5668008E3612 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = NO;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = macosx;
+ };
+ name = Debug;
+ };
+ 83B06698180D5668008E3612 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = YES;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ ENABLE_NS_ASSERTIONS = NO;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
+ SDKROOT = macosx;
+ };
+ name = Release;
+ };
+ 83B0669A180D5668008E3612 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COMBINE_HIDPI_IMAGES = YES;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "MIDI/MIDI-Prefix.pch";
+ INFOPLIST_FILE = "MIDI/MIDI-Info.plist";
+ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles";
+ LIBRARY_SEARCH_PATHS = (
+ "$(inherited)",
+ /Users/Chris/Source/Repos/cog/ThirdParty/BASS,
+ );
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ WRAPPER_EXTENSION = bundle;
+ };
+ name = Debug;
+ };
+ 83B0669B180D5668008E3612 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COMBINE_HIDPI_IMAGES = YES;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "MIDI/MIDI-Prefix.pch";
+ INFOPLIST_FILE = "MIDI/MIDI-Info.plist";
+ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles";
+ LIBRARY_SEARCH_PATHS = (
+ "$(inherited)",
+ /Users/Chris/Source/Repos/cog/ThirdParty/BASS,
+ );
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ WRAPPER_EXTENSION = bundle;
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 83B06682180D5668008E3612 /* Build configuration list for PBXProject "MIDI" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 83B06697180D5668008E3612 /* Debug */,
+ 83B06698180D5668008E3612 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 83B06699180D5668008E3612 /* Build configuration list for PBXNativeTarget "MIDI" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 83B0669A180D5668008E3612 /* Debug */,
+ 83B0669B180D5668008E3612 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 83B0667F180D5668008E3612 /* Project object */;
+}
diff --git a/Plugins/MIDI/MIDI/BMPlayer.cpp b/Plugins/MIDI/MIDI/BMPlayer.cpp
new file mode 100644
index 000000000..895defafa
--- /dev/null
+++ b/Plugins/MIDI/MIDI/BMPlayer.cpp
@@ -0,0 +1,351 @@
+#include "BMPlayer.h"
+
+#include
+
+#include
+
+#include
+
+#define SF2PACK
+
+#define _countof(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+static const uint8_t sysex_gm_reset[] = { 0xF0, 0x7E, 0x7F, 0x09, 0x01, 0xF7 };
+static const uint8_t sysex_gm2_reset[]= { 0xF0, 0x7E, 0x7F, 0x09, 0x03, 0xF7 };
+static const uint8_t sysex_gs_reset[] = { 0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7 };
+static const uint8_t sysex_xg_reset[] = { 0xF0, 0x43, 0x10, 0x4C, 0x00, 0x00, 0x7E, 0x00, 0xF7 };
+
+static bool is_gs_reset(const unsigned char * data, unsigned long size)
+{
+ if ( size != _countof( sysex_gs_reset ) ) return false;
+
+ if ( memcmp( data, sysex_gs_reset, 5 ) != 0 ) return false;
+ if ( memcmp( data + 7, sysex_gs_reset + 7, 2 ) != 0 ) return false;
+ if ( ( ( data[ 5 ] + data[ 6 ] + 1 ) & 127 ) != data[ 9 ] ) return false;
+ if ( data[ 10 ] != sysex_gs_reset[ 10 ] ) return false;
+
+ return true;
+}
+
+class Bass_Initializer
+{
+ pthread_mutex_t lock;
+
+ bool initialized;
+
+ std::string base_path;
+
+public:
+ Bass_Initializer() : initialized(false)
+ {
+ pthread_mutex_init( &lock, NULL );
+ }
+
+ ~Bass_Initializer()
+ {
+ if ( initialized )
+ {
+ BASS_Free();
+ }
+ pthread_mutex_destroy( &lock );
+ }
+
+ bool check_initialized()
+ {
+ pthread_mutex_lock(&lock);
+ bool initialized = this->initialized;
+ pthread_mutex_unlock(&lock);
+ return initialized;
+ }
+
+ void set_base_path()
+ {
+ Dl_info info;
+ dladdr( (void*) &BASS_Init, &info );
+ base_path = info.dli_fname;
+ size_t slash = base_path.find_last_of( '/' );
+ base_path.erase( base_path.begin() + slash + 1, base_path.end() );
+ }
+
+ void load_plugin(const char * name)
+ {
+ std::string full_path = base_path;
+ full_path += name;
+ BASS_PluginLoad( full_path.c_str(), 0 );
+ }
+
+ bool initialize()
+ {
+ pthread_mutex_lock(&lock);
+ bool initialized = this->initialized;
+ if ( !initialized )
+ {
+#ifdef SF2PACK
+ set_base_path();
+ load_plugin( "libbassflac.dylib" );
+ load_plugin( "libbasswv.dylib" );
+ load_plugin( "libbassopus.dylib" );
+ load_plugin( "libbass_mpc.dylib" );
+#endif
+ BASS_SetConfig( BASS_CONFIG_UPDATEPERIOD, 0 );
+ initialized = !!BASS_Init( 0, 44100, 0, NULL, NULL );
+ if ( initialized )
+ {
+ BASS_SetConfigPtr( BASS_CONFIG_MIDI_DEFFONT, NULL );
+ BASS_SetConfig( BASS_CONFIG_MIDI_VOICES, 256 );
+ this->initialized = initialized;
+ }
+ }
+ pthread_mutex_unlock(&lock);
+ return initialized;
+ }
+} g_initializer;
+
+BMPlayer::BMPlayer() : MIDIPlayer()
+{
+ _stream = 0;
+ bSincInterpolation = false;
+
+ if ( !g_initializer.initialize() ) throw std::runtime_error( "Unable to initialize BASS" );
+}
+
+BMPlayer::~BMPlayer()
+{
+ shutdown();
+}
+
+void BMPlayer::setSincInterpolation(bool enable)
+{
+ bSincInterpolation = enable;
+
+ shutdown();
+}
+
+void BMPlayer::send_event(uint32_t b)
+{
+ if (!(b & 0x80000000))
+ {
+ unsigned char event[ 3 ];
+ event[ 0 ] = (unsigned char)b;
+ event[ 1 ] = (unsigned char)( b >> 8 );
+ event[ 2 ] = (unsigned char)( b >> 16 );
+ unsigned port = (b >> 24) & 0x7F;
+ unsigned channel = b & 0x0F;
+ unsigned command = b & 0xF0;
+ unsigned event_length = ( command == 0xC0 || command == 0xD0 ) ? 2 : 3;
+ channel += 16 * port;
+ BASS_MIDI_StreamEvents( _stream, BASS_MIDI_EVENTS_RAW + 1 + channel, event, event_length );
+ if ( command == 0xB0 && event[ 1 ] == 0 )
+ {
+ if ( synth_mode == mode_xg )
+ {
+ if ( event[ 2 ] == 127 ) drum_channels[ channel ] = 1;
+ else drum_channels[ channel ] = 0;
+ }
+ else if ( synth_mode == mode_gm2 )
+ {
+ if ( event[ 2 ] == 120 ) drum_channels[ channel ] = 1;
+ else if ( event[ 2 ] == 121 ) drum_channels[ channel ] = 0;
+ }
+ }
+ else if ( command == 0xC0 )
+ {
+ unsigned channel_masked = channel & 0x0F;
+ unsigned drum_channel = drum_channels[ channel ];
+ if ( ( channel_masked == 9 && !drum_channel ) ||
+ ( channel_masked != 9 && drum_channel ) )
+ BASS_MIDI_StreamEvent( _stream, channel, MIDI_EVENT_DRUMS, drum_channel );
+ }
+ }
+ else
+ {
+ unsigned long n = b & 0xffffff;
+ const uint8_t * data;
+ std::size_t size, port;
+ mSysexMap.get_entry( n, data, size, port );
+ if ( port > 2 ) port = 2;
+ BASS_MIDI_StreamEvents( _stream, BASS_MIDI_EVENTS_RAW, data, size );
+ if ( ( size == _countof( sysex_gm_reset ) && !memcmp( data, sysex_gm_reset, _countof( sysex_gm_reset ) ) ) ||
+ ( size == _countof( sysex_gm2_reset ) && !memcmp( data, sysex_gm2_reset, _countof( sysex_gm2_reset ) ) ) ||
+ is_gs_reset( data, size ) ||
+ ( size == _countof( sysex_xg_reset ) && !memcmp( data, sysex_xg_reset, _countof( sysex_xg_reset ) ) ) )
+ {
+ reset_drum_channels();
+ synth_mode = ( size == _countof( sysex_xg_reset ) ) ? mode_xg :
+ ( size == _countof( sysex_gs_reset ) ) ? mode_gs :
+ ( data [4] == 0x01 ) ? mode_gm :
+ mode_gm2;
+ }
+ else if ( synth_mode == mode_gs && size == 11 &&
+ data [0] == 0xF0 && data [1] == 0x41 && data [3] == 0x42 &&
+ data [4] == 0x12 && data [5] == 0x40 && (data [6] & 0xF0) == 0x10 &&
+ data [10] == 0xF7)
+ {
+ if (data [7] == 2)
+ {
+ // GS MIDI channel to part assign
+ gs_part_to_ch [ port ][ data [6] & 15 ] = data [8];
+ }
+ else if ( data [7] == 0x15 )
+ {
+ // GS part to rhythm allocation
+ unsigned int drum_channel = gs_part_to_ch [ port ][ data [6] & 15 ];
+ if ( drum_channel < 16 )
+ {
+ drum_channel += 16 * port;
+ drum_channels [ drum_channel ] = data [8];
+ }
+ }
+ }
+ }
+}
+
+void BMPlayer::render(float * out, unsigned long count)
+{
+ BASS_ChannelGetData( _stream, out, BASS_DATA_FLOAT | (unsigned int) ( count * sizeof( float ) * 2 ) );
+}
+
+void BMPlayer::setSoundFont( const char * in )
+{
+ sSoundFontName = in;
+ shutdown();
+}
+
+void BMPlayer::setFileSoundFont( const char * in )
+{
+ sFileSoundFontName = in;
+ shutdown();
+}
+
+void BMPlayer::shutdown()
+{
+ if ( _stream ) BASS_StreamFree( _stream );
+ _stream = NULL;
+ for ( unsigned long i = 0; i < _soundFonts.size(); ++i )
+ {
+ BASS_MIDI_FontFree( _soundFonts[i] );
+ }
+ _soundFonts.resize( 0 );
+}
+
+bool BMPlayer::startup()
+{
+ if ( _stream ) return true;
+
+ _stream = BASS_MIDI_StreamCreate( 48, BASS_SAMPLE_FLOAT | BASS_STREAM_DECODE | ( bSincInterpolation ? BASS_MIDI_SINCINTER : 0 ), (unsigned int) uSampleRate );
+ if (!_stream)
+ {
+ return false;
+ }
+ if (sSoundFontName.length())
+ {
+ std::string ext;
+ size_t dot = sSoundFontName.find_last_of('.');
+ if (dot != std::string::npos) ext.assign( sSoundFontName.begin() + dot + 1, sSoundFontName.end() );
+ if ( !strcasecmp( ext.c_str(), "sf2" )
+#ifdef SF2PACK
+ || !strcasecmp( ext.c_str(), "sf2pack" )
+#endif
+ )
+ {
+ HSOUNDFONT font = BASS_MIDI_FontInit( sSoundFontName.c_str(), 0 );
+ if ( !font )
+ {
+ shutdown();
+ return false;
+ }
+ _soundFonts.push_back( font );
+ }
+ else if ( !strcasecmp( ext.c_str(), "sflist" ) )
+ {
+ FILE * fl = fopen( sSoundFontName.c_str(), "r" );
+ if ( fl )
+ {
+ std::string path, temp;
+ char name[32768];
+ size_t slash = sSoundFontName.find_last_of('/');
+ if ( slash != std::string::npos ) path.assign( sSoundFontName.begin(), sSoundFontName.begin() + slash + 1 );
+ while ( !feof( fl ) )
+ {
+ if ( !fgets( name, 32767, fl ) ) break;
+ name[32767] = 0;
+ char * cr = strchr( name, '\n' );
+ if ( cr ) *cr = 0;
+ cr = strchr( name, '\r' );
+ if ( cr ) *cr = 0;
+ if ( name[0] == '/' )
+ {
+ temp = name;
+ }
+ else
+ {
+ temp = path;
+ temp += name;
+ }
+ HSOUNDFONT font = BASS_MIDI_FontInit( temp.c_str(), 0 );
+ if ( !font )
+ {
+ fclose( fl );
+ shutdown();
+ return false;
+ }
+ _soundFonts.push_back( font );
+ }
+ fclose( fl );
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
+ if ( sFileSoundFontName.length() )
+ {
+ HSOUNDFONT font = BASS_MIDI_FontInit( sFileSoundFontName.c_str(), 0 );
+ if ( !font )
+ {
+ shutdown();
+ return false;
+ }
+ _soundFonts.push_back( font );
+ }
+
+ std::vector< BASS_MIDI_FONT > fonts;
+ for ( unsigned long i = 0, j = _soundFonts.size(); i < j; ++i )
+ {
+ BASS_MIDI_FONT sf;
+ sf.font = _soundFonts[ j - i - 1 ];
+ sf.preset = -1;
+ sf.bank = 0;
+ fonts.push_back( sf );
+ }
+ BASS_MIDI_StreamSetFonts( _stream, &fonts[0], (unsigned int) fonts.size() );
+
+ reset_drum_channels();
+
+ synth_mode = mode_gm;
+
+ return true;
+}
+
+void BMPlayer::reset_drum_channels()
+{
+ static const uint8_t part_to_ch[16] = { 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15 };
+
+ memset( drum_channels, 0, sizeof( drum_channels ) );
+ drum_channels[ 9 ] = 1;
+ drum_channels[ 25 ] = 1;
+ drum_channels[ 41 ] = 1;
+
+ for ( unsigned long i = 0; i < 3; i++ )
+ memcpy( gs_part_to_ch[ i ], part_to_ch, sizeof( gs_part_to_ch[ i ] ) );
+
+ if ( _stream )
+ {
+ for ( unsigned i = 0; i < 48; ++i )
+ {
+ BASS_MIDI_StreamEvent( _stream, i, MIDI_EVENT_DRUMS, drum_channels[ i ] );
+ }
+ }
+}
diff --git a/Plugins/MIDI/MIDI/BMPlayer.h b/Plugins/MIDI/MIDI/BMPlayer.h
new file mode 100644
index 000000000..7f450003e
--- /dev/null
+++ b/Plugins/MIDI/MIDI/BMPlayer.h
@@ -0,0 +1,52 @@
+#ifndef __BMPlayer_h__
+#define __BMPlayer_h__
+
+#include "MIDIPlayer.h"
+
+#include "../../../ThirdParty/BASS/bassmidi.h"
+
+class BMPlayer : public MIDIPlayer
+{
+public:
+ // zero variables
+ BMPlayer();
+
+ // close, unload
+ virtual ~BMPlayer();
+
+ // configuration
+ void setSoundFont( const char * in );
+ void setFileSoundFont( const char * in );
+ void setSincInterpolation(bool enable = true);
+
+private:
+ virtual void send_event(uint32_t b);
+ virtual void render(float * out, unsigned long count);
+
+ virtual void shutdown();
+ virtual bool startup();
+
+ void reset_drum_channels();
+
+ std::vector _soundFonts;
+ std::string sSoundFontName;
+ std::string sFileSoundFontName;
+
+ HSTREAM _stream;
+
+ bool bSincInterpolation;
+
+ enum
+ {
+ mode_gm = 0,
+ mode_gm2,
+ mode_gs,
+ mode_xg
+ }
+ synth_mode;
+
+ uint8_t gs_part_to_ch[3][16];
+ uint8_t drum_channels[48];
+};
+
+#endif
diff --git a/Plugins/MIDI/MIDI/MIDI-Info.plist b/Plugins/MIDI/MIDI/MIDI-Info.plist
new file mode 100644
index 000000000..845d65c31
--- /dev/null
+++ b/Plugins/MIDI/MIDI/MIDI-Info.plist
@@ -0,0 +1,30 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ English
+ CFBundleExecutable
+ ${EXECUTABLE_NAME}
+ CFBundleIconFile
+
+ CFBundleIdentifier
+ net.kode54.midi
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundleName
+ ${PRODUCT_NAME}
+ CFBundlePackageType
+ BNDL
+ CFBundleShortVersionString
+ 1.0
+ CFBundleSignature
+ ????
+ CFBundleVersion
+ 1
+ NSHumanReadableCopyright
+ Copyright © 2013 Christopher Snowhill. All rights reserved.
+ NSPrincipalClass
+
+
+
diff --git a/Plugins/MIDI/MIDI/MIDI-Prefix.pch b/Plugins/MIDI/MIDI/MIDI-Prefix.pch
new file mode 100644
index 000000000..35d76409f
--- /dev/null
+++ b/Plugins/MIDI/MIDI/MIDI-Prefix.pch
@@ -0,0 +1,9 @@
+//
+// Prefix header
+//
+// The contents of this file are implicitly included at the beginning of every source file.
+//
+
+#ifdef __OBJC__
+ #import
+#endif
diff --git a/Plugins/MIDI/MIDI/MIDIDecoder.h b/Plugins/MIDI/MIDI/MIDIDecoder.h
new file mode 100755
index 000000000..5580af063
--- /dev/null
+++ b/Plugins/MIDI/MIDI/MIDIDecoder.h
@@ -0,0 +1,27 @@
+//
+// MIDIDecoder.h
+// MIDI
+//
+// Created by Christopher Snowhill on 10/15/13.
+// Copyright 2013 __NoWork, Inc__. All rights reserved.
+//
+
+#import
+
+#import "MIDIPlayer.h"
+
+#import "Plugin.h"
+
+@interface MIDIDecoder : NSObject {
+ MIDIPlayer* player;
+ midi_container midi_file;
+
+ BOOL soundFontsAssigned;
+
+ long totalFrames;
+ long framesLength;
+ long framesFade;
+ long framesRead;
+}
+
+@end
diff --git a/Plugins/MIDI/MIDI/MIDIDecoder.mm b/Plugins/MIDI/MIDI/MIDIDecoder.mm
new file mode 100755
index 000000000..6f228dc54
--- /dev/null
+++ b/Plugins/MIDI/MIDI/MIDIDecoder.mm
@@ -0,0 +1,167 @@
+//
+// MIDIDecoder.mm
+// MIDI
+//
+// Created by Christopher Snowhill on 10/15/13.
+// Copyright 2013 __NoWork, Inc__. All rights reserved.
+//
+
+#import "MIDIDecoder.h"
+
+#import "BMPlayer.h"
+
+#import "Logging.h"
+
+#import
+
+@implementation MIDIDecoder
+
+- (BOOL)open:(id)s
+{
+ //We need file-size to use midi_processing
+ if (![s seekable]) {
+ return NO;
+ }
+
+ std::vector file_data;
+
+ [s seek:0 whence:SEEK_END];
+ size_t size = [s tell];
+ [s seek:0 whence:SEEK_SET];
+ file_data.resize( size );
+ [s read:&file_data[0] amount:size];
+
+ if ( !midi_processor::process_file(file_data, [[[[s url] absoluteString] lastPathComponent] UTF8String], midi_file) )
+ return NO;
+
+ int track_num = [[[s url] fragment] intValue]; //What if theres no fragment? Assuming we get 0.
+
+ midi_file.scan_for_loops( true, true );
+
+ framesLength = midi_file.get_timestamp_end( track_num, true ) + 1000;
+
+ unsigned long loopStart = midi_file.get_timestamp_loop_start( track_num, true );
+ unsigned long loopEnd = midi_file.get_timestamp_loop_end( track_num, true );
+
+ if ( loopStart != ~0UL && loopEnd != ~0UL )
+ {
+ // two loops and a fade
+ framesLength = loopStart + ( loopEnd - loopStart ) * 2;
+ framesFade = 8000;
+ }
+ else
+ {
+ framesFade = 0;
+ }
+
+ framesLength = framesLength * 441 / 10;
+ framesFade = framesFade * 441 / 10;
+
+ totalFrames = framesLength + framesFade;
+
+ DLog(@"Length: %li", totalFrames);
+
+ DLog(@"Track num: %i", track_num);
+
+ BMPlayer * bmplayer = new BMPlayer;
+ player = bmplayer;
+
+ bmplayer->setSincInterpolation( true );
+ bmplayer->setSampleRate( 44100 );
+
+ unsigned int loop_mode = framesFade ? MIDIPlayer::loop_mode_enable | MIDIPlayer::loop_mode_force : 0;
+ unsigned int clean_flags = midi_container::clean_flag_emidi;
+
+ if ( !bmplayer->Load( midi_file, track_num, loop_mode, clean_flags) )
+ return NO;
+
+ framesRead = 0;
+
+ [self willChangeValueForKey:@"properties"];
+ [self didChangeValueForKey:@"properties"];
+
+ return YES;
+}
+
+- (NSDictionary *)properties
+{
+ return [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt:0], @"bitrate",
+ [NSNumber numberWithFloat:44100], @"sampleRate",
+ [NSNumber numberWithLong:totalFrames], @"totalFrames",
+ [NSNumber numberWithInt:32], @"bitsPerSample",
+ [NSNumber numberWithBool:YES], @"floatingPoint",
+ [NSNumber numberWithInt:2], @"channels", //output from gme_play is in stereo
+ [NSNumber numberWithBool:YES], @"seekable",
+ @"host", @"endian",
+ nil];
+}
+
+- (int)readAudio:(void *)buf frames:(UInt32)frames
+{
+ if ( !soundFontsAssigned ) {
+ NSString * soundFontPath = [[NSUserDefaults standardUserDefaults] stringForKey:@"soundFontPath"];
+ if (soundFontPath == nil)
+ return 0;
+
+ ((BMPlayer *)player)->setSoundFont( [soundFontPath UTF8String] );
+
+ soundFontsAssigned = YES;
+ }
+
+ player->Play( (float *) buf, frames );
+
+ if ( framesRead + frames > framesLength ) {
+ if ( framesFade ) {
+ long fadeStart = (framesLength > framesRead) ? framesLength : framesRead;
+ long fadeEnd = (framesRead + frames > totalFrames) ? totalFrames : (framesRead + frames);
+ long fadePos;
+
+ float * buff = ( float * ) buf;
+
+ float fadeScale = (fadeStart - framesLength) / framesFade;
+ float fadeStep = 1 / framesFade;
+ for (fadePos = fadeStart; fadePos < fadeEnd; ++fadePos) {
+ buff[ 0 ] *= fadeScale;
+ buff[ 1 ] *= fadeScale;
+ buff += 2;
+ fadeScale -= fadeStep;
+ if (fadeScale < 0) break;
+ }
+
+ if (fadePos < totalFrames)
+ frames = (int)(fadePos - fadeStart);
+ }
+ else {
+ frames = (int)(totalFrames - framesRead);
+ }
+ }
+
+ framesRead += frames;
+ return frames;
+}
+
+- (long)seek:(long)frame
+{
+ player->Seek( frame );
+
+ return frame;
+}
+
+- (void)close
+{
+ delete player;
+ player = NULL;
+}
+
++ (NSArray *)fileTypes
+{
+ return [NSArray arrayWithObjects:@"mid", @"midi", @"kar", @"rmi", @"mids", @"mds", @"hmi", @"hmp", @"mus", @"xmi", @"lds", nil];
+}
+
++ (NSArray *)mimeTypes
+{
+ return [NSArray arrayWithObjects:@"audio/midi", @"audio/x-midi", nil];
+}
+
+@end
diff --git a/Plugins/MIDI/MIDI/MIDIPlayer.cpp b/Plugins/MIDI/MIDI/MIDIPlayer.cpp
new file mode 100644
index 000000000..d753f3472
--- /dev/null
+++ b/Plugins/MIDI/MIDI/MIDIPlayer.cpp
@@ -0,0 +1,313 @@
+#include
+
+#include "MIDIPlayer.h"
+
+MIDIPlayer::MIDIPlayer()
+{
+ uSamplesRemaining = 0;
+ uSampleRate = 1000;
+ uTimeCurrent = 0;
+ uTimeEnd = 0;
+ uTimeLoopStart = 0;
+}
+
+void MIDIPlayer::setSampleRate(unsigned long rate)
+{
+ if (mStream.size())
+ {
+ for (unsigned long i = 0; i < mStream.size(); i++)
+ {
+ mStream[i].m_timestamp = mStream[i].m_timestamp * rate / uSampleRate;
+ }
+ }
+
+ if (uTimeCurrent)
+ {
+ uTimeCurrent = uTimeCurrent * rate / uSampleRate;
+ }
+
+ if (uTimeEnd)
+ {
+ uTimeEnd = uTimeEnd * rate / uSampleRate;
+ }
+
+ if (uTimeLoopStart)
+ {
+ uTimeLoopStart = uTimeLoopStart * rate / uSampleRate;
+ }
+
+ uSampleRate = rate;
+
+ shutdown();
+}
+
+bool MIDIPlayer::Load(const midi_container & midi_file, unsigned subsong, unsigned loop_mode, unsigned clean_flags)
+{
+ assert(!mStream.size());
+
+ midi_file.serialize_as_stream( subsong, mStream, mSysexMap, clean_flags );
+
+ if (mStream.size())
+ {
+ uStreamPosition = 0;
+ uTimeCurrent = 0;
+
+ uLoopMode = loop_mode;
+
+ if (uLoopMode & loop_mode_enable)
+ {
+ uTimeLoopStart = midi_file.get_timestamp_loop_start( subsong, true );
+ unsigned long uTimeLoopEnd = midi_file.get_timestamp_loop_end( subsong, true );
+ uTimeEnd = midi_file.get_timestamp_end( subsong, true );
+
+ if ( uTimeLoopStart != ~0UL || uTimeLoopEnd != ~0UL )
+ {
+ uLoopMode |= loop_mode_force;
+ }
+
+ if ( uTimeLoopStart != ~0 )
+ {
+ for ( unsigned i = 0; i < mStream.size(); ++i )
+ {
+ if ( mStream[ i ].m_timestamp >= uTimeLoopStart )
+ {
+ uStreamLoopStart = i;
+ break;
+ }
+ }
+ }
+ else uStreamLoopStart = ~0UL;
+
+ if ( uTimeLoopEnd != ~0UL )
+ {
+ uTimeEnd = uTimeLoopEnd;
+ }
+
+ if (!(uLoopMode & loop_mode_force)) uTimeEnd += 1000;
+ else
+ {
+ unsigned long i;
+ unsigned char note_on[128 * 16];
+ memset( note_on, 0, sizeof( note_on ) );
+ for (i = 0; i < mStream.size(); i++)
+ {
+ if (mStream[ i ].m_timestamp > uTimeEnd) break;
+ uint32_t ev = mStream[ i ].m_event & 0x800000F0;
+ if ( ev == 0x90 || ev == 0x80 )
+ {
+ unsigned long port = ( mStream[ i ].m_event & 0x7F000000 ) >> 24;
+ unsigned long ch = mStream[ i ].m_event & 0x0F;
+ unsigned long note = ( mStream[ i ].m_event >> 8 ) & 0x7F;
+ unsigned long on = ( ev == 0x90 ) && ( mStream[ i ].m_event & 0xFF0000 );
+ unsigned long bit = 1 << port;
+ note_on [ ch * 128 + note ] = ( note_on [ ch * 128 + note ] & ~bit ) | ( bit * on );
+ }
+ }
+ mStream.resize( i );
+ for ( unsigned long j = 0; j < 128 * 16; j++ )
+ {
+ if ( note_on[ j ] )
+ {
+ for ( unsigned long k = 0; k < 8; k++ )
+ {
+ if ( note_on[ j ] & ( 1 << k ) )
+ {
+ mStream.push_back( midi_stream_event( uTimeEnd, (uint32_t)(( k << 24 ) + ( j >> 7 ) + ( j & 0x7F ) * 0x100 + 0x90 )) );
+ }
+ }
+ }
+ }
+ }
+ }
+ else uTimeEnd = midi_file.get_timestamp_end( subsong, true ) + 1000;
+
+ if (uSampleRate != 1000)
+ {
+ unsigned long rate = uSampleRate;
+ uSampleRate = 1000;
+ setSampleRate(rate);
+ }
+
+ return true;
+ }
+
+ return false;
+}
+
+unsigned long MIDIPlayer::Play(float * out, unsigned long count)
+{
+ assert(mStream.size());
+
+ if ( !startup() ) return 0;
+
+ unsigned long done = 0;
+
+ if ( uSamplesRemaining )
+ {
+ unsigned long todo = uSamplesRemaining;
+ if (todo > count) todo = count;
+ render( out, todo );
+ uSamplesRemaining -= todo;
+ done += todo;
+ uTimeCurrent += todo;
+ }
+
+ while (done < count)
+ {
+ unsigned long todo = uTimeEnd - uTimeCurrent;
+ if (todo > count - done) todo = count - done;
+
+ unsigned long time_target = todo + uTimeCurrent;
+ unsigned long stream_end = uStreamPosition;
+
+ while (stream_end < mStream.size() && mStream[stream_end].m_timestamp < time_target) stream_end++;
+
+ if (stream_end > uStreamPosition)
+ {
+ for (; uStreamPosition < stream_end; uStreamPosition++)
+ {
+ midi_stream_event * me = &mStream[uStreamPosition];
+
+ unsigned long samples_todo = me->m_timestamp - uTimeCurrent;
+ if ( samples_todo )
+ {
+ if ( samples_todo > count - done )
+ {
+ uSamplesRemaining = samples_todo - ( count - done );
+ samples_todo = count - done;
+ }
+ render( out + done * 2, samples_todo );
+ done += samples_todo;
+
+ if ( uSamplesRemaining )
+ {
+ uTimeCurrent = me->m_timestamp;
+ return done;
+ }
+ }
+
+ send_event( me->m_event );
+
+ uTimeCurrent = me->m_timestamp;
+ }
+ }
+
+ if ( done < count )
+ {
+ unsigned long samples_todo;
+ if ( uStreamPosition < mStream.size() ) samples_todo = mStream[uStreamPosition].m_timestamp;
+ else samples_todo = uTimeEnd;
+ samples_todo -= uTimeCurrent;
+ if ( samples_todo > count - done ) samples_todo = count - done;
+ render( out + done * 2, samples_todo );
+ done += samples_todo;
+ }
+
+ uTimeCurrent = time_target;
+
+ if (uTimeCurrent >= uTimeEnd)
+ {
+ if ( uStreamPosition < mStream.size() )
+ {
+ for (; uStreamPosition < mStream.size(); uStreamPosition++)
+ {
+ send_event( mStream[ uStreamPosition ].m_event );
+ }
+ }
+
+ if ((uLoopMode & (loop_mode_enable | loop_mode_force)) == (loop_mode_enable | loop_mode_force))
+ {
+ if (uStreamLoopStart == ~0)
+ {
+ uStreamPosition = 0;
+ uTimeCurrent = 0;
+ }
+ else
+ {
+ uStreamPosition = uStreamLoopStart;
+ uTimeCurrent = uTimeLoopStart;
+ }
+ }
+ else break;
+ }
+ }
+
+ return done;
+}
+
+void MIDIPlayer::Seek(unsigned long sample)
+{
+ if (sample >= uTimeEnd)
+ {
+ if ((uLoopMode & (loop_mode_enable | loop_mode_force)) == (loop_mode_enable | loop_mode_force))
+ {
+ while (sample >= uTimeEnd) sample -= uTimeEnd - uTimeLoopStart;
+ }
+ else
+ {
+ sample = uTimeEnd;
+ }
+ }
+
+ if (uTimeCurrent > sample)
+ {
+ // hokkai, let's kill any hanging notes
+ uStreamPosition = 0;
+
+ shutdown();
+ }
+
+ if (!startup()) return;
+
+ uTimeCurrent = sample;
+
+ std::vector filler;
+
+ unsigned long stream_start = uStreamPosition;
+
+ for (; uStreamPosition < mStream.size() && mStream[uStreamPosition].m_timestamp < uTimeCurrent; uStreamPosition++);
+
+ uSamplesRemaining = mStream[uStreamPosition].m_timestamp - uTimeCurrent;
+
+ if (uStreamPosition > stream_start)
+ {
+ filler.resize( uStreamPosition - stream_start );
+ filler.assign( &mStream[stream_start], &mStream[uStreamPosition] );
+
+ unsigned long i, j;
+ midi_stream_event * me = &filler[0];
+
+ for (i = 0, stream_start = uStreamPosition - stream_start; i < stream_start; i++)
+ {
+ midi_stream_event & e = me[i];
+ if ((e.m_event & 0x800000F0) == 0x90 && (e.m_event & 0xFF0000)) // note on
+ {
+ if ((e.m_event & 0x0F) == 9) // hax
+ {
+ e.m_event = 0;
+ continue;
+ }
+ uint32_t m = (e.m_event & 0x7F00FF0F) | 0x80; // note off
+ uint32_t m2 = e.m_event & 0x7F00FFFF; // also note off
+ for (j = i + 1; j < stream_start; j++)
+ {
+ midi_stream_event & e2 = me[j];
+ if ((e2.m_event & 0xFF00FFFF) == m || e2.m_event == m2)
+ {
+ // kill 'em
+ e.m_event = 0;
+ e2.m_event = 0;
+ break;
+ }
+ }
+ }
+ }
+
+ for (i = 0; i < stream_start; i++)
+ {
+ if (me[i].m_event)
+ send_event(me[i].m_event);
+ }
+ }
+}
+
diff --git a/Plugins/MIDI/MIDI/MIDIPlayer.h b/Plugins/MIDI/MIDI/MIDIPlayer.h
new file mode 100644
index 000000000..9332f63eb
--- /dev/null
+++ b/Plugins/MIDI/MIDI/MIDIPlayer.h
@@ -0,0 +1,54 @@
+#ifndef __MIDIPlayer_h__
+#define __MIDIPlayer_h__
+
+#include
+
+class MIDIPlayer
+{
+public:
+ enum
+ {
+ loop_mode_enable = 1 << 0,
+ loop_mode_force = 1 << 1
+ };
+
+ // zero variables
+ MIDIPlayer();
+
+ // close, unload
+ virtual ~MIDIPlayer() {};
+
+ // setup
+ void setSampleRate(unsigned long rate);
+
+ bool Load(const midi_container & midi_file, unsigned subsong, unsigned loop_mode, unsigned clean_flags);
+ unsigned long Play(float * out, unsigned long count);
+ void Seek(unsigned long sample);
+
+protected:
+ virtual void send_event(uint32_t b) {}
+ virtual void render(float * out, unsigned long count) {}
+
+ virtual void shutdown() {};
+ virtual bool startup() {return false;}
+
+ unsigned long uSampleRate;
+ system_exclusive_table mSysexMap;
+
+private:
+ unsigned long uSamplesRemaining;
+
+ unsigned uLoopMode;
+
+ std::vector mStream;
+
+ unsigned long uStreamPosition;
+ unsigned long uTimeCurrent;
+ unsigned long uTimeEnd;
+
+ unsigned long uStreamLoopStart;
+ unsigned long uTimeLoopStart;
+};
+
+#endif
+
diff --git a/Plugins/MIDI/MIDI/en.lproj/InfoPlist.strings b/Plugins/MIDI/MIDI/en.lproj/InfoPlist.strings
new file mode 100644
index 000000000..477b28ff8
--- /dev/null
+++ b/Plugins/MIDI/MIDI/en.lproj/InfoPlist.strings
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
diff --git a/Preferences/General/English.lproj/Localizable.strings b/Preferences/General/English.lproj/Localizable.strings
index 4d2a9e87a..dc8cbaff3 100644
--- a/Preferences/General/English.lproj/Localizable.strings
+++ b/Preferences/General/English.lproj/Localizable.strings
@@ -12,6 +12,7 @@
"Playlist" = "Playlist";
"Growl" = "Growl";
"Appearance" = "Appearance";
+"MIDI" = "MIDI";
"Press Key..." = "Press Key...";
diff --git a/Preferences/General/English.lproj/Preferences.xib b/Preferences/General/English.lproj/Preferences.xib
index fd13c62c2..277174e4a 100644
--- a/Preferences/General/English.lproj/Preferences.xib
+++ b/Preferences/General/English.lproj/Preferences.xib
@@ -10,6 +10,7 @@
+
@@ -267,6 +268,11 @@
+
+
+
+
+
name
@@ -442,5 +448,22 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Preferences/General/General.xcodeproj/project.pbxproj b/Preferences/General/General.xcodeproj/project.pbxproj
index 005c90740..329f8e0c9 100644
--- a/Preferences/General/General.xcodeproj/project.pbxproj
+++ b/Preferences/General/General.xcodeproj/project.pbxproj
@@ -22,6 +22,8 @@
8384917718084D9F00E7332D /* appearance.png in Resources */ = {isa = PBXBuildFile; fileRef = 8384917518084D9F00E7332D /* appearance.png */; };
8384917818084D9F00E7332D /* growl.png in Resources */ = {isa = PBXBuildFile; fileRef = 8384917618084D9F00E7332D /* growl.png */; };
8384918C1808596A00E7332D /* NDHotKey.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 838491841808588D00E7332D /* NDHotKey.framework */; };
+ 83B06729180D85B8008E3612 /* MIDIPane.m in Sources */ = {isa = PBXBuildFile; fileRef = 83B06728180D85B8008E3612 /* MIDIPane.m */; };
+ 83B0672B180D8B39008E3612 /* midi.png in Resources */ = {isa = PBXBuildFile; fileRef = 83B0672A180D8B39008E3612 /* midi.png */; };
83EF495F17FBC96A00642E3C /* VolumeBehaviorArrayController.m in Sources */ = {isa = PBXBuildFile; fileRef = 83EF495E17FBC96A00642E3C /* VolumeBehaviorArrayController.m */; };
8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; };
8E07AA880AAC8EA200A4B32F /* HotKeyPane.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E07AA810AAC8EA200A4B32F /* HotKeyPane.m */; };
@@ -89,6 +91,9 @@
8384917518084D9F00E7332D /* appearance.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = appearance.png; path = Icons/appearance.png; sourceTree = ""; };
8384917618084D9F00E7332D /* growl.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = growl.png; path = Icons/growl.png; sourceTree = ""; };
8384917F1808588D00E7332D /* NDHotKey.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = NDHotKey.xcodeproj; path = ../../Frameworks/NDHotKey/NDHotKey.xcodeproj; sourceTree = ""; };
+ 83B06727180D85B8008E3612 /* MIDIPane.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MIDIPane.h; sourceTree = ""; };
+ 83B06728180D85B8008E3612 /* MIDIPane.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIDIPane.m; sourceTree = ""; };
+ 83B0672A180D8B39008E3612 /* midi.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = midi.png; path = Icons/midi.png; sourceTree = ""; };
83EF495D17FBC96A00642E3C /* VolumeBehaviorArrayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VolumeBehaviorArrayController.h; sourceTree = ""; };
83EF495E17FBC96A00642E3C /* VolumeBehaviorArrayController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VolumeBehaviorArrayController.m; sourceTree = ""; };
8D5B49B6048680CD000E48DA /* General.preferencePane */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = General.preferencePane; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -197,6 +202,8 @@
8E07AA810AAC8EA200A4B32F /* HotKeyPane.m */,
17C6433D0B8A783F00C53518 /* OutputPane.h */,
17C6433E0B8A783F00C53518 /* OutputPane.m */,
+ 83B06727180D85B8008E3612 /* MIDIPane.h */,
+ 83B06728180D85B8008E3612 /* MIDIPane.m */,
);
name = Panes;
sourceTree = "";
@@ -245,6 +252,7 @@
8E07ABD90AAC95AF00A4B32F /* Icons */ = {
isa = PBXGroup;
children = (
+ 83B0672A180D8B39008E3612 /* midi.png */,
8384917518084D9F00E7332D /* appearance.png */,
8384917618084D9F00E7332D /* growl.png */,
17C7E5AF0DCCC30A003CBCF7 /* playlist.png */,
@@ -333,6 +341,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 83B0672B180D8B39008E3612 /* midi.png in Resources */,
178E386E0C3DA64500EE6711 /* InfoPlist.strings in Resources */,
8E07ABDD0AAC95BC00A4B32F /* hot_keys.png in Resources */,
172D72AD0B8926CA00D095BB /* apple_remote.png in Resources */,
@@ -355,6 +364,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 83B06729180D85B8008E3612 /* MIDIPane.m in Sources */,
8E07AA880AAC8EA200A4B32F /* HotKeyPane.m in Sources */,
8E07AA890AAC8EA200A4B32F /* GeneralPreferencePane.m in Sources */,
8E07AA8A0AAC8EA200A4B32F /* GeneralPreferencesPlugin.m in Sources */,
diff --git a/Preferences/General/GeneralPreferencesPlugin.h b/Preferences/General/GeneralPreferencesPlugin.h
index 271167938..65cc6de6a 100644
--- a/Preferences/General/GeneralPreferencesPlugin.h
+++ b/Preferences/General/GeneralPreferencesPlugin.h
@@ -12,10 +12,12 @@
#import "HotKeyPane.h"
#import "OutputPane.h"
+#import "MIDIPane.h"
@interface GeneralPreferencesPlugin : NSObject {
IBOutlet HotKeyPane *hotKeyPane;
IBOutlet OutputPane *outputPane;
+ IBOutlet MIDIPane *midiPane;
IBOutlet NSView *playlistView;
IBOutlet NSView *scrobblerView;
@@ -23,10 +25,12 @@
IBOutlet NSView *updatesView;
IBOutlet NSView *growlView;
IBOutlet NSView *appearanceView;
+ IBOutlet NSView *midiView;
}
- (HotKeyPane *)hotKeyPane;
- (OutputPane *)outputPane;
+- (MIDIPane *)midiPane;
- (GeneralPreferencePane *)remotePane;
- (GeneralPreferencePane *)updatesPane;
diff --git a/Preferences/General/GeneralPreferencesPlugin.m b/Preferences/General/GeneralPreferencesPlugin.m
index 8a82e8b50..832137fc7 100644
--- a/Preferences/General/GeneralPreferencesPlugin.m
+++ b/Preferences/General/GeneralPreferencesPlugin.m
@@ -24,6 +24,7 @@
[plugin scrobblerPane],
[plugin growlPane],
[plugin appearancePane],
+ [plugin midiPane],
nil];
}
@@ -37,6 +38,11 @@
return outputPane;
}
+- (MIDIPane *)midiPane
+{
+ return midiPane;
+}
+
- (GeneralPreferencePane *)remotePane
{
return [GeneralPreferencePane preferencePaneWithView:remoteView title:NSLocalizedStringFromTableInBundle(@"Remote", nil, [NSBundle bundleForClass:[self class]], @"") iconNamed:@"apple_remote"];
diff --git a/Preferences/General/Icons/midi.png b/Preferences/General/Icons/midi.png
new file mode 100644
index 000000000..ffca4bf99
Binary files /dev/null and b/Preferences/General/Icons/midi.png differ
diff --git a/Preferences/General/MIDIPane.h b/Preferences/General/MIDIPane.h
new file mode 100644
index 000000000..f98ccb618
--- /dev/null
+++ b/Preferences/General/MIDIPane.h
@@ -0,0 +1,17 @@
+//
+// MIDIPane.h
+// General
+//
+// Created by Christopher Snowhill on 10/15/13.
+//
+//
+
+#import
+#import "GeneralPreferencePane.h"
+
+@interface MIDIPane : GeneralPreferencePane {
+}
+
+- (IBAction)setSoundFont:(id)sender;
+
+@end
diff --git a/Preferences/General/MIDIPane.m b/Preferences/General/MIDIPane.m
new file mode 100644
index 000000000..cef8b769b
--- /dev/null
+++ b/Preferences/General/MIDIPane.m
@@ -0,0 +1,42 @@
+//
+// MIDIPane.m
+// General
+//
+// Created by Christopher Snowhill on 10/15/13.
+//
+//
+
+#import "MIDIPane.h"
+
+@implementation MIDIPane
+
+- (NSString *)title
+{
+ return NSLocalizedStringFromTableInBundle(@"MIDI", nil, [NSBundle bundleForClass:[self class]], @"");
+}
+
+- (NSImage *)icon
+{
+ return [[[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[self class]] pathForImageResource:@"midi"]] autorelease];
+}
+
+- (IBAction)setSoundFont:(id)sender
+{
+ NSArray *fileTypes = [NSArray arrayWithObjects:@"sf2",@"sf2pack",@"sflist",nil];
+ NSOpenPanel * panel = [NSOpenPanel openPanel];
+ [panel setAllowsMultipleSelection:NO];
+ [panel setCanChooseDirectories:NO];
+ [panel setCanChooseFiles:YES];
+ [panel setFloatingPanel:YES];
+ [panel setAllowedFileTypes:fileTypes];
+ NSString * oldPath = [[NSUserDefaults standardUserDefaults] stringForKey:@"soundFontPath"];
+ if ( oldPath != nil )
+ [panel setDirectoryURL:[NSURL fileURLWithPath:oldPath]];
+ NSInteger result = [panel runModal];
+ if(result == NSOKButton)
+ {
+ [[NSUserDefaults standardUserDefaults] setValue:[[panel URL] path] forKey:@"soundFontPath"];
+ }
+}
+
+@end
diff --git a/ThirdParty/BASS/bass.h b/ThirdParty/BASS/bass.h
new file mode 100644
index 000000000..f49e061a9
--- /dev/null
+++ b/ThirdParty/BASS/bass.h
@@ -0,0 +1,990 @@
+/*
+ BASS 2.4 C/C++ header file
+ Copyright (c) 1999-2013 Un4seen Developments Ltd.
+
+ See the BASS.CHM file for more detailed documentation
+*/
+
+#ifndef BASS_H
+#define BASS_H
+
+#ifdef _WIN32
+#include
+typedef unsigned __int64 QWORD;
+#else
+#include
+#define WINAPI
+#define CALLBACK
+typedef uint8_t BYTE;
+typedef uint16_t WORD;
+typedef uint32_t DWORD;
+typedef uint64_t QWORD;
+#ifndef __OBJC__
+typedef int BOOL;
+#endif
+#ifndef TRUE
+#define TRUE 1
+#define FALSE 0
+#endif
+#define LOBYTE(a) (BYTE)(a)
+#define HIBYTE(a) (BYTE)((a)>>8)
+#define LOWORD(a) (WORD)(a)
+#define HIWORD(a) (WORD)((a)>>16)
+#define MAKEWORD(a,b) (WORD)(((a)&0xff)|((b)<<8))
+#define MAKELONG(a,b) (DWORD)(((a)&0xffff)|((b)<<16))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define BASSVERSION 0x204 // API version
+#define BASSVERSIONTEXT "2.4"
+
+#ifndef BASSDEF
+#define BASSDEF(f) WINAPI f
+#endif
+
+typedef DWORD HMUSIC; // MOD music handle
+typedef DWORD HSAMPLE; // sample handle
+typedef DWORD HCHANNEL; // playing sample's channel handle
+typedef DWORD HSTREAM; // sample stream handle
+typedef DWORD HRECORD; // recording handle
+typedef DWORD HSYNC; // synchronizer handle
+typedef DWORD HDSP; // DSP handle
+typedef DWORD HFX; // DX8 effect handle
+typedef DWORD HPLUGIN; // Plugin handle
+
+// Error codes returned by BASS_ErrorGetCode
+#define BASS_OK 0 // all is OK
+#define BASS_ERROR_MEM 1 // memory error
+#define BASS_ERROR_FILEOPEN 2 // can't open the file
+#define BASS_ERROR_DRIVER 3 // can't find a free/valid driver
+#define BASS_ERROR_BUFLOST 4 // the sample buffer was lost
+#define BASS_ERROR_HANDLE 5 // invalid handle
+#define BASS_ERROR_FORMAT 6 // unsupported sample format
+#define BASS_ERROR_POSITION 7 // invalid position
+#define BASS_ERROR_INIT 8 // BASS_Init has not been successfully called
+#define BASS_ERROR_START 9 // BASS_Start has not been successfully called
+#define BASS_ERROR_ALREADY 14 // already initialized/paused/whatever
+#define BASS_ERROR_NOCHAN 18 // can't get a free channel
+#define BASS_ERROR_ILLTYPE 19 // an illegal type was specified
+#define BASS_ERROR_ILLPARAM 20 // an illegal parameter was specified
+#define BASS_ERROR_NO3D 21 // no 3D support
+#define BASS_ERROR_NOEAX 22 // no EAX support
+#define BASS_ERROR_DEVICE 23 // illegal device number
+#define BASS_ERROR_NOPLAY 24 // not playing
+#define BASS_ERROR_FREQ 25 // illegal sample rate
+#define BASS_ERROR_NOTFILE 27 // the stream is not a file stream
+#define BASS_ERROR_NOHW 29 // no hardware voices available
+#define BASS_ERROR_EMPTY 31 // the MOD music has no sequence data
+#define BASS_ERROR_NONET 32 // no internet connection could be opened
+#define BASS_ERROR_CREATE 33 // couldn't create the file
+#define BASS_ERROR_NOFX 34 // effects are not available
+#define BASS_ERROR_NOTAVAIL 37 // requested data is not available
+#define BASS_ERROR_DECODE 38 // the channel is/isn't a "decoding channel"
+#define BASS_ERROR_DX 39 // a sufficient DirectX version is not installed
+#define BASS_ERROR_TIMEOUT 40 // connection timedout
+#define BASS_ERROR_FILEFORM 41 // unsupported file format
+#define BASS_ERROR_SPEAKER 42 // unavailable speaker
+#define BASS_ERROR_VERSION 43 // invalid BASS version (used by add-ons)
+#define BASS_ERROR_CODEC 44 // codec is not available/supported
+#define BASS_ERROR_ENDED 45 // the channel/file has ended
+#define BASS_ERROR_BUSY 46 // the device is busy
+#define BASS_ERROR_UNKNOWN -1 // some other mystery problem
+
+// BASS_SetConfig options
+#define BASS_CONFIG_BUFFER 0
+#define BASS_CONFIG_UPDATEPERIOD 1
+#define BASS_CONFIG_GVOL_SAMPLE 4
+#define BASS_CONFIG_GVOL_STREAM 5
+#define BASS_CONFIG_GVOL_MUSIC 6
+#define BASS_CONFIG_CURVE_VOL 7
+#define BASS_CONFIG_CURVE_PAN 8
+#define BASS_CONFIG_FLOATDSP 9
+#define BASS_CONFIG_3DALGORITHM 10
+#define BASS_CONFIG_NET_TIMEOUT 11
+#define BASS_CONFIG_NET_BUFFER 12
+#define BASS_CONFIG_PAUSE_NOPLAY 13
+#define BASS_CONFIG_NET_PREBUF 15
+#define BASS_CONFIG_NET_PASSIVE 18
+#define BASS_CONFIG_REC_BUFFER 19
+#define BASS_CONFIG_NET_PLAYLIST 21
+#define BASS_CONFIG_MUSIC_VIRTUAL 22
+#define BASS_CONFIG_VERIFY 23
+#define BASS_CONFIG_UPDATETHREADS 24
+#define BASS_CONFIG_DEV_BUFFER 27
+#define BASS_CONFIG_VISTA_TRUEPOS 30
+#define BASS_CONFIG_IOS_MIXAUDIO 34
+#define BASS_CONFIG_DEV_DEFAULT 36
+#define BASS_CONFIG_NET_READTIMEOUT 37
+#define BASS_CONFIG_VISTA_SPEAKERS 38
+#define BASS_CONFIG_IOS_SPEAKER 39
+#define BASS_CONFIG_HANDLES 41
+#define BASS_CONFIG_UNICODE 42
+#define BASS_CONFIG_SRC 43
+#define BASS_CONFIG_SRC_SAMPLE 44
+#define BASS_CONFIG_ASYNCFILE_BUFFER 45
+#define BASS_CONFIG_OGG_PRESCAN 47
+
+// BASS_SetConfigPtr options
+#define BASS_CONFIG_NET_AGENT 16
+#define BASS_CONFIG_NET_PROXY 17
+#define BASS_CONFIG_IOS_NOTIFY 46
+
+// BASS_Init flags
+#define BASS_DEVICE_8BITS 1 // 8 bit resolution, else 16 bit
+#define BASS_DEVICE_MONO 2 // mono, else stereo
+#define BASS_DEVICE_3D 4 // enable 3D functionality
+#define BASS_DEVICE_LATENCY 0x100 // calculate device latency (BASS_INFO struct)
+#define BASS_DEVICE_CPSPEAKERS 0x400 // detect speakers via Windows control panel
+#define BASS_DEVICE_SPEAKERS 0x800 // force enabling of speaker assignment
+#define BASS_DEVICE_NOSPEAKER 0x1000 // ignore speaker arrangement
+#define BASS_DEVICE_DMIX 0x2000 // use ALSA "dmix" plugin
+#define BASS_DEVICE_FREQ 0x4000 // set device sample rate
+
+// DirectSound interfaces (for use with BASS_GetDSoundObject)
+#define BASS_OBJECT_DS 1 // IDirectSound
+#define BASS_OBJECT_DS3DL 2 // IDirectSound3DListener
+
+// Device info structure
+typedef struct {
+#ifdef _WIN32_WCE
+ const wchar_t *name; // description
+ const wchar_t *driver; // driver
+#else
+ const char *name; // description
+ const char *driver; // driver
+#endif
+ DWORD flags;
+} BASS_DEVICEINFO;
+
+// BASS_DEVICEINFO flags
+#define BASS_DEVICE_ENABLED 1
+#define BASS_DEVICE_DEFAULT 2
+#define BASS_DEVICE_INIT 4
+
+typedef struct {
+ DWORD flags; // device capabilities (DSCAPS_xxx flags)
+ DWORD hwsize; // size of total device hardware memory
+ DWORD hwfree; // size of free device hardware memory
+ DWORD freesam; // number of free sample slots in the hardware
+ DWORD free3d; // number of free 3D sample slots in the hardware
+ DWORD minrate; // min sample rate supported by the hardware
+ DWORD maxrate; // max sample rate supported by the hardware
+ BOOL eax; // device supports EAX? (always FALSE if BASS_DEVICE_3D was not used)
+ DWORD minbuf; // recommended minimum buffer length in ms (requires BASS_DEVICE_LATENCY)
+ DWORD dsver; // DirectSound version
+ DWORD latency; // delay (in ms) before start of playback (requires BASS_DEVICE_LATENCY)
+ DWORD initflags; // BASS_Init "flags" parameter
+ DWORD speakers; // number of speakers available
+ DWORD freq; // current output rate
+} BASS_INFO;
+
+// BASS_INFO flags (from DSOUND.H)
+#define DSCAPS_CONTINUOUSRATE 0x00000010 // supports all sample rates between min/maxrate
+#define DSCAPS_EMULDRIVER 0x00000020 // device does NOT have hardware DirectSound support
+#define DSCAPS_CERTIFIED 0x00000040 // device driver has been certified by Microsoft
+#define DSCAPS_SECONDARYMONO 0x00000100 // mono
+#define DSCAPS_SECONDARYSTEREO 0x00000200 // stereo
+#define DSCAPS_SECONDARY8BIT 0x00000400 // 8 bit
+#define DSCAPS_SECONDARY16BIT 0x00000800 // 16 bit
+
+// Recording device info structure
+typedef struct {
+ DWORD flags; // device capabilities (DSCCAPS_xxx flags)
+ DWORD formats; // supported standard formats (WAVE_FORMAT_xxx flags)
+ DWORD inputs; // number of inputs
+ BOOL singlein; // TRUE = only 1 input can be set at a time
+ DWORD freq; // current input rate
+} BASS_RECORDINFO;
+
+// BASS_RECORDINFO flags (from DSOUND.H)
+#define DSCCAPS_EMULDRIVER DSCAPS_EMULDRIVER // device does NOT have hardware DirectSound recording support
+#define DSCCAPS_CERTIFIED DSCAPS_CERTIFIED // device driver has been certified by Microsoft
+
+// defines for formats field of BASS_RECORDINFO (from MMSYSTEM.H)
+#ifndef WAVE_FORMAT_1M08
+#define WAVE_FORMAT_1M08 0x00000001 /* 11.025 kHz, Mono, 8-bit */
+#define WAVE_FORMAT_1S08 0x00000002 /* 11.025 kHz, Stereo, 8-bit */
+#define WAVE_FORMAT_1M16 0x00000004 /* 11.025 kHz, Mono, 16-bit */
+#define WAVE_FORMAT_1S16 0x00000008 /* 11.025 kHz, Stereo, 16-bit */
+#define WAVE_FORMAT_2M08 0x00000010 /* 22.05 kHz, Mono, 8-bit */
+#define WAVE_FORMAT_2S08 0x00000020 /* 22.05 kHz, Stereo, 8-bit */
+#define WAVE_FORMAT_2M16 0x00000040 /* 22.05 kHz, Mono, 16-bit */
+#define WAVE_FORMAT_2S16 0x00000080 /* 22.05 kHz, Stereo, 16-bit */
+#define WAVE_FORMAT_4M08 0x00000100 /* 44.1 kHz, Mono, 8-bit */
+#define WAVE_FORMAT_4S08 0x00000200 /* 44.1 kHz, Stereo, 8-bit */
+#define WAVE_FORMAT_4M16 0x00000400 /* 44.1 kHz, Mono, 16-bit */
+#define WAVE_FORMAT_4S16 0x00000800 /* 44.1 kHz, Stereo, 16-bit */
+#endif
+
+// Sample info structure
+typedef struct {
+ DWORD freq; // default playback rate
+ float volume; // default volume (0-1)
+ float pan; // default pan (-1=left, 0=middle, 1=right)
+ DWORD flags; // BASS_SAMPLE_xxx flags
+ DWORD length; // length (in bytes)
+ DWORD max; // maximum simultaneous playbacks
+ DWORD origres; // original resolution bits
+ DWORD chans; // number of channels
+ DWORD mingap; // minimum gap (ms) between creating channels
+ DWORD mode3d; // BASS_3DMODE_xxx mode
+ float mindist; // minimum distance
+ float maxdist; // maximum distance
+ DWORD iangle; // angle of inside projection cone
+ DWORD oangle; // angle of outside projection cone
+ float outvol; // delta-volume outside the projection cone
+ DWORD vam; // voice allocation/management flags (BASS_VAM_xxx)
+ DWORD priority; // priority (0=lowest, 0xffffffff=highest)
+} BASS_SAMPLE;
+
+#define BASS_SAMPLE_8BITS 1 // 8 bit
+#define BASS_SAMPLE_FLOAT 256 // 32-bit floating-point
+#define BASS_SAMPLE_MONO 2 // mono
+#define BASS_SAMPLE_LOOP 4 // looped
+#define BASS_SAMPLE_3D 8 // 3D functionality
+#define BASS_SAMPLE_SOFTWARE 16 // not using hardware mixing
+#define BASS_SAMPLE_MUTEMAX 32 // mute at max distance (3D only)
+#define BASS_SAMPLE_VAM 64 // DX7 voice allocation & management
+#define BASS_SAMPLE_FX 128 // old implementation of DX8 effects
+#define BASS_SAMPLE_OVER_VOL 0x10000 // override lowest volume
+#define BASS_SAMPLE_OVER_POS 0x20000 // override longest playing
+#define BASS_SAMPLE_OVER_DIST 0x30000 // override furthest from listener (3D only)
+
+#define BASS_STREAM_PRESCAN 0x20000 // enable pin-point seeking/length (MP3/MP2/MP1)
+#define BASS_MP3_SETPOS BASS_STREAM_PRESCAN
+#define BASS_STREAM_AUTOFREE 0x40000 // automatically free the stream when it stop/ends
+#define BASS_STREAM_RESTRATE 0x80000 // restrict the download rate of internet file streams
+#define BASS_STREAM_BLOCK 0x100000 // download/play internet file stream in small blocks
+#define BASS_STREAM_DECODE 0x200000 // don't play the stream, only decode (BASS_ChannelGetData)
+#define BASS_STREAM_STATUS 0x800000 // give server status info (HTTP/ICY tags) in DOWNLOADPROC
+
+#define BASS_MUSIC_FLOAT BASS_SAMPLE_FLOAT
+#define BASS_MUSIC_MONO BASS_SAMPLE_MONO
+#define BASS_MUSIC_LOOP BASS_SAMPLE_LOOP
+#define BASS_MUSIC_3D BASS_SAMPLE_3D
+#define BASS_MUSIC_FX BASS_SAMPLE_FX
+#define BASS_MUSIC_AUTOFREE BASS_STREAM_AUTOFREE
+#define BASS_MUSIC_DECODE BASS_STREAM_DECODE
+#define BASS_MUSIC_PRESCAN BASS_STREAM_PRESCAN // calculate playback length
+#define BASS_MUSIC_CALCLEN BASS_MUSIC_PRESCAN
+#define BASS_MUSIC_RAMP 0x200 // normal ramping
+#define BASS_MUSIC_RAMPS 0x400 // sensitive ramping
+#define BASS_MUSIC_SURROUND 0x800 // surround sound
+#define BASS_MUSIC_SURROUND2 0x1000 // surround sound (mode 2)
+#define BASS_MUSIC_FT2MOD 0x2000 // play .MOD as FastTracker 2 does
+#define BASS_MUSIC_PT1MOD 0x4000 // play .MOD as ProTracker 1 does
+#define BASS_MUSIC_NONINTER 0x10000 // non-interpolated sample mixing
+#define BASS_MUSIC_SINCINTER 0x800000 // sinc interpolated sample mixing
+#define BASS_MUSIC_POSRESET 0x8000 // stop all notes when moving position
+#define BASS_MUSIC_POSRESETEX 0x400000 // stop all notes and reset bmp/etc when moving position
+#define BASS_MUSIC_STOPBACK 0x80000 // stop the music on a backwards jump effect
+#define BASS_MUSIC_NOSAMPLE 0x100000 // don't load the samples
+
+// Speaker assignment flags
+#define BASS_SPEAKER_FRONT 0x1000000 // front speakers
+#define BASS_SPEAKER_REAR 0x2000000 // rear/side speakers
+#define BASS_SPEAKER_CENLFE 0x3000000 // center & LFE speakers (5.1)
+#define BASS_SPEAKER_REAR2 0x4000000 // rear center speakers (7.1)
+#define BASS_SPEAKER_N(n) ((n)<<24) // n'th pair of speakers (max 15)
+#define BASS_SPEAKER_LEFT 0x10000000 // modifier: left
+#define BASS_SPEAKER_RIGHT 0x20000000 // modifier: right
+#define BASS_SPEAKER_FRONTLEFT BASS_SPEAKER_FRONT|BASS_SPEAKER_LEFT
+#define BASS_SPEAKER_FRONTRIGHT BASS_SPEAKER_FRONT|BASS_SPEAKER_RIGHT
+#define BASS_SPEAKER_REARLEFT BASS_SPEAKER_REAR|BASS_SPEAKER_LEFT
+#define BASS_SPEAKER_REARRIGHT BASS_SPEAKER_REAR|BASS_SPEAKER_RIGHT
+#define BASS_SPEAKER_CENTER BASS_SPEAKER_CENLFE|BASS_SPEAKER_LEFT
+#define BASS_SPEAKER_LFE BASS_SPEAKER_CENLFE|BASS_SPEAKER_RIGHT
+#define BASS_SPEAKER_REAR2LEFT BASS_SPEAKER_REAR2|BASS_SPEAKER_LEFT
+#define BASS_SPEAKER_REAR2RIGHT BASS_SPEAKER_REAR2|BASS_SPEAKER_RIGHT
+
+#define BASS_ASYNCFILE 0x40000000
+#define BASS_UNICODE 0x80000000
+
+#define BASS_RECORD_PAUSE 0x8000 // start recording paused
+
+// DX7 voice allocation & management flags
+#define BASS_VAM_HARDWARE 1
+#define BASS_VAM_SOFTWARE 2
+#define BASS_VAM_TERM_TIME 4
+#define BASS_VAM_TERM_DIST 8
+#define BASS_VAM_TERM_PRIO 16
+
+// Channel info structure
+typedef struct {
+ DWORD freq; // default playback rate
+ DWORD chans; // channels
+ DWORD flags; // BASS_SAMPLE/STREAM/MUSIC/SPEAKER flags
+ DWORD ctype; // type of channel
+ DWORD origres; // original resolution
+ HPLUGIN plugin; // plugin
+ HSAMPLE sample; // sample
+ const char *filename; // filename
+} BASS_CHANNELINFO;
+
+// BASS_CHANNELINFO types
+#define BASS_CTYPE_SAMPLE 1
+#define BASS_CTYPE_RECORD 2
+#define BASS_CTYPE_STREAM 0x10000
+#define BASS_CTYPE_STREAM_OGG 0x10002
+#define BASS_CTYPE_STREAM_MP1 0x10003
+#define BASS_CTYPE_STREAM_MP2 0x10004
+#define BASS_CTYPE_STREAM_MP3 0x10005
+#define BASS_CTYPE_STREAM_AIFF 0x10006
+#define BASS_CTYPE_STREAM_CA 0x10007
+#define BASS_CTYPE_STREAM_MF 0x10008
+#define BASS_CTYPE_STREAM_WAV 0x40000 // WAVE flag, LOWORD=codec
+#define BASS_CTYPE_STREAM_WAV_PCM 0x50001
+#define BASS_CTYPE_STREAM_WAV_FLOAT 0x50003
+#define BASS_CTYPE_MUSIC_MOD 0x20000
+#define BASS_CTYPE_MUSIC_MTM 0x20001
+#define BASS_CTYPE_MUSIC_S3M 0x20002
+#define BASS_CTYPE_MUSIC_XM 0x20003
+#define BASS_CTYPE_MUSIC_IT 0x20004
+#define BASS_CTYPE_MUSIC_MO3 0x00100 // MO3 flag
+
+typedef struct {
+ DWORD ctype; // channel type
+#ifdef _WIN32_WCE
+ const wchar_t *name; // format description
+ const wchar_t *exts; // file extension filter (*.ext1;*.ext2;etc...)
+#else
+ const char *name; // format description
+ const char *exts; // file extension filter (*.ext1;*.ext2;etc...)
+#endif
+} BASS_PLUGINFORM;
+
+typedef struct {
+ DWORD version; // version (same form as BASS_GetVersion)
+ DWORD formatc; // number of formats
+ const BASS_PLUGINFORM *formats; // the array of formats
+} BASS_PLUGININFO;
+
+// 3D vector (for 3D positions/velocities/orientations)
+typedef struct BASS_3DVECTOR {
+#ifdef __cplusplus
+ BASS_3DVECTOR() {};
+ BASS_3DVECTOR(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {};
+#endif
+ float x; // +=right, -=left
+ float y; // +=up, -=down
+ float z; // +=front, -=behind
+} BASS_3DVECTOR;
+
+// 3D channel modes
+#define BASS_3DMODE_NORMAL 0 // normal 3D processing
+#define BASS_3DMODE_RELATIVE 1 // position is relative to the listener
+#define BASS_3DMODE_OFF 2 // no 3D processing
+
+// software 3D mixing algorithms (used with BASS_CONFIG_3DALGORITHM)
+#define BASS_3DALG_DEFAULT 0
+#define BASS_3DALG_OFF 1
+#define BASS_3DALG_FULL 2
+#define BASS_3DALG_LIGHT 3
+
+// EAX environments, use with BASS_SetEAXParameters
+enum
+{
+ EAX_ENVIRONMENT_GENERIC,
+ EAX_ENVIRONMENT_PADDEDCELL,
+ EAX_ENVIRONMENT_ROOM,
+ EAX_ENVIRONMENT_BATHROOM,
+ EAX_ENVIRONMENT_LIVINGROOM,
+ EAX_ENVIRONMENT_STONEROOM,
+ EAX_ENVIRONMENT_AUDITORIUM,
+ EAX_ENVIRONMENT_CONCERTHALL,
+ EAX_ENVIRONMENT_CAVE,
+ EAX_ENVIRONMENT_ARENA,
+ EAX_ENVIRONMENT_HANGAR,
+ EAX_ENVIRONMENT_CARPETEDHALLWAY,
+ EAX_ENVIRONMENT_HALLWAY,
+ EAX_ENVIRONMENT_STONECORRIDOR,
+ EAX_ENVIRONMENT_ALLEY,
+ EAX_ENVIRONMENT_FOREST,
+ EAX_ENVIRONMENT_CITY,
+ EAX_ENVIRONMENT_MOUNTAINS,
+ EAX_ENVIRONMENT_QUARRY,
+ EAX_ENVIRONMENT_PLAIN,
+ EAX_ENVIRONMENT_PARKINGLOT,
+ EAX_ENVIRONMENT_SEWERPIPE,
+ EAX_ENVIRONMENT_UNDERWATER,
+ EAX_ENVIRONMENT_DRUGGED,
+ EAX_ENVIRONMENT_DIZZY,
+ EAX_ENVIRONMENT_PSYCHOTIC,
+
+ EAX_ENVIRONMENT_COUNT // total number of environments
+};
+
+// EAX presets, usage: BASS_SetEAXParameters(EAX_PRESET_xxx)
+#define EAX_PRESET_GENERIC EAX_ENVIRONMENT_GENERIC,0.5F,1.493F,0.5F
+#define EAX_PRESET_PADDEDCELL EAX_ENVIRONMENT_PADDEDCELL,0.25F,0.1F,0.0F
+#define EAX_PRESET_ROOM EAX_ENVIRONMENT_ROOM,0.417F,0.4F,0.666F
+#define EAX_PRESET_BATHROOM EAX_ENVIRONMENT_BATHROOM,0.653F,1.499F,0.166F
+#define EAX_PRESET_LIVINGROOM EAX_ENVIRONMENT_LIVINGROOM,0.208F,0.478F,0.0F
+#define EAX_PRESET_STONEROOM EAX_ENVIRONMENT_STONEROOM,0.5F,2.309F,0.888F
+#define EAX_PRESET_AUDITORIUM EAX_ENVIRONMENT_AUDITORIUM,0.403F,4.279F,0.5F
+#define EAX_PRESET_CONCERTHALL EAX_ENVIRONMENT_CONCERTHALL,0.5F,3.961F,0.5F
+#define EAX_PRESET_CAVE EAX_ENVIRONMENT_CAVE,0.5F,2.886F,1.304F
+#define EAX_PRESET_ARENA EAX_ENVIRONMENT_ARENA,0.361F,7.284F,0.332F
+#define EAX_PRESET_HANGAR EAX_ENVIRONMENT_HANGAR,0.5F,10.0F,0.3F
+#define EAX_PRESET_CARPETEDHALLWAY EAX_ENVIRONMENT_CARPETEDHALLWAY,0.153F,0.259F,2.0F
+#define EAX_PRESET_HALLWAY EAX_ENVIRONMENT_HALLWAY,0.361F,1.493F,0.0F
+#define EAX_PRESET_STONECORRIDOR EAX_ENVIRONMENT_STONECORRIDOR,0.444F,2.697F,0.638F
+#define EAX_PRESET_ALLEY EAX_ENVIRONMENT_ALLEY,0.25F,1.752F,0.776F
+#define EAX_PRESET_FOREST EAX_ENVIRONMENT_FOREST,0.111F,3.145F,0.472F
+#define EAX_PRESET_CITY EAX_ENVIRONMENT_CITY,0.111F,2.767F,0.224F
+#define EAX_PRESET_MOUNTAINS EAX_ENVIRONMENT_MOUNTAINS,0.194F,7.841F,0.472F
+#define EAX_PRESET_QUARRY EAX_ENVIRONMENT_QUARRY,1.0F,1.499F,0.5F
+#define EAX_PRESET_PLAIN EAX_ENVIRONMENT_PLAIN,0.097F,2.767F,0.224F
+#define EAX_PRESET_PARKINGLOT EAX_ENVIRONMENT_PARKINGLOT,0.208F,1.652F,1.5F
+#define EAX_PRESET_SEWERPIPE EAX_ENVIRONMENT_SEWERPIPE,0.652F,2.886F,0.25F
+#define EAX_PRESET_UNDERWATER EAX_ENVIRONMENT_UNDERWATER,1.0F,1.499F,0.0F
+#define EAX_PRESET_DRUGGED EAX_ENVIRONMENT_DRUGGED,0.875F,8.392F,1.388F
+#define EAX_PRESET_DIZZY EAX_ENVIRONMENT_DIZZY,0.139F,17.234F,0.666F
+#define EAX_PRESET_PSYCHOTIC EAX_ENVIRONMENT_PSYCHOTIC,0.486F,7.563F,0.806F
+
+typedef DWORD (CALLBACK STREAMPROC)(HSTREAM handle, void *buffer, DWORD length, void *user);
+/* User stream callback function. NOTE: A stream function should obviously be as quick
+as possible, other streams (and MOD musics) can't be mixed until it's finished.
+handle : The stream that needs writing
+buffer : Buffer to write the samples in
+length : Number of bytes to write
+user : The 'user' parameter value given when calling BASS_StreamCreate
+RETURN : Number of bytes written. Set the BASS_STREAMPROC_END flag to end
+ the stream. */
+
+#define BASS_STREAMPROC_END 0x80000000 // end of user stream flag
+
+// special STREAMPROCs
+#define STREAMPROC_DUMMY (STREAMPROC*)0 // "dummy" stream
+#define STREAMPROC_PUSH (STREAMPROC*)-1 // push stream
+
+// BASS_StreamCreateFileUser file systems
+#define STREAMFILE_NOBUFFER 0
+#define STREAMFILE_BUFFER 1
+#define STREAMFILE_BUFFERPUSH 2
+
+// User file stream callback functions
+typedef void (CALLBACK FILECLOSEPROC)(void *user);
+typedef QWORD (CALLBACK FILELENPROC)(void *user);
+typedef DWORD (CALLBACK FILEREADPROC)(void *buffer, DWORD length, void *user);
+typedef BOOL (CALLBACK FILESEEKPROC)(QWORD offset, void *user);
+
+typedef struct {
+ FILECLOSEPROC *close;
+ FILELENPROC *length;
+ FILEREADPROC *read;
+ FILESEEKPROC *seek;
+} BASS_FILEPROCS;
+
+// BASS_StreamPutFileData options
+#define BASS_FILEDATA_END 0 // end & close the file
+
+// BASS_StreamGetFilePosition modes
+#define BASS_FILEPOS_CURRENT 0
+#define BASS_FILEPOS_DECODE BASS_FILEPOS_CURRENT
+#define BASS_FILEPOS_DOWNLOAD 1
+#define BASS_FILEPOS_END 2
+#define BASS_FILEPOS_START 3
+#define BASS_FILEPOS_CONNECTED 4
+#define BASS_FILEPOS_BUFFER 5
+#define BASS_FILEPOS_SOCKET 6
+
+typedef void (CALLBACK DOWNLOADPROC)(const void *buffer, DWORD length, void *user);
+/* Internet stream download callback function.
+buffer : Buffer containing the downloaded data... NULL=end of download
+length : Number of bytes in the buffer
+user : The 'user' parameter value given when calling BASS_StreamCreateURL */
+
+// BASS_ChannelSetSync types
+#define BASS_SYNC_POS 0
+#define BASS_SYNC_END 2
+#define BASS_SYNC_META 4
+#define BASS_SYNC_SLIDE 5
+#define BASS_SYNC_STALL 6
+#define BASS_SYNC_DOWNLOAD 7
+#define BASS_SYNC_FREE 8
+#define BASS_SYNC_SETPOS 11
+#define BASS_SYNC_MUSICPOS 10
+#define BASS_SYNC_MUSICINST 1
+#define BASS_SYNC_MUSICFX 3
+#define BASS_SYNC_OGG_CHANGE 12
+#define BASS_SYNC_MIXTIME 0x40000000 // FLAG: sync at mixtime, else at playtime
+#define BASS_SYNC_ONETIME 0x80000000 // FLAG: sync only once, else continuously
+
+typedef void (CALLBACK SYNCPROC)(HSYNC handle, DWORD channel, DWORD data, void *user);
+/* Sync callback function. NOTE: a sync callback function should be very
+quick as other syncs can't be processed until it has finished. If the sync
+is a "mixtime" sync, then other streams and MOD musics can't be mixed until
+it's finished either.
+handle : The sync that has occured
+channel: Channel that the sync occured in
+data : Additional data associated with the sync's occurance
+user : The 'user' parameter given when calling BASS_ChannelSetSync */
+
+typedef void (CALLBACK DSPPROC)(HDSP handle, DWORD channel, void *buffer, DWORD length, void *user);
+/* DSP callback function. NOTE: A DSP function should obviously be as quick as
+possible... other DSP functions, streams and MOD musics can not be processed
+until it's finished.
+handle : The DSP handle
+channel: Channel that the DSP is being applied to
+buffer : Buffer to apply the DSP to
+length : Number of bytes in the buffer
+user : The 'user' parameter given when calling BASS_ChannelSetDSP */
+
+typedef BOOL (CALLBACK RECORDPROC)(HRECORD handle, const void *buffer, DWORD length, void *user);
+/* Recording callback function.
+handle : The recording handle
+buffer : Buffer containing the recorded sample data
+length : Number of bytes
+user : The 'user' parameter value given when calling BASS_RecordStart
+RETURN : TRUE = continue recording, FALSE = stop */
+
+// BASS_ChannelIsActive return values
+#define BASS_ACTIVE_STOPPED 0
+#define BASS_ACTIVE_PLAYING 1
+#define BASS_ACTIVE_STALLED 2
+#define BASS_ACTIVE_PAUSED 3
+
+// Channel attributes
+#define BASS_ATTRIB_FREQ 1
+#define BASS_ATTRIB_VOL 2
+#define BASS_ATTRIB_PAN 3
+#define BASS_ATTRIB_EAXMIX 4
+#define BASS_ATTRIB_NOBUFFER 5
+#define BASS_ATTRIB_CPU 7
+#define BASS_ATTRIB_SRC 8
+#define BASS_ATTRIB_MUSIC_AMPLIFY 0x100
+#define BASS_ATTRIB_MUSIC_PANSEP 0x101
+#define BASS_ATTRIB_MUSIC_PSCALER 0x102
+#define BASS_ATTRIB_MUSIC_BPM 0x103
+#define BASS_ATTRIB_MUSIC_SPEED 0x104
+#define BASS_ATTRIB_MUSIC_VOL_GLOBAL 0x105
+#define BASS_ATTRIB_MUSIC_VOL_CHAN 0x200 // + channel #
+#define BASS_ATTRIB_MUSIC_VOL_INST 0x300 // + instrument #
+
+// BASS_ChannelGetData flags
+#define BASS_DATA_AVAILABLE 0 // query how much data is buffered
+#define BASS_DATA_FLOAT 0x40000000 // flag: return floating-point sample data
+#define BASS_DATA_FFT256 0x80000000 // 256 sample FFT
+#define BASS_DATA_FFT512 0x80000001 // 512 FFT
+#define BASS_DATA_FFT1024 0x80000002 // 1024 FFT
+#define BASS_DATA_FFT2048 0x80000003 // 2048 FFT
+#define BASS_DATA_FFT4096 0x80000004 // 4096 FFT
+#define BASS_DATA_FFT8192 0x80000005 // 8192 FFT
+#define BASS_DATA_FFT16384 0x80000006 // 16384 FFT
+#define BASS_DATA_FFT_INDIVIDUAL 0x10 // FFT flag: FFT for each channel, else all combined
+#define BASS_DATA_FFT_NOWINDOW 0x20 // FFT flag: no Hanning window
+#define BASS_DATA_FFT_REMOVEDC 0x40 // FFT flag: pre-remove DC bias
+#define BASS_DATA_FFT_COMPLEX 0x80 // FFT flag: return complex data
+
+// BASS_ChannelGetTags types : what's returned
+#define BASS_TAG_ID3 0 // ID3v1 tags : TAG_ID3 structure
+#define BASS_TAG_ID3V2 1 // ID3v2 tags : variable length block
+#define BASS_TAG_OGG 2 // OGG comments : series of null-terminated UTF-8 strings
+#define BASS_TAG_HTTP 3 // HTTP headers : series of null-terminated ANSI strings
+#define BASS_TAG_ICY 4 // ICY headers : series of null-terminated ANSI strings
+#define BASS_TAG_META 5 // ICY metadata : ANSI string
+#define BASS_TAG_APE 6 // APE tags : series of null-terminated UTF-8 strings
+#define BASS_TAG_MP4 7 // MP4/iTunes metadata : series of null-terminated UTF-8 strings
+#define BASS_TAG_VENDOR 9 // OGG encoder : UTF-8 string
+#define BASS_TAG_LYRICS3 10 // Lyric3v2 tag : ASCII string
+#define BASS_TAG_CA_CODEC 11 // CoreAudio codec info : TAG_CA_CODEC structure
+#define BASS_TAG_MF 13 // Media Foundation tags : series of null-terminated UTF-8 strings
+#define BASS_TAG_WAVEFORMAT 14 // WAVE format : WAVEFORMATEEX structure
+#define BASS_TAG_RIFF_INFO 0x100 // RIFF "INFO" tags : series of null-terminated ANSI strings
+#define BASS_TAG_RIFF_BEXT 0x101 // RIFF/BWF "bext" tags : TAG_BEXT structure
+#define BASS_TAG_RIFF_CART 0x102 // RIFF/BWF "cart" tags : TAG_CART structure
+#define BASS_TAG_RIFF_DISP 0x103 // RIFF "DISP" text tag : ANSI string
+#define BASS_TAG_APE_BINARY 0x1000 // + index #, binary APE tag : TAG_APE_BINARY structure
+#define BASS_TAG_MUSIC_NAME 0x10000 // MOD music name : ANSI string
+#define BASS_TAG_MUSIC_MESSAGE 0x10001 // MOD message : ANSI string
+#define BASS_TAG_MUSIC_ORDERS 0x10002 // MOD order list : BYTE array of pattern numbers
+#define BASS_TAG_MUSIC_INST 0x10100 // + instrument #, MOD instrument name : ANSI string
+#define BASS_TAG_MUSIC_SAMPLE 0x10300 // + sample #, MOD sample name : ANSI string
+
+// ID3v1 tag structure
+typedef struct {
+ char id[3];
+ char title[30];
+ char artist[30];
+ char album[30];
+ char year[4];
+ char comment[30];
+ BYTE genre;
+} TAG_ID3;
+
+// Binary APE tag structure
+typedef struct {
+ const char *key;
+ const void *data;
+ DWORD length;
+} TAG_APE_BINARY;
+
+// BWF "bext" tag structure
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable:4200)
+#endif
+#pragma pack(push,1)
+typedef struct {
+ char Description[256]; // description
+ char Originator[32]; // name of the originator
+ char OriginatorReference[32]; // reference of the originator
+ char OriginationDate[10]; // date of creation (yyyy-mm-dd)
+ char OriginationTime[8]; // time of creation (hh-mm-ss)
+ QWORD TimeReference; // first sample count since midnight (little-endian)
+ WORD Version; // BWF version (little-endian)
+ BYTE UMID[64]; // SMPTE UMID
+ BYTE Reserved[190];
+#if defined(__GNUC__) && __GNUC__<3
+ char CodingHistory[0]; // history
+#elif 1 // change to 0 if compiler fails the following line
+ char CodingHistory[]; // history
+#else
+ char CodingHistory[1]; // history
+#endif
+} TAG_BEXT;
+#pragma pack(pop)
+
+// BWF "cart" tag structures
+typedef struct
+{
+ DWORD dwUsage; // FOURCC timer usage ID
+ DWORD dwValue; // timer value in samples from head
+} TAG_CART_TIMER;
+
+typedef struct
+{
+ char Version[4]; // version of the data structure
+ char Title[64]; // title of cart audio sequence
+ char Artist[64]; // artist or creator name
+ char CutID[64]; // cut number identification
+ char ClientID[64]; // client identification
+ char Category[64]; // category ID, PSA, NEWS, etc
+ char Classification[64]; // classification or auxiliary key
+ char OutCue[64]; // out cue text
+ char StartDate[10]; // yyyy-mm-dd
+ char StartTime[8]; // hh:mm:ss
+ char EndDate[10]; // yyyy-mm-dd
+ char EndTime[8]; // hh:mm:ss
+ char ProducerAppID[64]; // name of vendor or application
+ char ProducerAppVersion[64]; // version of producer application
+ char UserDef[64]; // user defined text
+ DWORD dwLevelReference; // sample value for 0 dB reference
+ TAG_CART_TIMER PostTimer[8]; // 8 time markers after head
+ char Reserved[276];
+ char URL[1024]; // uniform resource locator
+#if defined(__GNUC__) && __GNUC__<3
+ char TagText[0]; // free form text for scripts or tags
+#elif 1 // change to 0 if compiler fails the following line
+ char TagText[]; // free form text for scripts or tags
+#else
+ char TagText[1]; // free form text for scripts or tags
+#endif
+} TAG_CART;
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
+// CoreAudio codec info structure
+typedef struct {
+ DWORD ftype; // file format
+ DWORD atype; // audio format
+ const char *name; // description
+} TAG_CA_CODEC;
+
+#ifndef _WAVEFORMATEX_
+#define _WAVEFORMATEX_
+#pragma pack(push,1)
+typedef struct tWAVEFORMATEX
+{
+ WORD wFormatTag;
+ WORD nChannels;
+ DWORD nSamplesPerSec;
+ DWORD nAvgBytesPerSec;
+ WORD nBlockAlign;
+ WORD wBitsPerSample;
+ WORD cbSize;
+} WAVEFORMATEX, *PWAVEFORMATEX, *LPWAVEFORMATEX;
+typedef const WAVEFORMATEX *LPCWAVEFORMATEX;
+#pragma pack(pop)
+#endif
+
+// BASS_ChannelGetLength/GetPosition/SetPosition modes
+#define BASS_POS_BYTE 0 // byte position
+#define BASS_POS_MUSIC_ORDER 1 // order.row position, MAKELONG(order,row)
+#define BASS_POS_OGG 3 // OGG bitstream number
+#define BASS_POS_DECODE 0x10000000 // flag: get the decoding (not playing) position
+#define BASS_POS_DECODETO 0x20000000 // flag: decode to the position instead of seeking
+
+// BASS_RecordSetInput flags
+#define BASS_INPUT_OFF 0x10000
+#define BASS_INPUT_ON 0x20000
+
+#define BASS_INPUT_TYPE_MASK 0xff000000
+#define BASS_INPUT_TYPE_UNDEF 0x00000000
+#define BASS_INPUT_TYPE_DIGITAL 0x01000000
+#define BASS_INPUT_TYPE_LINE 0x02000000
+#define BASS_INPUT_TYPE_MIC 0x03000000
+#define BASS_INPUT_TYPE_SYNTH 0x04000000
+#define BASS_INPUT_TYPE_CD 0x05000000
+#define BASS_INPUT_TYPE_PHONE 0x06000000
+#define BASS_INPUT_TYPE_SPEAKER 0x07000000
+#define BASS_INPUT_TYPE_WAVE 0x08000000
+#define BASS_INPUT_TYPE_AUX 0x09000000
+#define BASS_INPUT_TYPE_ANALOG 0x0a000000
+
+// DX8 effect types, use with BASS_ChannelSetFX
+enum
+{
+ BASS_FX_DX8_CHORUS,
+ BASS_FX_DX8_COMPRESSOR,
+ BASS_FX_DX8_DISTORTION,
+ BASS_FX_DX8_ECHO,
+ BASS_FX_DX8_FLANGER,
+ BASS_FX_DX8_GARGLE,
+ BASS_FX_DX8_I3DL2REVERB,
+ BASS_FX_DX8_PARAMEQ,
+ BASS_FX_DX8_REVERB
+};
+
+typedef struct {
+ float fWetDryMix;
+ float fDepth;
+ float fFeedback;
+ float fFrequency;
+ DWORD lWaveform; // 0=triangle, 1=sine
+ float fDelay;
+ DWORD lPhase; // BASS_DX8_PHASE_xxx
+} BASS_DX8_CHORUS;
+
+typedef struct {
+ float fGain;
+ float fAttack;
+ float fRelease;
+ float fThreshold;
+ float fRatio;
+ float fPredelay;
+} BASS_DX8_COMPRESSOR;
+
+typedef struct {
+ float fGain;
+ float fEdge;
+ float fPostEQCenterFrequency;
+ float fPostEQBandwidth;
+ float fPreLowpassCutoff;
+} BASS_DX8_DISTORTION;
+
+typedef struct {
+ float fWetDryMix;
+ float fFeedback;
+ float fLeftDelay;
+ float fRightDelay;
+ BOOL lPanDelay;
+} BASS_DX8_ECHO;
+
+typedef struct {
+ float fWetDryMix;
+ float fDepth;
+ float fFeedback;
+ float fFrequency;
+ DWORD lWaveform; // 0=triangle, 1=sine
+ float fDelay;
+ DWORD lPhase; // BASS_DX8_PHASE_xxx
+} BASS_DX8_FLANGER;
+
+typedef struct {
+ DWORD dwRateHz; // Rate of modulation in hz
+ DWORD dwWaveShape; // 0=triangle, 1=square
+} BASS_DX8_GARGLE;
+
+typedef struct {
+ int lRoom; // [-10000, 0] default: -1000 mB
+ int lRoomHF; // [-10000, 0] default: 0 mB
+ float flRoomRolloffFactor; // [0.0, 10.0] default: 0.0
+ float flDecayTime; // [0.1, 20.0] default: 1.49s
+ float flDecayHFRatio; // [0.1, 2.0] default: 0.83
+ int lReflections; // [-10000, 1000] default: -2602 mB
+ float flReflectionsDelay; // [0.0, 0.3] default: 0.007 s
+ int lReverb; // [-10000, 2000] default: 200 mB
+ float flReverbDelay; // [0.0, 0.1] default: 0.011 s
+ float flDiffusion; // [0.0, 100.0] default: 100.0 %
+ float flDensity; // [0.0, 100.0] default: 100.0 %
+ float flHFReference; // [20.0, 20000.0] default: 5000.0 Hz
+} BASS_DX8_I3DL2REVERB;
+
+typedef struct {
+ float fCenter;
+ float fBandwidth;
+ float fGain;
+} BASS_DX8_PARAMEQ;
+
+typedef struct {
+ float fInGain; // [-96.0,0.0] default: 0.0 dB
+ float fReverbMix; // [-96.0,0.0] default: 0.0 db
+ float fReverbTime; // [0.001,3000.0] default: 1000.0 ms
+ float fHighFreqRTRatio; // [0.001,0.999] default: 0.001
+} BASS_DX8_REVERB;
+
+#define BASS_DX8_PHASE_NEG_180 0
+#define BASS_DX8_PHASE_NEG_90 1
+#define BASS_DX8_PHASE_ZERO 2
+#define BASS_DX8_PHASE_90 3
+#define BASS_DX8_PHASE_180 4
+
+typedef void (CALLBACK IOSNOTIFYPROC)(DWORD status);
+/* iOS notification callback function.
+status : The notification (BASS_IOSNOTIFY_xxx) */
+
+#define BASS_IOSNOTIFY_INTERRUPT 1 // interruption started
+#define BASS_IOSNOTIFY_INTERRUPT_END 2 // interruption ended
+
+BOOL BASSDEF(BASS_SetConfig)(DWORD option, DWORD value);
+DWORD BASSDEF(BASS_GetConfig)(DWORD option);
+BOOL BASSDEF(BASS_SetConfigPtr)(DWORD option, const void *value);
+void *BASSDEF(BASS_GetConfigPtr)(DWORD option);
+DWORD BASSDEF(BASS_GetVersion)();
+int BASSDEF(BASS_ErrorGetCode)();
+BOOL BASSDEF(BASS_GetDeviceInfo)(DWORD device, BASS_DEVICEINFO *info);
+#if defined(_WIN32) && !defined(_WIN32_WCE)
+BOOL BASSDEF(BASS_Init)(int device, DWORD freq, DWORD flags, HWND win, const GUID *dsguid);
+#else
+BOOL BASSDEF(BASS_Init)(int device, DWORD freq, DWORD flags, void *win, void *dsguid);
+#endif
+BOOL BASSDEF(BASS_SetDevice)(DWORD device);
+DWORD BASSDEF(BASS_GetDevice)();
+BOOL BASSDEF(BASS_Free)();
+#if defined(_WIN32) && !defined(_WIN32_WCE)
+void *BASSDEF(BASS_GetDSoundObject)(DWORD object);
+#endif
+BOOL BASSDEF(BASS_GetInfo)(BASS_INFO *info);
+BOOL BASSDEF(BASS_Update)(DWORD length);
+float BASSDEF(BASS_GetCPU)();
+BOOL BASSDEF(BASS_Start)();
+BOOL BASSDEF(BASS_Stop)();
+BOOL BASSDEF(BASS_Pause)();
+BOOL BASSDEF(BASS_SetVolume)(float volume);
+float BASSDEF(BASS_GetVolume)();
+
+HPLUGIN BASSDEF(BASS_PluginLoad)(const char *file, DWORD flags);
+BOOL BASSDEF(BASS_PluginFree)(HPLUGIN handle);
+const BASS_PLUGININFO *BASSDEF(BASS_PluginGetInfo)(HPLUGIN handle);
+
+BOOL BASSDEF(BASS_Set3DFactors)(float distf, float rollf, float doppf);
+BOOL BASSDEF(BASS_Get3DFactors)(float *distf, float *rollf, float *doppf);
+BOOL BASSDEF(BASS_Set3DPosition)(const BASS_3DVECTOR *pos, const BASS_3DVECTOR *vel, const BASS_3DVECTOR *front, const BASS_3DVECTOR *top);
+BOOL BASSDEF(BASS_Get3DPosition)(BASS_3DVECTOR *pos, BASS_3DVECTOR *vel, BASS_3DVECTOR *front, BASS_3DVECTOR *top);
+void BASSDEF(BASS_Apply3D)();
+#if defined(_WIN32) && !defined(_WIN32_WCE)
+BOOL BASSDEF(BASS_SetEAXParameters)(int env, float vol, float decay, float damp);
+BOOL BASSDEF(BASS_GetEAXParameters)(DWORD *env, float *vol, float *decay, float *damp);
+#endif
+
+HMUSIC BASSDEF(BASS_MusicLoad)(BOOL mem, const void *file, QWORD offset, DWORD length, DWORD flags, DWORD freq);
+BOOL BASSDEF(BASS_MusicFree)(HMUSIC handle);
+
+HSAMPLE BASSDEF(BASS_SampleLoad)(BOOL mem, const void *file, QWORD offset, DWORD length, DWORD max, DWORD flags);
+HSAMPLE BASSDEF(BASS_SampleCreate)(DWORD length, DWORD freq, DWORD chans, DWORD max, DWORD flags);
+BOOL BASSDEF(BASS_SampleFree)(HSAMPLE handle);
+BOOL BASSDEF(BASS_SampleSetData)(HSAMPLE handle, const void *buffer);
+BOOL BASSDEF(BASS_SampleGetData)(HSAMPLE handle, void *buffer);
+BOOL BASSDEF(BASS_SampleGetInfo)(HSAMPLE handle, BASS_SAMPLE *info);
+BOOL BASSDEF(BASS_SampleSetInfo)(HSAMPLE handle, const BASS_SAMPLE *info);
+HCHANNEL BASSDEF(BASS_SampleGetChannel)(HSAMPLE handle, BOOL onlynew);
+DWORD BASSDEF(BASS_SampleGetChannels)(HSAMPLE handle, HCHANNEL *channels);
+BOOL BASSDEF(BASS_SampleStop)(HSAMPLE handle);
+
+HSTREAM BASSDEF(BASS_StreamCreate)(DWORD freq, DWORD chans, DWORD flags, STREAMPROC *proc, void *user);
+HSTREAM BASSDEF(BASS_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags);
+HSTREAM BASSDEF(BASS_StreamCreateURL)(const char *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user);
+HSTREAM BASSDEF(BASS_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *proc, void *user);
+BOOL BASSDEF(BASS_StreamFree)(HSTREAM handle);
+QWORD BASSDEF(BASS_StreamGetFilePosition)(HSTREAM handle, DWORD mode);
+DWORD BASSDEF(BASS_StreamPutData)(HSTREAM handle, const void *buffer, DWORD length);
+DWORD BASSDEF(BASS_StreamPutFileData)(HSTREAM handle, const void *buffer, DWORD length);
+
+BOOL BASSDEF(BASS_RecordGetDeviceInfo)(DWORD device, BASS_DEVICEINFO *info);
+BOOL BASSDEF(BASS_RecordInit)(int device);
+BOOL BASSDEF(BASS_RecordSetDevice)(DWORD device);
+DWORD BASSDEF(BASS_RecordGetDevice)();
+BOOL BASSDEF(BASS_RecordFree)();
+BOOL BASSDEF(BASS_RecordGetInfo)(BASS_RECORDINFO *info);
+const char *BASSDEF(BASS_RecordGetInputName)(int input);
+BOOL BASSDEF(BASS_RecordSetInput)(int input, DWORD flags, float volume);
+DWORD BASSDEF(BASS_RecordGetInput)(int input, float *volume);
+HRECORD BASSDEF(BASS_RecordStart)(DWORD freq, DWORD chans, DWORD flags, RECORDPROC *proc, void *user);
+
+double BASSDEF(BASS_ChannelBytes2Seconds)(DWORD handle, QWORD pos);
+QWORD BASSDEF(BASS_ChannelSeconds2Bytes)(DWORD handle, double pos);
+DWORD BASSDEF(BASS_ChannelGetDevice)(DWORD handle);
+BOOL BASSDEF(BASS_ChannelSetDevice)(DWORD handle, DWORD device);
+DWORD BASSDEF(BASS_ChannelIsActive)(DWORD handle);
+BOOL BASSDEF(BASS_ChannelGetInfo)(DWORD handle, BASS_CHANNELINFO *info);
+const char *BASSDEF(BASS_ChannelGetTags)(DWORD handle, DWORD tags);
+DWORD BASSDEF(BASS_ChannelFlags)(DWORD handle, DWORD flags, DWORD mask);
+BOOL BASSDEF(BASS_ChannelUpdate)(DWORD handle, DWORD length);
+BOOL BASSDEF(BASS_ChannelLock)(DWORD handle, BOOL lock);
+BOOL BASSDEF(BASS_ChannelPlay)(DWORD handle, BOOL restart);
+BOOL BASSDEF(BASS_ChannelStop)(DWORD handle);
+BOOL BASSDEF(BASS_ChannelPause)(DWORD handle);
+BOOL BASSDEF(BASS_ChannelSetAttribute)(DWORD handle, DWORD attrib, float value);
+BOOL BASSDEF(BASS_ChannelGetAttribute)(DWORD handle, DWORD attrib, float *value);
+BOOL BASSDEF(BASS_ChannelSlideAttribute)(DWORD handle, DWORD attrib, float value, DWORD time);
+BOOL BASSDEF(BASS_ChannelIsSliding)(DWORD handle, DWORD attrib);
+BOOL BASSDEF(BASS_ChannelSet3DAttributes)(DWORD handle, int mode, float min, float max, int iangle, int oangle, float outvol);
+BOOL BASSDEF(BASS_ChannelGet3DAttributes)(DWORD handle, DWORD *mode, float *min, float *max, DWORD *iangle, DWORD *oangle, float *outvol);
+BOOL BASSDEF(BASS_ChannelSet3DPosition)(DWORD handle, const BASS_3DVECTOR *pos, const BASS_3DVECTOR *orient, const BASS_3DVECTOR *vel);
+BOOL BASSDEF(BASS_ChannelGet3DPosition)(DWORD handle, BASS_3DVECTOR *pos, BASS_3DVECTOR *orient, BASS_3DVECTOR *vel);
+QWORD BASSDEF(BASS_ChannelGetLength)(DWORD handle, DWORD mode);
+BOOL BASSDEF(BASS_ChannelSetPosition)(DWORD handle, QWORD pos, DWORD mode);
+QWORD BASSDEF(BASS_ChannelGetPosition)(DWORD handle, DWORD mode);
+DWORD BASSDEF(BASS_ChannelGetLevel)(DWORD handle);
+DWORD BASSDEF(BASS_ChannelGetData)(DWORD handle, void *buffer, DWORD length);
+HSYNC BASSDEF(BASS_ChannelSetSync)(DWORD handle, DWORD type, QWORD param, SYNCPROC *proc, void *user);
+BOOL BASSDEF(BASS_ChannelRemoveSync)(DWORD handle, HSYNC sync);
+HDSP BASSDEF(BASS_ChannelSetDSP)(DWORD handle, DSPPROC *proc, void *user, int priority);
+BOOL BASSDEF(BASS_ChannelRemoveDSP)(DWORD handle, HDSP dsp);
+BOOL BASSDEF(BASS_ChannelSetLink)(DWORD handle, DWORD chan);
+BOOL BASSDEF(BASS_ChannelRemoveLink)(DWORD handle, DWORD chan);
+HFX BASSDEF(BASS_ChannelSetFX)(DWORD handle, DWORD type, int priority);
+BOOL BASSDEF(BASS_ChannelRemoveFX)(DWORD handle, HFX fx);
+
+BOOL BASSDEF(BASS_FXSetParameters)(HFX handle, const void *params);
+BOOL BASSDEF(BASS_FXGetParameters)(HFX handle, void *params);
+BOOL BASSDEF(BASS_FXReset)(HFX handle);
+
+#ifdef __cplusplus
+}
+
+#ifdef _WIN32
+static inline HPLUGIN BASS_PluginLoad(const WCHAR *file, DWORD flags)
+{
+ return BASS_PluginLoad((const char*)file, flags|BASS_UNICODE);
+}
+
+static inline HMUSIC BASS_MusicLoad(BOOL mem, const WCHAR *file, QWORD offset, DWORD length, DWORD flags, DWORD freq)
+{
+ return BASS_MusicLoad(mem, (const void*)file, offset, length, flags|BASS_UNICODE, freq);
+}
+
+static inline HSAMPLE BASS_SampleLoad(BOOL mem, const WCHAR *file, QWORD offset, DWORD length, DWORD max, DWORD flags)
+{
+ return BASS_SampleLoad(mem, (const void*)file, offset, length, max, flags|BASS_UNICODE);
+}
+
+static inline HSTREAM BASS_StreamCreateFile(BOOL mem, const WCHAR *file, QWORD offset, QWORD length, DWORD flags)
+{
+ return BASS_StreamCreateFile(mem, (const void*)file, offset, length, flags|BASS_UNICODE);
+}
+
+static inline HSTREAM BASS_StreamCreateURL(const WCHAR *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user)
+{
+ return BASS_StreamCreateURL((const char*)url, offset, flags|BASS_UNICODE, proc, user);
+}
+#endif
+#endif
+
+#endif
diff --git a/ThirdParty/BASS/bassmidi.h b/ThirdParty/BASS/bassmidi.h
new file mode 100644
index 000000000..727f7aec9
--- /dev/null
+++ b/ThirdParty/BASS/bassmidi.h
@@ -0,0 +1,301 @@
+/*
+ BASSMIDI 2.4 C/C++ header file
+ Copyright (c) 2006-2013 Un4seen Developments Ltd.
+
+ See the BASSMIDI.CHM file for more detailed documentation
+*/
+
+#ifndef BASSMIDI_H
+#define BASSMIDI_H
+
+#include "bass.h"
+
+#if BASSVERSION!=0x204
+#error conflicting BASS and BASSMIDI versions
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef BASSMIDIDEF
+#define BASSMIDIDEF(f) WINAPI f
+#endif
+
+typedef DWORD HSOUNDFONT; // soundfont handle
+
+// Additional BASS_SetConfig options
+#define BASS_CONFIG_MIDI_COMPACT 0x10400
+#define BASS_CONFIG_MIDI_VOICES 0x10401
+#define BASS_CONFIG_MIDI_AUTOFONT 0x10402
+
+// Additional BASS_SetConfigPtr options
+#define BASS_CONFIG_MIDI_DEFFONT 0x10403
+
+// Additional sync types
+#define BASS_SYNC_MIDI_MARK 0x10000
+#define BASS_SYNC_MIDI_MARKER 0x10000
+#define BASS_SYNC_MIDI_CUE 0x10001
+#define BASS_SYNC_MIDI_LYRIC 0x10002
+#define BASS_SYNC_MIDI_TEXT 0x10003
+#define BASS_SYNC_MIDI_EVENT 0x10004
+#define BASS_SYNC_MIDI_TICK 0x10005
+#define BASS_SYNC_MIDI_TIMESIG 0x10006
+#define BASS_SYNC_MIDI_KEYSIG 0x10007
+
+// Additional BASS_MIDI_StreamCreateFile/etc flags
+#define BASS_MIDI_DECAYEND 0x1000
+#define BASS_MIDI_NOFX 0x2000
+#define BASS_MIDI_DECAYSEEK 0x4000
+#define BASS_MIDI_NOCROP 0x8000
+#define BASS_MIDI_SINCINTER 0x800000
+
+// BASS_MIDI_FontInit flags
+#define BASS_MIDI_FONT_MEM 0x10000
+#define BASS_MIDI_FONT_MMAP 0x20000
+
+typedef struct {
+ HSOUNDFONT font; // soundfont
+ int preset; // preset number (-1=all)
+ int bank;
+} BASS_MIDI_FONT;
+
+typedef struct {
+ HSOUNDFONT font; // soundfont
+ int spreset; // source preset number
+ int sbank; // source bank number
+ int dpreset; // destination preset/program number
+ int dbank; // destination bank number
+ int dbanklsb; // destination bank number LSB
+} BASS_MIDI_FONTEX;
+
+// BASS_MIDI_StreamSet/GetFonts flag
+#define BASS_MIDI_FONT_EX 0x1000000 // BASS_MIDI_FONTEX
+
+typedef struct {
+ const char *name;
+ const char *copyright;
+ const char *comment;
+ DWORD presets; // number of presets/instruments
+ DWORD samsize; // total size (in bytes) of the sample data
+ DWORD samload; // amount of sample data currently loaded
+ DWORD samtype; // sample format (CTYPE) if packed
+} BASS_MIDI_FONTINFO;
+
+typedef struct {
+ DWORD track; // track containing marker
+ DWORD pos; // marker position
+ const char *text; // marker text
+} BASS_MIDI_MARK;
+
+// Marker types
+#define BASS_MIDI_MARK_MARKER 0 // marker
+#define BASS_MIDI_MARK_CUE 1 // cue point
+#define BASS_MIDI_MARK_LYRIC 2 // lyric
+#define BASS_MIDI_MARK_TEXT 3 // text
+#define BASS_MIDI_MARK_TIMESIG 4 // time signature
+#define BASS_MIDI_MARK_KEYSIG 5 // key signature
+#define BASS_MIDI_MARK_COPY 6 // copyright notice
+#define BASS_MIDI_MARK_TRACK 7 // track name
+#define BASS_MIDI_MARK_INST 8 // instrument name
+#define BASS_MIDI_MARK_TICK 0x10000 // FLAG: get position in ticks (otherwise bytes)
+
+// MIDI events
+#define MIDI_EVENT_NOTE 1
+#define MIDI_EVENT_PROGRAM 2
+#define MIDI_EVENT_CHANPRES 3
+#define MIDI_EVENT_PITCH 4
+#define MIDI_EVENT_PITCHRANGE 5
+#define MIDI_EVENT_DRUMS 6
+#define MIDI_EVENT_FINETUNE 7
+#define MIDI_EVENT_COARSETUNE 8
+#define MIDI_EVENT_MASTERVOL 9
+#define MIDI_EVENT_BANK 10
+#define MIDI_EVENT_MODULATION 11
+#define MIDI_EVENT_VOLUME 12
+#define MIDI_EVENT_PAN 13
+#define MIDI_EVENT_EXPRESSION 14
+#define MIDI_EVENT_SUSTAIN 15
+#define MIDI_EVENT_SOUNDOFF 16
+#define MIDI_EVENT_RESET 17
+#define MIDI_EVENT_NOTESOFF 18
+#define MIDI_EVENT_PORTAMENTO 19
+#define MIDI_EVENT_PORTATIME 20
+#define MIDI_EVENT_PORTANOTE 21
+#define MIDI_EVENT_MODE 22
+#define MIDI_EVENT_REVERB 23
+#define MIDI_EVENT_CHORUS 24
+#define MIDI_EVENT_CUTOFF 25
+#define MIDI_EVENT_RESONANCE 26
+#define MIDI_EVENT_RELEASE 27
+#define MIDI_EVENT_ATTACK 28
+#define MIDI_EVENT_REVERB_MACRO 30
+#define MIDI_EVENT_CHORUS_MACRO 31
+#define MIDI_EVENT_REVERB_TIME 32
+#define MIDI_EVENT_REVERB_DELAY 33
+#define MIDI_EVENT_REVERB_LOCUTOFF 34
+#define MIDI_EVENT_REVERB_HICUTOFF 35
+#define MIDI_EVENT_REVERB_LEVEL 36
+#define MIDI_EVENT_CHORUS_DELAY 37
+#define MIDI_EVENT_CHORUS_DEPTH 38
+#define MIDI_EVENT_CHORUS_RATE 39
+#define MIDI_EVENT_CHORUS_FEEDBACK 40
+#define MIDI_EVENT_CHORUS_LEVEL 41
+#define MIDI_EVENT_CHORUS_REVERB 42
+#define MIDI_EVENT_DRUM_FINETUNE 50
+#define MIDI_EVENT_DRUM_COARSETUNE 51
+#define MIDI_EVENT_DRUM_PAN 52
+#define MIDI_EVENT_DRUM_REVERB 53
+#define MIDI_EVENT_DRUM_CHORUS 54
+#define MIDI_EVENT_DRUM_CUTOFF 55
+#define MIDI_EVENT_DRUM_RESONANCE 56
+#define MIDI_EVENT_DRUM_LEVEL 57
+#define MIDI_EVENT_SOFT 60
+#define MIDI_EVENT_SYSTEM 61
+#define MIDI_EVENT_TEMPO 62
+#define MIDI_EVENT_SCALETUNING 63
+#define MIDI_EVENT_CONTROL 64
+#define MIDI_EVENT_CHANPRES_VIBRATO 65
+#define MIDI_EVENT_CHANPRES_PITCH 66
+#define MIDI_EVENT_CHANPRES_FILTER 67
+#define MIDI_EVENT_CHANPRES_VOLUME 68
+#define MIDI_EVENT_MODRANGE 69
+#define MIDI_EVENT_BANK_LSB 70
+#define MIDI_EVENT_MIXLEVEL 0x10000
+#define MIDI_EVENT_TRANSPOSE 0x10001
+#define MIDI_EVENT_SYSTEMEX 0x10002
+
+#define MIDI_EVENT_END 0
+#define MIDI_EVENT_END_TRACK 0x10003
+
+#define MIDI_SYSTEM_DEFAULT 0
+#define MIDI_SYSTEM_GM1 1
+#define MIDI_SYSTEM_GM2 2
+#define MIDI_SYSTEM_XG 3
+#define MIDI_SYSTEM_GS 4
+
+typedef struct {
+ DWORD event; // MIDI_EVENT_xxx
+ DWORD param;
+ DWORD chan;
+ DWORD tick; // event position (ticks)
+ DWORD pos; // event position (bytes)
+} BASS_MIDI_EVENT;
+
+// BASS_MIDI_StreamEvents modes
+#define BASS_MIDI_EVENTS_STRUCT 0 // BASS_MIDI_EVENT structures
+#define BASS_MIDI_EVENTS_RAW 0x10000 // raw MIDI event data
+#define BASS_MIDI_EVENTS_SYNC 0x1000000 // FLAG: trigger event syncs
+
+// BASS_CHANNELINFO type
+#define BASS_CTYPE_STREAM_MIDI 0x10d00
+
+// Additional attributes
+#define BASS_ATTRIB_MIDI_PPQN 0x12000
+#define BASS_ATTRIB_MIDI_CPU 0x12001
+#define BASS_ATTRIB_MIDI_CHANS 0x12002
+#define BASS_ATTRIB_MIDI_VOICES 0x12003
+#define BASS_ATTRIB_MIDI_VOICES_ACTIVE 0x12004
+#define BASS_ATTRIB_MIDI_TRACK_VOL 0x12100 // + track #
+
+// Additional tag type
+#define BASS_TAG_MIDI_TRACK 0x11000 // + track #, track text : array of null-terminated ANSI strings
+
+// BASS_ChannelGetLength/GetPosition/SetPosition mode
+#define BASS_POS_MIDI_TICK 2 // tick position
+
+// BASS_MIDI_FontPack flags
+#define BASS_MIDI_PACK_NOHEAD 1 // don't send a WAV header to the encoder
+
+typedef struct {
+ const char *name; // description
+ DWORD id;
+ DWORD flags;
+} BASS_MIDI_DEVICEINFO;
+
+typedef void (CALLBACK MIDIINPROC)(DWORD device, double time, const void *buffer, DWORD length, void *user);
+/* User MIDI input callback function.
+device : MIDI input device
+time : Timestamp
+buffer : Buffer containing MIDI data
+length : Number of bytes of data
+user : The 'user' parameter value given when calling BASS_MIDI_InInit */
+
+HSTREAM BASSMIDIDEF(BASS_MIDI_StreamCreate)(DWORD channels, DWORD flags, DWORD freq);
+HSTREAM BASSMIDIDEF(BASS_MIDI_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags, DWORD freq);
+HSTREAM BASSMIDIDEF(BASS_MIDI_StreamCreateURL)(const char *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user, DWORD freq);
+HSTREAM BASSMIDIDEF(BASS_MIDI_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *procs, void *user, DWORD freq);
+HSTREAM BASSMIDIDEF(BASS_MIDI_StreamCreateEvents)(const BASS_MIDI_EVENT *events, DWORD ppqn, DWORD flags, DWORD freq);
+BOOL BASSMIDIDEF(BASS_MIDI_StreamGetMark)(HSTREAM handle, DWORD type, DWORD index, BASS_MIDI_MARK *mark);
+DWORD BASSMIDIDEF(BASS_MIDI_StreamGetMarks)(HSTREAM handle, int track, DWORD type, BASS_MIDI_MARK *marks);
+BOOL BASSMIDIDEF(BASS_MIDI_StreamSetFonts)(HSTREAM handle, const void *fonts, DWORD count);
+DWORD BASSMIDIDEF(BASS_MIDI_StreamGetFonts)(HSTREAM handle, void *fonts, DWORD count);
+BOOL BASSMIDIDEF(BASS_MIDI_StreamLoadSamples)(HSTREAM handle);
+BOOL BASSMIDIDEF(BASS_MIDI_StreamEvent)(HSTREAM handle, DWORD chan, DWORD event, DWORD param);
+DWORD BASSMIDIDEF(BASS_MIDI_StreamEvents)(HSTREAM handle, DWORD mode, const void *events, DWORD length);
+DWORD BASSMIDIDEF(BASS_MIDI_StreamGetEvent)(HSTREAM handle, DWORD chan, DWORD event);
+DWORD BASSMIDIDEF(BASS_MIDI_StreamGetEvents)(HSTREAM handle, int track, DWORD filter, BASS_MIDI_EVENT *events);
+HSTREAM BASSMIDIDEF(BASS_MIDI_StreamGetChannel)(HSTREAM handle, DWORD chan);
+
+HSOUNDFONT BASSMIDIDEF(BASS_MIDI_FontInit)(const void *file, DWORD flags);
+HSOUNDFONT BASSMIDIDEF(BASS_MIDI_FontInitUser)(const BASS_FILEPROCS *procs, void *user, DWORD flags);
+BOOL BASSMIDIDEF(BASS_MIDI_FontFree)(HSOUNDFONT handle);
+BOOL BASSMIDIDEF(BASS_MIDI_FontGetInfo)(HSOUNDFONT handle, BASS_MIDI_FONTINFO *info);
+BOOL BASSMIDIDEF(BASS_MIDI_FontGetPresets)(HSOUNDFONT handle, DWORD *presets);
+const char *BASSMIDIDEF(BASS_MIDI_FontGetPreset)(HSOUNDFONT handle, int preset, int bank);
+BOOL BASSMIDIDEF(BASS_MIDI_FontLoad)(HSOUNDFONT handle, int preset, int bank);
+BOOL BASSMIDIDEF(BASS_MIDI_FontUnload)(HSOUNDFONT handle, int preset, int bank);
+BOOL BASSMIDIDEF(BASS_MIDI_FontCompact)(HSOUNDFONT handle);
+BOOL BASSMIDIDEF(BASS_MIDI_FontPack)(HSOUNDFONT handle, const void *outfile, const void *encoder, DWORD flags);
+BOOL BASSMIDIDEF(BASS_MIDI_FontUnpack)(HSOUNDFONT handle, const void *outfile, DWORD flags);
+BOOL BASSMIDIDEF(BASS_MIDI_FontSetVolume)(HSOUNDFONT handle, float volume);
+float BASSMIDIDEF(BASS_MIDI_FontGetVolume)(HSOUNDFONT handle);
+
+BOOL BASSMIDIDEF(BASS_MIDI_InGetDeviceInfo)(DWORD device, BASS_MIDI_DEVICEINFO *info);
+BOOL BASSMIDIDEF(BASS_MIDI_InInit)(DWORD device, MIDIINPROC *proc, void *user);
+BOOL BASSMIDIDEF(BASS_MIDI_InFree)(DWORD device);
+BOOL BASSMIDIDEF(BASS_MIDI_InStart)(DWORD device);
+BOOL BASSMIDIDEF(BASS_MIDI_InStop)(DWORD device);
+
+#ifdef __cplusplus
+}
+
+static inline BOOL BASS_MIDI_StreamSetFonts(HSTREAM handle, const BASS_MIDI_FONTEX *fonts, DWORD count)
+{
+ return BASS_MIDI_StreamSetFonts(handle, (const void*)fonts, count|BASS_MIDI_FONT_EX);
+}
+
+static inline DWORD BASS_MIDI_StreamGetFonts(HSTREAM handle, BASS_MIDI_FONTEX *fonts, DWORD count)
+{
+ return BASS_MIDI_StreamGetFonts(handle, (void*)fonts, count|BASS_MIDI_FONT_EX);
+}
+
+#ifdef _WIN32
+static inline HSTREAM BASS_MIDI_StreamCreateFile(BOOL mem, const WCHAR *file, QWORD offset, QWORD length, DWORD flags, DWORD freq)
+{
+ return BASS_MIDI_StreamCreateFile(mem, (const void*)file, offset, length, flags|BASS_UNICODE, freq);
+}
+
+static inline HSTREAM BASS_MIDI_StreamCreateURL(const WCHAR *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user, DWORD freq)
+{
+ return BASS_MIDI_StreamCreateURL((const char*)url, offset, flags|BASS_UNICODE, proc, user, freq);
+}
+
+static inline HSOUNDFONT BASS_MIDI_FontInit(const WCHAR *file, DWORD flags)
+{
+ return BASS_MIDI_FontInit((const void*)file, flags|BASS_UNICODE);
+}
+
+static inline BOOL BASS_MIDI_FontPack(HSOUNDFONT handle, const WCHAR *outfile, const WCHAR *encoder, DWORD flags)
+{
+ return BASS_MIDI_FontPack(handle, (const void*)outfile, (const void*)encoder, flags|BASS_UNICODE);
+}
+
+static inline BOOL BASS_MIDI_FontUnpack(HSOUNDFONT handle, const WCHAR *outfile, DWORD flags)
+{
+ return BASS_MIDI_FontUnpack(handle, (const void*)outfile, flags|BASS_UNICODE);
+}
+#endif
+#endif
+
+#endif
diff --git a/ThirdParty/BASS/libbass.dylib b/ThirdParty/BASS/libbass.dylib
new file mode 100644
index 000000000..85d810a2f
Binary files /dev/null and b/ThirdParty/BASS/libbass.dylib differ
diff --git a/ThirdParty/BASS/libbass_mpc.dylib b/ThirdParty/BASS/libbass_mpc.dylib
new file mode 100644
index 000000000..2269a37a6
Binary files /dev/null and b/ThirdParty/BASS/libbass_mpc.dylib differ
diff --git a/ThirdParty/BASS/libbassflac.dylib b/ThirdParty/BASS/libbassflac.dylib
new file mode 100644
index 000000000..c738d3558
Binary files /dev/null and b/ThirdParty/BASS/libbassflac.dylib differ
diff --git a/ThirdParty/BASS/libbassmidi.dylib b/ThirdParty/BASS/libbassmidi.dylib
new file mode 100644
index 000000000..3732bc4a9
Binary files /dev/null and b/ThirdParty/BASS/libbassmidi.dylib differ
diff --git a/ThirdParty/BASS/libbassopus.dylib b/ThirdParty/BASS/libbassopus.dylib
new file mode 100644
index 000000000..30e151059
Binary files /dev/null and b/ThirdParty/BASS/libbassopus.dylib differ
diff --git a/ThirdParty/BASS/libbasswv.dylib b/ThirdParty/BASS/libbasswv.dylib
new file mode 100644
index 000000000..0bc544531
Binary files /dev/null and b/ThirdParty/BASS/libbasswv.dylib differ