---
title: "MIDISourceCreateWithProtocol(_:_:_:_:)"
framework: coremidi
role: symbol
role_heading: Function
path: "coremidi/midisourcecreatewithprotocol(_:_:_:_:)"
---

# MIDISourceCreateWithProtocol(_:_:_:_:)

Creates a virtual source in a client.

## Declaration

```swift
func MIDISourceCreateWithProtocol(_ client: MIDIClientRef, _ name: CFString, _ protocol: MIDIProtocolID, _ outSrc: UnsafeMutablePointer<MIDIEndpointRef>) -> OSStatus
```

## Parameters

- `client`: The client to own the virtual source.
- `name`: The name of the virtual source.
- `protocol`: The MIDI protocol variant to send from this source. The system automatically converts messages from this protocol to the protocol of the destination.
- `outSrc`: On successful return, a pointer to the newly created source.

## Return Value

Return Value An OSStatus result code.

## Discussion

Discussion Drivers don’t need to call this function. When they create devices and entities, the system automatically creates sources and destinations at that time. After creating a virtual source, use MIDIReceivedEventList(_:_:) to transmit MIDI messages from your virtual source to any clients connected to the virtual source. tip: After creating a virtual source, assign it the same unique ID it had the last time your app created it. Doing so permits other clients to retain persistent references to your virtual source.

## See Also

### Endpoint management

- [MIDIEndpointDispose(_:)](coremidi/midiendpointdispose(_:).md)
- [MIDIEndpointGetEntity(_:_:)](coremidi/midiendpointgetentity(_:_:).md)
- [MIDIEndpointGetRefCons(_:_:_:)](coremidi/midiendpointgetrefcons(_:_:_:).md)
- [MIDIEndpointSetRefCons(_:_:_:)](coremidi/midiendpointsetrefcons(_:_:_:).md)
- [MIDIGetSource(_:)](coremidi/midigetsource(_:).md)
- [MIDIGetNumberOfSources()](coremidi/midigetnumberofsources().md)
- [MIDIDestinationCreateWithProtocol(_:_:_:_:_:)](coremidi/mididestinationcreatewithprotocol(_:_:_:_:_:).md)
- [MIDIGetDestination(_:)](coremidi/midigetdestination(_:).md)
- [MIDIGetNumberOfDestinations()](coremidi/midigetnumberofdestinations().md)
- [MIDIEndpointRef](coremidi/midiendpointref.md)
