From 27113f6443aa416852daf8fb9be148e56d93c052 Mon Sep 17 00:00:00 2001 From: Zachary Hall Date: Sun, 8 Dec 2024 09:55:27 -0800 Subject: [PATCH] WTF - Asserting the return value of a function causes it to not run?! --- .genio | Bin 0 -> 758 bytes CMakeLists.txt.user | 52 +++++++++++++------------- backends/playback/zsm/zsm_backend.cpp | 10 ++--- backends/ui/haiku/main_window.cpp | 9 ++++- backends/ui/qt/aboutwindow.cpp | 3 +- backends/ui/qt/main_window.cpp | 10 ++++- backends/ui/qt/preferences.cpp | 3 +- haiku-res.rdef | 2 +- ipc/common.proto | 1 + ipc/internal.proto | 10 +++++ log.cpp | 2 + main.cpp | 13 ++++++- options.cpp | 2 +- playback.cpp | 5 +++ playback.h | 5 +++ playback_process.cpp | 2 + subprojects/fmt | 2 +- subprojects/googletest | 2 +- 18 files changed, 93 insertions(+), 40 deletions(-) create mode 100644 .genio diff --git a/.genio b/.genio new file mode 100644 index 0000000000000000000000000000000000000000..d206db3932f6c0be09497a03e6556959ec8b6c08 GIT binary patch literal 758 zcmbtQO-sW-5S+Kfr+pGjHBJX6Ewh{0JyK!uvPzO3iiZFU{x{DCbxt_^<&N*U^AIxaM%$eYm;1 zJ!5{8uto3*9(?g3)hC2C%kMS%6{?>Iypjjo4c{g1nZSJyb{qbX>Nmo2i)a51E#Q2* zjh^T4iC?w)PQ$bRWUBXJ2L@4e%KI~3ru?u@^F$P7f - + EnvironmentId @@ -86,7 +86,7 @@ true - true + false true @@ -109,19 +109,19 @@ CMAKE_CXX_COMPILER_LAUNCHER=ccache CMAKE_C_COMPILER_LAUNCHER=ccache - -DBUILD_SOUNDTOUCH:BOOL=ON --DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=ON --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake --DCMAKE_C_FLAGS:STRING=-O2 -march=native -g --DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo --DDISABLE_GTK_UI:BOOL=ON --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} + -DCMAKE_C_FLAGS:STRING=-O2 -march=native -g -DCMAKE_CXX_FLAGS:STRING=-O2 -march=native -g --DCMAKE_POLICY_DEFAULT_CMP0069:STRING=NEW +-DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=ON +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_POLICY_DEFAULT_CMP0069:STRING=NEW +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DBUILD_SOUNDTOUCH:BOOL=ON +-DDISABLE_GTK_UI:BOOL=ON +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} /boot/home/Desktop/looper/build/default @@ -222,19 +222,19 @@ CMAKE_CXX_COMPILER_LAUNCHER=ccache CMAKE_C_COMPILER_LAUNCHER=ccache - -DBUILD_SOUNDTOUCH:BOOL=ON --DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=OFF --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake --DCMAKE_C_FLAGS:STRING=-O2 -march=native -g --DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo --DDISABLE_GTK_UI:BOOL=ON --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} + -DCMAKE_C_FLAGS:STRING=-O2 -march=native -g -DCMAKE_CXX_FLAGS:STRING=-O2 -march=native -g --DCMAKE_POLICY_DEFAULT_CMP0069:STRING=NEW +-DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=OFF +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_POLICY_DEFAULT_CMP0069:STRING=NEW +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DBUILD_SOUNDTOUCH:BOOL=ON +-DDISABLE_GTK_UI:BOOL=ON +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} /boot/home/Desktop/looper/build/Fast_building_config_CMake_preset-RelWithDebInfo diff --git a/backends/playback/zsm/zsm_backend.cpp b/backends/playback/zsm/zsm_backend.cpp index 361ef74..0916614 100644 --- a/backends/playback/zsm/zsm_backend.cpp +++ b/backends/playback/zsm/zsm_backend.cpp @@ -140,7 +140,7 @@ void ZsmBackend::load(const char *filename) { loop_end = length; loop_start = this->loop_pos; fm_stream = SDL_NewAudioStream(AUDIO_S16SYS, 2, YM_FREQ, AUDIO_S16SYS, 2, PSG_FREQ); - DEBUG.writefln("fm_stream: %ld -> %ld", YM_FREQ, PSG_FREQ); + DEBUG.writefln("fm_stream: %ld -> %ld (Is null: %s)", YM_FREQ, PSG_FREQ, fm_stream == NULL ? "true" : "false"); #define _PROPERTY(name, type, default_value) \ { \ std::string type_str = #type; \ @@ -456,10 +456,10 @@ void ZsmBackend::audio_step(size_t samples) { size_t needed_samples = ((size_t)std::floor(samples * ratio)) / 2; int16_t *ym_ptr = ym_buf.get_item_sized(needed_samples * 2); YM_stream_update(ym_ptr, needed_samples); - assert(SDL_AudioStreamPut(fm_stream, ym_ptr, needed_samples * 2 * sizeof(int16_t)) == 0); - while (SDL_AudioStreamAvailable(fm_stream) < ((samples + 2) * sizeof(int16_t))) { - YM_stream_update(ym_ptr, 1); - assert(SDL_AudioStreamPut(fm_stream, ym_ptr, 2 * sizeof(int16_t)) == 0); + SDL_AudioStreamPut(fm_stream, ym_ptr, needed_samples * 2 * sizeof(int16_t)); + while (SDL_AudioStreamAvailable(fm_stream) < (samples * sizeof(int16_t))) { + YM_stream_update(ym_ptr, 8); + SDL_AudioStreamPut(fm_stream, ym_ptr, 8 * 2 * sizeof(int16_t)); } int16_t *ym_resample_ptr = ym_resample_buf.get_item_sized(samples); ssize_t ym_resample_len = SDL_AudioStreamGet(fm_stream, ym_resample_ptr, (samples + 2) * sizeof(int16_t)); diff --git a/backends/ui/haiku/main_window.cpp b/backends/ui/haiku/main_window.cpp index 63f6a26..b6c456a 100644 --- a/backends/ui/haiku/main_window.cpp +++ b/backends/ui/haiku/main_window.cpp @@ -94,6 +94,7 @@ HaikuLooperWindow::HaikuLooperWindow(Playback *playback) : BWindow(BRect(100, 10 menu_bar->AddItem(help_menu); layout->AddView(menu_bar); BView *spacer = new BView("spacer", B_SUPPORTS_LAYOUT|B_FRAME_EVENTS); + spacer->SetExplicitPreferredSize(BSize(0, 0)); spacer->SetExplicitMinSize(BSize(0, 0)); layout->AddView(spacer); BGroupView *top_row = new BGroupView(B_HORIZONTAL); @@ -314,7 +315,13 @@ void HaikuLooperWindow::Pulse() { speed_slider->SetLabel(fmt::format("Speed: {:.02f}x", speed).c_str()); if (!tempo_clicked) tempo_slider->SetValueDouble(tempo); tempo_slider->SetLabel(fmt::format("Tempo: {:.02f}x", tempo).c_str()); - UpdateIfNeeded(); + UpdateIfNeeded(); + auto title = playback->get_current_title(); + if (title.has_value()) { + SetTitle(fmt::format("{} - Looper", title.value()).c_str()); + } else { + SetTitle("Looper"); + } } void HaikuLooperWindow::FrameResized(float newWidth, float newHeight) { InvalidateLayout(true); diff --git a/backends/ui/qt/aboutwindow.cpp b/backends/ui/qt/aboutwindow.cpp index 95e7696..6c4db5e 100644 --- a/backends/ui/qt/aboutwindow.cpp +++ b/backends/ui/qt/aboutwindow.cpp @@ -63,4 +63,5 @@ AboutWindow::AboutWindow() { mainLayout->addWidget(splitter); setLayout(mainLayout); license_list->clicked(license_list->model()->index(0, 0)); -} \ No newline at end of file + setWindowTitle("About Looper"); +} diff --git a/backends/ui/qt/main_window.cpp b/backends/ui/qt/main_window.cpp index f610877..52ede56 100644 --- a/backends/ui/qt/main_window.cpp +++ b/backends/ui/qt/main_window.cpp @@ -32,10 +32,18 @@ void LooperWindow::Pulse() { pitch_slider->SetLabel(fmt::format("Pitch {:.02f}x", pitch).c_str()); speed_slider->SetLabel(fmt::format("Speed: {:.02f}x", speed).c_str()); tempo_slider->SetLabel(fmt::format("Tempo: {:.02f}x", tempo).c_str()); + if (playback->handle_signals(PlaybackSignalFileChanged|PlaybackSignalStarted|PlaybackSignalStopped)) { + if (playback->IsStopped()) { + setWindowTitle("Looper"); + } else { + setWindowTitle(fmt::format("{} - Looper", playback->get_current_title().value_or(fs::path(playback->get_current_file().value_or("")).stem().string())).c_str()); + } + } } LooperWindow::LooperWindow(Playback *playback) : QMainWindow() { labels_visible = false; icons_visible = true; + this->layout()->setContentsMargins(QMargins(0, 0, 0, 0)); this->playback = playback; this->root_layout = new QBoxLayout(QBoxLayout::TopToBottom); QWidget *central_widget = new QWidget(); @@ -164,4 +172,4 @@ void LooperWindow::update_label_setting(bool labels_visible, bool icons_visible) buttons[i]->setIcon(emptyIcon); } } -} \ No newline at end of file +} diff --git a/backends/ui/qt/preferences.cpp b/backends/ui/qt/preferences.cpp index b6a58b7..95987ed 100644 --- a/backends/ui/qt/preferences.cpp +++ b/backends/ui/qt/preferences.cpp @@ -60,6 +60,7 @@ PrefsWindow::PrefsWindow() { btn_box->addWidget(apply_btn); root_layout->addWidget(btn_view); revert(); + setWindowTitle("Looper Preferences"); } void PrefsWindow::set_options_changed(bool changed) { this->revert_btn->setEnabled(changed); @@ -92,4 +93,4 @@ void PrefsWindow::apply() { else restart_warning->hide(); frontend_btn->setText(new_frontend.c_str()); update_label_setting(); -} \ No newline at end of file +} diff --git a/haiku-res.rdef b/haiku-res.rdef index 5d01cec..ebd844b 100644 --- a/haiku-res.rdef +++ b/haiku-res.rdef @@ -1,5 +1,5 @@ resource app_signature "application/x-vnd.com.complecwaft.Looper"; -resource app_flags B_EXCLUSIVE_LAUNCH; +resource app_flags B_MULTIPLE_LAUNCH; resource file_types message { "types" = "audio", diff --git a/ipc/common.proto b/ipc/common.proto index 8ff58b7..b9a752e 100644 --- a/ipc/common.proto +++ b/ipc/common.proto @@ -14,6 +14,7 @@ enum PropertyId { BackendName = 9; PlaybackRate = 10; LengthProperty = 11; + PriorityProperty = 12; }; message StringProperty { string value = 506; diff --git a/ipc/internal.proto b/ipc/internal.proto index f16fa79..23af3a7 100644 --- a/ipc/internal.proto +++ b/ipc/internal.proto @@ -13,6 +13,12 @@ message RenderResponse { uint64 len = 302; bytes data = 303; }; +message Ping { + bytes data = 1; +}; +message Pong { + bytes data = 1; +}; message LogMessage { uint64 timespec = 6000; uint32 level = 6001; @@ -45,6 +51,8 @@ message RPCCall { QuitCmd quit = 6; InitCommand init = 7; GetPropertyListCommand get_property_list = 8; + Ping = 9; + Pong = 10; }; }; message PropertyList { @@ -59,5 +67,7 @@ message RPCResponse { ResetResponse reset = 5; ErrorResponse err = 6; PropertyList property_list = 7; + Ping = 8; + Pong = 9; }; }; diff --git a/log.cpp b/log.cpp index 4aa39b4..e607b99 100644 --- a/log.cpp +++ b/log.cpp @@ -218,6 +218,7 @@ namespace Looper::Log { std::recursive_mutex log_stream_mutex; void init_logging_custom(log_stream_creation_function_t fn) { std::lock_guard guard(log_stream_mutex); + make_log_stream(-2, fn); make_log_stream(-1, fn); make_log_stream(0, fn); make_log_stream(1, fn); @@ -228,6 +229,7 @@ namespace Looper::Log { } void pop_log_streams() { std::lock_guard guard(log_stream_mutex); + pop_log_stream(-2); pop_log_stream(-1); pop_log_stream(0); pop_log_stream(1); diff --git a/main.cpp b/main.cpp index 3ab740a..371352e 100644 --- a/main.cpp +++ b/main.cpp @@ -6,12 +6,14 @@ #include "thirdparty/CLI11.hpp" #include "data.h" #include "license.hpp" +#include #include "assets/assets.h" #ifdef __EMSCRIPTEN__ #include #endif #ifdef __HAIKU__ #include +#include #endif #include "web_functions.hpp" using namespace Looper; @@ -243,7 +245,16 @@ int main(int argc, char **argv) { size = GetModuleFileNameA(NULL, executable_path, size); realloc(executable_path, size); #elif defined(__HAIKU__) - executable_path = strdup(fs::canonical(argv[0]).c_str()); + { + int32 cookie = 0; + image_info info; + while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) { + if (info.type == B_APP_IMAGE) { + executable_path = strdup(info.name); + break; + } + } + } #else executable_path = strdup(fs::canonical("/proc/self/exe").c_str()); #endif diff --git a/options.cpp b/options.cpp index 4434410..d358a05 100644 --- a/options.cpp +++ b/options.cpp @@ -83,4 +83,4 @@ namespace Looper::Options { output.close(); #endif } -} \ No newline at end of file +} diff --git a/playback.cpp b/playback.cpp index cc696d1..26aeb5a 100644 --- a/playback.cpp +++ b/playback.cpp @@ -387,6 +387,11 @@ void PlaybackInstance::LoopFunction() { } } +void PlaybackInstance::Render(std::string opath) { + output_file_mutex.lock(); + output_file = opath; + output_file_mutex.unlock(); +} void PlaybackInstance::DeinitLoopFunction() { playback_ready.store(false); // ==== diff --git a/playback.h b/playback.h index d2fed32..317d52b 100644 --- a/playback.h +++ b/playback.h @@ -220,6 +220,8 @@ class Playback { virtual std::vector get_property_list() { return {}; } + inline virtual void Render(std::string path) { } + static Playback *Create(bool *daemon_found, bool daemon = false); }; @@ -294,6 +296,8 @@ private: float prev_pitch, prev_speed, prev_tempo; FILE_TYPE *file; bool initial_render = false; + std::mutex output_file_mutex; + std::optional output_file; inline void wait(std::function fn) { while (!fn()) { #ifdef NO_THREADS @@ -338,6 +342,7 @@ public: std::optional get_property(std::string path) override; std::optional reset_property(std::string path) override; std::vector get_property_list() override; + void Render(std::string opath) override; float volume; float speed; float tempo; diff --git a/playback_process.cpp b/playback_process.cpp index 5a5e3b1..1d26563 100644 --- a/playback_process.cpp +++ b/playback_process.cpp @@ -396,6 +396,7 @@ PlaybackProcess::PlaybackProcess(PlaybackProcess *parent) { DEBUG.writeln("Host process address: (in-process)"); } PlaybackProcess::PlaybackProcess(std::vector args) { + SDL_InitSubSystem(SDL_INIT_AUDIO); done = false; is_playback_process = true; Looper::Log::init_logging(); @@ -528,6 +529,7 @@ void PlaybackProcess::run_playback_process() { int looper_run_playback_process(std::vector args) { auto proc = PlaybackProcess(args); proc.run_playback_process(); + SDL_QuitSubSystem(SDL_INIT_AUDIO); return 0; } PropertyData PlaybackProcess::get_property(PropertyId property, std::optional idx) { diff --git a/subprojects/fmt b/subprojects/fmt index 0379bf3..720da57 160000 --- a/subprojects/fmt +++ b/subprojects/fmt @@ -1 +1 @@ -Subproject commit 0379bf3a5d52d8542aec1874677c9df5ff9ba5f9 +Subproject commit 720da57baba83b3b1829e20133575e57aa1a8a4f diff --git a/subprojects/googletest b/subprojects/googletest index 6dae7eb..d144031 160000 --- a/subprojects/googletest +++ b/subprojects/googletest @@ -1 +1 @@ -Subproject commit 6dae7eb4a5c3a169f3e298392bff4680224aa94a +Subproject commit d144031940543e15423a25ae5a8a74141044862f