Skip to content

Commit

Permalink
Midi Library as .NET Standard 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Koseng committed Apr 28, 2023
1 parent 7f07ae7 commit 728682f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 148 deletions.
87 changes: 17 additions & 70 deletions Midi/Midi.csproj
Original file line number Diff line number Diff line change
@@ -1,74 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2CEE0914-509B-40BF-975C-B523434578DB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>M</RootNamespace>
<AssemblyName>Midi</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;MIDILIB</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Midi.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;MIDILIB</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Midi.xml</DocumentationFile>
<TargetFramework>netstandard2.0</TargetFramework>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<FileVersion>1.1.0.0</FileVersion>
<Copyright>Copyright © 2020</Copyright>
<Version>1.1.0.0</Version>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>$(DefineConstants);MIDILIB</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>$(DefineConstants);MIDILIB</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MidiContext.cs" />
<Compile Include="MidiDevice.cs" />
<Compile Include="MidiEvent.cs" />
<Compile Include="MidiFile.cs" />
<Compile Include="MidiInputDevice.cs" />
<Compile Include="MidiKeySignature.cs" />
<Compile Include="MidiMessage.cs" />
<Compile Include="MidiNote.cs" />
<Compile Include="MidiOutputDevice.cs" />
<Compile Include="MidiStream.cs" />
<Compile Include="MidiSequence.cs" />
<Compile Include="MidiSmpteTime.cs" />
<Compile Include="MidiTimeSignature.cs" />
<Compile Include="MidiUtility.cs" />
<Compile Include="MidiVolume.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Key.snk" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

</Project>
48 changes: 24 additions & 24 deletions Midi/MidiInputDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,30 +550,30 @@ void _MidiInProc(IntPtr handle, int msg, int instance, int lparam, int wparam)
case MIM_LONGERROR:
break;
case MIM_LONGDATA:
// TODO: Semi tested
var hdr = (MIDIHDR)Marshal.PtrToStructure(new IntPtr(lparam), typeof(MIDIHDR));
// for some reason we're getting bogus MIDIHDRs from lparam sometimes.
// hopefully this catches it:
if (0 == hdr.dwBytesRecorded || 65536<hdr.dwBytesRecorded)
return; // no message
// this code assumes it's a sysex message but I should probably check it.
if (IntPtr.Zero != hdr.lpData)
{
var status = Marshal.ReadByte(hdr.lpData, 0);
var payload = new byte[hdr.dwBytesRecorded - 1];
Marshal.Copy(new IntPtr((int)hdr.lpData + 1), payload, 0, payload.Length);
m = new MidiMessageSysex(payload);
var sz = Marshal.SizeOf(typeof(MIDIHDR));
_inHeader.dwBufferLength = _inHeader.dwBytesRecorded = 65536u;
_inHeader.lpData = _buffer;
_CheckInResult(midiInPrepareHeader(_handle, ref _inHeader, sz));
_CheckInResult(midiInAddBuffer(_handle, ref _inHeader, sz));
_ProcessRecording(m);
if (MIM_LONGDATA == msg)
Input?.Invoke(this, new MidiInputEventArgs(new TimeSpan(0, 0, 0, 0, wparam), m));
else
Error?.Invoke(this, new MidiInputEventArgs(new TimeSpan(0, 0, 0, 0, wparam), m));
}
//// TODO: Semi tested
//var hdr = (MIDIHDR)Marshal.PtrToStructure(new IntPtr(lparam), typeof(MIDIHDR));
//// for some reason we're getting bogus MIDIHDRs from lparam sometimes.
//// hopefully this catches it:
//if (0 == hdr.dwBytesRecorded || 65536<hdr.dwBytesRecorded)
// return; // no message
//// this code assumes it's a sysex message but I should probably check it.
//if (IntPtr.Zero != hdr.lpData)
//{
// var status = Marshal.ReadByte(hdr.lpData, 0);
// var payload = new byte[hdr.dwBytesRecorded - 1];
// Marshal.Copy(new IntPtr((int)hdr.lpData + 1), payload, 0, payload.Length);
// m = new MidiMessageSysex(payload);
// var sz = Marshal.SizeOf(typeof(MIDIHDR));
// _inHeader.dwBufferLength = _inHeader.dwBytesRecorded = 65536u;
// _inHeader.lpData = _buffer;
// _CheckInResult(midiInPrepareHeader(_handle, ref _inHeader, sz));
// _CheckInResult(midiInAddBuffer(_handle, ref _inHeader, sz));
// _ProcessRecording(m);
// if (MIM_LONGDATA == msg)
// Input?.Invoke(this, new MidiInputEventArgs(new TimeSpan(0, 0, 0, 0, wparam), m));
// else
// Error?.Invoke(this, new MidiInputEventArgs(new TimeSpan(0, 0, 0, 0, wparam), m));
//}
break;
case MIM_MOREDATA:
break;
Expand Down
36 changes: 0 additions & 36 deletions Midi/Properties/AssemblyInfo.cs

