| @@ -187,7 +187,7 @@ public: | |||||
| if (isInput) | if (isInput) | ||||
| { | { | ||||
| jassert (midiInputs[index]->inDevice.get() == nullptr); | jassert (midiInputs[index]->inDevice.get() == nullptr); | ||||
| midiInputs[index]->inDevice.reset (MidiInput::openDevice (midiInputs[index]->deviceInfo.identifier, this)); | |||||
| midiInputs[index]->inDevice = MidiInput::openDevice (midiInputs[index]->deviceInfo.identifier, this); | |||||
| if (midiInputs[index]->inDevice.get() == nullptr) | if (midiInputs[index]->inDevice.get() == nullptr) | ||||
| { | { | ||||
| @@ -200,7 +200,7 @@ public: | |||||
| else | else | ||||
| { | { | ||||
| jassert (midiOutputs[index]->outDevice.get() == nullptr); | jassert (midiOutputs[index]->outDevice.get() == nullptr); | ||||
| midiOutputs[index]->outDevice.reset (MidiOutput::openDevice (midiOutputs[index]->deviceInfo.identifier)); | |||||
| midiOutputs[index]->outDevice = MidiOutput::openDevice (midiOutputs[index]->deviceInfo.identifier); | |||||
| if (midiOutputs[index]->outDevice.get() == nullptr) | if (midiOutputs[index]->outDevice.get() == nullptr) | ||||
| { | { | ||||
| @@ -93,10 +93,10 @@ public: | |||||
| /** Tries to open one of the midi input devices. | /** Tries to open one of the midi input devices. | ||||
| This will return a MidiInput object if it manages to open it. You can then | |||||
| call start() and stop() on this device, and delete it when no longer needed. | |||||
| This will return a MidiInput object if it manages to open it, you can then | |||||
| call start() and stop() on this device. | |||||
| If the device can't be opened, this will return nullptr. | |||||
| If the device can't be opened, this will return an empty object. | |||||
| @param deviceIdentifier the ID of the device to open - use the getAvailableDevices() method to | @param deviceIdentifier the ID of the device to open - use the getAvailableDevices() method to | ||||
| find the available devices that can be opened | find the available devices that can be opened | ||||
| @@ -104,7 +104,7 @@ public: | |||||
| @see MidiInputCallback, getDevices | @see MidiInputCallback, getDevices | ||||
| */ | */ | ||||
| static MidiInput* openDevice (const String& deviceIdentifier, MidiInputCallback* callback); | |||||
| static std::unique_ptr<MidiInput> openDevice (const String& deviceIdentifier, MidiInputCallback* callback); | |||||
| #if JUCE_LINUX || JUCE_MAC || JUCE_IOS || DOXYGEN | #if JUCE_LINUX || JUCE_MAC || JUCE_IOS || DOXYGEN | ||||
| /** This will try to create a new midi input device (only available on Linux, macOS and iOS). | /** This will try to create a new midi input device (only available on Linux, macOS and iOS). | ||||
| @@ -115,12 +115,12 @@ public: | |||||
| NB - if you are calling this method on iOS you must have enabled the "Audio Background Capability" | NB - if you are calling this method on iOS you must have enabled the "Audio Background Capability" | ||||
| setting in the iOS exporter otherwise this method will fail. | setting in the iOS exporter otherwise this method will fail. | ||||
| Returns nullptr if a device can't be created. | |||||
| Returns an empty object if a device can't be created. | |||||
| @param deviceName the name of the device to create | @param deviceName the name of the device to create | ||||
| @param callback the object that will receive the midi messages from this device | @param callback the object that will receive the midi messages from this device | ||||
| */ | */ | ||||
| static MidiInput* createNewDevice (const String& deviceName, MidiInputCallback* callback); | |||||
| static std::unique_ptr<MidiInput> createNewDevice (const String& deviceName, MidiInputCallback* callback); | |||||
| #endif | #endif | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -160,7 +160,7 @@ public: | |||||
| /** Deprecated. */ | /** Deprecated. */ | ||||
| static int getDefaultDeviceIndex(); | static int getDefaultDeviceIndex(); | ||||
| /** Deprecated. */ | /** Deprecated. */ | ||||
| static MidiInput* openDevice (int, MidiInputCallback*); | |||||
| static std::unique_ptr<MidiInput> openDevice (int, MidiInputCallback*); | |||||
| private: | private: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -251,16 +251,16 @@ public: | |||||
| /** Tries to open one of the midi output devices. | /** Tries to open one of the midi output devices. | ||||
| This will return a MidiOutput object if it manages to open it. You can then | |||||
| send messages to this device, and delete it when no longer needed. | |||||
| This will return a MidiOutput object if it manages to open it, you can then | |||||
| send messages to this device. | |||||
| If the device can't be opened, this will return nullptr. | |||||
| If the device can't be opened, this will return an empty object. | |||||
| @param deviceIdentifier the ID of the device to open - use the getAvailableDevices() method to | @param deviceIdentifier the ID of the device to open - use the getAvailableDevices() method to | ||||
| find the available devices that can be opened | find the available devices that can be opened | ||||
| @see getDevices | @see getDevices | ||||
| */ | */ | ||||
| static MidiOutput* openDevice (const String& deviceIdentifier); | |||||
| static std::unique_ptr<MidiOutput> openDevice (const String& deviceIdentifier); | |||||
| #if JUCE_LINUX || JUCE_MAC || JUCE_IOS || DOXYGEN | #if JUCE_LINUX || JUCE_MAC || JUCE_IOS || DOXYGEN | ||||
| /** This will try to create a new midi output device (only available on Linux, macOS and iOS). | /** This will try to create a new midi output device (only available on Linux, macOS and iOS). | ||||
| @@ -271,11 +271,11 @@ public: | |||||
| NB - if you are calling this method on iOS you must have enabled the "Audio Background Capability" | NB - if you are calling this method on iOS you must have enabled the "Audio Background Capability" | ||||
| setting in the iOS exporter otherwise this method will fail. | setting in the iOS exporter otherwise this method will fail. | ||||
| Returns nullptr if a device can't be created. | |||||
| Returns an empty object if a device can't be created. | |||||
| @param deviceName the name of the device to create | @param deviceName the name of the device to create | ||||
| */ | */ | ||||
| static MidiOutput* createNewDevice (const String& deviceName); | |||||
| static std::unique_ptr<MidiOutput> createNewDevice (const String& deviceName); | |||||
| #endif | #endif | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -341,7 +341,7 @@ public: | |||||
| /** Deprecated. */ | /** Deprecated. */ | ||||
| static int getDefaultDeviceIndex(); | static int getDefaultDeviceIndex(); | ||||
| /** Deprecated. */ | /** Deprecated. */ | ||||
| static MidiOutput* openDevice (int); | |||||
| static std::unique_ptr<MidiOutput> openDevice (int); | |||||
| private: | private: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -554,10 +554,10 @@ MidiDeviceInfo MidiInput::getDefaultDevice() | |||||
| return getAvailableDevices().getFirst(); | return getAvailableDevices().getFirst(); | ||||
| } | } | ||||
| MidiInput* MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallback* callback) | |||||
| std::unique_ptr<MidiInput> MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallback* callback) | |||||
| { | { | ||||
| if (getAndroidSDKVersion() < 23 || deviceIdentifier.isEmpty()) | if (getAndroidSDKVersion() < 23 || deviceIdentifier.isEmpty()) | ||||
| return nullptr; | |||||
| return {}; | |||||
| AndroidMidiDeviceManager manager; | AndroidMidiDeviceManager manager; | ||||
| @@ -568,10 +568,10 @@ MidiInput* MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallb | |||||
| midiInput->internal = port; | midiInput->internal = port; | ||||
| midiInput->setName (port->getName()); | midiInput->setName (port->getName()); | ||||
| return midiInput.release(); | |||||
| return midiInput; | |||||
| } | } | ||||
| return nullptr; | |||||
| return {}; | |||||
| } | } | ||||
| StringArray MidiInput::getDevices() | StringArray MidiInput::getDevices() | ||||
| @@ -592,7 +592,7 @@ int MidiInput::getDefaultDeviceIndex() | |||||
| return (getAndroidSDKVersion() < 23 ? -1 : 0); | return (getAndroidSDKVersion() < 23 ? -1 : 0); | ||||
| } | } | ||||
| MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback) | |||||
| std::unique_ptr<MidiInput> MidiInput::openDevice (int index, MidiInputCallback* callback) | |||||
| { | { | ||||
| return openDevice (getAvailableDevices()[index].identifier, callback); | return openDevice (getAvailableDevices()[index].identifier, callback); | ||||
| } | } | ||||
| @@ -637,10 +637,10 @@ MidiDeviceInfo MidiOutput::getDefaultDevice() | |||||
| return getAvailableDevices().getFirst(); | return getAvailableDevices().getFirst(); | ||||
| } | } | ||||
| MidiOutput* MidiOutput::openDevice (const String& deviceIdentifier) | |||||
| std::unique_ptr<MidiOutput> MidiOutput::openDevice (const String& deviceIdentifier) | |||||
| { | { | ||||
| if (getAndroidSDKVersion() < 23 || deviceIdentifier.isEmpty()) | if (getAndroidSDKVersion() < 23 || deviceIdentifier.isEmpty()) | ||||
| return nullptr; | |||||
| return {}; | |||||
| AndroidMidiDeviceManager manager; | AndroidMidiDeviceManager manager; | ||||
| @@ -650,10 +650,10 @@ MidiOutput* MidiOutput::openDevice (const String& deviceIdentifier) | |||||
| midiOutput->internal = port; | midiOutput->internal = port; | ||||
| midiOutput->setName (port->getName()); | midiOutput->setName (port->getName()); | ||||
| return midiOutput.release(); | |||||
| return midiOutput; | |||||
| } | } | ||||
| return nullptr; | |||||
| return {}; | |||||
| } | } | ||||
| StringArray MidiOutput::getDevices() | StringArray MidiOutput::getDevices() | ||||
| @@ -674,7 +674,7 @@ int MidiOutput::getDefaultDeviceIndex() | |||||
| return (getAndroidSDKVersion() < 23 ? -1 : 0); | return (getAndroidSDKVersion() < 23 ? -1 : 0); | ||||
| } | } | ||||
| MidiOutput* MidiOutput::openDevice (int index) | |||||
| std::unique_ptr<MidiOutput> MidiOutput::openDevice (int index) | |||||
| { | { | ||||
| return openDevice (getAvailableDevices()[index].identifier); | return openDevice (getAvailableDevices()[index].identifier); | ||||
| } | } | ||||
| @@ -528,22 +528,22 @@ MidiDeviceInfo MidiInput::getDefaultDevice() | |||||
| return getAvailableDevices().getFirst(); | return getAvailableDevices().getFirst(); | ||||
| } | } | ||||
| MidiInput* MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallback* callback) | |||||
| std::unique_ptr<MidiInput> MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallback* callback) | |||||
| { | { | ||||
| if (deviceIdentifier.isEmpty()) | if (deviceIdentifier.isEmpty()) | ||||
| return nullptr; | |||||
| return {}; | |||||
| std::unique_ptr<MidiInput> midiInput (new MidiInput (deviceIdentifier, deviceIdentifier)); | std::unique_ptr<MidiInput> midiInput (new MidiInput (deviceIdentifier, deviceIdentifier)); | ||||
| midiInput->internal = new BelaMidiInput (deviceIdentifier, result, callback); | midiInput->internal = new BelaMidiInput (deviceIdentifier, result, callback); | ||||
| return midiInput.release(); | |||||
| return midiInput; | |||||
| } | } | ||||
| MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) | |||||
| std::unique_ptr<MidiInput> MidiInput::createNewDevice (const String&, MidiInputCallback*) | |||||
| { | { | ||||
| // N/A on Bela | // N/A on Bela | ||||
| jassertfalse; | jassertfalse; | ||||
| return nullptr; | |||||
| return {}; | |||||
| } | } | ||||
| StringArray MidiInput::getDevices() | StringArray MidiInput::getDevices() | ||||
| @@ -561,21 +561,21 @@ int MidiInput::getDefaultDeviceIndex() | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback) | |||||
| std::unique_ptr<MidiInput> MidiInput::openDevice (int index, MidiInputCallback* callback) | |||||
| { | { | ||||
| return openDevice (getAvailableDevices()[index].identifier, callback); | return openDevice (getAvailableDevices()[index].identifier, callback); | ||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| // TODO: Add Bela MidiOutput support | // TODO: Add Bela MidiOutput support | ||||
| MidiOutput::~MidiOutput() {} | |||||
| void MidiOutput::sendMessageNow (const MidiMessage&) {} | |||||
| Array<MidiDeviceInfo> MidiOutput::getAvailableDevices() { return {}; } | |||||
| MidiDeviceInfo MidiOutput::getDefaultDevice() { return {}; } | |||||
| MidiOutput* MidiOutput::openDevice (const String&) { return nullptr; } | |||||
| MidiOutput* MidiOutput::createNewDevice (const String&) { return nullptr; } | |||||
| StringArray MidiOutput::getDevices() { return {}; } | |||||
| int MidiOutput::getDefaultDeviceIndex() { return 0;} | |||||
| MidiOutput* MidiOutput::openDevice (int) { return nullptr; } | |||||
| MidiOutput::~MidiOutput() {} | |||||
| void MidiOutput::sendMessageNow (const MidiMessage&) {} | |||||
| Array<MidiDeviceInfo> MidiOutput::getAvailableDevices() { return {}; } | |||||
| MidiDeviceInfo MidiOutput::getDefaultDevice() { return {}; } | |||||
| std::unique_ptr<MidiOutput> MidiOutput::openDevice (const String&) { return {}; } | |||||
| std::unique_ptr<MidiOutput> MidiOutput::createNewDevice (const String&) { return {}; } | |||||
| StringArray MidiOutput::getDevices() { return {}; } | |||||
| int MidiOutput::getDefaultDeviceIndex() { return 0;} | |||||
| std::unique_ptr<MidiOutput> MidiOutput::openDevice (int) { return {}; } | |||||
| } // namespace juce | } // namespace juce | ||||
| @@ -469,16 +469,16 @@ MidiDeviceInfo MidiInput::getDefaultDevice() | |||||
| return getAvailableDevices().getFirst(); | return getAvailableDevices().getFirst(); | ||||
| } | } | ||||
| MidiInput* MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallback* callback) | |||||
| std::unique_ptr<MidiInput> MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallback* callback) | |||||
| { | { | ||||
| if (deviceIdentifier.isEmpty()) | if (deviceIdentifier.isEmpty()) | ||||
| return nullptr; | |||||
| return {}; | |||||
| Array<MidiDeviceInfo> devices; | Array<MidiDeviceInfo> devices; | ||||
| auto* port = iterateMidiDevices (true, devices, deviceIdentifier); | auto* port = iterateMidiDevices (true, devices, deviceIdentifier); | ||||
| if (port == nullptr) | |||||
| return nullptr; | |||||
| if (port == nullptr || ! port->isValid()) | |||||
| return {}; | |||||
| jassert (port->isValid()); | jassert (port->isValid()); | ||||
| @@ -487,22 +487,23 @@ MidiInput* MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallb | |||||
| port->setupInput (midiInput.get(), callback); | port->setupInput (midiInput.get(), callback); | ||||
| midiInput->internal = port; | midiInput->internal = port; | ||||
| return midiInput.release(); | |||||
| return midiInput; | |||||
| } | } | ||||
| MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback) | |||||
| std::unique_ptr<MidiInput> MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback) | |||||
| { | { | ||||
| auto client = AlsaClient::getInstance(); | auto client = AlsaClient::getInstance(); | ||||
| auto* port = client->createPort (deviceName, true, true); | auto* port = client->createPort (deviceName, true, true); | ||||
| jassert (port->isValid()); | |||||
| if (port == nullptr || ! port->isValid()) | |||||
| return {}; | |||||
| std::unique_ptr<MidiInput> midiInput (new MidiInput (deviceName, getFormattedPortIdentifier (client->getId(), port->portId))); | std::unique_ptr<MidiInput> midiInput (new MidiInput (deviceName, getFormattedPortIdentifier (client->getId(), port->portId))); | ||||
| port->setupInput (midiInput.get(), callback); | port->setupInput (midiInput.get(), callback); | ||||
| midiInput->internal = port; | midiInput->internal = port; | ||||
| return midiInput.release(); | |||||
| return midiInput; | |||||
| } | } | ||||
| StringArray MidiInput::getDevices() | StringArray MidiInput::getDevices() | ||||
| @@ -522,7 +523,7 @@ int MidiInput::getDefaultDeviceIndex() | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback) | |||||
| std::unique_ptr<MidiInput> MidiInput::openDevice (int index, MidiInputCallback* callback) | |||||
| { | { | ||||
| return openDevice (getAvailableDevices()[index].identifier, callback); | return openDevice (getAvailableDevices()[index].identifier, callback); | ||||
| } | } | ||||
| @@ -562,40 +563,39 @@ MidiDeviceInfo MidiOutput::getDefaultDevice() | |||||
| return getAvailableDevices().getFirst(); | return getAvailableDevices().getFirst(); | ||||
| } | } | ||||
| MidiOutput* MidiOutput::openDevice (const String& deviceIdentifier) | |||||
| std::unique_ptr<MidiOutput> MidiOutput::openDevice (const String& deviceIdentifier) | |||||
| { | { | ||||
| if (deviceIdentifier.isEmpty()) | if (deviceIdentifier.isEmpty()) | ||||
| return nullptr; | |||||
| return {}; | |||||
| Array<MidiDeviceInfo> devices; | Array<MidiDeviceInfo> devices; | ||||
| auto* port = iterateMidiDevices (false, devices, deviceIdentifier); | auto* port = iterateMidiDevices (false, devices, deviceIdentifier); | ||||
| if (port == nullptr) | |||||
| return nullptr; | |||||
| jassert (port->isValid()); | |||||
| if (port == nullptr || ! port->isValid()) | |||||
| return {}; | |||||
| std::unique_ptr<MidiOutput> midiOutput (new MidiOutput (port->portName, deviceIdentifier)); | std::unique_ptr<MidiOutput> midiOutput (new MidiOutput (port->portName, deviceIdentifier)); | ||||
| port->setupOutput(); | port->setupOutput(); | ||||
| midiOutput->internal = port; | midiOutput->internal = port; | ||||
| return midiOutput.release(); | |||||
| return midiOutput; | |||||
| } | } | ||||
| MidiOutput* MidiOutput::createNewDevice (const String& deviceName) | |||||
| std::unique_ptr<MidiOutput> MidiOutput::createNewDevice (const String& deviceName) | |||||
| { | { | ||||
| auto client = AlsaClient::getInstance(); | auto client = AlsaClient::getInstance(); | ||||
| auto* port = client->createPort (deviceName, false, true); | auto* port = client->createPort (deviceName, false, true); | ||||
| jassert (port != nullptr && port->isValid()); | |||||
| if (port == nullptr || ! port->isValid()) | |||||
| return {}; | |||||
| std::unique_ptr<MidiOutput> midiOutput (new MidiOutput (deviceName, getFormattedPortIdentifier (client->getId(), port->portId))); | std::unique_ptr<MidiOutput> midiOutput (new MidiOutput (deviceName, getFormattedPortIdentifier (client->getId(), port->portId))); | ||||
| port->setupOutput(); | port->setupOutput(); | ||||
| midiOutput->internal = port; | midiOutput->internal = port; | ||||
| return midiOutput.release(); | |||||
| return midiOutput; | |||||
| } | } | ||||
| StringArray MidiOutput::getDevices() | StringArray MidiOutput::getDevices() | ||||
| @@ -615,7 +615,7 @@ int MidiOutput::getDefaultDeviceIndex() | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| MidiOutput* MidiOutput::openDevice (int index) | |||||
| std::unique_ptr<MidiOutput> MidiOutput::openDevice (int index) | |||||
| { | { | ||||
| return openDevice (getAvailableDevices()[index].identifier); | return openDevice (getAvailableDevices()[index].identifier); | ||||
| } | } | ||||
| @@ -640,26 +640,26 @@ MidiInput::MidiInput (const String& deviceName, const String& deviceID) | |||||
| { | { | ||||
| } | } | ||||
| MidiInput::~MidiInput() {} | |||||
| void MidiInput::start() {} | |||||
| void MidiInput::stop() {} | |||||
| Array<MidiDeviceInfo> MidiInput::getAvailableDevices() { return {}; } | |||||
| MidiDeviceInfo MidiInput::getDefaultDevice() { return {}; } | |||||
| MidiInput* MidiInput::openDevice (const String&, MidiInputCallback*) { return nullptr; } | |||||
| MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return nullptr; } | |||||
| StringArray MidiInput::getDevices() { return {}; } | |||||
| int MidiInput::getDefaultDeviceIndex() { return 0;} | |||||
| MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return nullptr; } | |||||
| MidiOutput::~MidiOutput() {} | |||||
| void MidiOutput::sendMessageNow (const MidiMessage&) {} | |||||
| Array<MidiDeviceInfo> MidiOutput::getAvailableDevices() { return {}; } | |||||
| MidiDeviceInfo MidiOutput::getDefaultDevice() { return {}; } | |||||
| MidiOutput* MidiOutput::openDevice (const String&) { return nullptr; } | |||||
| MidiOutput* MidiOutput::createNewDevice (const String&) { return nullptr; } | |||||
| StringArray MidiOutput::getDevices() { return {}; } | |||||
| int MidiOutput::getDefaultDeviceIndex() { return 0;} | |||||
| MidiOutput* MidiOutput::openDevice (int) { return nullptr; } | |||||
| MidiInput::~MidiInput() {} | |||||
| void MidiInput::start() {} | |||||
| void MidiInput::stop() {} | |||||
| Array<MidiDeviceInfo> MidiInput::getAvailableDevices() { return {}; } | |||||
| MidiDeviceInfo MidiInput::getDefaultDevice() { return {}; } | |||||
| std::unique_ptr<MidiInput> MidiInput::openDevice (const String&, MidiInputCallback*) { return {}; } | |||||
| std::unique_ptr<MidiInput> MidiInput::createNewDevice (const String&, MidiInputCallback*) { return {}; } | |||||
| StringArray MidiInput::getDevices() { return {}; } | |||||
| int MidiInput::getDefaultDeviceIndex() { return 0;} | |||||
| std::unique_ptr<MidiInput> MidiInput::openDevice (int, MidiInputCallback*) { return {}; } | |||||
| MidiOutput::~MidiOutput() {} | |||||
| void MidiOutput::sendMessageNow (const MidiMessage&) {} | |||||
| Array<MidiDeviceInfo> MidiOutput::getAvailableDevices() { return {}; } | |||||
| MidiDeviceInfo MidiOutput::getDefaultDevice() { return {}; } | |||||
| std::unique_ptr<MidiOutput> MidiOutput::openDevice (const String&) { return {}; } | |||||
| std::unique_ptr<MidiOutput> MidiOutput::createNewDevice (const String&) { return {}; } | |||||
| StringArray MidiOutput::getDevices() { return {}; } | |||||
| int MidiOutput::getDefaultDeviceIndex() { return 0;} | |||||
| std::unique_ptr<MidiOutput> MidiOutput::openDevice (int) { return {}; } | |||||
| #endif | #endif | ||||
| @@ -395,7 +395,7 @@ MidiDeviceInfo MidiInput::getDefaultDevice() | |||||
| return getAvailableDevices().getFirst(); | return getAvailableDevices().getFirst(); | ||||
| } | } | ||||
| MidiInput* MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallback* callback) | |||||
| std::unique_ptr<MidiInput> MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallback* callback) | |||||
| { | { | ||||
| if (deviceIdentifier.isEmpty()) | if (deviceIdentifier.isEmpty()) | ||||
| return nullptr; | return nullptr; | ||||
| @@ -415,13 +415,13 @@ MidiInput* MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallb | |||||
| if (CHECK_ERROR (MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &cfName.cfString))) | if (CHECK_ERROR (MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &cfName.cfString))) | ||||
| { | { | ||||
| MIDIPortRef port; | MIDIPortRef port; | ||||
| std::unique_ptr<MidiPortAndCallback> mpc (new MidiPortAndCallback (*callback)); | |||||
| auto mpc = std::make_unique<MidiPortAndCallback> (*callback); | |||||
| if (CHECK_ERROR (MIDIInputPortCreate (client, cfName.cfString, midiInputProc, mpc.get(), &port))) | if (CHECK_ERROR (MIDIInputPortCreate (client, cfName.cfString, midiInputProc, mpc.get(), &port))) | ||||
| { | { | ||||
| if (CHECK_ERROR (MIDIPortConnectSource (port, endpoint, nullptr))) | if (CHECK_ERROR (MIDIPortConnectSource (port, endpoint, nullptr))) | ||||
| { | { | ||||
| mpc->portAndEndpoint.reset (new MidiPortAndEndpoint (port, endpoint)); | |||||
| mpc->portAndEndpoint = std::make_unique<MidiPortAndEndpoint> (port, endpoint); | |||||
| std::unique_ptr<MidiInput> midiInput (new MidiInput (endpointInfo.name, endpointInfo.identifier)); | std::unique_ptr<MidiInput> midiInput (new MidiInput (endpointInfo.name, endpointInfo.identifier)); | ||||
| @@ -431,7 +431,7 @@ MidiInput* MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallb | |||||
| const ScopedLock sl (callbackLock); | const ScopedLock sl (callbackLock); | ||||
| activeCallbacks.add (mpc.release()); | activeCallbacks.add (mpc.release()); | ||||
| return midiInput.release(); | |||||
| return midiInput; | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| @@ -443,10 +443,10 @@ MidiInput* MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallb | |||||
| } | } | ||||
| } | } | ||||
| return nullptr; | |||||
| return {}; | |||||
| } | } | ||||
| MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback) | |||||
| std::unique_ptr<MidiInput> MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback) | |||||
| { | { | ||||
| using namespace CoreMidiHelpers; | using namespace CoreMidiHelpers; | ||||
| jassert (callback != nullptr); | jassert (callback != nullptr); | ||||
| @@ -477,7 +477,7 @@ MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallba | |||||
| if (CHECK_ERROR (MIDIObjectSetIntegerProperty (endpoint, kMIDIPropertyUniqueID, (SInt32) deviceIdentifier))) | if (CHECK_ERROR (MIDIObjectSetIntegerProperty (endpoint, kMIDIPropertyUniqueID, (SInt32) deviceIdentifier))) | ||||
| { | { | ||||
| mpc->portAndEndpoint.reset (new MidiPortAndEndpoint (0, endpoint)); | |||||
| mpc->portAndEndpoint = std::make_unique<MidiPortAndEndpoint> (0, endpoint); | |||||
| std::unique_ptr<MidiInput> midiInput (new MidiInput (deviceName, String (deviceIdentifier))); | std::unique_ptr<MidiInput> midiInput (new MidiInput (deviceName, String (deviceIdentifier))); | ||||
| @@ -487,12 +487,12 @@ MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallba | |||||
| const ScopedLock sl (callbackLock); | const ScopedLock sl (callbackLock); | ||||
| activeCallbacks.add (mpc.release()); | activeCallbacks.add (mpc.release()); | ||||
| return midiInput.release(); | |||||
| return midiInput; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return nullptr; | |||||
| return {}; | |||||
| } | } | ||||
| StringArray MidiInput::getDevices() | StringArray MidiInput::getDevices() | ||||
| @@ -510,7 +510,7 @@ int MidiInput::getDefaultDeviceIndex() | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback) | |||||
| std::unique_ptr<MidiInput> MidiInput::openDevice (int index, MidiInputCallback* callback) | |||||
| { | { | ||||
| return openDevice (getAvailableDevices()[index].identifier, callback); | return openDevice (getAvailableDevices()[index].identifier, callback); | ||||
| } | } | ||||
| @@ -548,7 +548,7 @@ MidiDeviceInfo MidiOutput::getDefaultDevice() | |||||
| return getAvailableDevices().getFirst(); | return getAvailableDevices().getFirst(); | ||||
| } | } | ||||
| MidiOutput* MidiOutput::openDevice (const String& deviceIdentifier) | |||||
| std::unique_ptr<MidiOutput> MidiOutput::openDevice (const String& deviceIdentifier) | |||||
| { | { | ||||
| if (deviceIdentifier.isEmpty()) | if (deviceIdentifier.isEmpty()) | ||||
| return nullptr; | return nullptr; | ||||
| @@ -574,17 +574,17 @@ MidiOutput* MidiOutput::openDevice (const String& deviceIdentifier) | |||||
| std::unique_ptr<MidiOutput> midiOutput (new MidiOutput (endpointInfo.name, endpointInfo.identifier)); | std::unique_ptr<MidiOutput> midiOutput (new MidiOutput (endpointInfo.name, endpointInfo.identifier)); | ||||
| midiOutput->internal = new MidiPortAndEndpoint (port, endpoint); | midiOutput->internal = new MidiPortAndEndpoint (port, endpoint); | ||||
| return midiOutput.release(); | |||||
| return midiOutput; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return nullptr; | |||||
| return {}; | |||||
| } | } | ||||
| MidiOutput* MidiOutput::createNewDevice (const String& deviceName) | |||||
| std::unique_ptr<MidiOutput> MidiOutput::createNewDevice (const String& deviceName) | |||||
| { | { | ||||
| using namespace CoreMidiHelpers; | using namespace CoreMidiHelpers; | ||||
| @@ -615,12 +615,12 @@ MidiOutput* MidiOutput::createNewDevice (const String& deviceName) | |||||
| std::unique_ptr<MidiOutput> midiOutput (new MidiOutput (deviceName, String (deviceIdentifier))); | std::unique_ptr<MidiOutput> midiOutput (new MidiOutput (deviceName, String (deviceIdentifier))); | ||||
| midiOutput->internal = new MidiPortAndEndpoint (0, endpoint); | midiOutput->internal = new MidiPortAndEndpoint (0, endpoint); | ||||
| return midiOutput.release(); | |||||
| return midiOutput; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return nullptr; | |||||
| return {}; | |||||
| } | } | ||||
| StringArray MidiOutput::getDevices() | StringArray MidiOutput::getDevices() | ||||
| @@ -638,7 +638,7 @@ int MidiOutput::getDefaultDeviceIndex() | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| MidiOutput* MidiOutput::openDevice (int index) | |||||
| std::unique_ptr<MidiOutput> MidiOutput::openDevice (int index) | |||||
| { | { | ||||
| return openDevice (getAvailableDevices()[index].identifier); | return openDevice (getAvailableDevices()[index].identifier); | ||||
| } | } | ||||
| @@ -1820,10 +1820,10 @@ MidiDeviceInfo MidiInput::getDefaultDevice() | |||||
| return MidiService::getService().getDefaultDevice (true); | return MidiService::getService().getDefaultDevice (true); | ||||
| } | } | ||||
| MidiInput* MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallback* callback) | |||||
| std::unique_ptr<MidiInput> MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallback* callback) | |||||
| { | { | ||||
| if (deviceIdentifier.isEmpty() || callback == nullptr) | if (deviceIdentifier.isEmpty() || callback == nullptr) | ||||
| return nullptr; | |||||
| return {}; | |||||
| std::unique_ptr<MidiInput> in (new MidiInput ({}, deviceIdentifier)); | std::unique_ptr<MidiInput> in (new MidiInput ({}, deviceIdentifier)); | ||||
| std::unique_ptr<MidiServiceType::InputWrapper> wrapper; | std::unique_ptr<MidiServiceType::InputWrapper> wrapper; | ||||
| @@ -1834,13 +1834,13 @@ MidiInput* MidiInput::openDevice (const String& deviceIdentifier, MidiInputCallb | |||||
| } | } | ||||
| catch (std::runtime_error&) | catch (std::runtime_error&) | ||||
| { | { | ||||
| return nullptr; | |||||
| return {}; | |||||
| } | } | ||||
| in->setName (wrapper->getDeviceName()); | in->setName (wrapper->getDeviceName()); | ||||
| in->internal = wrapper.release(); | in->internal = wrapper.release(); | ||||
| return in.release(); | |||||
| return in; | |||||
| } | } | ||||
| StringArray MidiInput::getDevices() | StringArray MidiInput::getDevices() | ||||
| @@ -1858,7 +1858,7 @@ int MidiInput::getDefaultDeviceIndex() | |||||
| return findDefaultDeviceIndex (getAvailableDevices(), getDefaultDevice()); | return findDefaultDeviceIndex (getAvailableDevices(), getDefaultDevice()); | ||||
| } | } | ||||
| MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback) | |||||
| std::unique_ptr<MidiInput> MidiInput::openDevice (int index, MidiInputCallback* callback) | |||||
| { | { | ||||
| return openDevice (getAvailableDevices()[index].identifier, callback); | return openDevice (getAvailableDevices()[index].identifier, callback); | ||||
| } | } | ||||
| @@ -1887,10 +1887,10 @@ MidiDeviceInfo MidiOutput::getDefaultDevice() | |||||
| return MidiService::getService().getDefaultDevice (false); | return MidiService::getService().getDefaultDevice (false); | ||||
| } | } | ||||
| MidiOutput* MidiOutput::openDevice (const String& deviceIdentifier) | |||||
| std::unique_ptr<MidiOutput> MidiOutput::openDevice (const String& deviceIdentifier) | |||||
| { | { | ||||
| if (deviceIdentifier.isEmpty()) | if (deviceIdentifier.isEmpty()) | ||||
| return nullptr; | |||||
| return {}; | |||||
| std::unique_ptr<MidiServiceType::OutputWrapper> wrapper; | std::unique_ptr<MidiServiceType::OutputWrapper> wrapper; | ||||
| @@ -1900,7 +1900,7 @@ MidiOutput* MidiOutput::openDevice (const String& deviceIdentifier) | |||||
| } | } | ||||
| catch (std::runtime_error&) | catch (std::runtime_error&) | ||||
| { | { | ||||
| return nullptr; | |||||
| return {}; | |||||
| } | } | ||||
| std::unique_ptr<MidiOutput> out; | std::unique_ptr<MidiOutput> out; | ||||
| @@ -1908,7 +1908,7 @@ MidiOutput* MidiOutput::openDevice (const String& deviceIdentifier) | |||||
| out->internal = wrapper.release(); | out->internal = wrapper.release(); | ||||
| return out.release(); | |||||
| return out; | |||||
| } | } | ||||
| StringArray MidiOutput::getDevices() | StringArray MidiOutput::getDevices() | ||||
| @@ -1926,7 +1926,7 @@ int MidiOutput::getDefaultDeviceIndex() | |||||
| return findDefaultDeviceIndex (getAvailableDevices(), getDefaultDevice()); | return findDefaultDeviceIndex (getAvailableDevices(), getDefaultDevice()); | ||||
| } | } | ||||
| MidiOutput* MidiOutput::openDevice (int index) | |||||
| std::unique_ptr<MidiOutput> MidiOutput::openDevice (int index) | |||||
| { | { | ||||
| return openDevice (getAvailableDevices()[index].identifier); | return openDevice (getAvailableDevices()[index].identifier); | ||||
| } | } | ||||
| @@ -51,8 +51,8 @@ struct MIDIDeviceDetector : public PhysicalTopologySource::DeviceDetector | |||||
| lockedFromOutside = false; | lockedFromOutside = false; | ||||
| dev->setLockAgainstOtherProcesses (lock); | dev->setLockAgainstOtherProcesses (lock); | ||||
| dev->midiInput.reset (MidiInput::openDevice (pair.input.identifier, dev.get())); | |||||
| dev->midiOutput.reset (MidiOutput::openDevice (pair.output.identifier)); | |||||
| dev->midiInput = MidiInput::openDevice (pair.input.identifier, dev.get()); | |||||
| dev->midiOutput = MidiOutput::openDevice (pair.output.identifier); | |||||
| if (dev->midiInput != nullptr) | if (dev->midiInput != nullptr) | ||||
| { | { | ||||