Skip to content

Commit

Permalink
Fixed timing bug in metadata listener plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Psychlist1972 committed Feb 14, 2024
1 parent 6f57071 commit cd807e2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 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 5" ?>
<?define SetupVersionNumber="1.0.24045.0131" ?>
<?define SetupVersionNumber="1.0.24045.0225" ?>
</Include>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26031-preview" />
<PackageReference Include="Windows.Devices.Midi2" Version="1.0.0-preview.3-0157" />
<PackageReference Include="Windows.Devices.Midi2" Version="1.0.0-preview.3-0158" />
<PackageReference Include="WinUIEx" Version="2.3.3" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
Expand Down
50 changes: 41 additions & 9 deletions src/api/Client/Midi2Client/MidiVirtualEndpointDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ namespace winrt::Windows::Devices::Midi2::implementation
}


// TODO: Any message sending from inside this function should
// be done on another thread via a queue, like we do in the service
// That way no long-running or recursive callbacks.

_Use_decl_annotations_
void MidiVirtualEndpointDevice::ProcessIncomingMessage(
midi2::MidiMessageReceivedEventArgs const& args,
Expand All @@ -130,10 +126,12 @@ namespace winrt::Windows::Devices::Midi2::implementation

if (internal::EndpointDiscoveryFilterRequestsEndpointInfoNotification(filterFlags))
{
internal::LogInfo(__FUNCTION__, L"Sending Endpoint Info Notification");

// send endpoint info notification

auto notification = midi2::MidiStreamMessageBuilder::BuildEndpointInformationNotificationMessage(
0,
MidiClock::TimestampConstantSendImmediately(),
MIDI_PREFERRED_UMP_VERSION_MAJOR,
MIDI_PREFERRED_UMP_VERSION_MINOR,
m_areFunctionBlocksStatic,
Expand All @@ -144,7 +142,10 @@ namespace winrt::Windows::Devices::Midi2::implementation
false // todo: pull from jr timestamp handling
);

m_endpointConnection.SendMessagePacket(notification);
if (midi2::MidiEndpointConnection::SendMessageFailed(m_endpointConnection.SendMessagePacket(notification)))
{
internal::LogGeneralError(__FUNCTION__, L"SendMessagePacket failed - sending endpoint info notification");
}
}

if (internal::EndpointDiscoveryFilterRequestsDeviceIdentityNotification(filterFlags))
Expand All @@ -154,13 +155,42 @@ namespace winrt::Windows::Devices::Midi2::implementation

if (internal::EndpointDiscoveryFilterRequestsEndpointNameNotification(filterFlags))
{
internal::LogInfo(__FUNCTION__, L"Sending Endpoint Name Notification");

// send endpoint name notification messages

if (!m_endpointName.empty())
{
auto nameMessages = midi2::MidiStreamMessageBuilder::BuildEndpointNameNotificationMessages(
MidiClock::TimestampConstantSendImmediately(),
m_endpointName
);

if (midi2::MidiEndpointConnection::SendMessageFailed(m_endpointConnection.SendMessagePacketList(nameMessages.GetView())))
{
internal::LogGeneralError(__FUNCTION__, L"SendMessagePacketList failed - sending endpoint name notification list");
}
}
}

if (internal::EndpointDiscoveryFilterRequestsProductInstanceIdNotification(filterFlags))
{
internal::LogInfo(__FUNCTION__, L"Sending Endpoint Product Instance Id Notification");

// send product instance id notification messages


if (!m_endpointProductInstanceId.empty())
{
auto instanceIdMessages = midi2::MidiStreamMessageBuilder::BuildProductInstanceIdNotificationMessages(
MidiClock::TimestampConstantSendImmediately(),
m_endpointProductInstanceId
);

if (midi2::MidiEndpointConnection::SendMessageFailed(m_endpointConnection.SendMessagePacketList(instanceIdMessages.GetView())))
{
internal::LogGeneralError(__FUNCTION__, L"SendMessagePacketList failed - sending product instance id messages");
}
}
}

if (internal::EndpointDiscoveryFilterRequestsStreamConfigurationNotification(filterFlags))
Expand All @@ -179,6 +209,8 @@ namespace winrt::Windows::Devices::Midi2::implementation

if (fbNumber == MIDI_STREAM_MESSAGE_FUNCTION_BLOCK_REQUEST_ALL_FUNCTION_BLOCKS)
{
internal::LogInfo(__FUNCTION__, L"Sending All function blocks, as requested");

// send all function blocks

for (uint8_t i = 0; i < (uint8_t)m_functionBlocks.Size(); i++)
Expand All @@ -193,7 +225,8 @@ namespace winrt::Windows::Devices::Midi2::implementation
else
{
// send single requested function block

internal::LogInfo(__FUNCTION__, L"Sending only a single function block, as requested");

if (m_functionBlocks.HasKey(fbNumber))
{
auto fb = m_functionBlocks.Lookup(fbNumber);
Expand All @@ -210,7 +243,6 @@ namespace winrt::Windows::Devices::Midi2::implementation
handled = false;
}
}

}

else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ CMidi2EndpointMetadataListenerMidiTransform::Cleanup()
}


#define MIDI_ENDPOINT_METADATA_LISTENER_THREAD_SLEEP_DURATION_MS 2000
#define MIDI_ENDPOINT_METADATA_LISTENER_THREAD_SLEEP_DURATION_MS 10000

void CMidi2EndpointMetadataListenerMidiTransform::QueueWorker()
{
Expand Down Expand Up @@ -215,6 +215,8 @@ CMidi2EndpointMetadataListenerMidiTransform::SendMidiMessage(
m_queueMutex.lock();
m_workQueue.push(ump);
m_queueMutex.unlock();

m_messageProcessorWakeup.SetEvent();
}
else
{
Expand Down

0 comments on commit cd807e2

Please sign in to comment.