Skip to content

Commit

Permalink
Merge pull request #235 from microsoft/pete-dev
Browse files Browse the repository at this point in the history
DP 4 NAMM Official Build
  • Loading branch information
Psychlist1972 authored Jan 23, 2024
2 parents 31345f0 + b97f922 commit b4e2b80
Show file tree
Hide file tree
Showing 46 changed files with 1,451 additions and 500 deletions.
3 changes: 2 additions & 1 deletion build/staging/reg/WinRTActivationEntries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class RegistryEntries
new RegEntry{ ClassName="Windows.Devices.Midi2.MidiChannelEndpointListener", ActivationType=0, Threading=0, TrustLevel=0 },
new RegEntry{ ClassName="Windows.Devices.Midi2.MidiGroupEndpointListener", ActivationType=0, Threading=0, TrustLevel=0 },
new RegEntry{ ClassName="Windows.Devices.Midi2.MidiMessageTypeEndpointListener", ActivationType=0, Threading=0, TrustLevel=0 },
new RegEntry{ ClassName="Windows.Devices.Midi2.MidiVirtualDevice", ActivationType=0, Threading=0, TrustLevel=0 },
new RegEntry{ ClassName="Windows.Devices.Midi2.MidiVirtualEndpointDevice", ActivationType=0, Threading=0, TrustLevel=0 },
new RegEntry{ ClassName="Windows.Devices.Midi2.MidiVirtualEndpointDeviceDefinition", ActivationType=0, Threading=0, TrustLevel=0 },
new RegEntry{ ClassName="Windows.Devices.Midi2.MidiMessageReceivedEventArgs", ActivationType=0, Threading=0, TrustLevel=0 },
new RegEntry{ ClassName="Windows.Devices.Midi2.MidiEndpointConnection", ActivationType=0, Threading=0, TrustLevel=0 },
new RegEntry{ ClassName="Windows.Devices.Midi2.IMidiEndpointConnectionStatics", ActivationType=0, Threading=0, TrustLevel=0 },
Expand Down
7 changes: 6 additions & 1 deletion build/staging/reg/WinRTActivationEntries.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@
trustLevel="Base"
/>
<class
activatableClassId="Windows.Devices.Midi2.MidiVirtualDevice"
activatableClassId="Windows.Devices.Midi2.MidiVirtualEndpointDevice"
threading="Both"
trustLevel="Base"
/>
<class
activatableClassId="Windows.Devices.Midi2.MidiVirtualEndpointDeviceDefinition"
threading="Both"
trustLevel="Base"
/>
Expand Down
2 changes: 1 addition & 1 deletion build/staging/version/BundleInfo.wxi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Include>
<?define SetupVersionName="Developer Preview 4" ?>
<?define SetupVersionNumber="1.0.24020.2356" ?>
<?define SetupVersionNumber="1.0.24022.2031" ?>
</Include>
Binary file modified diagnostics/trace-logging/TraceCaptureFile.etl
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
using Windows.Foundation;
using Windows.Foundation.Collections;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace MidiSample.AppToAppMidi
{
/// <summary>
Expand All @@ -45,6 +42,6 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar
m_window.Activate();
}

private Window m_window;
private Microsoft.UI.Xaml.Window m_window;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,30 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">


<Grid Background="Black">
<Grid.Resources>
<ResourceDictionary>
<Style TargetType="Rectangle">
<Setter Property="Fill" Value="Orange" />
<Setter Property="Margin" Value="5" />
</Style>
</ResourceDictionary>
</Grid.Resources>


<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- Thanks to Morten (twitter @dotMorten) for the code and markup refactor here! -->

<Grid Background="#252525">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<Grid x:Name="PadContainer" Grid.Row="0" Margin="5,25,5,5">
<GridView ItemsSource="{x:Bind Notes}" HorizontalAlignment="Center" VerticalAlignment="Center" >
<ItemsPanelTemplate>
<UniformGridLayout x:Name="PadLayout" MaximumRowsOrColumns="4" />
<!--<ItemsWrapGrid x:Name="MaxItemsWrapGrid" MaximumRowsOrColumns="4" Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> -->
</ItemsPanelTemplate>

