diff --git a/auxiliary/libs/signalflow_cli/__init__.py b/auxiliary/libs/signalflow_cli/__init__.py index b84d5766..918e27e7 100755 --- a/auxiliary/libs/signalflow_cli/__init__.py +++ b/auxiliary/libs/signalflow_cli/__init__.py @@ -65,10 +65,16 @@ def run_list_output_device_names(backend_name: str = None): print(" - %s" % name) -def run_list_output_backend_names(): - output_backend_names = AudioGraph.get_output_backend_names() +def run_list_input_device_names(backend_name: str = None): + input_device_names = AudioGraph.get_input_device_names(backend_name) + print("Available input device names:") + for name in input_device_names: + print(" - %s" % name) + +def run_list_backend_names(): + backend_names = AudioGraph.get_backend_names() print("Available output backend names:") - for name in output_backend_names: + for name in backend_names: print(" - %s" % name) @@ -129,8 +135,16 @@ def main(): # Command: list-output-device-names # -------------------------------------------------------------------------------- list_output_device_names = subparsers.add_parser('list-output-device-names', help='list available output devices') - list_output_device_names.add_argument('--output-backend-name', type=str, - help='name of output backend to use (default: system default backend)', + list_output_device_names.add_argument('--backend-name', type=str, + help='name of audio backend to use (default: system default backend)', + default=None) + + # -------------------------------------------------------------------------------- + # Command: list-input-device-names + # -------------------------------------------------------------------------------- + list_input_device_names = subparsers.add_parser('list-input-device-names', help='list available input devices') + list_input_device_names.add_argument('--backend-name', type=str, + help='name of audio backend to use (default: system default backend)', default=None) # -------------------------------------------------------------------------------- @@ -168,9 +182,11 @@ def main(): elif args.command == 'test': run_test(args.frequency, args.gain, args.output_backend_name, args.output_device_name) elif args.command == 'list-output-device-names': - run_list_output_device_names(args.output_backend_name) - elif args.command == 'list-output-backend-names': - run_list_output_backend_names() + run_list_output_device_names(args.backend_name) + elif args.command == 'list-input-device-names': + run_list_input_device_names(args.backend_name) + elif args.command == 'list-backend-names': + run_list_backend_names() elif args.command == 'list-midi-output-device-names': run_list_midi_output_device_names() elif args.command == 'list-midi-input-device-names': diff --git a/source/include/signalflow/core/graph.h b/source/include/signalflow/core/graph.h index b47c710b..7b91d271 100644 --- a/source/include/signalflow/core/graph.h +++ b/source/include/signalflow/core/graph.h @@ -201,13 +201,21 @@ class AudioGraph *--------------------------------------------------------------------------------*/ static std::list get_output_device_names(std::string backend_name = ""); + /**-------------------------------------------------------------------------------- + * Returns a list of available audio I/O input devices. + * + * @return The list of device names. + * + *--------------------------------------------------------------------------------*/ + static std::list get_input_device_names(std::string backend_name = ""); + /**-------------------------------------------------------------------------------- * Returns a list of available audio I/O output backends. * * @return The list of backend names. * *--------------------------------------------------------------------------------*/ - static std::list get_output_backend_names(); + static std::list get_backend_names(); /**-------------------------------------------------------------------------------- * Schedule a node for rendering without connecting the node to the graph's output. diff --git a/source/include/signalflow/node/io/output/miniaudio.h b/source/include/signalflow/node/io/output/miniaudio.h index 9b79cc40..36bfa4ca 100644 --- a/source/include/signalflow/node/io/output/miniaudio.h +++ b/source/include/signalflow/node/io/output/miniaudio.h @@ -26,7 +26,8 @@ class AudioOut : public AudioOut_Abstract virtual void destroy() override; static std::list get_output_device_names(std::string backend_name = ""); - static std::list get_output_backend_names(); + static std::list get_input_device_names(std::string backend_name = ""); + static std::list get_backend_names(); private: /*-------------------------------------------------------------------------------- diff --git a/source/src/core/graph.cpp b/source/src/core/graph.cpp index 65babff8..0182159a 100644 --- a/source/src/core/graph.cpp +++ b/source/src/core/graph.cpp @@ -594,9 +594,15 @@ std::list AudioGraph::get_output_device_names(std::string backend_n } // static -std::list AudioGraph::get_output_backend_names() +std::list AudioGraph::get_input_device_names(std::string backend_name) { - return AudioOut::get_output_backend_names(); + return AudioOut::get_input_device_names(backend_name); +} + +// static +std::list AudioGraph::get_backend_names() +{ + return AudioOut::get_backend_names(); } NodeRef AudioGraph::add_node(NodeRef node) diff --git a/source/src/node/io/output/miniaudio.cpp b/source/src/node/io/output/miniaudio.cpp index c333ca3a..d69b291b 100644 --- a/source/src/node/io/output/miniaudio.cpp +++ b/source/src/node/io/output/miniaudio.cpp @@ -243,8 +243,6 @@ std::list AudioOut::get_output_device_names(std::string backend_nam ma_result rv; ma_device_info *playback_devices; ma_uint32 playback_device_count; - ma_device_info *capture_devices; - ma_uint32 capture_device_count; ma_context context; AudioOut::init_context(&context, backend_name); @@ -252,8 +250,8 @@ std::list AudioOut::get_output_device_names(std::string backend_nam rv = ma_context_get_devices(&context, &playback_devices, &playback_device_count, - &capture_devices, - &capture_device_count); + NULL, + NULL); if (rv != MA_SUCCESS) { throw audio_io_exception("miniaudio: Failure querying audio devices"); @@ -268,7 +266,37 @@ std::list AudioOut::get_output_device_names(std::string backend_nam return device_names; } -std::list AudioOut::get_output_backend_names() +std::list AudioOut::get_input_device_names(std::string backend_name) +{ + std::list device_names; + + ma_result rv; + ma_device_info *capture_devices; + ma_uint32 capture_device_count; + ma_context context; + + AudioOut::init_context(&context, backend_name); + + rv = ma_context_get_devices(&context, + NULL, + NULL, + &capture_devices, + &capture_device_count); + if (rv != MA_SUCCESS) + { + throw audio_io_exception("miniaudio: Failure querying audio devices"); + } + for (unsigned int i = 0; i < capture_device_count; i++) + { + device_names.push_back(std::string(capture_devices[i].name)); + } + + ma_context_uninit(&context); + + return device_names; +} + +std::list AudioOut::get_backend_names() { std::list backend_names; ma_backend enabled_backends[MA_BACKEND_COUNT]; diff --git a/source/src/python/graph.cpp b/source/src/python/graph.cpp index 70d3a2c0..e1ff39c1 100644 --- a/source/src/python/graph.cpp +++ b/source/src/python/graph.cpp @@ -55,7 +55,13 @@ void init_python_graph(py::module &m) return AudioGraph::get_output_device_names(backend_name_str); }, "backend_name"_a = "", R"pbdoc(list[str]: List the available output device names.)pbdoc") - .def_static("get_output_backend_names", &AudioGraph::get_output_backend_names, R"pbdoc(list[str]: List the available output backend names.)pbdoc") + .def_static( + "get_input_device_names", [](py::object backend_name) { + std::string backend_name_str = backend_name.is_none() ? "" : backend_name.cast(); + return AudioGraph::get_input_device_names(backend_name_str); + }, + "backend_name"_a = "", R"pbdoc(list[str]: List the available input device names.)pbdoc") + .def_static("get_backend_names", &AudioGraph::get_backend_names, R"pbdoc(list[str]: List the available audio backend names.)pbdoc") /*-------------------------------------------------------------------------------- * Methods