Skip to content

Commit

Permalink
Browser: allow tracks to be previewed or loaded using mouse
Browse files Browse the repository at this point in the history
single click: preview
double click: load
  • Loading branch information
samsta committed Jul 12, 2022
1 parent f541168 commit f7ce8d5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
25 changes: 20 additions & 5 deletions Browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
24 changes: 14 additions & 10 deletions src/LiveMusicBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
}
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit f7ce8d5

Please sign in to comment.