From f7ce8d5cf3b98fce6e1c0b667f880e6ef6b64711 Mon Sep 17 00:00:00 2001 From: Sam Nobs <3915450+samsta@users.noreply.github.com> Date: Tue, 12 Jul 2022 19:15:35 +1200 Subject: [PATCH] Browser: allow tracks to be previewed or loaded using mouse single click: preview double click: load --- Browser.py | 25 ++++++++++++++++++++----- src/LiveMusicBrowser.cpp | 24 ++++++++++++++---------- src/main.cpp | 3 +++ 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/Browser.py b/Browser.py index 0795d1d..d626a0c 100644 --- a/Browser.py +++ b/Browser.py @@ -231,11 +231,18 @@ def _iterate_and_find_audio(self, node): def scroll_horizontal(self, right_not_left): pass + def set_current_index(self, index): + if index >= len(self._filtered): + index = len(self._filtered) - 1 + elif index < 0: + index = 0 + self._current_index = index + def scroll_vertical(self, down_not_up): - if down_not_up and self._current_index < len(self._filtered) - 1: - self._current_index = self._current_index + 1 - elif not down_not_up and self._current_index > 0: - self._current_index = self._current_index - 1 + if down_not_up: + self.set_current_index(self._current_index + 1) + else: + self.set_current_index(self._current_index - 1) self._update() def preview(self): @@ -343,7 +350,7 @@ def set_decks(self, decks, master_deck_index): def _start_ui(self): pwd = pathlib.Path(__file__).parent.resolve() - os.system("'%s/build/LiveMusicBrowser' &" % pwd) + os.system("'%s/build/LiveMusicBrowser' > /tmp/LiveMusicBrowser.log &" % pwd) timeout = 10 while (timeout > 0 and not os.path.exists(self.SOCKET_OUT)): time.sleep(0.1) @@ -365,6 +372,14 @@ def poll(self): elif "bpm_percent" in data: filter_changed = filter_changed or self._bpm_tolerance_percent != data["bpm_percent"] self._bpm_tolerance_percent = data["bpm_percent"] + elif "preview_ix" in data: + self.set_current_index(data["preview_ix"]) + self.preview() + self._update() + elif "load_ix" in data: + self.set_current_index(data["load_ix"]) + self.load() + self._update() if filter_changed: self._apply_filter() diff --git a/src/LiveMusicBrowser.cpp b/src/LiveMusicBrowser.cpp index 9d99209..b7661ab 100644 --- a/src/LiveMusicBrowser.cpp +++ b/src/LiveMusicBrowser.cpp @@ -93,7 +93,7 @@ void drawPlayingDecks(const json11::Json& data) } } -void drawBrowserList(const json11::Json& data) +void drawBrowserList(const json11::Json& data, json11::Json& send_data) { ImGui::Text("Browse Files:"); ImGuiTableFlags flags = ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit; @@ -157,15 +157,19 @@ void drawBrowserList(const json11::Json& data) ImGui::TableSetColumnIndex(column - display_column_offset); if (column == 0) { - ImGui::Selectable(row[column].string_value().c_str(), row_ix == data["sel_ix"].int_value(), ImGuiSelectableFlags_SpanAllColumns); - } - else - { - if (row[column].is_number()) { - ImGui::Text("%3.5g", row[column].number_value()); - } else { - ImGui::TextUnformatted(row[column].string_value().c_str()); + std::string unique_id = "##track" + std::to_string(row_ix); + if (ImGui::Selectable(unique_id.c_str(), row_ix == data["sel_ix"].int_value(), + ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowDoubleClick)) + { + send_data = json11::Json::object{{ImGui::IsMouseDoubleClicked(0) ? "load_ix" : "preview_ix", json11::Json(row_ix)}}; } + ImGui::SameLine(); + } + + if (row[column].is_number()) { + ImGui::Text("%3.5g", row[column].number_value()); + } else { + ImGui::TextUnformatted(row[column].string_value().c_str()); } } } @@ -208,7 +212,7 @@ void drawFrame(int display_w, int display_h, const json11::Json& data, json11::J ImGui::Separator(); drawFilters(data, send_data); ImGui::Separator(); - drawBrowserList(data); + drawBrowserList(data, send_data); ImGui::End(); ImGui::PopStyleVar(); diff --git a/src/main.cpp b/src/main.cpp index b8d08ac..fa6ec3c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,6 +73,9 @@ extern void drawFrame(int display_w, int display_h, const json11::Json& data, js int main(int, char**) { + // turn off line buffering to stdout to ease debugging + setlinebuf(stdout); + // Setup window glfwSetErrorCallback(glfw_error_callback); if (!glfwInit())