diff --git a/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.Initialization.dll b/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.Initialization.dll
index dca31714f..4c7d029c4 100644
Binary files a/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.Initialization.dll and b/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.Initialization.dll differ
diff --git a/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.Initialization.winmd b/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.Initialization.winmd
index 8f2861740..8b785af16 100644
Binary files a/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.Initialization.winmd and b/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.Initialization.winmd differ
diff --git a/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.dll b/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.dll
index 9c27bb813..13c5eeb69 100644
Binary files a/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.dll and b/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.dll differ
diff --git a/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.winmd b/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.winmd
index b376467fd..89390b684 100644
Binary files a/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.winmd and b/build/staging/app-sdk/Arm64EC/Microsoft.Windows.Devices.Midi2.winmd differ
diff --git a/build/staging/app-sdk/Arm64EC/mididiag.exe b/build/staging/app-sdk/Arm64EC/mididiag.exe
index f9086088d..305a19a50 100644
Binary files a/build/staging/app-sdk/Arm64EC/mididiag.exe and b/build/staging/app-sdk/Arm64EC/mididiag.exe differ
diff --git a/build/staging/version/BundleInfo.wxi b/build/staging/version/BundleInfo.wxi
index cc1ec1cc8..0d8d2c475 100644
--- a/build/staging/version/BundleInfo.wxi
+++ b/build/staging/version/BundleInfo.wxi
@@ -1,4 +1,4 @@
-
+
diff --git a/src/api/Abstraction/KSAbstraction/Midi2.KSMidiEndpointManager.cpp b/src/api/Abstraction/KSAbstraction/Midi2.KSMidiEndpointManager.cpp
index 10f80202e..3c051e3d2 100644
--- a/src/api/Abstraction/KSAbstraction/Midi2.KSMidiEndpointManager.cpp
+++ b/src/api/Abstraction/KSAbstraction/Midi2.KSMidiEndpointManager.cpp
@@ -951,8 +951,8 @@ CMidi2KSMidiEndpointManager::Cleanup()
m_DeviceStopped.revoke();
m_DeviceEnumerationCompleted.revoke();
- m_MidiDeviceManager.reset();
- m_MidiProtocolManager.reset();
+ m_MidiDeviceManager.reset();
+ m_MidiProtocolManager.reset();
return S_OK;
}
diff --git a/src/api/Abstraction/KSAggregateAbstraction/Midi2.KSAggregateMidiEndpointManager.cpp b/src/api/Abstraction/KSAggregateAbstraction/Midi2.KSAggregateMidiEndpointManager.cpp
index 55fee7254..5a019b781 100644
--- a/src/api/Abstraction/KSAggregateAbstraction/Midi2.KSAggregateMidiEndpointManager.cpp
+++ b/src/api/Abstraction/KSAggregateAbstraction/Midi2.KSAggregateMidiEndpointManager.cpp
@@ -46,7 +46,8 @@ CMidi2KSAggregateMidiEndpointManager::Initialize(
MIDI_TRACE_EVENT_INFO,
TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD),
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
- TraceLoggingPointer(this, "this")
+ TraceLoggingPointer(this, "this"),
+ TraceLoggingWideString(L"Enter", MIDI_TRACE_EVENT_MESSAGE_FIELD)
);
RETURN_HR_IF(E_INVALIDARG, nullptr == midiDeviceManager);
@@ -86,7 +87,7 @@ CMidi2KSAggregateMidiEndpointManager::Initialize(
_Use_decl_annotations_
HRESULT
CMidi2KSAggregateMidiEndpointManager::CreateMidiUmpEndpoint(
- KsAggregateEndpointDefinition& MasterEndpointDefinition
+ KsAggregateEndpointDefinition& masterEndpointDefinition
)
{
TraceLoggingWrite(
@@ -96,21 +97,24 @@ CMidi2KSAggregateMidiEndpointManager::CreateMidiUmpEndpoint(
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
TraceLoggingPointer(this, "this"),
TraceLoggingWideString(L"Creating aggregate UMP endpoint", MIDI_TRACE_EVENT_MESSAGE_FIELD),
- TraceLoggingWideString(MasterEndpointDefinition.EndpointName.c_str(), "name")
- );
+ TraceLoggingWideString(masterEndpointDefinition.EndpointName.c_str(), "name"),
+ TraceLoggingWideString(masterEndpointDefinition.EndpointDeviceInstanceId.c_str(), "Endpoint Device Instance Id"),
+ TraceLoggingWideString(masterEndpointDefinition.FilterDeviceId.c_str(), "Filter Device Id"),
+ TraceLoggingWideString(masterEndpointDefinition.ParentDeviceInstanceId.c_str(), "Parent Device Instance Id")
+ );
// we require at least one valid pin
- RETURN_HR_IF(E_INVALIDARG, MasterEndpointDefinition.Pins.size() < 1);
+ RETURN_HR_IF(E_INVALIDARG, masterEndpointDefinition.Pins.size() < 1);
std::vector interfaceDevProperties;
MIDIENDPOINTCOMMONPROPERTIES commonProperties{};
commonProperties.AbstractionLayerGuid = ABSTRACTION_LAYER_GUID;
commonProperties.EndpointPurpose = MidiEndpointDevicePurposePropertyValue::NormalMessageEndpoint;
- commonProperties.FriendlyName = MasterEndpointDefinition.EndpointName.c_str();
+ commonProperties.FriendlyName = masterEndpointDefinition.EndpointName.c_str();
commonProperties.TransportCode = TRANSPORT_CODE;
- commonProperties.TransportSuppliedEndpointName = MasterEndpointDefinition.FilterName.c_str();
+ commonProperties.TransportSuppliedEndpointName = masterEndpointDefinition.FilterName.c_str();
commonProperties.TransportSuppliedEndpointDescription = nullptr;
commonProperties.UserSuppliedEndpointName = nullptr;
commonProperties.UserSuppliedEndpointDescription = nullptr;
@@ -126,10 +130,10 @@ CMidi2KSAggregateMidiEndpointManager::CreateMidiUmpEndpoint(
commonProperties.SupportsMidi2ProtocolDefaultValue = false;
interfaceDevProperties.push_back({ {DEVPKEY_KsMidiPort_KsFilterInterfaceId, DEVPROP_STORE_SYSTEM, nullptr},
- DEVPROP_TYPE_STRING, static_cast((MasterEndpointDefinition.FilterDeviceId.length() + 1) * sizeof(WCHAR)), (PVOID)MasterEndpointDefinition.FilterDeviceId.c_str() });
+ DEVPROP_TYPE_STRING, static_cast((masterEndpointDefinition.FilterDeviceId.length() + 1) * sizeof(WCHAR)), (PVOID)masterEndpointDefinition.FilterDeviceId.c_str() });
interfaceDevProperties.push_back({ {DEVPKEY_KsTransport, DEVPROP_STORE_SYSTEM, nullptr },
- DEVPROP_TYPE_UINT32, static_cast(sizeof(UINT32)), (PVOID)&MasterEndpointDefinition.TransportCapability });
+ DEVPROP_TYPE_UINT32, static_cast(sizeof(UINT32)), (PVOID)&masterEndpointDefinition.TransportCapability });
// create group terminal blocks and the pin map
@@ -140,7 +144,7 @@ CMidi2KSAggregateMidiEndpointManager::CreateMidiUmpEndpoint(
KSMIDI_PIN_MAP pinMap{ };
std::vector blocks;
- for (auto const& pin : MasterEndpointDefinition.Pins)
+ for (auto const& pin : masterEndpointDefinition.Pins)
{
internal::GroupTerminalBlockInternal gtb;
@@ -218,9 +222,9 @@ CMidi2KSAggregateMidiEndpointManager::CreateMidiUmpEndpoint(
SW_DEVICE_CREATE_INFO createInfo{ };
createInfo.cbSize = sizeof(createInfo);
- createInfo.pszInstanceId = MasterEndpointDefinition.EndpointDeviceInstanceId.c_str();
+ createInfo.pszInstanceId = masterEndpointDefinition.EndpointDeviceInstanceId.c_str();
createInfo.CapabilityFlags = SWDeviceCapabilitiesNone;
- createInfo.pszDeviceDescription = MasterEndpointDefinition.EndpointName.c_str();
+ createInfo.pszDeviceDescription = masterEndpointDefinition.EndpointName.c_str();
// Call the device manager and finish the creation
@@ -231,7 +235,7 @@ CMidi2KSAggregateMidiEndpointManager::CreateMidiUmpEndpoint(
LOG_IF_FAILED(
swdCreationResult = m_MidiDeviceManager->ActivateEndpoint(
- MasterEndpointDefinition.ParentDeviceInstanceId.c_str(),
+ masterEndpointDefinition.ParentDeviceInstanceId.c_str(),
false, // TODO: create UMP only, handle the MIDI 1.0 compat ports
MidiFlow::MidiFlowBidirectional, // bidi only for the UMP endpoint
&commonProperties,
@@ -254,13 +258,18 @@ CMidi2KSAggregateMidiEndpointManager::CreateMidiUmpEndpoint(
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
TraceLoggingPointer(this, "this"),
TraceLoggingWideString(L"Aggregate UMP endpoint created", MIDI_TRACE_EVENT_MESSAGE_FIELD),
- TraceLoggingWideString(MasterEndpointDefinition.EndpointName.c_str(), "name"),
- TraceLoggingWideString(newDeviceInterfaceId, "endpoint id")
+ TraceLoggingWideString(masterEndpointDefinition.EndpointName.c_str(), "name"),
+ TraceLoggingWideString(newDeviceInterfaceId, MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD)
);
- // TODO: Add to internal endpoint manager, and also return the device interface id
+ // todo: return new device interface id
+
- return swdCreationResult; // TODO change this to account for other steps
+
+ // Add to internal endpoint manager
+ m_availableEndpointDefinitions.push_back(std::move(masterEndpointDefinition));
+
+ return swdCreationResult;
}
else
{
@@ -271,7 +280,7 @@ CMidi2KSAggregateMidiEndpointManager::CreateMidiUmpEndpoint(
TraceLoggingLevel(WINEVENT_LEVEL_ERROR),
TraceLoggingPointer(this, "this"),
TraceLoggingWideString(L"Aggregate UMP endpoint creation failed", MIDI_TRACE_EVENT_MESSAGE_FIELD),
- TraceLoggingWideString(MasterEndpointDefinition.EndpointName.c_str(), "name"),
+ TraceLoggingWideString(masterEndpointDefinition.EndpointName.c_str(), "name"),
TraceLoggingHResult(swdCreationResult, MIDI_TRACE_EVENT_HRESULT_FIELD)
);
@@ -358,7 +367,7 @@ CMidi2KSAggregateMidiEndpointManager::OnDeviceAdded(
auto prop = properties.Lookup(winrt::to_hstring(L"System.Devices.DeviceInstanceId"));
RETURN_HR_IF_NULL(E_INVALIDARG, prop);
endpointDefinition.ParentDeviceInstanceId = winrt::unbox_value(prop).c_str();
- endpointDefinition.FilterDeviceId = device.Id().c_str();
+ endpointDefinition.FilterDeviceId = internal::NormalizeDeviceInstanceIdWStringCopy(device.Id().c_str());
// get the parent device
auto parentDeviceInfo = DeviceInformation::CreateFromIdAsync(endpointDefinition.ParentDeviceInstanceId,
@@ -584,43 +593,51 @@ HRESULT CMidi2KSAggregateMidiEndpointManager::OnDeviceRemoved(DeviceWatcher, Dev
TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD),
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
TraceLoggingPointer(this, "this"),
+ TraceLoggingWideString(L"Enter", MIDI_TRACE_EVENT_MESSAGE_FIELD),
TraceLoggingWideString(device.Id().c_str(), "device id")
);
+ auto cleanDeviceId = internal::NormalizeDeviceInstanceIdWStringCopy(device.Id().c_str());
- // TODO
+ // the interface is no longer active, search through our m_AvailableMidiPins to identify
+ // every entry with this filter interface id, and remove the SWD and remove the pin(s) from
+ // the m_AvailableMidiPins list.
+ do
+ {
+ auto item = std::find_if(m_availableEndpointDefinitions.begin(),
+ m_availableEndpointDefinitions.end(), [&](const KsAggregateEndpointDefinition& endpointDefinition)
+ {
+ if (endpointDefinition.FilterDeviceId == cleanDeviceId)
+ {
+ return true;
+ }
+
+ return false;
+ });
+ if (item == m_availableEndpointDefinitions.end())
+ {
+ break;
+ }
+ TraceLoggingWrite(
+ MidiKSAggregateAbstractionTelemetryProvider::Provider(),
+ MIDI_TRACE_EVENT_INFO,
+ TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD),
+ TraceLoggingLevel(WINEVENT_LEVEL_INFO),
+ TraceLoggingPointer(this, "this"),
+ TraceLoggingWideString(L"Found device to remove", MIDI_TRACE_EVENT_MESSAGE_FIELD),
+ TraceLoggingWideString(device.Id().c_str(), "device id")
+ );
- // the interface is no longer active, search through our m_AvailableMidiPins to identify
- // every entry with this filter interface id, and remove the SWD and remove the pin(s) from
- // the m_AvailableMidiPins list.
- //do
- //{
- // auto item = std::find_if(m_AvailableMidiPins.begin(), m_AvailableMidiPins.end(), [&](const std::unique_ptr& Pin)
- // {
- // // if this interface id already activated, then we cannot activate/create a second time,
- // if (device.Id() == Pin->Id)
- // {
- // return true;
- // }
-
- // return false;
- // });
-
- // if (item == m_AvailableMidiPins.end())
- // {
- // break;
- // }
-
- // // notify the device manager using the InstanceId for this midi device
- // LOG_IF_FAILED(m_MidiDeviceManager->RemoveEndpoint(item->get()->InstanceId.c_str()));
-
- // // remove the MIDI_PIN_INFO from the list
- // m_AvailableMidiPins.erase(item);
- //}
- //while (TRUE);
+ // notify the device manager using the InstanceId for this midi device
+ LOG_IF_FAILED(m_MidiDeviceManager->RemoveEndpoint(device.Id().c_str()));
+
+ // remove the MIDI_PIN_INFO from the list
+ m_availableEndpointDefinitions.erase(item);
+ }
+ while (TRUE);
return S_OK;
}
@@ -669,8 +686,8 @@ CMidi2KSAggregateMidiEndpointManager::Cleanup()
m_DeviceStopped.revoke();
m_DeviceEnumerationCompleted.revoke();
- m_MidiDeviceManager.reset();
- m_MidiProtocolManager.reset();
+ m_MidiDeviceManager.reset();
+ m_MidiProtocolManager.reset();
return S_OK;
}
diff --git a/src/api/Abstraction/KSAggregateAbstraction/Midi2.KSAggregateMidiEndpointManager.h b/src/api/Abstraction/KSAggregateAbstraction/Midi2.KSAggregateMidiEndpointManager.h
index 811b95bfb..b4ff321c7 100644
--- a/src/api/Abstraction/KSAggregateAbstraction/Midi2.KSAggregateMidiEndpointManager.h
+++ b/src/api/Abstraction/KSAggregateAbstraction/Midi2.KSAggregateMidiEndpointManager.h
@@ -30,7 +30,6 @@ struct KsAggregateEndpointDefinition
MidiTransport TransportCapability;
-
std::vector Pins;
};
@@ -59,7 +58,7 @@ class CMidi2KSAggregateMidiEndpointManager :
wil::com_ptr_nothrow m_MidiDeviceManager;
wil::com_ptr_nothrow m_MidiProtocolManager;
- //std::vector> m_AvailableMidiPins;
+ std::vector m_availableEndpointDefinitions;
DeviceWatcher m_Watcher{0};
winrt::impl::consume_Windows_Devices_Enumeration_IDeviceWatcher::Added_revoker m_DeviceAdded;