From d54398700e934633b8d9a70d9e1a8921ab3c8592 Mon Sep 17 00:00:00 2001 From: Jan Wilczek <24981875+JanWilczek@users.noreply.github.com> Date: Thu, 27 Feb 2025 15:53:26 +0100 Subject: [PATCH 1/5] Bumped project version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd65842..55a5481 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.22 FATAL_ERROR) -project(WolfSoundDspUtils VERSION 0.1.0) +project(WolfSoundDspUtils VERSION 0.1.1) if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 20) From 35cfbae98dc988f317a3dabf1a5d5a70544c4bf9 Mon Sep 17 00:00:00 2001 From: Jan Wilczek <24981875+JanWilczek@users.noreply.github.com> Date: Thu, 27 Feb 2025 15:53:37 +0100 Subject: [PATCH 2/5] Fixed relative path --- tests/src/dsp/TestSignalsTests.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/src/dsp/TestSignalsTests.cpp b/tests/src/dsp/TestSignalsTests.cpp index e8271bd..dd9ddbf 100644 --- a/tests/src/dsp/TestSignalsTests.cpp +++ b/tests/src/dsp/TestSignalsTests.cpp @@ -9,6 +9,13 @@ TEST(TestSignals, GenerateSineAndWriteToFile) { const auto sine = wolfsound::generateSine(440_Hz, SAMPLE_RATE, 5s); - WavFileWriter::writeToFile("sine440Hz.wav", sine, SAMPLE_RATE); + const auto outputPath = + juce::File::getSpecialLocation( + juce::File::SpecialLocationType::currentExecutableFile) + .getParentDirectory() + .getChildFile("sine440Hz.wav") + .getFullPathName() + .toStdString(); + WavFileWriter::writeToFile(outputPath, sine, SAMPLE_RATE); } } // namespace wolfsound From 483c1c859c2fc1deaa8c92bff267673c47d6af9d Mon Sep 17 00:00:00 2001 From: Jan Wilczek <24981875+JanWilczek@users.noreply.github.com> Date: Thu, 27 Feb 2025 15:54:20 +0100 Subject: [PATCH 3/5] Added callOnMessageThreadIfExists with test --- ...wolfsound_callOnMessageThreadIfNotNull.hpp | 85 +++++++++++++++++++ tests/CMakeLists.txt | 6 +- .../callOnMessageThreadIfNotNullTests.cpp | 14 +++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/include/wolfsound/juce/wolfsound_callOnMessageThreadIfNotNull.hpp create mode 100644 tests/src/juce/callOnMessageThreadIfNotNullTests.cpp diff --git a/src/include/wolfsound/juce/wolfsound_callOnMessageThreadIfNotNull.hpp b/src/include/wolfsound/juce/wolfsound_callOnMessageThreadIfNotNull.hpp new file mode 100644 index 0000000..9e1d9a5 --- /dev/null +++ b/src/include/wolfsound/juce/wolfsound_callOnMessageThreadIfNotNull.hpp @@ -0,0 +1,85 @@ +/** + + +++++ + +++ + =++ ++ + ++ += +++ ++ + ++ ++ ++ +++ ++ + + ++ ++ +++ ++++++++ +++ + ++ ++ ++ ++++ +++++++ + + + + *+++++ +++ + + ++++ +++ +++ + +++++ ++ ++ + +++ ++++* ++ + ++++++ ++ + +++ + + +++ ++ + +++ +++ ++++= =+++ +++= +++ ++++======= ++ ++ ==== +++++ ++++ ++++ +++ ++++ ======== ++ ==== +++++ ++++ ++++ ++++++ +++ +++++++++= +++++= ++++ +++ +++=+++= =++==+++ + ++++++++++++ ++++++++ +++ +++++ =+++++ +++=++++ ++++ +++ ++++=++++ ++++++++ + ++++++++++++ +++ +++ +++ +++ ++++++++++ ++++ ++++ +++ ++++ ++++ ++++++++ + ***+*+++++++ **+ +*+ *** *** ++++++++ =+++ ++++ +++ ++++ ++++ ++++++++ + ***** ****+ *** **** *** *** ++++ ++++ +++ ++++ ++++ +++ ++++ ++++ ++++++++ + **** **** ****** *** *** ++++++++ +++++++ +++++++ ++++ ++++ ++++++++ + * + ____ _ _ _ _ _ + / ___| _ _ | | | | | |_ (_) | | ___ + | | _| |_ _| |_ | | | | | __| | | | | / __| + | |___ |_ _| |_ _| | |_| | | |_ | | | | \__ \ + \____| |_| |_| \___/ \__| |_| |_| |___/ + + + WolfSound C++ Utils + + License: + + MIT License + + Copyright (c) 2024 Jan Wilczek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once +#include +#include + +namespace wolfsound { +/** + * @brief Calls callback \p f on the message (main, GUI) thread if such is + * available. + * + * Otherwise, executes the call inline. + * + * @param f function to call + */ +inline void callOnMessageThreadIfNotNull(std::function f) { + if (const auto* messageManager = + juce::MessageManager::getInstanceWithoutCreating(); + messageManager != nullptr) { + // Execute on the GUI thread + messageManager->callAsync(std::move(f)); + } else { + // Execute inline + f(); + } +} +} // namespace wolfsound diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 84e5d4d..ec91746 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -30,7 +30,10 @@ cpmaddpackage( ${LIB_DIR}/juce ) -add_executable(WolfSoundDspUtilsTests src/common/MidiNoteNumberTests.cpp src/dsp/TestSignalsTests.cpp) +add_executable( + WolfSoundDspUtilsTests src/common/MidiNoteNumberTests.cpp src/dsp/TestSignalsTests.cpp + src/juce/callOnMessageThreadIfNotNullTests.cpp +) target_link_libraries( WolfSoundDspUtilsTests @@ -38,6 +41,7 @@ target_link_libraries( wolfsound::wolfsound_dsp_utils juce::juce_core juce::juce_audio_formats + juce::juce_events ) target_compile_definitions(WolfSoundDspUtilsTests PUBLIC JUCE_WEB_BROWSER=0 JUCE_USE_CURL=0) diff --git a/tests/src/juce/callOnMessageThreadIfNotNullTests.cpp b/tests/src/juce/callOnMessageThreadIfNotNullTests.cpp new file mode 100644 index 0000000..9aed555 --- /dev/null +++ b/tests/src/juce/callOnMessageThreadIfNotNullTests.cpp @@ -0,0 +1,14 @@ +#include +#include +#include +#include + +namespace wolfsound { +TEST(callOnMessageThreadIfNotNull, ExecutesInlineWhenNoMessageThread) { + bool called = false; + + callOnMessageThreadIfNotNull([&] { called = true; }); + + ASSERT_TRUE(called); +} +} // namespace wolfsound From a02a7ddff0ecfabf181e302a390e45ab2a3717d5 Mon Sep 17 00:00:00 2001 From: Jan Wilczek <24981875+JanWilczek@users.noreply.github.com> Date: Thu, 27 Feb 2025 15:57:13 +0100 Subject: [PATCH 4/5] Bumped JUCE version in tests --- tests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ec91746..6edbe6b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,9 +21,9 @@ cpmaddpackage( NAME JUCE GIT_TAG - 8.0.3 + 8.0.6 VERSION - 8.0.3 + 8.0.6 GITHUB_REPOSITORY juce-framework/JUCE SOURCE_DIR From 109c43ebeff0f8c99c6cc87d593f28b6034a910b Mon Sep 17 00:00:00 2001 From: Jan Wilczek <24981875+JanWilczek@users.noreply.github.com> Date: Thu, 27 Feb 2025 15:58:14 +0100 Subject: [PATCH 5/5] Bumped project version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 55a5481..92b94a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.22 FATAL_ERROR) -project(WolfSoundDspUtils VERSION 0.1.1) +project(WolfSoundDspUtils VERSION 0.2.0) if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 20)