From 3643bc1aa54f511cbf94d22e7d19caed9555af27 Mon Sep 17 00:00:00 2001 From: Almog Hamdani Date: Mon, 16 Dec 2019 18:45:03 +0200 Subject: [PATCH] feat: implement wrappers for getDefaultInputDevice and getDefaultOutputDevice --- src/rt_audio.cpp | 14 +++++++++++++- src/rt_audio.h | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/rt_audio.cpp b/src/rt_audio.cpp index 3dd01b8..bb1a88f 100644 --- a/src/rt_audio.cpp +++ b/src/rt_audio.cpp @@ -72,7 +72,9 @@ Napi::Object RtAudioWrap::Init(Napi::Env env, Napi::Object exports) InstanceMethod("getStreamSampleRate", &RtAudioWrap::getStreamSampleRate), InstanceMethod("getStreamTime", &RtAudioWrap::getStreamTime), InstanceMethod("setStreamTime", &RtAudioWrap::setStreamTime), - InstanceMethod("getDevices", &RtAudioWrap::getDevices)}); + InstanceMethod("getDevices", &RtAudioWrap::getDevices), + InstanceMethod("getDefaultInputDevice", &RtAudioWrap::getDefaultInputDevice), + InstanceMethod("getDefaultOutputDevice", &RtAudioWrap::getDefaultOutputDevice)}); // Set the class's ctor function as a persistent object to keep it in memory constructor = Napi::Persistent(ctor_func); @@ -137,6 +139,16 @@ Napi::Value RtAudioWrap::getDevices(const Napi::CallbackInfo &info) return devicesArray; } +Napi::Value RtAudioWrap::getDefaultInputDevice(const Napi::CallbackInfo &info) +{ + return Napi::Number::New(info.Env(), _rtAudio->getDefaultInputDevice()); +} + +Napi::Value RtAudioWrap::getDefaultOutputDevice(const Napi::CallbackInfo &info) +{ + return Napi::Number::New(info.Env(), _rtAudio->getDefaultOutputDevice()); +} + void RtAudioWrap::openStream(const Napi::CallbackInfo &info) { RtAudio::StreamParameters outputParams = info[0].IsNull() || info[0].IsUndefined() ? RtAudio::StreamParameters() : RtAudioConverter::ConvertStreamParameters(info[0].As()); diff --git a/src/rt_audio.h b/src/rt_audio.h index bbbb147..eba045f 100644 --- a/src/rt_audio.h +++ b/src/rt_audio.h @@ -14,6 +14,8 @@ class RtAudioWrap : public Napi::ObjectWrap ~RtAudioWrap(); Napi::Value getDevices(const Napi::CallbackInfo &info); + Napi::Value getDefaultInputDevice(const Napi::CallbackInfo& info); + Napi::Value getDefaultOutputDevice(const Napi::CallbackInfo& info); void openStream(const Napi::CallbackInfo &info); void closeStream(const Napi::CallbackInfo &info);