This file was deleted.

9 changes: 6 additions & 3 deletions MidiMessageSender/MidiMessageSender.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Midi">
<HintPath>..\Midi\bin\Debug\Midi.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -84,5 +81,11 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Midi\Midi.csproj">
<Project>{5d968a66-1b88-4aaf-ae67-c7fde8a92088}</Project>
<Name>Midi</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
2 changes: 1 addition & 1 deletion MidiMonitor/MidiMonitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Midi\Midi.csproj">
<Project>{2cee0914-509b-40bf-975c-b523434578db}</Project>
<Project>{5d968a66-1b88-4aaf-ae67-c7fde8a92088}</Project>
<Name>Midi</Name>
</ProjectReference>
</ItemGroup>
Expand Down
28 changes: 14 additions & 14 deletions SimpleMidiLib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Standard MIDI file format.html = Standard MIDI file format.html
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Midi", "Midi\Midi.csproj", "{2CEE0914-509B-40BF-975C-B523434578DB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MidiMonitor", "MidiMonitor\MidiMonitor.csproj", "{55256B98-8D56-4607-8313-A6200D6339B3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MidiMessageSender", "MidiMessageSender\MidiMessageSender.csproj", "{C5A50D2D-E16D-4D24-B621-438EA2DF395D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Midi", "Midi\Midi.csproj", "{5D968A66-1B88-4AAF-AE67-C7FDE8A92088}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -25,18 +25,6 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2CEE0914-509B-40BF-975C-B523434578DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CEE0914-509B-40BF-975C-B523434578DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CEE0914-509B-40BF-975C-B523434578DB}.Debug|x64.ActiveCfg = Debug|Any CPU
{2CEE0914-509B-40BF-975C-B523434578DB}.Debug|x64.Build.0 = Debug|Any CPU
{2CEE0914-509B-40BF-975C-B523434578DB}.Debug|x86.ActiveCfg = Debug|Any CPU
{2CEE0914-509B-40BF-975C-B523434578DB}.Debug|x86.Build.0 = Debug|Any CPU
{2CEE0914-509B-40BF-975C-B523434578DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CEE0914-509B-40BF-975C-B523434578DB}.Release|Any CPU.Build.0 = Release|Any CPU
{2CEE0914-509B-40BF-975C-B523434578DB}.Release|x64.ActiveCfg = Release|Any CPU
{2CEE0914-509B-40BF-975C-B523434578DB}.Release|x64.Build.0 = Release|Any CPU
{2CEE0914-509B-40BF-975C-B523434578DB}.Release|x86.ActiveCfg = Release|Any CPU
{2CEE0914-509B-40BF-975C-B523434578DB}.Release|x86.Build.0 = Release|Any CPU
{55256B98-8D56-4607-8313-A6200D6339B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{55256B98-8D56-4607-8313-A6200D6339B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{55256B98-8D56-4607-8313-A6200D6339B3}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -61,6 +49,18 @@ Global
{C5A50D2D-E16D-4D24-B621-438EA2DF395D}.Release|x64.Build.0 = Release|Any CPU
{C5A50D2D-E16D-4D24-B621-438EA2DF395D}.Release|x86.ActiveCfg = Release|Any CPU
{C5A50D2D-E16D-4D24-B621-438EA2DF395D}.Release|x86.Build.0 = Release|Any CPU
{5D968A66-1B88-4AAF-AE67-C7FDE8A92088}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D968A66-1B88-4AAF-AE67-C7FDE8A92088}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D968A66-1B88-4AAF-AE67-C7FDE8A92088}.Debug|x64.ActiveCfg = Debug|Any CPU
{5D968A66-1B88-4AAF-AE67-C7FDE8A92088}.Debug|x64.Build.0 = Debug|Any CPU
{5D968A66-1B88-4AAF-AE67-C7FDE8A92088}.Debug|x86.ActiveCfg = Debug|Any CPU
{5D968A66-1B88-4AAF-AE67-C7FDE8A92088}.Debug|x86.Build.0 = Debug|Any CPU
{5D968A66-1B88-4AAF-AE67-C7FDE8A92088}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D968A66-1B88-4AAF-AE67-C7FDE8A92088}.Release|Any CPU.Build.0 = Release|Any CPU
{5D968A66-1B88-4AAF-AE67-C7FDE8A92088}.Release|x64.ActiveCfg = Release|Any CPU
{5D968A66-1B88-4AAF-AE67-C7FDE8A92088}.Release|x64.Build.0 = Release|Any CPU
{5D968A66-1B88-4AAF-AE67-C7FDE8A92088}.Release|x86.ActiveCfg = Release|Any CPU
{5D968A66-1B88-4AAF-AE67-C7FDE8A92088}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 728682f

Please sign in to comment.