Skip to content

Commit

Permalink
DP4 NAMM prep
Browse files Browse the repository at this point in the history
  • Loading branch information
Psychlist1972 committed Jan 23, 2024
1 parent cd3c26f commit b97f922
Show file tree
Hide file tree
Showing 21 changed files with 478 additions and 158 deletions.
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.24022.0303" ?>
<?define SetupVersionNumber="1.0.24022.2031" ?>
</Include>
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public MainWindow()
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<ClCompile Include="MidiEndpointTable.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="swd_shared.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Midl Include="Midi2VirtualMidiAbstraction.idl">
Expand Down Expand Up @@ -73,6 +76,9 @@
<ClInclude Include="Midi2.VirtualMidiBidi.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="swd_shared.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Midi2.VirtualMidiAbstraction.rc">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ CMidi2VirtualMidiBiDi::Initialize(
LONGLONG Context
)
{
OutputDebugString(__FUNCTION__ L" - enter\n");

TraceLoggingWrite(
MidiVirtualMidiAbstractionTelemetryProvider::Provider(),
__FUNCTION__,
Expand All @@ -30,7 +32,7 @@ CMidi2VirtualMidiBiDi::Initialize(

m_callback = Callback;
m_callbackContext = Context;
m_endpointId = internal::ToUpperTrimmedWStringCopy(endpointId);
m_endpointId = internal::NormalizeEndpointInterfaceIdCopy(endpointId);

//if (Context != MIDI_PROTOCOL_MANAGER_ENDPOINT_CREATION_CONTEXT)
{
Expand All @@ -41,15 +43,15 @@ CMidi2VirtualMidiBiDi::Initialize(

// This should use SWD properties and not a string search

if (m_endpointId.find(MIDI_VIRT_INSTANCE_ID_DEVICE_PREFIX) != std::wstring::npos)
if (internal::EndpointInterfaceIdContainsString(m_endpointId, MIDI_VIRT_INSTANCE_ID_DEVICE_PREFIX))
{
OutputDebugString(__FUNCTION__ L" - endpoint id is a virtual device\n");

m_isDeviceSide = true;

LOG_IF_FAILED(hr = MidiEndpointTable::Current().OnDeviceConnected(m_endpointId, this));
}
else if (m_endpointId.find(MIDI_VIRT_INSTANCE_ID_CLIENT_PREFIX) != std::wstring::npos)
else if (internal::EndpointInterfaceIdContainsString(m_endpointId, MIDI_VIRT_INSTANCE_ID_CLIENT_PREFIX))
{
OutputDebugString(__FUNCTION__ L" - endpoint id is a virtual client\n");

Expand Down Expand Up @@ -80,8 +82,7 @@ CMidi2VirtualMidiBiDi::Initialize(
HRESULT
CMidi2VirtualMidiBiDi::Cleanup()
{
// TODO: Cleanup here needs additional logic to tear down the client endpoint
// when this endpoint goes away
OutputDebugString(__FUNCTION__ L" - enter\n");

TraceLoggingWrite(
MidiVirtualMidiAbstractionTelemetryProvider::Provider(),
Expand All @@ -97,12 +98,18 @@ CMidi2VirtualMidiBiDi::Cleanup()

if (m_isDeviceSide)
{
OutputDebugString(__FUNCTION__ L" - this is the device BiDi, so calling OnDeviceDisconnected\n");

MidiEndpointTable::Current().OnDeviceDisconnected(m_endpointId);
}
else
{
OutputDebugString(__FUNCTION__ L" - this is the client BiDi. Nothing needed here.\n");
}

UnlinkAssociatedBiDi();

//m_LinkedClientBiDi->Release();
m_linkedBiDiCallback = nullptr;
m_linkedBiDi = nullptr;
OutputDebugString(__FUNCTION__ L" - exit\n");

return S_OK;
}
Expand Down
12 changes: 10 additions & 2 deletions src/api/Abstraction/VirtualMidiAbstraction/Midi2.VirtualMidiBidi.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ class CMidi2VirtualMidiBiDi :
return S_OK;
}

HRESULT UnlinkAssociatedBiDi()
{
m_linkedBiDi = nullptr;
m_linkedBiDiCallback = nullptr;

return S_OK;
}

private:
wil::com_ptr_nothrow<IMidiBiDi> m_linkedBiDi;

IMidiCallback* m_linkedBiDiCallback;
IMidiCallback* m_callback;
wil::com_ptr_nothrow<IMidiCallback> m_linkedBiDiCallback;
wil::com_ptr_nothrow <IMidiCallback> m_callback;

LONGLONG m_callbackContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ CMidi2VirtualMidiEndpointManager::ApplyJson(json::JsonObject jsonObject)
deviceEntry.BaseEndpointName = GetJsonStringValue(jsonEntry, MIDI_VIRT_JSON_DEVICE_PROPERTY_NAME, L"");
deviceEntry.Description = GetJsonStringValue(jsonEntry, MIDI_VIRT_JSON_DEVICE_PROPERTY_DESCRIPTION, L"");


// if no association id, or it already exists in the table, bail

// if no unique Id, bail or maybe generate one
Expand All @@ -177,6 +178,37 @@ CMidi2VirtualMidiEndpointManager::ApplyJson(json::JsonObject jsonObject)



_Use_decl_annotations_
HRESULT
CMidi2VirtualMidiEndpointManager::DeleteClientEndpoint(std::wstring clientShortInstanceId)
{
OutputDebugString(__FUNCTION__ L" - enter\n");

// get the instance id for the device

if (m_MidiDeviceManager != nullptr)
{
//auto instanceId = GetSwdPropertyInstanceId(clientEndpointInterfaceId);
auto instanceId = internal::NormalizeDeviceInstanceIdCopy(clientShortInstanceId);

if (instanceId != L"")
{
return m_MidiDeviceManager->RemoveEndpoint(instanceId.c_str());
}
else
{
OutputDebugString(__FUNCTION__ L" - could not find instanceId property for client\n");

return E_FAIL;
}
}
else
{
// null device manager
return E_FAIL;
}
}


HRESULT
CMidi2VirtualMidiEndpointManager::CreateParentDevice()
Expand All @@ -185,7 +217,7 @@ CMidi2VirtualMidiEndpointManager::CreateParentDevice()

// the parent device parameters are set by the transport (this)
std::wstring parentDeviceName{ TRANSPORT_PARENT_DEVICE_NAME };
std::wstring parentDeviceId{ TRANSPORT_PARENT_ID };
std::wstring parentDeviceId{ internal::NormalizeDeviceInstanceIdCopy(TRANSPORT_PARENT_ID) };

SW_DEVICE_CREATE_INFO createInfo = {};
createInfo.cbSize = sizeof(createInfo);
Expand All @@ -205,9 +237,9 @@ CMidi2VirtualMidiEndpointManager::CreateParentDevice()
deviceIdMaxSize
));

m_parentDeviceId = std::wstring(newDeviceId);
m_parentDeviceId = internal::NormalizeDeviceInstanceIdCopy(newDeviceId);

OutputDebugString(__FUNCTION__ L" New parent device id: ");
OutputDebugString(__FUNCTION__ L" New parent device instance id: ");
OutputDebugString(newDeviceId);
OutputDebugString(L"\n");

Expand Down Expand Up @@ -314,7 +346,8 @@ CMidi2VirtualMidiEndpointManager::CreateClientVisibleEndpoint(
createInfo.cbSize = sizeof(createInfo);


std::wstring instanceId = MIDI_VIRT_INSTANCE_ID_CLIENT_PREFIX + entry.ShortUniqueId;
std::wstring instanceId = internal::NormalizeDeviceInstanceIdCopy(MIDI_VIRT_INSTANCE_ID_CLIENT_PREFIX + entry.ShortUniqueId);



createInfo.pszInstanceId = instanceId.c_str();
Expand Down Expand Up @@ -348,7 +381,10 @@ CMidi2VirtualMidiEndpointManager::CreateClientVisibleEndpoint(
// loopback transport.
m_MidiDeviceManager->DeleteAllEndpointInProtocolDiscoveredProperties(newDeviceInterfaceId);

entry.CreatedClientEndpointId = newDeviceInterfaceId;
// we need this for removal later
entry.CreatedShortClientInstanceId = instanceId;

entry.CreatedClientEndpointId = internal::NormalizeEndpointInterfaceIdCopy(newDeviceInterfaceId);

//MidiEndpointTable::Current().AddCreatedEndpointDevice(entry);
//MidiEndpointTable::Current().AddCreatedClient(entry.VirtualEndpointAssociationId, entry.CreatedClientEndpointId);
Expand Down Expand Up @@ -440,7 +476,7 @@ HRESULT CMidi2VirtualMidiEndpointManager::CreateDeviceSideEndpoint(
createInfo.cbSize = sizeof(createInfo);


std::wstring instanceId = MIDI_VIRT_INSTANCE_ID_DEVICE_PREFIX + entry.ShortUniqueId;
std::wstring instanceId = internal::NormalizeDeviceInstanceIdCopy(MIDI_VIRT_INSTANCE_ID_DEVICE_PREFIX + entry.ShortUniqueId);


createInfo.pszInstanceId = instanceId.c_str();
Expand Down Expand Up @@ -474,7 +510,7 @@ HRESULT CMidi2VirtualMidiEndpointManager::CreateDeviceSideEndpoint(
// loopback transport.
m_MidiDeviceManager->DeleteAllEndpointInProtocolDiscoveredProperties(newDeviceInterfaceId);

entry.CreatedDeviceEndpointId = newDeviceInterfaceId;
entry.CreatedDeviceEndpointId = internal::NormalizeEndpointInterfaceIdCopy(newDeviceInterfaceId);

MidiEndpointTable::Current().AddCreatedEndpointDevice(entry);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class CMidi2VirtualMidiEndpointManager :

HRESULT ApplyJson(_In_ json::JsonObject jsonObject);

HRESULT NegotiateAndRequestMetadata(_In_ std::wstring endpointId);
HRESULT NegotiateAndRequestMetadata(_In_ std::wstring endpointInterfaceId);

HRESULT DeleteClientEndpoint(_In_ std::wstring clientShortInstanceId);

//HRESULT DeleteEndpointPair(
// _In_ GUID const VirtualEndpointAssociationGuid
Expand Down
Loading

0 comments on commit b97f922

Please sign in to comment.