Skip to content

Commit

Permalink
Merge pull request #326 from microsoft/pete-dev
Browse files Browse the repository at this point in the history
Connection bug fixes
  • Loading branch information
Psychlist1972 authored Apr 26, 2024
2 parents aa03ac2 + 37a639f commit 8e47c7c
Show file tree
Hide file tree
Showing 49 changed files with 1,353 additions and 431 deletions.
26 changes: 13 additions & 13 deletions build/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ Task("BuildConsoleApp")
Configuration = configuration,

PublishSingleFile = false,
PublishTrimmed = true,
//PublishAot = true, // not currently supported in cake, so make sure this is set in project file
PublishTrimmed = false, // must be true for AOT
//PublishAot = false, // not currently supported in cake, so make sure this is set in project file
SelfContained = false,
Framework = frameworkVersion,
Runtime = rid
Expand Down Expand Up @@ -613,17 +613,17 @@ Task("CopyAPIArtifacts")
if (!DirectoryExists(platReleaseFolder))
CreateDirectory(platReleaseFolder);

CopyFiles(System.IO.Path.Combine(apiStagingDir, "Windows.Devices.Midi2.winmd"), platReleaseFolder);
CopyFiles(System.IO.Path.Combine(apiStagingDir, "Windows.Devices.Midi2.dll"), platReleaseFolder);
CopyFiles(System.IO.Path.Combine(apiStagingDir, "Windows.Devices.Midi2.pri"), platReleaseFolder);
CopyFiles(System.IO.Path.Combine(apiStagingDir, "Windows.Devices.Midi2.h"), platReleaseFolder);
CopyFiles(System.IO.Path.Combine(apiStagingDir, "winrt/base.h"), System.IO.Path.Combine(platReleaseFolder, "winrt/"));
CopyFiles(System.IO.Path.Combine(apiStagingDir, "winrt/Windows.Devices.h"), System.IO.Path.Combine(platReleaseFolder, "winrt/"));
CopyFiles(System.IO.Path.Combine(apiStagingDir, "winrt/impl/Windows.Devices.Enumeration.2.h"), System.IO.Path.Combine(platReleaseFolder, "winrt/impl/"));
CopyFiles(System.IO.Path.Combine(apiStagingDir, "winrt/impl/Windows.Devices.Midi.2.h"), System.IO.Path.Combine(platReleaseFolder, "winrt/impl/"));
CopyFiles(System.IO.Path.Combine(apiStagingDir, "winrt/impl/Windows.Foundation.2.h"), System.IO.Path.Combine(platReleaseFolder, "winrt/impl/"));
CopyFiles(System.IO.Path.Combine(apiStagingDir, "winrt/impl/Windows.Foundation.Collections.2.h"), System.IO.Path.Combine(platReleaseFolder, "winrt/impl/"));
CopyFiles(System.IO.Path.Combine(apiStagingDir, "winrt/impl/Windows.Devices.Midi2.2.h"), System.IO.Path.Combine(platReleaseFolder, "winrt/impl/"));
CopyFiles(System.IO.Path.Combine(apiStagingDir, $"{MIDI2_NAMESPACE}.winmd"), platReleaseFolder);
CopyFiles(System.IO.Path.Combine(apiStagingDir, $"{MIDI2_NAMESPACE}.dll"), platReleaseFolder);
CopyFiles(System.IO.Path.Combine(apiStagingDir, $"{MIDI2_NAMESPACE}.pri"), platReleaseFolder);
CopyFiles(System.IO.Path.Combine(apiStagingDir, $"{MIDI2_NAMESPACE}.h"), platReleaseFolder);
CopyFiles(System.IO.Path.Combine(apiStagingDir, $"winrt/base.h"), System.IO.Path.Combine(platReleaseFolder, "winrt/"));
CopyFiles(System.IO.Path.Combine(apiStagingDir, $"winrt/Windows.Devices.h"), System.IO.Path.Combine(platReleaseFolder, "winrt/"));
CopyFiles(System.IO.Path.Combine(apiStagingDir, $"winrt/impl/Windows.Devices.Enumeration.2.h"), System.IO.Path.Combine(platReleaseFolder, "winrt/impl/"));
CopyFiles(System.IO.Path.Combine(apiStagingDir, $"winrt/impl/Windows.Devices.Midi.2.h"), System.IO.Path.Combine(platReleaseFolder, "winrt/impl/"));
CopyFiles(System.IO.Path.Combine(apiStagingDir, $"winrt/impl/Windows.Foundation.2.h"), System.IO.Path.Combine(platReleaseFolder, "winrt/impl/"));
CopyFiles(System.IO.Path.Combine(apiStagingDir, $"winrt/impl/Windows.Foundation.Collections.2.h"), System.IO.Path.Combine(platReleaseFolder, "winrt/impl/"));
CopyFiles(System.IO.Path.Combine(apiStagingDir, $"winrt/impl/{MIDI2_NAMESPACE}.2.h"), System.IO.Path.Combine(platReleaseFolder, "winrt/impl/"));


});
Expand Down
8 changes: 4 additions & 4 deletions build/replace_running_service_x64.bat
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ copy /Y %buildoutput%\MidiSrv.exe %servicepath%
copy /Y %buildoutput%\Midi2.*Abstraction.dll %servicepath%
copy /Y %buildoutput%\Midi2.*Transform.dll %servicepath%

