diff options
author | Juan Linietsky <reduzio@gmail.com> | 2018-08-24 12:17:14 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-24 12:17:14 -0300 |
commit | c6b340ea98708c27cb5a5a8380ef4072ad2fa839 (patch) | |
tree | 4b0f7f0b23641f5675c5402e860c062a2673b5c1 | |
parent | 77185aaf21f6235dd7aab664d191e149390ad5ee (diff) | |
parent | 05fc12ddb631c111b96bf03d84100d270f296b21 (diff) |
Merge pull request #20712 from marcelofg55/midi_open_close
Add OS::open_midi_inputs and OS::close_midi_inputs
-rw-r--r-- | core/bind/core_bind.cpp | 10 | ||||
-rw-r--r-- | core/bind/core_bind.h | 2 | ||||
-rw-r--r-- | core/os/os.cpp | 12 | ||||
-rw-r--r-- | core/os/os.h | 2 | ||||
-rw-r--r-- | drivers/coremidi/core_midi.cpp | 19 | ||||
-rw-r--r-- | drivers/coremidi/core_midi.h | 2 | ||||
-rw-r--r-- | drivers/winmidi/win_midi.cpp | 6 | ||||
-rw-r--r-- | platform/osx/os_osx.mm | 4 | ||||
-rw-r--r-- | platform/windows/os_windows.cpp | 4 | ||||
-rw-r--r-- | platform/x11/os_x11.cpp | 4 |
10 files changed, 55 insertions, 10 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 26ba28370f..2bd271205a 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -240,6 +240,14 @@ PoolStringArray _OS::get_connected_midi_inputs() { return OS::get_singleton()->get_connected_midi_inputs(); } +void _OS::open_midi_inputs() { + return OS::get_singleton()->open_midi_inputs(); +} + +void _OS::close_midi_inputs() { + return OS::get_singleton()->close_midi_inputs(); +} + void _OS::set_video_mode(const Size2 &p_size, bool p_fullscreen, bool p_resizeable, int p_screen) { OS::VideoMode vm; @@ -1085,6 +1093,8 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_audio_driver_count"), &_OS::get_audio_driver_count); ClassDB::bind_method(D_METHOD("get_audio_driver_name", "driver"), &_OS::get_audio_driver_name); ClassDB::bind_method(D_METHOD("get_connected_midi_inputs"), &_OS::get_connected_midi_inputs); + ClassDB::bind_method(D_METHOD("open_midi_inputs"), &_OS::open_midi_inputs); + ClassDB::bind_method(D_METHOD("close_midi_inputs"), &_OS::close_midi_inputs); ClassDB::bind_method(D_METHOD("get_screen_count"), &_OS::get_screen_count); ClassDB::bind_method(D_METHOD("get_current_screen"), &_OS::get_current_screen); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index b587b9257f..21aea12b23 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -157,6 +157,8 @@ public: virtual String get_audio_driver_name(int p_driver) const; virtual PoolStringArray get_connected_midi_inputs(); + virtual void open_midi_inputs(); + virtual void close_midi_inputs(); virtual int get_screen_count() const; virtual int get_current_screen() const; diff --git a/core/os/os.cpp b/core/os/os.cpp index 97dae05919..e90d714450 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -689,6 +689,18 @@ PoolStringArray OS::get_connected_midi_inputs() { return list; } +void OS::open_midi_inputs() { + + if (MIDIDriver::get_singleton()) + MIDIDriver::get_singleton()->open(); +} + +void OS::close_midi_inputs() { + + if (MIDIDriver::get_singleton()) + MIDIDriver::get_singleton()->close(); +} + OS::OS() { void *volatile stack_bottom; diff --git a/core/os/os.h b/core/os/os.h index 12c0222ad4..6f9a72d451 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -190,6 +190,8 @@ public: virtual const char *get_audio_driver_name(int p_driver) const; virtual PoolStringArray get_connected_midi_inputs(); + virtual void open_midi_inputs(); + virtual void close_midi_inputs(); virtual int get_screen_count() const { return 1; } virtual int get_current_screen() const { return 0; } diff --git a/drivers/coremidi/core_midi.cpp b/drivers/coremidi/core_midi.cpp index 3619be4a8e..6d4624e05b 100644 --- a/drivers/coremidi/core_midi.cpp +++ b/drivers/coremidi/core_midi.cpp @@ -92,6 +92,25 @@ void MIDIDriverCoreMidi::close() { } } +PoolStringArray MIDIDriverCoreMidi::get_connected_inputs() { + + PoolStringArray list; + + for (int i = 0; i < connected_sources.size(); i++) { + MIDIEndpointRef source = connected_sources[i]; + CFStringRef ref = NULL; + char name[256]; + + MIDIObjectGetStringProperty(source, kMIDIPropertyDisplayName, &ref); + CFStringGetCString(ref, name, sizeof(name), kCFStringEncodingUTF8); + CFRelease(ref); + + list.push_back(name); + } + + return list; +} + MIDIDriverCoreMidi::MIDIDriverCoreMidi() { client = 0; diff --git a/drivers/coremidi/core_midi.h b/drivers/coremidi/core_midi.h index fd35e12f4b..c6b443764f 100644 --- a/drivers/coremidi/core_midi.h +++ b/drivers/coremidi/core_midi.h @@ -53,6 +53,8 @@ public: virtual Error open(); virtual void close(); + PoolStringArray get_connected_inputs(); + MIDIDriverCoreMidi(); virtual ~MIDIDriverCoreMidi(); }; diff --git a/drivers/winmidi/win_midi.cpp b/drivers/winmidi/win_midi.cpp index 6da6e31b2b..63f7f13685 100644 --- a/drivers/winmidi/win_midi.cpp +++ b/drivers/winmidi/win_midi.cpp @@ -53,6 +53,12 @@ Error MIDIDriverWinMidi::open() { char err[256]; midiInGetErrorText(res, err, 256); ERR_PRINTS("midiInOpen error: " + String(err)); + + MIDIINCAPS caps; + res = midiInGetDevCaps(i, &caps, sizeof(MIDIINCAPS)); + if (res == MMSYSERR_NOERROR) { + ERR_PRINTS("Can't open MIDI device \"" + String(caps.szPname) + "\", is it being used by another application?"); + } } } diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 7bf274310d..41cfada723 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1351,8 +1351,6 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a AudioDriverManager::initialize(p_audio_driver); - midi_driver.open(); - input = memnew(InputDefault); joypad_osx = memnew(JoypadOSX); @@ -1370,6 +1368,8 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a void OS_OSX::finalize() { + midi_driver.close(); + CFNotificationCenterRemoveObserver(CFNotificationCenterGetDistributedCenter(), NULL, kTISNotifySelectedKeyboardInputSourceChanged, NULL); CGDisplayRemoveReconfigurationCallback(displays_arrangement_changed, NULL); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index b7b207dde1..fa8717a4b8 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1321,10 +1321,6 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int AudioDriverManager::initialize(p_audio_driver); -#ifdef WINMIDI_ENABLED - driver_midi.open(); -#endif - TRACKMOUSEEVENT tme; tme.cbSize = sizeof(TRACKMOUSEEVENT); tme.dwFlags = TME_LEAVE; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 043902f48c..56b0c975c4 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -341,10 +341,6 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a AudioDriverManager::initialize(p_audio_driver); -#ifdef ALSAMIDI_ENABLED - driver_alsamidi.open(); -#endif - ERR_FAIL_COND_V(!visual_server, ERR_UNAVAILABLE); ERR_FAIL_COND_V(x11_window == 0, ERR_UNAVAILABLE); |