From ba15b51d40ccbfa8a372f840efe2eef9af89b778 Mon Sep 17 00:00:00 2001 From: Pete Brown Date: Mon, 22 Jul 2024 20:14:58 -0400 Subject: [PATCH 01/32] Fix Virtual Device bug #371 --- .../Midi2.VirtualMidiBidi.cpp | 79 +++++++----- .../MidiEndpointTable.cpp | 116 +++++++++++++----- src/api/Inc/MidiDefs.h | 1 + 3 files changed, 132 insertions(+), 64 deletions(-) diff --git a/src/api/Abstraction/VirtualMidiAbstraction/Midi2.VirtualMidiBidi.cpp b/src/api/Abstraction/VirtualMidiAbstraction/Midi2.VirtualMidiBidi.cpp index df700d43c..7305aa573 100644 --- a/src/api/Abstraction/VirtualMidiAbstraction/Midi2.VirtualMidiBidi.cpp +++ b/src/api/Abstraction/VirtualMidiAbstraction/Midi2.VirtualMidiBidi.cpp @@ -27,7 +27,8 @@ CMidi2VirtualMidiBiDi::Initialize( TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_INFO), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(endpointId, "endpoint id") + TraceLoggingWideString(L"Enter", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(endpointId, MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); m_callbackContext = Context; @@ -43,12 +44,12 @@ CMidi2VirtualMidiBiDi::Initialize( { TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - MIDI_TRACE_EVENT_INFO, + MIDI_TRACE_EVENT_VERBOSE, TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), - TraceLoggingLevel(WINEVENT_LEVEL_INFO), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), TraceLoggingPointer(this, "this"), TraceLoggingWideString(L"Initializing device-side BiDi", MIDI_TRACE_EVENT_MESSAGE_FIELD), - TraceLoggingWideString(m_endpointId.c_str(), "endpoint id") + TraceLoggingWideString(m_endpointId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); m_callback = Callback; @@ -60,12 +61,12 @@ CMidi2VirtualMidiBiDi::Initialize( { TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - MIDI_TRACE_EVENT_INFO, + MIDI_TRACE_EVENT_VERBOSE, TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), - TraceLoggingLevel(WINEVENT_LEVEL_INFO), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), TraceLoggingPointer(this, "this"), TraceLoggingWideString(L"Initializing client-side BiDi", MIDI_TRACE_EVENT_MESSAGE_FIELD), - TraceLoggingWideString(m_endpointId.c_str(), "endpoint id") + TraceLoggingWideString(m_endpointId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); m_callback = Callback; @@ -82,7 +83,7 @@ CMidi2VirtualMidiBiDi::Initialize( TraceLoggingLevel(WINEVENT_LEVEL_ERROR), TraceLoggingPointer(this, "this"), TraceLoggingWideString(L"We don't understand the endpoint Id", MIDI_TRACE_EVENT_MESSAGE_FIELD), - TraceLoggingWideString(m_endpointId.c_str(), "endpoint id") + TraceLoggingWideString(m_endpointId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); // we don't understand this endpoint id @@ -109,7 +110,8 @@ CMidi2VirtualMidiBiDi::Cleanup() TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_INFO), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(m_endpointId.c_str(), "endpoint id"), + TraceLoggingWideString(L"Enter", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(m_endpointId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD), TraceLoggingBool(m_isDeviceSide, "is device side") ); @@ -140,36 +142,50 @@ CMidi2VirtualMidiBiDi::SendMidiMessage( { TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - MIDI_TRACE_EVENT_INFO, + MIDI_TRACE_EVENT_VERBOSE, TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), - TraceLoggingLevel(WINEVENT_LEVEL_INFO), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(m_endpointId.c_str(), "endpoint id"), - TraceLoggingBool(m_isDeviceSide, "is device side") + TraceLoggingWideString(L"Enter", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(m_endpointId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD), + TraceLoggingBool(m_isDeviceSide, "is device side"), + TraceLoggingUInt32(Size, "bytes"), + TraceLoggingUInt64(Position, "timestamp") ); + // message received from the device RETURN_HR_IF_NULL(E_INVALIDARG, Message); RETURN_HR_IF(E_INVALIDARG, Size < sizeof(uint32_t)); - for (auto connection : m_linkedBiDiConnections) + if (m_linkedBiDiConnections.size() > 0) { - auto cb = connection->GetCallback(); - - if (cb != nullptr) + for (auto connection : m_linkedBiDiConnections) { - return cb->Callback(Message, Size, Position, m_callbackContext); + auto cb = connection->GetCallback(); + + if (cb != nullptr) + { + LOG_IF_FAILED(cb->Callback(Message, Size, Position, m_callbackContext)); + } } } - - - //// if there's no linked bidi, it's not a failure. We just lose the message - //if (m_linkedBiDiCallback != nullptr) - //{ - // //return m_linkedBiDi->SendMidiMessage(Message, Size, Position); - // return m_linkedBiDiCallback->Callback(Message, Size, Position, m_callbackContext); - //} + else + { + TraceLoggingWrite( + MidiVirtualMidiAbstractionTelemetryProvider::Provider(), + MIDI_TRACE_EVENT_VERBOSE, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), + TraceLoggingPointer(this, "this"), + TraceLoggingWideString(L"No linked connections", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(m_endpointId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD), + TraceLoggingBool(m_isDeviceSide, "is device side"), + TraceLoggingUInt32(Size, "bytes"), + TraceLoggingUInt64(Position, "timestamp") + ); + } return S_OK; @@ -186,12 +202,15 @@ CMidi2VirtualMidiBiDi::Callback( { TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - MIDI_TRACE_EVENT_INFO, + MIDI_TRACE_EVENT_VERBOSE, TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), - TraceLoggingLevel(WINEVENT_LEVEL_INFO), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(m_endpointId.c_str(), "endpoint id"), - TraceLoggingBool(m_isDeviceSide, "is device side") + TraceLoggingWideString(L"Enter", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(m_endpointId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD), + TraceLoggingBool(m_isDeviceSide, "is device side"), + TraceLoggingUInt32(Size, "bytes"), + TraceLoggingUInt64(Position, "timestamp") ); // message received from the client diff --git a/src/api/Abstraction/VirtualMidiAbstraction/MidiEndpointTable.cpp b/src/api/Abstraction/VirtualMidiAbstraction/MidiEndpointTable.cpp index d2c41947d..e83bb93a8 100644 --- a/src/api/Abstraction/VirtualMidiAbstraction/MidiEndpointTable.cpp +++ b/src/api/Abstraction/VirtualMidiAbstraction/MidiEndpointTable.cpp @@ -12,7 +12,8 @@ HRESULT MidiEndpointTable::Cleanup() { TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, + MIDI_TRACE_EVENT_INFO, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_INFO), TraceLoggingPointer(this, "this") ); @@ -27,7 +28,8 @@ HRESULT MidiEndpointTable::AddCreatedEndpointDevice(MidiVirtualDeviceEndpointEnt { TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, + MIDI_TRACE_EVENT_INFO, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_INFO), TraceLoggingPointer(this, "this"), TraceLoggingWideString(entry.VirtualEndpointAssociationId.c_str(), "entry.VirtualEndpointAssociationId"), @@ -56,10 +58,12 @@ MidiEndpointTable::OnClientConnected( { TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, + MIDI_TRACE_EVENT_INFO, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_INFO), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(clientEndpointInterfaceId.c_str()) + TraceLoggingWideString(L"Enter", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(clientEndpointInterfaceId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); // get the device BiDi, and then wire them together @@ -74,7 +78,7 @@ MidiEndpointTable::OnClientConnected( auto associationId = internal::GetSwdPropertyVirtualEndpointAssociationId(clientEndpointInterfaceId); - if (associationId != L"") + if (!associationId.empty()) { if (m_endpoints.find(associationId) != m_endpoints.end()) { @@ -94,13 +98,19 @@ MidiEndpointTable::OnClientConnected( else { // couldn't find the entry + + LOG_IF_FAILED(E_FAIL); // cause fallback error to be logged + TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, + MIDI_TRACE_EVENT_ERROR, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_ERROR), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(L"Unable to find device table entry", MIDI_TRACE_EVENT_MESSAGE_FIELD) + TraceLoggingWideString(L"Unable to find device table entry", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(clientEndpointInterfaceId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); + } } } @@ -118,10 +128,12 @@ MidiEndpointTable::OnClientDisconnected( { TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, + MIDI_TRACE_EVENT_INFO, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_INFO), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(clientEndpointInterfaceId.c_str()) + TraceLoggingWideString(L"Enter", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(clientEndpointInterfaceId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); try @@ -143,11 +155,14 @@ MidiEndpointTable::OnClientDisconnected( TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, + MIDI_TRACE_EVENT_ERROR, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_ERROR), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(L"Association id property was not present in device table", MIDI_TRACE_EVENT_MESSAGE_FIELD) + TraceLoggingWideString(L"Association id property was not present in device table", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(clientEndpointInterfaceId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); + } } else @@ -156,11 +171,14 @@ MidiEndpointTable::OnClientDisconnected( TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, + MIDI_TRACE_EVENT_ERROR, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_ERROR), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(L"Association id property was blank", MIDI_TRACE_EVENT_MESSAGE_FIELD) + TraceLoggingWideString(L"Association id property was blank", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(clientEndpointInterfaceId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); + } } CATCH_RETURN(); @@ -176,12 +194,15 @@ HRESULT MidiEndpointTable::OnDeviceConnected(std::wstring deviceEndpointInterfac { TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, + MIDI_TRACE_EVENT_INFO, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_INFO), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(deviceEndpointInterfaceId.c_str(), "deviceEndpointInterfaceId") + TraceLoggingWideString(L"Enter", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(deviceEndpointInterfaceId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); + try { // look up the association ID in SWD properties @@ -233,12 +254,16 @@ HRESULT MidiEndpointTable::OnDeviceConnected(std::wstring deviceEndpointInterfac } else { + LOG_IF_FAILED(E_FAIL); // cause fallback error to be logged + TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, + MIDI_TRACE_EVENT_ERROR, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_ERROR), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(L"Endpoint Manager is null", MIDI_TRACE_EVENT_MESSAGE_FIELD) + TraceLoggingWideString(L"Endpoint Manager is null", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(deviceEndpointInterfaceId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); return E_FAIL; @@ -247,13 +272,16 @@ HRESULT MidiEndpointTable::OnDeviceConnected(std::wstring deviceEndpointInterfac else { // association id isn't present. That's not right. + LOG_IF_FAILED(E_FAIL); // cause fallback error to be logged TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, + MIDI_TRACE_EVENT_ERROR, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_ERROR), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(L"Association id property was not present in device table", MIDI_TRACE_EVENT_MESSAGE_FIELD) + TraceLoggingWideString(L"Association id property was not present in device table", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(deviceEndpointInterfaceId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); return E_FAIL; @@ -262,13 +290,16 @@ HRESULT MidiEndpointTable::OnDeviceConnected(std::wstring deviceEndpointInterfac else { // association id is blank, which is also not right + LOG_IF_FAILED(E_FAIL); // cause fallback error to be logged TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, + MIDI_TRACE_EVENT_ERROR, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_ERROR), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(L"Association id property was blank", MIDI_TRACE_EVENT_MESSAGE_FIELD) + TraceLoggingWideString(L"Association id property was blank", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(deviceEndpointInterfaceId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); return E_FAIL; @@ -284,12 +315,15 @@ HRESULT MidiEndpointTable::OnDeviceDisconnected(std::wstring deviceEndpointInter { TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, + MIDI_TRACE_EVENT_INFO, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_INFO), - TraceLoggingPointer(this, "this"), - TraceLoggingWideString(deviceEndpointInterfaceId.c_str(), "deviceEndpointInterfaceId") + TraceLoggingPointer(this, "this"), + TraceLoggingWideString(L"Enter", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(deviceEndpointInterfaceId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); + try { if (AbstractionState::Current().GetEndpointManager() != nullptr) @@ -306,11 +340,12 @@ HRESULT MidiEndpointTable::OnDeviceDisconnected(std::wstring deviceEndpointInter { TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, - TraceLoggingLevel(WINEVENT_LEVEL_INFO), + MIDI_TRACE_EVENT_VERBOSE, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(deviceEndpointInterfaceId.c_str(), "deviceEndpointInterfaceId"), - TraceLoggingWideString(L"Unlinking from MidiDeviceBiDi", MIDI_TRACE_EVENT_MESSAGE_FIELD) + TraceLoggingWideString(L"Unlinking from MidiDeviceBiDi", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(deviceEndpointInterfaceId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); // unlink the bidi devices @@ -330,36 +365,49 @@ HRESULT MidiEndpointTable::OnDeviceDisconnected(std::wstring deviceEndpointInter } else { + LOG_IF_FAILED(E_FAIL); // fallback error + TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, + MIDI_TRACE_EVENT_ERROR, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_ERROR), TraceLoggingPointer(this, "this"), TraceLoggingWideString(L"Unexpected. There's no entry for associationId", MIDI_TRACE_EVENT_MESSAGE_FIELD), - TraceLoggingWideString(associationId.c_str()) + TraceLoggingWideString(deviceEndpointInterfaceId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); + } } else { + LOG_IF_FAILED(E_FAIL); // fallback error + TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, + MIDI_TRACE_EVENT_ERROR, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_ERROR), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(L"unable to get association id for this endpoint", MIDI_TRACE_EVENT_MESSAGE_FIELD) + TraceLoggingWideString(L"Unable to get association id for this endpoint", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(deviceEndpointInterfaceId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); } } else { + LOG_IF_FAILED(E_FAIL); // fallback error + TraceLoggingWrite( MidiVirtualMidiAbstractionTelemetryProvider::Provider(), - __FUNCTION__, + MIDI_TRACE_EVENT_ERROR, + TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD), TraceLoggingLevel(WINEVENT_LEVEL_ERROR), TraceLoggingPointer(this, "this"), - TraceLoggingWideString(L"endpoint manager is null", MIDI_TRACE_EVENT_MESSAGE_FIELD) + TraceLoggingWideString(L"Endpoint Manager is null", MIDI_TRACE_EVENT_MESSAGE_FIELD), + TraceLoggingWideString(deviceEndpointInterfaceId.c_str(), MIDI_TRACE_EVENT_DEVICE_SWD_ID_FIELD) ); + } } CATCH_LOG(); diff --git a/src/api/Inc/MidiDefs.h b/src/api/Inc/MidiDefs.h index d57f833e6..7e368a376 100644 --- a/src/api/Inc/MidiDefs.h +++ b/src/api/Inc/MidiDefs.h @@ -14,6 +14,7 @@ #define MIDI_TRACE_EVENT_ERROR "Midi.Error" #define MIDI_TRACE_EVENT_WARNING "Midi.Warning" #define MIDI_TRACE_EVENT_INFO "Midi.Info" +#define MIDI_TRACE_EVENT_VERBOSE "Midi.Verbose" #define MIDI_TRACE_EVENT_MESSAGE_FIELD "message" From dc1fe4163bbc2fff7765e82bdb97cf01aaab628b Mon Sep 17 00:00:00 2001 From: Pete Brown Date: Mon, 22 Jul 2024 20:15:43 -0400 Subject: [PATCH 02/32] Update CS samples solution and remove WPF version --- .../basics/client-basics-cs.exe.manifest | 42 ++--- samples/csharp-net/csharp-net-samples.sln | 10 -- .../virtual-device-app-wpf/App.xaml | 9 - .../virtual-device-app-wpf/App.xaml.cs | 14 -- .../virtual-device-app-wpf/AssemblyInfo.cs | 10 -- .../virtual-device-app-wpf/MainWindow.xaml | 33 ---- .../virtual-device-app-wpf/MainWindow.xaml.cs | 160 ------------------ .../csharp-net/virtual-device-app-wpf/Note.cs | 63 ------- .../virtual-device-app-wpf.csproj | 16 -- 9 files changed, 15 insertions(+), 342 deletions(-) delete mode 100644 samples/csharp-net/virtual-device-app-wpf/App.xaml delete mode 100644 samples/csharp-net/virtual-device-app-wpf/App.xaml.cs delete mode 100644 samples/csharp-net/virtual-device-app-wpf/AssemblyInfo.cs delete mode 100644 samples/csharp-net/virtual-device-app-wpf/MainWindow.xaml delete mode 100644 samples/csharp-net/virtual-device-app-wpf/MainWindow.xaml.cs delete mode 100644 samples/csharp-net/virtual-device-app-wpf/Note.cs delete mode 100644 samples/csharp-net/virtual-device-app-wpf/virtual-device-app-wpf.csproj diff --git a/samples/csharp-net/basics/client-basics-cs.exe.manifest b/samples/csharp-net/basics/client-basics-cs.exe.manifest index 678ef4374..5c97d286a 100644 --- a/samples/csharp-net/basics/client-basics-cs.exe.manifest +++ b/samples/csharp-net/basics/client-basics-cs.exe.manifest @@ -8,7 +8,7 @@ @@ -18,29 +18,21 @@ name="Microsoft.Windows.Devices.Midi2.MidiChannel" threadingModel="both" xmlns="urn:schemas-microsoft-com:winrt.v1" /> - - @@ -67,11 +59,11 @@ xmlns="urn:schemas-microsoft-com:winrt.v1" /> @@ -81,10 +73,6 @@ name="Microsoft.Windows.Devices.Midi2.CapabilityInquiry.MidiUniqueId" threadingModel="both" xmlns="urn:schemas-microsoft-com:winrt.v1" /> - @@ -104,37 +92,37 @@ @@ -149,7 +137,7 @@ threadingModel="both" xmlns="urn:schemas-microsoft-com:winrt.v1" /> @@ -160,7 +148,7 @@ threadingModel="both" xmlns="urn:schemas-microsoft-com:winrt.v1" /> diff --git a/samples/csharp-net/csharp-net-samples.sln b/samples/csharp-net/csharp-net-samples.sln index 83b57d564..6b1b5272a 100644 --- a/samples/csharp-net/csharp-net-samples.sln +++ b/samples/csharp-net/csharp-net-samples.sln @@ -7,8 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "client-basics-cs", "basics\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "virtual-device-app-winui-cs", "virtual-device-app-winui\virtual-device-app-winui-cs.csproj", "{B2A27EAA-93BA-4FA4-AFDA-62CD5031950A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "virtual-device-app-wpf", "virtual-device-app-wpf\virtual-device-app-wpf.csproj", "{51C95EAA-B943-4DC6-92C8-855A6C50DBC1}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM64 = Debug|ARM64 @@ -33,14 +31,6 @@ Global {B2A27EAA-93BA-4FA4-AFDA-62CD5031950A}.Release|ARM64.Build.0 = Release|ARM64 {B2A27EAA-93BA-4FA4-AFDA-62CD5031950A}.Release|x64.ActiveCfg = Release|x64 {B2A27EAA-93BA-4FA4-AFDA-62CD5031950A}.Release|x64.Build.0 = Release|x64 - {51C95EAA-B943-4DC6-92C8-855A6C50DBC1}.Debug|ARM64.ActiveCfg = Debug|Any CPU - {51C95EAA-B943-4DC6-92C8-855A6C50DBC1}.Debug|ARM64.Build.0 = Debug|Any CPU - {51C95EAA-B943-4DC6-92C8-855A6C50DBC1}.Debug|x64.ActiveCfg = Debug|Any CPU - {51C95EAA-B943-4DC6-92C8-855A6C50DBC1}.Debug|x64.Build.0 = Debug|Any CPU - {51C95EAA-B943-4DC6-92C8-855A6C50DBC1}.Release|ARM64.ActiveCfg = Release|Any CPU - {51C95EAA-B943-4DC6-92C8-855A6C50DBC1}.Release|ARM64.Build.0 = Release|Any CPU - {51C95EAA-B943-4DC6-92C8-855A6C50DBC1}.Release|x64.ActiveCfg = Release|Any CPU - {51C95EAA-B943-4DC6-92C8-855A6C50DBC1}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/samples/csharp-net/virtual-device-app-wpf/App.xaml b/samples/csharp-net/virtual-device-app-wpf/App.xaml deleted file mode 100644 index 106a57de9..000000000 --- a/samples/csharp-net/virtual-device-app-wpf/App.xaml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - diff --git a/samples/csharp-net/virtual-device-app-wpf/App.xaml.cs b/samples/csharp-net/virtual-device-app-wpf/App.xaml.cs deleted file mode 100644 index 173f9898a..000000000 --- a/samples/csharp-net/virtual-device-app-wpf/App.xaml.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Configuration; -using System.Data; -using System.Windows; - -namespace virtual_device_app_wpf -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } - -} diff --git a/samples/csharp-net/virtual-device-app-wpf/AssemblyInfo.cs b/samples/csharp-net/virtual-device-app-wpf/AssemblyInfo.cs deleted file mode 100644 index b0ec82757..000000000 --- a/samples/csharp-net/virtual-device-app-wpf/AssemblyInfo.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Windows; - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] diff --git a/samples/csharp-net/virtual-device-app-wpf/MainWindow.xaml b/samples/csharp-net/virtual-device-app-wpf/MainWindow.xaml deleted file mode 100644 index de50df48b..000000000 --- a/samples/csharp-net/virtual-device-app-wpf/MainWindow.xaml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - diff --git a/samples/csharp-net/virtual-device-app-wpf/MainWindow.xaml.cs b/samples/csharp-net/virtual-device-app-wpf/MainWindow.xaml.cs deleted file mode 100644 index 59ce60e38..000000000 --- a/samples/csharp-net/virtual-device-app-wpf/MainWindow.xaml.cs +++ /dev/null @@ -1,160 +0,0 @@ -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -using midi2 = Microsoft.Windows.Devices.Midi2; -using msgs = Microsoft.Windows.Devices.Midi2.Messages; -using virt = Microsoft.Windows.Devices.Midi2.Endpoints.Virtual; - -namespace virtual_device_app_wpf -{ - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class MainWindow : Window - { - private midi2.MidiSession _session; - private midi2.MidiEndpointConnection _connection; - - public List Notes { get; } - - public MainWindow() - { - this.InitializeComponent(); - - OpenConnection(); - - 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(); - - this.Closed += MainWindow_Closed; - - this.Height = 550; - this.Width = 500; - this.Topmost = true; - } - - private void MainWindow_Closed(object? sender, EventArgs e) - { - System.Diagnostics.Debug.WriteLine("MainWindow_Closed"); - - if (_connection != null) - { - _session.DisconnectEndpointConnection(_connection.ConnectionId); - } - - _session.Dispose(); - } - - private void OpenConnection() - { - try - { - System.Diagnostics.Debug.WriteLine("Open Connection enter"); - - - // create our function blocks and endpoint info to be reported back through MIDI - - var deviceDefinition = new midi2.MidiVirtualEndpointDeviceDefinition(); - - 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.FunctionBlocks.Add(new midi2.MidiFunctionBlock() - { - Number = 1, - IsActive = true, - Name = "A Function Block", - UIHint = midi2.MidiFunctionBlockUIHint.Sender, - FirstGroupIndex = 1, - 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_3263827"; - deviceDefinition.SupportsMidi2ProtocolMessages = true; - deviceDefinition.SupportsMidi1ProtocolMessages = true; - deviceDefinition.SupportsReceivingJRTimestamps = false; - deviceDefinition.SupportsSendingJRTimestamps = false; - - - System.Diagnostics.Debug.WriteLine("Creating session"); - _session = midi2.MidiSession.CreateSession(deviceDefinition.EndpointName); - - if (_session != null) - { - System.Diagnostics.Debug.WriteLine("Creating virtual device"); - _connection = _session.CreateVirtualDeviceAndConnection(deviceDefinition); - - if (_connection != null) - { - System.Diagnostics.Debug.WriteLine("Created endpoint id: " + _connection.EndpointDeviceId); - System.Diagnostics.Debug.WriteLine("Connection created. Wiring up MessageReceived event"); - - _connection.MessageReceived += _connection_MessageReceived; - - // do anything else needed here. The public endpoint is not available to other - // applications until you open the device endpoint - - System.Diagnostics.Debug.WriteLine("Connection created. About to open it."); - - if (_connection.Open()) - { - System.Diagnostics.Debug.WriteLine("Connection Opened"); - - this.Title = deviceDefinition.EndpointName + ": Connected"; - } - else - { - System.Diagnostics.Debug.WriteLine("Connection Open Failed"); - this.Title = deviceDefinition.EndpointName + ": (no connection)"; - } - } - else - { - System.Diagnostics.Debug.WriteLine("Returned connection is null"); - } - } - else - { - System.Diagnostics.Debug.WriteLine("Session Open Failed"); - } - } - catch (Exception ex) - { - System.Diagnostics.Debug.WriteLine("Exception: " + ex.ToString()); - } - } - - private void _connection_MessageReceived(midi2.IMidiMessageReceivedEventSource sender, midi2.MidiMessageReceivedEventArgs args) - { - System.Diagnostics.Debug.WriteLine("Message Received " + msgs.MidiMessageUtility.GetMessageDisplayNameFromFirstWord( - args.PeekFirstWord())); - } - - } -} \ No newline at end of file diff --git a/samples/csharp-net/virtual-device-app-wpf/Note.cs b/samples/csharp-net/virtual-device-app-wpf/Note.cs deleted file mode 100644 index 37dfe1552..000000000 --- a/samples/csharp-net/virtual-device-app-wpf/Note.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Cryptography; -using System.Text; -using System.Threading.Tasks; - -namespace virtual_device_app_wpf -{ - 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() - { - System.Diagnostics.Debug.Write("Note On"); - - UInt16 index = NoteNumber; - index <<= 8; - - UInt16 velocity = 0xFFFF; - - UInt32 word1 = (UInt32)velocity << 16; - - if (MidiEndpointConnection.SendMessageSucceeded(Connection.SendSingleMessagePacket( - midi2.MidiMessageBuilder.BuildMidi2ChannelVoiceMessage( - 0, - new MidiGroup(GroupIndex), - midi2.Midi2ChannelVoiceMessageStatus.NoteOn, - new MidiChannel(ChannelIndex), - index, - word1)))) - { - System.Diagnostics.Debug.WriteLine(" - sent"); - } - } - public void NoteOff() - { - System.Diagnostics.Debug.Write("Note Off"); - - UInt16 index = NoteNumber; - index <<= 8; - - if (MidiEndpointConnection.SendMessageSucceeded(Connection.SendSingleMessagePacket( - midi2.MidiMessageBuilder.BuildMidi2ChannelVoiceMessage( - 0, - new MidiGroup(GroupIndex), - midi2.Midi2ChannelVoiceMessageStatus.NoteOff, - new MidiChannel(ChannelIndex), - index, - 0)))) - { - System.Diagnostics.Debug.WriteLine(" - sent"); - } - } - } - -} diff --git a/samples/csharp-net/virtual-device-app-wpf/virtual-device-app-wpf.csproj b/samples/csharp-net/virtual-device-app-wpf/virtual-device-app-wpf.csproj deleted file mode 100644 index 16845ff49..000000000 --- a/samples/csharp-net/virtual-device-app-wpf/virtual-device-app-wpf.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - WinExe - net8.0-windows - virtual_device_app_wpf - enable - enable - true - - - - - - - From 2615e28274e5a60e82343b4138dfa21b24c11f15 Mon Sep 17 00:00:00 2001 From: Pete Brown Date: Mon, 22 Jul 2024 20:16:09 -0400 Subject: [PATCH 03/32] Add name change feature to Virtual Device sample --- .../virtual-device-app-winui/MainWindow.xaml | 17 +++++++- .../MainWindow.xaml.cs | 25 ++++++++++- .../virtual-device-app-winui-cs.exe.manifest | 43 +++++++------------ 3 files changed, 55 insertions(+), 30 deletions(-) diff --git a/samples/csharp-net/virtual-device-app-winui/MainWindow.xaml b/samples/csharp-net/virtual-device-app-winui/MainWindow.xaml index c105badb4..df398805f 100644 --- a/samples/csharp-net/virtual-device-app-winui/MainWindow.xaml +++ b/samples/csharp-net/virtual-device-app-winui/MainWindow.xaml @@ -12,10 +12,25 @@ + - + + + + + + + + + + + +