echo Windows.Devices.Midi2.dll
copy /Y %buildoutput%\Windows.Devices.Midi2.dll %apipath%
echo Windows.Devices.Midi2.pri
copy /Y %buildoutput%\Windows.Devices.Midi2.pri %apipath%
echo API impl
copy /Y %buildoutput%\*.Devices.Midi2.dll %apipath%
echo API pri
copy /Y %buildoutput%\*.Devices.Midi2.pri %apipath%



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 6 arm64" ?>
<?define SetupVersionNumber="1.0.24112.1126" ?>
<?define SetupVersionNumber="1.0.24117.0049" ?>
</Include>
2 changes: 1 addition & 1 deletion diagnostics/trace-logging/MidiServices.wprp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<EventProvider Id="EventProvider_BluetoothMidiAbstraction" Name="*Microsoft.Windows.Midi2.BluetoothMidiAbstraction"/>
<EventProvider Id="EventProvider_LoopbackMidiAbstraction" Name="*Microsoft.Windows.Midi2.LoopbackMidiAbstraction"/>

<EventProvider Id="EventProvider_API" Name="*Microsoft.Devices.Midi2.Api"/>
<EventProvider Id="EventProvider_API" Name="*Microsoft.Windows.Devices.Midi2.Api"/>

<EventProvider Id="EventProvider_BS2UMPTransform" Name="*Microsoft.Windows.Midi2.BS2UMPTransform"/>
<EventProvider Id="EventProvider_EndpointMetadataListenerTransform" Name="*Microsoft.Windows.Midi2.EndpointMetadataListenerTransform"/>
Expand Down
2 changes: 2 additions & 0 deletions docs/api/service/MidiService.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ has_children: false

The MidiService class contains a number of static functions which enable working with the service outside of a specific session.

## Static Methods

### Service Health

| `IsAvailable()` | Returns true of Windows MIDI Services is available on this PC. Calling this function is typically the first step in using Windows MIDI Services in your application. |
Expand Down
2 changes: 1 addition & 1 deletion docs/api/service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ has_children: true

# Service

The MidiService class is a utility class which provides access to health and status information related to the MidiSrv Service. This is also where you can check to see if Windows MIDI Services is available on this PC.
The `MidiService` class is a utility class which provides access to health and status information related to the MidiSrv Service. This is also where you can check to see if Windows MIDI Services is available on this PC.
22 changes: 9 additions & 13 deletions docs/api/session/MidiSession.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,43 @@ has_children: false

# MidiSession

## Remarks

Before you can connect to an endpoint, you must start a new MIDI session.

An application may have any number of sessions open. For example, the application may open one session per open project, or one session per tab in the case of a browser. The lifetime of endpoint connections opened through a session are controlled through the session.

## Properties

| Property | Description |
| -------- | ----------- |
| `Id` | Generated Id for the session |
| `Name` | Name for this session. To change the name after creating the session, use the `UpdateName()` function. This will update the service |
| `Settings` | The settings used to create this session |
| `IsOpen` | True if this session is open and ready to use |
| `Connections` | Map of all endpoint connections created through this session. Disconnecting an endpoint using `DisconnectEndpointConnection` will remove the connection from this map. The map key is the generated connection GUID that identifies an instance of an endpoint connection |

## Static Member Functions
## Static Methods

The two static functions are factory-pattern methods for creating a new session.

| Static Function | Description |
| -------- | ----------- |
| `CreateSession(sessionName)` | Create and return a new session with the specified name |
| `CreateSession(sessionName, settings)` | Create and return a new session with the specified name and settings |

## Functions
## Methods