<GridView.ItemTemplate>
<DataTemplate x:DataType="local:Note">
<Rectangle Fill="Orange" Margin="5" Width="95" Height="95"
PointerPressed="{x:Bind NoteOn}"
PointerReleased="{x:Bind NoteOff}" />
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Grid>

<!-- D Minor: D, E, F, G, A, Bb, C -->
<!-- Tags are MIDI note numbers -->

<Rectangle x:Name="Pad00" Grid.Row="0" Grid.Column="0" Tag="50" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>
<Rectangle x:Name="Pad01" Grid.Row="0" Grid.Column="1" Tag="52" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>
<Rectangle x:Name="Pad02" Grid.Row="0" Grid.Column="2" Tag="53" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>
<Rectangle x:Name="Pad03" Grid.Row="0" Grid.Column="3" Tag="55" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>

<Rectangle x:Name="Pad10" Grid.Row="1" Grid.Column="0" Tag="57" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>
<Rectangle x:Name="Pad11" Grid.Row="1" Grid.Column="1" Tag="58" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>
<Rectangle x:Name="Pad12" Grid.Row="1" Grid.Column="2" Tag="60" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>
<Rectangle x:Name="Pad13" Grid.Row="1" Grid.Column="3" Tag="62" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>

<Rectangle x:Name="Pad20" Grid.Row="2" Grid.Column="0" Tag="64" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>
<Rectangle x:Name="Pad21" Grid.Row="2" Grid.Column="1" Tag="65" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>
<Rectangle x:Name="Pad22" Grid.Row="2" Grid.Column="2" Tag="67" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>
<Rectangle x:Name="Pad23" Grid.Row="2" Grid.Column="3" Tag="69" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>

<Rectangle x:Name="Pad30" Grid.Row="3" Grid.Column="0" Tag="70" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>
<Rectangle x:Name="Pad31" Grid.Row="3" Grid.Column="1" Tag="72" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>
<Rectangle x:Name="Pad32" Grid.Row="3" Grid.Column="2" Tag="74" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>
<Rectangle x:Name="Pad33" Grid.Row="3" Grid.Column="3" Tag="76" PointerPressed="OnPadPointerPressed" PointerReleased="OnPadPointerReleased"/>

</Grid>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,66 +14,129 @@
using Windows.AI.MachineLearning;
using Windows.Foundation;
using Windows.Foundation.Collections;

