| Namespace | Windows.Devices.Midi2 |
|---|---|
| Type Name | MidiSession |
| Type | WinRT Runtime Class |
| Implements | IClosable IStringable |
| IDL | MidiSession.idl |
You need a session before you can connect to an endpoint.
An application can have as many sessions open as it needs. For example, it might open one session for each open project, or a browser might open one for each tab. The connections you open through a session last only as long as the session does.
| Property | Description |
|---|---|
SessionId |
A GUID that identifies the session. The API creates it for you |
Name |
The session’s name. To change it later, call UpdateName(), which also tells the service |
IsOpen |
True if this session is open and ready to use |
Connections |
A map of every connection created through this session. The key is each connection’s ConnectionId. Calling DisconnectEndpointConnection removes the connection from the map |
| Static Method | Description |
|---|---|
Create(sessionName) |
Creates and returns a new session with this name. Tools that list sessions show the name, so pick one that tells people which application it belongs to |
| Method | Description |
|---|---|
CreateEndpointConnection(endpointDeviceId) |
Creates a connection to the endpoint with this id. The connection isn’t open yet: attach your event handlers, and then call Open() |
CreateEndpointConnection(endpointDeviceId, settings) |
The same, using the MidiEndpointConnectionSettings you pass in |
DisconnectEndpointConnection(endpointConnectionId) |
Closes a connection and removes it from Connections |
UpdateName(newName) |
Changes the session’s name, both here and in the MIDI service |
Close() |
(From IClosable) Closes the session and every connection opened through it |
Note: If you close a
MidiEndpointConnectionyourself throughIClosable(orIDisposablein C#), the session doesn’t know, and the connection stays in itsConnectionsmap. Call the session’sDisconnectEndpointConnectioninstead so the two stay in step. That’s also why we don’t recommend puttingCreateEndpointConnectioncalls in ausingstatement.
C#
using (var session = MidiSession.Create("API Sample Session"))
{
...
}
C++
// Initialize the WinRT apartment and the WinRT API runtime first.
// The samples show how.
auto session = MidiSession::Create("API Sample Session");
...
session.Close();
