Refactoring to Unity Package
This commit is contained in:
parent
3b1c06cf48
commit
4cf93f8bb0
30 changed files with 89 additions and 2 deletions
8
Packages/fr.mrdev023.portmidi/PortMidi.meta
Normal file
8
Packages/fr.mrdev023.portmidi/PortMidi.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8cdded048e612ce4f9d3040a1d2ffcc0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/fr.mrdev023.portmidi/PortMidi/Plugins.meta
Normal file
8
Packages/fr.mrdev023.portmidi/PortMidi/Plugins.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f50820b559e26334f9283556b1a4ac2e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e6f5080a4efe3d24081d6d73df1f6a60
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
|
@ -0,0 +1,111 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 22e72e9afa5ab6e4399d010a48e8572a
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
'': Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 0
|
||||
Exclude Editor: 0
|
||||
Exclude Linux: 1
|
||||
Exclude Linux64: 0
|
||||
Exclude LinuxUniversal: 0
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude WebGL: 0
|
||||
Exclude Win: 0
|
||||
Exclude Win64: 0
|
||||
Exclude iOS: 0
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: ARMv7
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
- first:
|
||||
Facebook: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Facebook: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Standalone: Linux
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Standalone: LinuxUniversal
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
WebGL: WebGL
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,33 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a425b391f01c8894aa43b87c20214852
|
||||
folderAsset: yes
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0c8566bc4c811b644b0a8835ff828101
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2aec25c95e75cf545912d023242af0d9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
|
@ -0,0 +1,32 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cc1e4960e482b2844b08013a26acb81e
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>11G63</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>libportmidi.dylib</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>fr.mrdev023.libportmidi</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.42</string>
|
||||
<key>CSResourcesFileMapped</key>
|
||||
<string>yes</string>
|
||||
<key>DTCompiler</key>
|
||||
<string></string>
|
||||
<key>DTPlatformBuild</key>
|
||||
<string>4H1503</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>GM</string>
|
||||
<key>DTSDKBuild</key>
|
||||
<string>11E52</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>macosx10.7</string>
|
||||
<key>DTXcode</key>
|
||||
<string>0463</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>4H1503</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4f5ae46c29a68fa4a817c8f8be1eaa43
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: db0ac4acc0f608449b230965b6888368
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
|
@ -0,0 +1,111 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7d8e64f45c558d542a7a304008255864
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
'': Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 0
|
||||
Exclude Editor: 0
|
||||
Exclude Linux: 0
|
||||
Exclude Linux64: 0
|
||||
Exclude LinuxUniversal: 0
|
||||
Exclude OSXUniversal: 0
|
||||
Exclude WebGL: 0
|
||||
Exclude Win: 1
|
||||
Exclude Win64: 0
|
||||
Exclude iOS: 0
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: ARMv7
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
- first:
|
||||
Facebook: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Facebook: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Standalone: Linux
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: x86
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Standalone: LinuxUniversal
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
WebGL: WebGL
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
17
Packages/fr.mrdev023.portmidi/PortMidi/PortMidi.asmdef
Normal file
17
Packages/fr.mrdev023.portmidi/PortMidi/PortMidi.asmdef
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "PortMidi",
|
||||
"references": [],
|
||||
"includePlatforms": [
|
||||
"Editor",
|
||||
"LinuxStandalone64",
|
||||
"macOSStandalone",
|
||||
"WindowsStandalone64"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": []
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8b814770768be93448b232f1b9e242a0
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/fr.mrdev023.portmidi/PortMidi/Scripts.meta
Normal file
8
Packages/fr.mrdev023.portmidi/PortMidi/Scripts.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b06b707b56f81a6499af6ad69a8d2953
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
392
Packages/fr.mrdev023.portmidi/PortMidi/Scripts/NativeMethods.cs
Normal file
392
Packages/fr.mrdev023.portmidi/PortMidi/Scripts/NativeMethods.cs
Normal file
|
@ -0,0 +1,392 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using System;
|
||||
|
||||
namespace PortMidi
|
||||
{
|
||||
public static unsafe class NativeMethods
|
||||
{
|
||||
public const string NativeLibrary = "portmidi";
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_Initialize", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern PmError Pm_Initialize();
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_Terminate", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern PmError Pm_Terminate();
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pt_Start", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern int Pt_Start(int a,int b,int c);
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pt_Stop", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern void Pt_Stop();
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_CountDevices", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern int Pm_CountDevices();
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_GetErrorText", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern string Pm_GetErrorText(PmError error);
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_GetDefaultInputDeviceID", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern int Pm_GetDefaultInputDeviceID();
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_GetDefaultOutputDeviceID", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern int Pm_GetDefaultOutputDeviceID();
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_GetDeviceInfo", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern IntPtr Pm_GetDeviceInfo(int id);
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_OpenOutput", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern PmError Pm_OpenOutput(IntPtr* stream, int outputDeviceID, IntPtr outputDriverInfo, int bufferSize, IntPtr time_proc, IntPtr time_info, int latency);
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_OpenInput", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern PmError Pm_OpenInput(IntPtr* stream, int inputDeviceID, IntPtr inputDriverInfo, int bufferSize, IntPtr time_proc, IntPtr time_info);
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_Close", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern PmError Pm_Close(IntPtr stream);
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_Write", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern PmError Pm_Write(IntPtr stream, PmEvent* buffer, int length);
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_WriteSysEx", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern PmError Pm_WriteSysEx(IntPtr stream, int when, byte* msg);
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_SetChannelMask", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern PmError Pm_SetChannelMask(IntPtr stream, int mask);
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_Abort", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern PmError Pm_Abort(IntPtr stream);
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_Poll", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern PmError Pm_Poll(IntPtr stream);
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_Synchronize", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern PmError Pm_Synchronize(IntPtr stream);
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_SetFilter", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern PmError Pm_SetFilter(IntPtr stream, int filters);
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pm_Read", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern int Pm_Read(IntPtr stream, PmEvent* e, int length);
|
||||
|
||||
[DllImport(NativeLibrary, EntryPoint = "Pt_Time", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern int Pt_Time();
|
||||
|
||||
// Initialize initializes the portmidi. Needs to be called before
|
||||
// making any other call from the portmidi package.
|
||||
// Once portmidi package is no longer required, Terminate should be
|
||||
// called to free the underlying resources.
|
||||
public static void Initialize()
|
||||
{
|
||||
PmError error = Pm_Initialize();
|
||||
if (error != 0)
|
||||
{
|
||||
throw new Exception(ConvertToError(error));
|
||||
}
|
||||
Pt_Start(1, 0, 0);
|
||||
}
|
||||
|
||||
// Terminate terminates and cleans up the midi streams.
|
||||
public static void Terminate()
|
||||
{
|
||||
Pt_Stop();
|
||||
PmError error = Pm_Terminate();
|
||||
if (error != 0)
|
||||
{
|
||||
throw new Exception(ConvertToError(error));
|
||||
}
|
||||
}
|
||||
|
||||
// CountDevices returns the number of MIDI devices.
|
||||
public static int CountDevices()
|
||||
{
|
||||
return Pm_CountDevices();
|
||||
}
|
||||
|
||||
// convertToError converts a portmidi error code to a error text.
|
||||
public static string ConvertToError(PmError error)
|
||||
{
|
||||
return Pm_GetErrorText(error);
|
||||
}
|
||||
|
||||
// Info returns the device info for the device indentified with deviceID.
|
||||
// If deviceID is out of range, Info returns null.
|
||||
public static PmDeviceInfo Info(int deviceID)
|
||||
{
|
||||
return Marshal.PtrToStructure<PmDeviceInfo>(Pm_GetDeviceInfo(deviceID));
|
||||
}
|
||||
|
||||
// DefaultInputDeviceID returns the default input device's ID.
|
||||
public static int DefaultInputDeviceID()
|
||||
{
|
||||
return Pm_GetDefaultInputDeviceID();
|
||||
}
|
||||
|
||||
// DefaultOutputDeviceID returns the default output device's ID.
|
||||
public static int DefaultOutputDeviceID()
|
||||
{
|
||||
return Pm_GetDefaultOutputDeviceID();
|
||||
}
|
||||
|
||||
// Time returns the portmidi timer's current time.
|
||||
public static int Time ()
|
||||
{
|
||||
return Pt_Time();
|
||||
}
|
||||
|
||||
// NewOutputStream initializes a new output stream.
|
||||
public static Stream NewOutputStream(int deviceID, int bufferSize, int latency)
|
||||
{
|
||||
IntPtr pmStream = IntPtr.Zero;
|
||||
|
||||
PmDeviceInfo deviceInfo = Info(deviceID);
|
||||
if (deviceInfo.output != 1) throw new Exception("Selected DeviceID is not an output");
|
||||
|
||||
PmError error = Pm_OpenOutput(&pmStream, deviceID, IntPtr.Zero, bufferSize, IntPtr.Zero, IntPtr.Zero, latency);
|
||||
if (error != 0)
|
||||
{
|
||||
throw new Exception(ConvertToError(error));
|
||||
}
|
||||
|
||||
return new Stream(deviceID, pmStream, StreamType.OUTPUT, bufferSize);
|
||||
}
|
||||
|
||||
// NewInputStream initializes a new input stream.
|
||||
public static Stream NewInputStream(int deviceID, int bufferSize)
|
||||
{
|
||||
IntPtr pmStream = IntPtr.Zero;
|
||||
|
||||
PmDeviceInfo deviceInfo = Info(deviceID);
|
||||
if (deviceInfo.input != 1) throw new Exception("Selected DeviceID is not an input");
|
||||
|
||||
PmError error = Pm_OpenInput(&pmStream, deviceID, IntPtr.Zero, bufferSize, IntPtr.Zero, IntPtr.Zero);
|
||||
if (error != 0)
|
||||
{
|
||||
throw new Exception(ConvertToError(error));
|
||||
}
|
||||
|
||||
return new Stream(deviceID, pmStream, StreamType.INPUT, bufferSize);
|
||||
}
|
||||
|
||||
// Write writes a buffer of MIDI events to the output stream.
|
||||
public static void Write(Stream stream, Event[] events)
|
||||
{
|
||||
int size = events.Length;
|
||||
if (size > stream.bufferSize)
|
||||
{
|
||||
throw new Exception("Out of Stream");
|
||||
}
|
||||
|
||||
if (stream.streamType != StreamType.OUTPUT)
|
||||
{
|
||||
throw new Exception("Stream is not an Output Buffer");
|
||||
}
|
||||
|
||||
PmEvent[] buffer = new PmEvent[size];
|
||||
for (int i = 0; i < events.Length; i++)
|
||||
{
|
||||
PmEvent e = new PmEvent();
|
||||
Event evt = events[i];
|
||||
e.timestamp = evt.Timestamp;
|
||||
e.message = (((evt.Data2 << 16) & 0xFF0000) | ((evt.Data1 << 8) & 0xFF00) | (evt.Status & 0xFF));
|
||||
buffer[i] = e;
|
||||
}
|
||||
fixed (PmEvent* p = &buffer[0])
|
||||
{
|
||||
PmError error = Pm_Write(stream.pmStream, p, size);
|
||||
if (error != 0)
|
||||
{
|
||||
throw new Exception(ConvertToError(error));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WriteShort writes a MIDI event of three bytes immediately to the output stream.
|
||||
public static void WriteShort(Stream stream, int status, int data1, int data2)
|
||||
{
|
||||
Event evt = new Event();
|
||||
evt.Timestamp = Pt_Time();
|
||||
evt.Status = status;
|
||||
evt.Data1 = data1;
|
||||
evt.Data2 = data2;
|
||||
Write(stream, new Event[] { evt });
|
||||
}
|
||||
|
||||
// WriteSysExBytes writes a system exclusive MIDI message given as a []byte to the output stream.
|
||||
public static void WriteSysExBytes(Stream stream,int when, byte[] msg)
|
||||
{
|
||||
fixed (byte* p = &msg[0])
|
||||
{
|
||||
PmError error = Pm_WriteSysEx(stream.pmStream, when, p);
|
||||
|
||||
if (error != 0)
|
||||
{
|
||||
throw new Exception(ConvertToError(error));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WriteSysEx writes a system exclusive MIDI message given as a string of hexadecimal characters to
|
||||
// the output stream. The string must only consist of hex digits (0-9A-F) and optional spaces. This
|
||||
// function is case-insenstive.
|
||||
public static void WriteSysEx(Stream stream, int when, string msg)
|
||||
{
|
||||
WriteSysExBytes(stream, when, StringToByteArrayFastest(msg.Replace(" ", "")));
|
||||
}
|
||||
|
||||
// SetChannelMask filters incoming stream based on channel.
|
||||
// In order to filter from more than a single channel, or multiple channels.
|
||||
// s.SetChannelMask(Channel(1) | Channel(10)) will both filter input
|
||||
// from channel 1 and 10.
|
||||
public static void SetChannelMask(Stream stream, int mask)
|
||||
{
|
||||
PmError error = Pm_SetChannelMask(stream.pmStream, mask);
|
||||
|
||||
if (error != 0)
|
||||
{
|
||||
throw new Exception(ConvertToError(error));
|
||||
}
|
||||
}
|
||||
|
||||
// Close closes the MIDI stream.
|
||||
public static void Close(Stream stream)
|
||||
{
|
||||
if (stream.pmStream == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PmError error = Pm_Close(stream.pmStream);
|
||||
if (error != 0)
|
||||
{
|
||||
throw new Exception(ConvertToError(error));
|
||||
}
|
||||
}
|
||||
|
||||
// Abort aborts the MIDI stream.
|
||||
public static void Abort(Stream stream)
|
||||
{
|
||||
if (stream.pmStream == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PmError error = Pm_Abort(stream.pmStream);
|
||||
if (error != 0)
|
||||
{
|
||||
throw new Exception(ConvertToError(error));
|
||||
}
|
||||
}
|
||||
|
||||
// Reads from the input stream, the max number events to be read are
|
||||
// determined by max.
|
||||
public static Event[] Read(Stream stream, int max)
|
||||
{
|
||||
Event[] events = new Event[0];
|
||||
if (max > stream.bufferSize) throw new Exception("Out of bounds");
|
||||
PmEvent[] pm_events = new PmEvent[max];
|
||||
fixed (PmEvent* p = &pm_events[0])
|
||||
{
|
||||
int numEvents = Pm_Read(stream.pmStream, p, max);
|
||||
events = new Event[numEvents];
|
||||
|
||||
for (int i = 0; i < numEvents; i++)
|
||||
{
|
||||
Event e = new Event();
|
||||
e.Timestamp = pm_events[i].timestamp;
|
||||
e.Status = (int)(pm_events[i].message) & 0xFF;
|
||||
e.Data1 = (int)(pm_events[i].message >> 8) & 0xFF;
|
||||
e.Data2 = (int)(pm_events[i].message >> 16) & 0xFF;
|
||||
events[i] = e;
|
||||
}
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
// ReadSysExBytes reads 4*max sysex bytes from the input stream.
|
||||
public static byte[] ReadSysExBytes(Stream stream, int max)
|
||||
{
|
||||
byte[] msg = new byte[0];
|
||||
if (max > stream.bufferSize) throw new Exception("Out of bounds");
|
||||
PmEvent[] pm_events = new PmEvent[max];
|
||||
fixed (PmEvent* p = &pm_events[0])
|
||||
{
|
||||
int numEvents = Pm_Read(stream.pmStream, p, max);
|
||||
msg = new byte[4 * numEvents];
|
||||
|
||||
for (int i = 0; i < numEvents; i++)
|
||||
{
|
||||
msg[4 * i + 0] = (byte)(pm_events[i].message & 0xFF);
|
||||
msg[4 * i + 1] = (byte)((pm_events[i].message >> 8) & 0xFF);
|
||||
msg[4 * i + 2] = (byte)((pm_events[i].message >> 16) & 0xFF);
|
||||
msg[4 * i + 3] = (byte)((pm_events[i].message >> 24) & 0xFF);
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
// Poll reports whether there is input available in the stream.
|
||||
public static bool Poll(Stream stream)
|
||||
{
|
||||
PmError error = Pm_Poll(stream.pmStream);
|
||||
if (error < 0)
|
||||
{
|
||||
throw new Exception(ConvertToError(error));
|
||||
}
|
||||
return error > 0;
|
||||
}
|
||||
|
||||
// instructs PortMidi to (re)synchronize to the time_proc passed when the stream was opened.
|
||||
public static bool Synchronize(Stream stream)
|
||||
{
|
||||
PmError error = Pm_Synchronize(stream.pmStream);
|
||||
if (error < 0)
|
||||
{
|
||||
throw new Exception(ConvertToError(error));
|
||||
}
|
||||
return error > 0;
|
||||
}
|
||||
|
||||
// sets filters on an open input stream to drop selected input types. By default, only active sensing messages are filtered
|
||||
public static void SetFilter(Stream stream, PortMidiFilter[] filters)
|
||||
{
|
||||
if (filters.Length == 0)
|
||||
{
|
||||
PmError err = Pm_SetFilter(stream.pmStream, (int)PortMidiFilter.PM_FILT_ACTIVE);
|
||||
if (err != 0)
|
||||
{
|
||||
throw new Exception(ConvertToError(err));
|
||||
}
|
||||
}
|
||||
|
||||
int filtersMask = 0;
|
||||
foreach (PortMidiFilter filter in filters)
|
||||
{
|
||||
filtersMask |= (int)filter;
|
||||
}
|
||||
|
||||
PmError error = Pm_SetFilter(stream.pmStream, (int)PortMidiFilter.PM_FILT_ACTIVE);
|
||||
if (error != 0)
|
||||
{
|
||||
throw new Exception(ConvertToError(error));
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] StringToByteArrayFastest(string hex)
|
||||
{
|
||||
if (hex.Length % 2 == 1)
|
||||
throw new Exception("The binary key cannot have an odd number of digits");
|
||||
|
||||
byte[] arr = new byte[hex.Length >> 1];
|
||||
|
||||
for (int i = 0; i < hex.Length >> 1; ++i)
|
||||
{
|
||||
arr[i] = (byte)((GetHexVal(hex[i << 1]) << 4) + (GetHexVal(hex[(i << 1) + 1])));
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static int GetHexVal(char hex)
|
||||
{
|
||||
int val = (int)hex;
|
||||
return val - (val < 58 ? 48 : (val < 97 ? 55 : 87));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c1dd5cd477f43c7479d7f99989927621
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,49 @@
|
|||
namespace PortMidi
|
||||
{
|
||||
// Filter bit-mask definitions
|
||||
public enum PortMidiFilter
|
||||
{
|
||||
// filter active sensing messages (0xFE)
|
||||
PM_FILT_ACTIVE = (1 << 0x0E),
|
||||
// filter system exclusive messages (0xF0)
|
||||
PM_FILT_SYSEX = (1 << 0x00),
|
||||
// filter MIDI clock message (0xF8)
|
||||
PM_FILT_CLOCK = (1 << 0x08),
|
||||
// filter play messages (start 0xFA, stop 0xFC, continue 0xFB)
|
||||
PM_FILT_PLAY = ((1 << 0x0A) | (1 << 0x0C) | (1 << 0x0B)),
|
||||
// filter tick messages (0xF9)
|
||||
PM_FILT_TICK = (1 << 0x09),
|
||||
// filter undefined FD messages
|
||||
PM_FILT_FD = (1 << 0x0D),
|
||||
// filter undefined real-time messages
|
||||
PM_FILT_UNDEFINED = PM_FILT_FD,
|
||||
// filter reset messages (0xFF)
|
||||
PM_FILT_RESET = (1 << 0x0F),
|
||||
// filter all real-time messages
|
||||
PM_FILT_REALTIME = (PM_FILT_ACTIVE | PM_FILT_SYSEX | PM_FILT_CLOCK | PM_FILT_PLAY | PM_FILT_UNDEFINED | PM_FILT_RESET | PM_FILT_TICK),
|
||||
// filter note-on and note-off (0x90-0x9F and 0x80-0x8F
|
||||
PM_FILT_NOTE = ((1 << 0x19) | (1 << 0x18)),
|
||||
// filter channel aftertouch (most midi controllers use this) (0xD0-0xDF)
|
||||
PM_FILT_CHANNEL_AFTERTOUCH = (1 << 0x1D),
|
||||
// per-note aftertouch (0xA0-0xAF)
|
||||
PM_FILT_POLY_AFTERTOUCH = (1 << 0x1A),
|
||||
// filter both channel and poly aftertouch
|
||||
PM_FILT_AFTERTOUCH = (PM_FILT_CHANNEL_AFTERTOUCH | PM_FILT_POLY_AFTERTOUCH),
|
||||
// Program changes (0xC0-0xCF)
|
||||
PM_FILT_PROGRAM = (1 << 0x1C),
|
||||
// Control Changes (CC's) (0xB0-0xBF)
|
||||
PM_FILT_CONTROL = (1 << 0x1B),
|
||||
// Pitch Bender (0xE0-0xEF)
|
||||
PM_FILT_PITCHBEND = (1 << 0x1E),
|
||||
// MIDI Time Code (0xF1)
|
||||
PM_FILT_MTC = (1 << 0x01),
|
||||
// Song Position (0xF2)
|
||||
PM_FILT_SONG_POSITION = (1 << 0x02),
|
||||
// Song Select (0xF3)
|
||||
PM_FILT_SONG_SELECT = (1 << 0x03),
|
||||
// Tuning request (0xF6)
|
||||
PM_FILT_TUNE = (1 << 0x06),
|
||||
// All System Common messages (mtc, song position, song select, tune request)
|
||||
PM_FILT_SYSTEMCOMMON = (PM_FILT_MTC | PM_FILT_SONG_POSITION | PM_FILT_SONG_SELECT | PM_FILT_TUNE),
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d30d9e7032bf4484eafd50da73c01059
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PortMidi
|
||||
{
|
||||
public enum PmError : int
|
||||
{
|
||||
pmNoError = 0,
|
||||
pmNoData = 0,
|
||||
pmGotData = 1,
|
||||
pmHostError = -10000,
|
||||
pmInvalidDeviceId,
|
||||
pmInsufficientMemory,
|
||||
pmBufferTooSmall,
|
||||
pmBufferOverflow,
|
||||
pmBadPtr,
|
||||
pmInternalError,
|
||||
pmBufferMaxSize
|
||||
}
|
||||
|
||||
public enum StreamType : int
|
||||
{
|
||||
OUTPUT = 0,
|
||||
INPUT = 1
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d14b20f71d5dd6f44a9e6e20ba805e38
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,44 @@
|
|||
using System;
|
||||
|
||||
namespace PortMidi
|
||||
{
|
||||
public struct PmDeviceInfo
|
||||
{
|
||||
public int structVersion;
|
||||
public string interf;
|
||||
public string name;
|
||||
public int input;
|
||||
public int output;
|
||||
public int opened;
|
||||
}
|
||||
|
||||
public struct PmEvent
|
||||
{
|
||||
public int message;
|
||||
public int timestamp;
|
||||
}
|
||||
|
||||
public struct Event
|
||||
{
|
||||
public int Timestamp;
|
||||
public int Status;
|
||||
public int Data1;
|
||||
public int Data2;
|
||||
}
|
||||
|
||||
public struct Stream
|
||||
{
|
||||
public int DeviceID;
|
||||
public IntPtr pmStream;
|
||||
public readonly StreamType streamType;
|
||||
public readonly int bufferSize;
|
||||
|
||||
public Stream(int DeviceID, IntPtr pmStream, StreamType streamType, int bufferSize)
|
||||
{
|
||||
this.streamType = streamType;
|
||||
this.DeviceID = DeviceID;
|
||||
this.pmStream = pmStream;
|
||||
this.bufferSize = bufferSize;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 71c219e3c5723c1449ecce4a18fc1ed9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
22
Packages/fr.mrdev023.portmidi/package.json
Normal file
22
Packages/fr.mrdev023.portmidi/package.json
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "fr.mrdev023.portmidi",
|
||||
"displayName": "Port Midi",
|
||||
"version": "0.1.1-preview",
|
||||
"unity": "2018.3",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mrdev023/UNITY_PORTMIDI_WRAPPER.git",
|
||||
"revision": "bdb556e64749c2dbd7218e31c080d48f3053388f"
|
||||
},
|
||||
"description": "PortMidi wrapper for Unity 3D. Compatibility for Mac OSX (64 bits only), Linux (64 bits only) and Windows (64 bits only)",
|
||||
"keywords": [
|
||||
"midi",
|
||||
"portmidi",
|
||||
"native",
|
||||
"unity3d",
|
||||
"64bits only",
|
||||
"desktop only"
|
||||
],
|
||||
"dependencies": {
|
||||
}
|
||||
}
|
7
Packages/fr.mrdev023.portmidi/package.json.meta
Normal file
7
Packages/fr.mrdev023.portmidi/package.json.meta
Normal file
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b9a8a64880d9fa444ae82f3273afbda5
|
||||
PackageManifestImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue