diff --git a/include/SFML/Audio/SoundRecorder.h b/include/SFML/Audio/SoundRecorder.h index 11a1645..aa4138e 100644 --- a/include/SFML/Audio/SoundRecorder.h +++ b/include/SFML/Audio/SoundRecorder.h @@ -76,8 +76,10 @@ CSFML_AUDIO_API void sfSoundRecorder_destroy(sfSoundRecorder* soundRecorder); /// \param soundRecorder Sound recorder object /// \param sampleRate Desired capture rate, in number of samples per second /// +/// \return True, if start of capture was successful +/// //////////////////////////////////////////////////////////// -CSFML_AUDIO_API void sfSoundRecorder_start(sfSoundRecorder* soundRecorder, unsigned int sampleRate); +CSFML_AUDIO_API sfBool sfSoundRecorder_start(sfSoundRecorder* soundRecorder, unsigned int sampleRate); //////////////////////////////////////////////////////////// /// \brief Stop the capture of a sound recorder @@ -132,5 +134,56 @@ CSFML_AUDIO_API sfBool sfSoundRecorder_isAvailable(void); //////////////////////////////////////////////////////////// CSFML_AUDIO_API void sfSoundRecorder_setProcessingInterval(sfSoundRecorder* soundRecorder, sfTime interval); +//////////////////////////////////////////////////////////// +/// \brief Get a list of the names of all availabe audio capture devices +/// +/// This function returns an array of strings (null terminated), +/// containing the names of all availabe audio capture devices. +/// If no devices are available then NULL is returned. +/// +/// \param count Pointer to a variable that will be filled with the number of modes in the array +/// +/// \return An array of strings containing the names +/// +//////////////////////////////////////////////////////////// +CSFML_AUDIO_API const char** sfSoundRecorder_getAvailableDevices(size_t* count); + +//////////////////////////////////////////////////////////// +/// \brief Get the name of the default audio capture device +/// +/// This function returns the name of the default audio +/// capture device. If none is available, NULL is returned. +/// +/// \return The name of the default audio capture device (null terminated) +/// +//////////////////////////////////////////////////////////// +CSFML_AUDIO_API const char* sfSoundRecorder_getDefaultDevice(); + +//////////////////////////////////////////////////////////// +/// \brief Set the audio capture device +/// +/// This function sets the audio capture device to the device +/// with the given name. It can be called on the fly (i.e: +/// while recording). If you do so while recording and +/// opening the device fails, it stops the recording. +/// +/// \param soundRecorder Sound recorder object +/// \param The name of the audio capture device +/// +/// \return sfTrue, if it was able to set the requested device +/// +//////////////////////////////////////////////////////////// +CSFML_AUDIO_API sfBool sfSoundRecorder_setDevice(sfSoundRecorder* soundRecorder, const char* name); + +//////////////////////////////////////////////////////////// +/// \brief Get the name of the current audio capture device +/// +/// \param soundRecorder Sound recorder object +/// +/// \return The name of the current audio capture device +/// +//////////////////////////////////////////////////////////// +CSFML_AUDIO_API const char* sfSoundRecorder_getDevice(sfSoundRecorder* soundRecorder); + #endif // SFML_SOUNDRECORDER_H diff --git a/include/SFML/Graphics/RenderWindow.h b/include/SFML/Graphics/RenderWindow.h index 4b46a5f..dd9ecfa 100644 --- a/include/SFML/Graphics/RenderWindow.h +++ b/include/SFML/Graphics/RenderWindow.h @@ -258,8 +258,6 @@ CSFML_GRAPHICS_API sfBool sfRenderWindow_setActive(sfRenderWindow* renderWindow, /// is free to deny the request. /// This is not to be confused with sfWindow_setActive(). /// -/// \see hasFocus -/// /////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfRenderWindow_requestFocus(sfRenderWindow* renderWindow); @@ -271,7 +269,6 @@ CSFML_GRAPHICS_API void sfRenderWindow_requestFocus(sfRenderWindow* renderWindow /// events. /// /// \return True if window has focus, false otherwise -/// \see requestFocus /// //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfBool sfRenderWindow_hasFocus(const sfRenderWindow* renderWindow); diff --git a/include/SFML/Window/Window.h b/include/SFML/Window/Window.h index bd9873d..52a545d 100644 --- a/include/SFML/Window/Window.h +++ b/include/SFML/Window/Window.h @@ -370,8 +370,6 @@ CSFML_WINDOW_API sfBool sfWindow_setActive(sfWindow* window, sfBool active); /// is free to deny the request. /// This is not to be confused with sfWindow_setActive(). /// -/// \see hasFocus -/// /////////////////////////////////////////////////////////// CSFML_WINDOW_API void sfWindow_requestFocus(sfWindow* window); @@ -383,7 +381,6 @@ CSFML_WINDOW_API void sfWindow_requestFocus(sfWindow* window); /// events. /// /// \return True if window has focus, false otherwise -/// \see requestFocus /// //////////////////////////////////////////////////////////// CSFML_WINDOW_API sfBool sfWindow_hasFocus(const sfWindow* window); diff --git a/src/SFML/Audio/SoundRecorder.cpp b/src/SFML/Audio/SoundRecorder.cpp index 46e0952..c940a41 100644 --- a/src/SFML/Audio/SoundRecorder.cpp +++ b/src/SFML/Audio/SoundRecorder.cpp @@ -48,9 +48,9 @@ void sfSoundRecorder_destroy(sfSoundRecorder* soundRecorder) //////////////////////////////////////////////////////////// -void sfSoundRecorder_start(sfSoundRecorder* soundRecorder, unsigned int sampleRate) +sfBool sfSoundRecorder_start(sfSoundRecorder* soundRecorder, unsigned int sampleRate) { - CSFML_CALL(soundRecorder, start(sampleRate)); + CSFML_CALL_RETURN(soundRecorder, start(sampleRate), sfFalse); } @@ -71,7 +71,7 @@ unsigned int sfSoundRecorder_getSampleRate(const sfSoundRecorder* soundRecorder) //////////////////////////////////////////////////////////// sfBool sfSoundRecorder_isAvailable(void) { - return sf::SoundRecorder::isAvailable() ? sfTrue : sfFalse; + return sf::SoundRecorder::isAvailable(); } @@ -80,3 +80,48 @@ void sfSoundRecorder_setProcessingInterval(sfSoundRecorder* soundRecorder, sfTim { CSFML_CALL(soundRecorder, setProcessingInterval(interval)); } + + +//////////////////////////////////////////////////////////// +const char** sfSoundRecorder_getAvailableDevices(size_t* count) +{ + static std::vector stringDevices = sf::SoundRecorder::getAvailableDevices(); + static std::vector cstringDevices; + + if (cstringDevices.empty() && !stringDevices.empty()) + { + for (std::vector::const_iterator it = stringDevices.begin(); it != stringDevices.end(); ++it) + { + cstringDevices.push_back(it->c_str()); + } + } + + if (count) + *count = cstringDevices.size(); + + return !cstringDevices.empty() ? &cstringDevices[0] : NULL; +} + +//////////////////////////////////////////////////////////// +const char* sfSoundRecorder_getDefaultDevice() +{ + static std::string defaultDevice = sf::SoundRecorder::getDefaultDevice(); + + return !defaultDevice.empty() ? defaultDevice.c_str() : NULL; +} + +//////////////////////////////////////////////////////////// +sfBool sfSoundRecorder_setDevice(sfSoundRecorder* soundRecorder, const char* name) +{ + CSFML_CALL_RETURN(soundRecorder, setDevice(name), sfFalse); +} + +//////////////////////////////////////////////////////////// +const char* sfSoundRecorder_getDevice(sfSoundRecorder* soundRecorder) +{ + CSFML_CHECK(soundRecorder); + + soundRecorder->DeviceName = soundRecorder->This.getDevice(); + + return soundRecorder->DeviceName.c_str(); +} diff --git a/src/SFML/Audio/SoundRecorderStruct.h b/src/SFML/Audio/SoundRecorderStruct.h index 6793e45..3e27321 100644 --- a/src/SFML/Audio/SoundRecorderStruct.h +++ b/src/SFML/Audio/SoundRecorderStruct.h @@ -88,7 +88,7 @@ private : //////////////////////////////////////////////////////////// -// Internal structure of sfPacket +// Internal structure of sfSoundRecorder //////////////////////////////////////////////////////////// struct sfSoundRecorder { @@ -101,6 +101,7 @@ struct sfSoundRecorder } sfSoundRecorderImpl This; + std::string DeviceName; };