| Function | Description |
| -------- | ----------- |
| `CreateEndpointConnection(endpointDeviceId)` | Create a new connection to the specified endpoint device Id |
| `CreateEndpointConnection(endpointDeviceId, options)` | Create a new connection to the specified endpoint device Id, using the provided connection options |
| `CreateEndpointConnection(endpointDeviceId, options, settings)` | Create a new connection to the specified endpoint device Id, using the provided connection options and the endpoint-specific settings |
| `CreateEndpointConnection(String)` | Create a new connection to the specified endpoint device Id |
| `CreateEndpointConnection(String, Boolean)` | Create a new connection to the specified endpoint device Id, with an option to reconnect if a device is disconnected and then reconnected while the connection object is alive |
| `CreateEndpointConnection(String, Boolean, IMidiEndpointConnectionSettings)` | Create a new connection to the specified endpoint device Id, using the provided reconnect value and endpoint-specific settings |
| `CreateVirtualDeviceAndConnection(deviceDefinition)` | Create the device-side of an app-to-app virtual endpoint. The calling application will perform as a MIDI device, responding to discovery and other MIDI 2.0 protocol messages. |
| `DisconnectEndpointConnection(endpointConnectionId)` | Cleanly disconnect an endpoint connection and remove it from the connection map |
| `UpdateName(newName)` | Update the name of this session locally and in the MIDI Service |

> Note: If you manually close a MidiEndpointConnection using `IClosable` (or `IDisposable`), it will not be removed from the MidiSession's collection of endpoints. Instead, use the `DisconnectEndpointConnection` method of the session to keep both in sync. For that reason, we do not recommend that you wrap the `CreateEndpointConnection` calls in a using statement.
## IDL
## See also

[MidiSession IDL](https://github.com/microsoft/MIDI/blob/main/src/api/Client/Midi2Client/MidiSession.idl)

## Sample
### Sample

```cs
using (var session = MidiSession.CreateSession("API Sample Session"))
Expand Down
4 changes: 0 additions & 4 deletions docs/api/simple-types/MidiUniqueId.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,11 @@ In the specification, Byte1 is the LSB and Byte4 is the MSB. We follow that conv

## Static Properties

| Static Property | Description |
| --------------- | ----------- |
| `LabelShort` | Returns the localized abbreviation for use in UI. |
| `LabelFull` | Returns the localized full name for use in UI. |

## Static Methods

| Function | Description |
| --------------- | ----------- |
| `CreateBroadcast()` | Constructs a broadcast `MidiUniqueId` per the MIDI CI specification |
| `CreateRandom()` | Constructs a random `MidiUniqueId` per the MIDI CI specification |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class CMidi2LoopbackMidiBiDi :
//wil::com_ptr_nothrow<IMidiCallback> m_associatedBiDiCallback;


wil::com_ptr_nothrow <IMidiCallback> m_callback;
LONGLONG m_callbackContext;
wil::com_ptr_nothrow <IMidiCallback> m_callback{ nullptr };
LONGLONG m_callbackContext{};

std::wstring m_endpointId{};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,44 @@ CMidi2MidiSrvSessionTracker::Initialize()
return S_OK;
}

HRESULT
CMidi2MidiSrvSessionTracker::VerifyConnectivity()
{
TraceLoggingWrite(
MidiSrvAbstractionTelemetryProvider::Provider(),
__FUNCTION__,
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
TraceLoggingPointer(this, "this")
);

wil::unique_rpc_binding bindingHandle;

RETURN_IF_FAILED(GetMidiSrvBindingHandle(&bindingHandle));

RETURN_IF_FAILED([&]()
{
// RPC calls are placed in a lambda to work around compiler error C2712, limiting use of try/except blocks
// with structured exception handling.
RpcTryExcept RETURN_IF_FAILED(MidiSrvVerifyConnectivity(bindingHandle.get()));
RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) RETURN_IF_FAILED(HRESULT_FROM_WIN32(RpcExceptionCode()));
RpcEndExcept

return S_OK;
}());

return S_OK;








}



_Use_decl_annotations_
HRESULT
CMidi2MidiSrvSessionTracker::AddClientSession(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class CMidi2MidiSrvSessionTracker :
// This is called from the API
STDMETHOD(GetSessionListJson(_Out_ BSTR* SessionList));

STDMETHOD(VerifyConnectivity)();

STDMETHOD(Cleanup());

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Microsoft.Devices.Midi2</id>
<version>1.0.0-preview.6-0194</version>
<authors>Microsoft Corporation</authors>
<version>1.0.0-preview.6-0198</version>
<authors>Microsoft</authors>
<description>Windows MIDI Services SDK. Minimum package necessary to use Windows MIDI Services from an app on a PC that has Windows MIDI Services installed.</description>
<license type="expression">MIT</license>
<projectUrl>https://github.com/microsoft/midi/</projectUrl>
Expand Down
Loading

0 comments on commit 8e47c7c

Please sign in to comment.