Add support for setting default input device#20
Open
samaaron wants to merge 1 commit intonagachika:masterfrom
Open
Add support for setting default input device#20samaaron wants to merge 1 commit intonagachika:masterfrom
samaaron wants to merge 1 commit intonagachika:masterfrom
Conversation
samaaron
added a commit
to sonic-pi-net/sonic-pi
that referenced
this pull request
Mar 22, 2020
A pull request has been sent upstream with this specific patch: nagachika/ruby-coreaudio#20 nagachika/ruby-coreaudio@13d4d67 From 13d4d67c952ae713cd7047119e0a2b0ad861485c Mon Sep 17 00:00:00 2001 From: Sam Aaron <samaaron@gmail.com> Date: Wed, 26 Feb 2020 13:03:11 +0000 Subject: [PATCH] Add support for setting default input device --- ext/coreaudio/coreaudio.m | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/ext/coreaudio/coreaudio.m b/ext/coreaudio/coreaudio.m index c0c6635..b2da98e 100644 --- a/ext/coreaudio/coreaudio.m +++ b/ext/coreaudio/coreaudio.m @@ -444,6 +444,35 @@ return Qtrue; } + +/* + * Document-method: CoreAudio.set_default_input_device + * call-seq: + * CoreAudio.set_default_input_device(audio_device) + * + * Set system default audio input device as CoreAudio::AudioDevice object. + */ +static VALUE +ca_set_default_input_device(VALUE self, VALUE device) +{ + AudioDeviceID devID = NUM2UINT(rb_ivar_get(device, sym_iv_devid)); + AudioObjectPropertyAddress address = PropertyAddress; + UInt32 size; + OSStatus status; + + address.mSelector = kAudioHardwarePropertyDefaultInputDevice; + address.mScope = kAudioObjectPropertyScopeGlobal; + address.mElement = kAudioObjectPropertyElementMaster; + + status = AudioObjectSetPropertyData(kAudioObjectSystemObject, &address, 0, NULL, sizeof(devID), &devID); + if (status != noErr) { + rb_raise(rb_eArgError, + "coreaudio: set default input device failed: %d", status); + } + + return Qtrue; +} + /* * Document-class: CoreAudio::OutLoop * @@ -1159,6 +1188,7 @@ rb_define_singleton_method(rb_mCoreAudio, "default_input_device", ca_default_input_device, -1); rb_define_singleton_method(rb_mCoreAudio, "default_output_device", ca_default_output_device, -1); rb_define_singleton_method(rb_mCoreAudio, "set_default_output_device", ca_set_default_output_device, 1); + rb_define_singleton_method(rb_mCoreAudio, "set_default_input_device", ca_set_default_input_device, 1); rb_define_method(rb_cOutLoop, "[]=", ca_out_loop_data_assign, 2); rb_define_method(rb_cOutLoop, "start", ca_out_loop_data_start, 0);
ethancrawford
pushed a commit
to ethancrawford/sonic-pi
that referenced
this pull request
Apr 5, 2020
A pull request has been sent upstream with this specific patch: nagachika/ruby-coreaudio#20 nagachika/ruby-coreaudio@13d4d67 From 13d4d67c952ae713cd7047119e0a2b0ad861485c Mon Sep 17 00:00:00 2001 From: Sam Aaron <samaaron@gmail.com> Date: Wed, 26 Feb 2020 13:03:11 +0000 Subject: [PATCH] Add support for setting default input device --- ext/coreaudio/coreaudio.m | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/ext/coreaudio/coreaudio.m b/ext/coreaudio/coreaudio.m index c0c6635..b2da98e 100644 --- a/ext/coreaudio/coreaudio.m +++ b/ext/coreaudio/coreaudio.m @@ -444,6 +444,35 @@ return Qtrue; } + +/* + * Document-method: CoreAudio.set_default_input_device + * call-seq: + * CoreAudio.set_default_input_device(audio_device) + * + * Set system default audio input device as CoreAudio::AudioDevice object. + */ +static VALUE +ca_set_default_input_device(VALUE self, VALUE device) +{ + AudioDeviceID devID = NUM2UINT(rb_ivar_get(device, sym_iv_devid)); + AudioObjectPropertyAddress address = PropertyAddress; + UInt32 size; + OSStatus status; + + address.mSelector = kAudioHardwarePropertyDefaultInputDevice; + address.mScope = kAudioObjectPropertyScopeGlobal; + address.mElement = kAudioObjectPropertyElementMaster; + + status = AudioObjectSetPropertyData(kAudioObjectSystemObject, &address, 0, NULL, sizeof(devID), &devID); + if (status != noErr) { + rb_raise(rb_eArgError, + "coreaudio: set default input device failed: %d", status); + } + + return Qtrue; +} + /* * Document-class: CoreAudio::OutLoop * @@ -1159,6 +1188,7 @@ rb_define_singleton_method(rb_mCoreAudio, "default_input_device", ca_default_input_device, -1); rb_define_singleton_method(rb_mCoreAudio, "default_output_device", ca_default_output_device, -1); rb_define_singleton_method(rb_mCoreAudio, "set_default_output_device", ca_set_default_output_device, 1); + rb_define_singleton_method(rb_mCoreAudio, "set_default_input_device", ca_set_default_input_device, 1); rb_define_method(rb_cOutLoop, "[]=", ca_out_loop_data_assign, 2); rb_define_method(rb_cOutLoop, "start", ca_out_loop_data_start, 0);
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enables the default input device to be set (similar to setting default output device).
This patch is currently in use in Sonic Pi :-)