using WinUIEx;
using midi2 = Windows.Devices.Midi2;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace MidiSample.AppToAppMidi
{
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
{

public sealed partial class MainWindow : Microsoft.UI.Xaml.Window
{
private midi2.MidiSession _session;
private midi2.MidiEndpointConnection _connection;

public List<Note> Notes { get; }

public MainWindow()
{
this.InitializeComponent();

this.Closed += MainWindow_Closed;
OpenConnection();

this.AppWindow.MoveAndResize(new Windows.Graphics.RectInt32(100, 100, 600, 600));
var notes = new byte[] { 50, 52, 53, 55, 57, 58, 60, 62, 64, 65, 67, 69, 70, 72, 74, 76 };

Notes = notes.Select(n=>new Note() { NoteNumber = n, Connection = _connection, GroupIndex = 0, ChannelIndex = 0 }).ToList();

OpenConnection();
//this.Closed += MainWindow_Closed;

//this.AppWindow.MoveAndResize(new Windows.Graphics.RectInt32(100, 100, 600, 600));

this.SetWindowSize(500, 550);
this.SetIsAlwaysOnTop(true);

this.Closed += MainWindow_Closed;

}

private void MainWindow_Closed(object sender, WindowEventArgs args)
{
_session.DisconnectEndpointConnection(_connection.ConnectionId);
_session.Dispose();
}

// in MIDI Services config file in Virtual Device MIDI section
//"createVirtualDevices":
//[
// {
// "associationIdentifier" : "{1EDD815E-B44B-488D-96EE-E8C81093D6AC}",
// "shortUniqueId": "PMB_APP2_8675309",
// "name": "Pad Controller",
// "description" : "App to app MIDI pad controller device app"
// }
//]
//
//const string _appDeviceConnectionId = "\\\\?\\SWD#MIDISRV#MIDIU_VIRTDEV_PMB_APP2_8675309#{e7cce071-3c03-423f-88d3-f1045d02552b}";
private void OpenConnection()
{
_session = midi2.MidiSession.CreateSession("App to app MIDI sample");
_connection = _session.CreateEndpointConnection(midi2.MidiEndpointDeviceInformation.DiagnosticsLoopbackAEndpointId);
_connection.Open();
}
System.Diagnostics.Debug.WriteLine("Open Connection enter");

private byte GetMidiNoteNumberFromPad(Rectangle pad)
{
return byte.Parse(pad.Tag!.ToString());
}

private void OnPadPointerPressed(object sender, PointerRoutedEventArgs e)
{
byte note = GetMidiNoteNumberFromPad((Rectangle)sender);
var message = midi2.MidiMessageBuilder.BuildMidi2ChannelVoiceMessage(0, 0, midi2.Midi2ChannelVoiceMessageStatus.NoteOn, 0, note, 1000);
// create our function blocks and endpoint info to be reported back through MIDI

_connection.SendMessagePacket(message);
}
var deviceDefinition = new midi2.MidiVirtualEndpointDeviceDefinition();

private void OnPadPointerReleased(object sender, PointerRoutedEventArgs e)
{
byte note = GetMidiNoteNumberFromPad((Rectangle)sender);
deviceDefinition.FunctionBlocks.Add(new midi2.MidiFunctionBlock()
{
Number = 0,
IsActive = true,
Name = "Pads Output",
UIHint = midi2.MidiFunctionBlockUIHint.Sender,
FirstGroupIndex = 0,
GroupCount = 1,
Direction = midi2.MidiFunctionBlockDirection.Bidirectional,
Midi10Connection = midi2.MidiFunctionBlockMidi10.Not10,
MaxSystemExclusive8Streams = 0,
MidiCIMessageVersionFormat = 0
}) ;

deviceDefinition.AreFunctionBlocksStatic = true;
deviceDefinition.EndpointName = "Pad Controller App";
deviceDefinition.EndpointProductInstanceId = "PMB_APP2_8675309"; // this needs to match pre-configuration for now
deviceDefinition.SupportsMidi2ProtocolMessages = true;
deviceDefinition.SupportsMidi1ProtocolMessages = true;
deviceDefinition.SupportsReceivingJRTimestamps = false;
deviceDefinition.SupportsSendingJRTimestamps = false;

var message = midi2.MidiMessageBuilder.BuildMidi2ChannelVoiceMessage(0, 0, midi2.Midi2ChannelVoiceMessageStatus.NoteOff, 0, note, 1000);
System.Diagnostics.Debug.WriteLine("Creating session");

_connection.SendMessagePacket(message);
_session = midi2.MidiSession.CreateSession("App to app MIDI sample");

if (_session != null)
{
System.Diagnostics.Debug.WriteLine("Creating virtual device");

_connection = _session.CreateVirtualDeviceAndConnection(deviceDefinition);

if (_connection != null)
{
_connection.MessageReceived += _connection_MessageReceived;

System.Diagnostics.Debug.WriteLine("Connection created. About to open it.");

if (_connection.Open())
{
System.Diagnostics.Debug.WriteLine("Connection Opened");

this.AppWindow.Title = "App-to-app MIDI Pad Controller: Connected";
}
else
{
System.Diagnostics.Debug.WriteLine("Connection Open Failed");
this.AppWindow.Title = "App-to-app MIDI Pad Controller: (no connection)";
}
}
}
else
{
System.Diagnostics.Debug.WriteLine("Session Open Failed");
// unable to open session
}
}

private void _connection_MessageReceived(midi2.IMidiMessageReceivedEventSource sender, midi2.MidiMessageReceivedEventArgs args)
{
System.Diagnostics.Debug.WriteLine("Message Received " + midi2.MidiMessageUtility.GetMessageFriendlyNameFromFirstWord(args.PeekFirstWord()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.230913002" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.755" />
<PackageReference Include="Windows.Devices.Midi2" Version="1.0.0-preview.3-0134" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25936-preview" />
<PackageReference Include="Windows.Devices.Midi2" Version="1.0.0-preview.3-0136" />
<PackageReference Include="WinUIEx" Version="2.3.3" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using midi2 = Windows.Devices.Midi2;

namespace MidiSample.AppToAppMidi
{

public class Note
{
public midi2.MidiEndpointConnection Connection { get; set; }
public byte NoteNumber { get; set; }

public byte GroupIndex { get; set; }

public byte ChannelIndex { get; set; }

public void NoteOn() => Connection.SendMessagePacket(
midi2.MidiMessageBuilder.BuildMidi2ChannelVoiceMessage(
0,
GroupIndex,
midi2.Midi2ChannelVoiceMessageStatus.NoteOn,
ChannelIndex,
(ushort)((ushort)NoteNumber << 8),
1000));
public void NoteOff() => Connection.SendMessagePacket(
midi2.MidiMessageBuilder.BuildMidi2ChannelVoiceMessage(
0,
GroupIndex,
midi2.Midi2ChannelVoiceMessageStatus.NoteOff,
ChannelIndex,
(ushort)((ushort)NoteNumber << 8),
0));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ CMidi2DiagnosticsEndpointManager::CreateLoopbackEndpoint(
DEVPROP_BOOLEAN devPropTrue = DEVPROP_TRUE;
DEVPROP_BOOLEAN devPropFalse = DEVPROP_FALSE;
BYTE nativeDataFormat = MIDI_PROP_NATIVEDATAFORMAT_UMP;
uint32_t supportedDataFormat = (BYTE)MidiDataFormat::MidiDataFormat_UMP;
UINT32 supportedDataFormat = (UINT32)MidiDataFormat::MidiDataFormat_UMP;

std::wstring description = L"Diagnostics loopback endpoint. For testing purposes.";

Expand All @@ -131,7 +131,7 @@ CMidi2DiagnosticsEndpointManager::CreateLoopbackEndpoint(
DEVPROP_TYPE_EMPTY, 0, nullptr},

{{PKEY_MIDI_SupportedDataFormats, DEVPROP_STORE_SYSTEM, nullptr},
DEVPROP_TYPE_BYTE, static_cast<ULONG>(sizeof(BYTE)), &supportedDataFormat},
DEVPROP_TYPE_UINT32, static_cast<ULONG>(sizeof(UINT32)), &supportedDataFormat},


{{DEVPKEY_DeviceInterface_FriendlyName, DEVPROP_STORE_SYSTEM, nullptr},
Expand Down Expand Up @@ -236,7 +236,7 @@ CMidi2DiagnosticsEndpointManager::CreatePingEndpoint(
DEVPROP_BOOLEAN devPropTrue = DEVPROP_TRUE;
DEVPROP_BOOLEAN devPropFalse = DEVPROP_FALSE;
BYTE nativeDataFormat = MIDI_PROP_NATIVEDATAFORMAT_UMP;
BYTE supportedDataFormat = (BYTE)MidiDataFormat::MidiDataFormat_UMP;
UINT32 supportedDataFormat = (UINT32)MidiDataFormat::MidiDataFormat_UMP;

auto endpointPurpose = (uint32_t)MidiEndpointDevicePurposePropertyValue::DiagnosticPing;

Expand All @@ -252,7 +252,7 @@ CMidi2DiagnosticsEndpointManager::CreatePingEndpoint(
DEVPROP_TYPE_BOOLEAN, static_cast<ULONG>(sizeof(devPropFalse)), &devPropFalse},

{{PKEY_MIDI_SupportedDataFormats, DEVPROP_STORE_SYSTEM, nullptr},
DEVPROP_TYPE_BYTE, static_cast<ULONG>(sizeof(BYTE)), &supportedDataFormat},
DEVPROP_TYPE_UINT32, static_cast<ULONG>(sizeof(UINT32)), &supportedDataFormat},



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@
<ClCompile Include="Midi2.VirtualMidiBidi.cpp" />
<ClCompile Include="MidiEndpointTable.cpp" />
<ClCompile Include="pch.cpp" />
<ClCompile Include="swd_shared.cpp" />
</ItemGroup>
<ItemGroup>
<Midl Include="Midi2VirtualMidiAbstraction.idl" />
Expand All @@ -298,6 +299,7 @@
<ClInclude Include="MidiEndpointTable.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="swd_shared.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Midi2.VirtualMidiAbstraction.rc" />
Expand Down
Loading

0 comments on commit b4e2b80

Please sign in to comment.