diff --git a/.dir-locals.el b/.dir-locals.el index 71e329e..40fedb5 100755 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -1,6 +1,35 @@ +;;; Directory Local Variables +;;; For more information see (info "(emacs) Directory Variables") + +;; (concat (cdr (project-current)) + ((nil . ((cmake-ide-project-dir . "~/repos/sample-hive") (cmake-ide-build-dir . "~/repos/sample-hive/build") (cmake-ide-cmake-opts . "-DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DPORTABLE=1 -DCMAKE_CXX_COMPILER='/usr/bin/g++'") + ;; (projectile-project-root . "~/repos/sample-hive") (projectile-project-name . "SampleHive") (projectile-project-run-cmd . "~/repos/sample-hive/build/SampleHive") - (projectile-project-test-cmd . "./test.sh")))) + ;; (projectile-project-run-cmd . "/tmp/SampleHive/bin/SampleHive") + (compile-command . "cd .. && ninja -C build install") + (fill-column . 110) + ;; Setup dap debugging template for the project + (setq dap-debug-template-configurations + '(("SampleHive::Core::Debug" + :type "gdb" + :request "launch" + :name "SampleHive::Core::Debug" + :target "${workspaceFolder}/build/SampleHive" + ;; :target "/tmp/SampleHive/bin/SampleHive" + :cwd "${workspaceFolder}" + :symbolLoadInfo "loadAll" + :additionalSOLibSearchPath "/tmp/SampleHive/bin/")))))) + +;; ((c++-mode . ((dap-debug-template-configurations . '(("SampleHive::Core::Debug" +;; :type "gdb" +;; :request "launch" +;; :name "SampleHive::Core::Debug" +;; :target "${workspaceFolder}/build/SampleHive" +;; ;; :target "/tmp/SampleHive/bin/SampleHive" +;; :cwd "${workspaceFolder}" +;; :symbolLoadInfo "loadAll" +;; :additionalSOLibSearchPath "/tmp/SampleHive/bin/")))))) diff --git a/meson.build b/meson.build index 5cab9d0..3f02b04 100755 --- a/meson.build +++ b/meson.build @@ -146,6 +146,14 @@ src = [ 'src/GUI/MainFrame.cpp', 'src/GUI/TransportControls.cpp', 'src/GUI/WaveformViewer.cpp', + 'src/GUI/Notebook.cpp', + 'src/GUI/DirectoryBrowser.cpp', + 'src/GUI/Hives.cpp', + 'src/GUI/Trash.cpp', + 'src/GUI/ListCtrl.cpp', + 'src/GUI/SearchBar.cpp', + 'src/GUI/InfoBar.cpp', + 'src/GUI/Library.cpp', 'src/GUI/Dialogs/Settings.cpp', 'src/GUI/Dialogs/TagEditor.cpp', @@ -156,6 +164,7 @@ src = [ 'src/Utility/Serialize.cpp', 'src/Utility/Tags.cpp', 'src/Utility/SH_Event.cpp', + 'src/Utility/Signal.cpp', 'src/Utility/Log.cpp', ] diff --git a/src/Database/Database.cpp b/src/Database/Database.cpp index 4167ea2..e06a106 100644 --- a/src/Database/Database.cpp +++ b/src/Database/Database.cpp @@ -53,7 +53,7 @@ void show_modal_dialog_and_log(const std::string &message, const std::string &ti const std::string &error_msg) { std::stringstream ss; - ss << message << error_msg; + ss << message << ": " << error_msg; const auto msg = ss.str(); @@ -899,7 +899,7 @@ void Database::LoadHivesDatabase(wxDataViewTreeCtrl &treeCtrl) } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot load hive from hives table", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot load data from HIVES", "Error", e.what()); } } diff --git a/src/GUI/Dialogs/TagEditor.cpp b/src/GUI/Dialogs/TagEditor.cpp index 993a595..fdfe52d 100644 --- a/src/GUI/Dialogs/TagEditor.cpp +++ b/src/GUI/Dialogs/TagEditor.cpp @@ -20,6 +20,7 @@ #include "Utility/ControlIDs.hpp" #include "Utility/SH_Event.hpp" +#include "Utility/Signal.hpp" #include "Utility/Log.hpp" #include "Utility/Paths.hpp" #include "Database/Database.hpp" @@ -312,20 +313,20 @@ void TagEditor::OnClickApply(wxCommandEvent& event) info_msg = "Error, cannot change tag!"; } - SendInfoBarMessage(info_msg, wxICON_INFORMATION); + SampleHive::Signal::SendInfoBarMessage(info_msg, wxICON_INFORMATION, *this, true); } -void TagEditor::SendInfoBarMessage(const wxString& msg, int mode) -{ - SH_LOG_INFO("{} called..", __FUNCTION__); +// void TagEditor::SendInfoBarMessage(const wxString& msg, int mode) +// { +// SH_LOG_INFO("{} called..", __FUNCTION__); - SampleHive::SH_InfoBarMessageEvent event(SampleHive::SH_EVT_INFOBAR_MESSAGE_SHOW, this->GetId()); - event.SetEventObject(this); +// SampleHive::SH_InfoBarMessageEvent event(SampleHive::SH_EVT_INFOBAR_MESSAGE_SHOW, this->GetId()); +// event.SetEventObject(this); - event.SetInfoBarMessage({ msg, mode }); +// event.SetInfoBarMessage({ msg, mode }); - GetParent()->GetEventHandler()->ProcessEvent(event); -} +// GetParent()->GetEventHandler()->ProcessEvent(event); +// } TagEditor::~TagEditor() { diff --git a/src/GUI/Dialogs/TagEditor.hpp b/src/GUI/Dialogs/TagEditor.hpp index 32a8d3d..b2a62f1 100644 --- a/src/GUI/Dialogs/TagEditor.hpp +++ b/src/GUI/Dialogs/TagEditor.hpp @@ -106,5 +106,5 @@ class TagEditor : public wxDialog void OnClickApply(wxCommandEvent& event); // ------------------------------------------------------------------- - void SendInfoBarMessage(const wxString& msg, int mode); + // void SendInfoBarMessage(const wxString& msg, int mode); }; diff --git a/src/GUI/DirectoryBrowser.cpp b/src/GUI/DirectoryBrowser.cpp new file mode 100644 index 0000000..3de7a15 --- /dev/null +++ b/src/GUI/DirectoryBrowser.cpp @@ -0,0 +1,44 @@ +#include "GUI/DirectoryBrowser.hpp" +#include "Utility/Paths.hpp" +#include "Utility/ControlIDs.hpp" +#include "Utility/Log.hpp" + +#include +#include + +cDirectoryBrowser::cDirectoryBrowser(wxWindow* window) + : wxGenericDirCtrl(window, BC_DirCtrl, wxDirDialogDefaultFolderStr, wxDefaultPosition, + wxDefaultSize, wxDIRCTRL_SHOW_FILTERS, + _("All files|*|Ogg files (*.ogg)|*.ogg|Wav files (*.wav)|*.wav|" + "Flac files (*.flac)|*.flac"), 0) +{ + SetPath(USER_HOME_DIR); + + Bind(wxEVT_DIRCTRL_FILEACTIVATED, &cDirectoryBrowser::OnClickDirCtrl, this, BC_DirCtrl); + Bind(wxEVT_TREE_BEGIN_DRAG, &cDirectoryBrowser::OnDragFromDirCtrl, this, this->GetTreeCtrl()->GetId()); +} + +void cDirectoryBrowser::OnClickDirCtrl(wxCommandEvent& event) +{ + wxArrayString path; + path.push_back(this->GetFilePath()); + + // TODO + // AddSamples(path); +} + +void cDirectoryBrowser::OnDragFromDirCtrl(wxTreeEvent& event) +{ + wxFileDataObject file_data; + file_data.AddFile(this->GetPath(event.GetItem())); + + wxDropSource drop_source(this); + drop_source.SetData(file_data); + + // LogDragResult(drop_source.DoDragDrop()); +} + +cDirectoryBrowser::~cDirectoryBrowser() +{ + +} diff --git a/src/GUI/DirectoryBrowser.hpp b/src/GUI/DirectoryBrowser.hpp new file mode 100644 index 0000000..26d1dbc --- /dev/null +++ b/src/GUI/DirectoryBrowser.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include + +class cDirectoryBrowser : public wxGenericDirCtrl +{ + public: + cDirectoryBrowser(wxWindow* window); + ~cDirectoryBrowser(); + + private: + // ------------------------------------------------------------------- + // DirCtrl event handlers + void OnClickDirCtrl(wxCommandEvent& event); + void OnDragFromDirCtrl(wxTreeEvent& event); +}; diff --git a/src/GUI/Hives.cpp b/src/GUI/Hives.cpp new file mode 100644 index 0000000..a1a6fce --- /dev/null +++ b/src/GUI/Hives.cpp @@ -0,0 +1,766 @@ +#include "GUI/Hives.hpp" +#include "GUI/ListCtrl.hpp" +#include "Database/Database.hpp" +#include "Utility/ControlIDs.hpp" +#include "Utility/Paths.hpp" +#include "Utility/Signal.hpp" +#include "Utility/Serialize.hpp" +#include "Utility/Log.hpp" + +#include + +#include +#include +#include + +cHivesPanel::cHivesPanel(wxWindow* window, wxDataViewListCtrl& listCtrl) + : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), + m_ListCtrl(listCtrl), m_pWindow(window) +{ + m_pMainSizer = new wxBoxSizer(wxVERTICAL); + m_pHivesSizer = new wxBoxSizer(wxVERTICAL); + m_pButtonSizer = new wxBoxSizer(wxHORIZONTAL); + + m_pAddHiveButton = new wxButton(this, BC_HiveAdd, "+", wxDefaultPosition, wxDefaultSize, 0); + m_pAddHiveButton->SetToolTip(_("Create new hive")); + + m_pButtonSizer->Add(m_pAddHiveButton, wxSizerFlags(1).Expand()); + + m_pRemoveHiveButton = new wxButton(this, BC_HiveRemove, "-", wxDefaultPosition, wxDefaultSize, 0); + m_pRemoveHiveButton->SetToolTip(_("Delete selected hive")); + + m_pButtonSizer->Add(m_pRemoveHiveButton, wxSizerFlags(1).Expand()); + + // Initializing wxDataViewTreeCtrl as another page of wxNotebook + m_pHives = new wxDataViewTreeCtrl(this, BC_Hives, wxDefaultPosition, wxDefaultSize, + wxDV_NO_HEADER | wxDV_SINGLE); + + m_pHivesSizer->Add(m_pHives, wxSizerFlags(1).Expand()); + + // Adding default hive + m_FavoritesHive = m_pHives->AppendContainer(wxDataViewItem(wxNullPtr), _("Favorites")); + + // Setting m_Hives to accept files to be dragged and dropped on it + m_pHives->DragAcceptFiles(true); + + m_pHives->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(cHivesPanel::OnDragAndDropToHives), NULL, this); + Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &cHivesPanel::OnShowHivesContextMenu, this, BC_Hives); + Bind(wxEVT_DATAVIEW_ITEM_START_EDITING, &cHivesPanel::OnHiveStartEditing, this, BC_Hives); + Bind(wxEVT_BUTTON, &cHivesPanel::OnClickAddHive, this, BC_HiveAdd); + Bind(wxEVT_BUTTON, &cHivesPanel::OnClickRemoveHive, this, BC_HiveRemove); + + m_pMainSizer->Add(m_pHivesSizer, wxSizerFlags(1).Expand()); + m_pMainSizer->Add(m_pButtonSizer, wxSizerFlags(0).Expand()); + + // Sizer for Hives page for wxNotebook + this->SetSizer(m_pMainSizer); + m_pMainSizer->Fit(this); + m_pMainSizer->SetSizeHints(this); + m_pMainSizer->Layout(); +} + +void cHivesPanel::OnDragAndDropToHives(wxDropFilesEvent& event) +{ + Serializer serializer; + Database db; + // cListCtrl m_ListCtrl.m_pWindow); + + if (event.GetNumberOfFiles() > 0) + { + wxFileDataObject file_data; + wxArrayString files; + + wxDataViewItemArray items; + int rows = m_ListCtrl.GetSelections(items); + // int rows = 2; + + wxDataViewItem drop_target;; + wxDataViewColumn* column; + wxPoint position = event.GetPosition(); + + m_pHives->HitTest(position, drop_target, column); + + wxString hive_name = m_pHives->GetItemText(drop_target); + + wxString msg; + + for (int i = 0; i < rows; i++) + { + int row = m_ListCtrl.ItemToRow(items[i]); + + wxString name = m_ListCtrl.GetTextValue(row, 1); + + file_data.AddFile(name); + + files = file_data.GetFilenames(); + + wxString file_name = serializer.DeserializeShowFileExtension() ? + files[i].BeforeLast('.') : files[i]; + + SH_LOG_DEBUG("Dropping {} file(s) {} on {}", rows - i, files[i], m_pHives->GetItemText(drop_target)); + + if (drop_target.IsOk() && m_pHives->IsContainer(drop_target) && + db.GetFavoriteColumnValueByFilename(file_name.ToStdString()) == 0) + { + m_pHives->AppendItem(drop_target, files[i]); + + m_ListCtrl.SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), row, 0); + + db.UpdateFavoriteColumn(file_name.ToStdString(), 1); + db.UpdateHiveName(file_name.ToStdString(), hive_name.ToStdString()); + + msg = wxString::Format(_("%s added to %s."), files[i], hive_name); + } + else + { + if (db.GetFavoriteColumnValueByFilename(file_name.ToStdString()) == 1) + { + wxMessageBox(wxString::Format(_("%s is already added to %s hive"), files[i], + db.GetHiveByFilename(file_name.ToStdString())), + _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this); + } + else + { + if (m_pHives->GetItemText(drop_target) == "") + wxMessageBox(_("Cannot drop item outside of a hive, try dropping on a hive."), + _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this); + else + wxMessageBox(wxString::Format(_("%s is not a hive, try dropping on a hive."), + m_pHives->GetItemText(drop_target)), _("Error!"), + wxOK | wxICON_ERROR | wxCENTRE, this); + } + } + + if (!msg.IsEmpty()) + SampleHive::Signal::SendInfoBarMessage(msg, wxICON_ERROR, *this); + // m_InfoBar->ShowMessage(msg, wxICON_ERROR); + } + } +} + +void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) +{ + Serializer serializer; + Database db; + // cListCtrl m_ListCtrl.m_pWindow); + + wxDataViewItem selected_hive = event.GetItem(); + + wxString hive_name = m_pHives->GetItemText(selected_hive); + + wxMenu menu; + + if (m_pHives->IsContainer(selected_hive)) + { + // Container menu items + menu.Append(MN_RenameHive, _("Rename hive"), _("Rename selected hive")); + menu.Append(MN_DeleteHive, _("Delete hive"), _("Delete selected hive")); + + if (!m_bFiltered) + menu.Append(MN_FilterLibrary, _("Filter library"), + _("Show only samples from current hive in library")); + else + menu.Append(MN_FilterLibrary, _("Clear filter"), _("Clear the filter")); + } + else + { + // Child menu items + menu.Append(MN_RemoveSample, _("Remove sample"), _("Remove the selected sample(s)")); + menu.Append(MN_ShowInLibrary, _("Show sample in library"), _("Show the selected in library")); + } + + if (selected_hive.IsOk() && m_pHives->IsContainer(selected_hive)) + { + switch (m_pHives->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) + { + case MN_RenameHive: + { + std::deque nodes; + nodes.push_back(m_pHives->GetNthChild(wxDataViewItem(wxNullPtr), 0)); + + wxDataViewItem current_item, found_item; + + int row = 0; + int hive_count = m_pHives->GetChildCount(wxDataViewItem(wxNullPtr)); + + wxString msg; + + wxTextEntryDialog renameEntry(this, _("Enter new name"), wxGetTextFromUserPromptStr, + wxEmptyString, wxTextEntryDialogStyle, wxDefaultPosition); + + renameEntry.SetTextValidator(wxFILTER_EMPTY); + + switch (renameEntry.ShowModal()) + { + case wxID_OK: + { + wxString hive_name = renameEntry.GetValue(); + + while(!nodes.empty()) + { + current_item = nodes.front(); + nodes.pop_front(); + + if (m_pHives->GetItemText(current_item) == hive_name) + { + found_item = current_item; + SH_LOG_DEBUG("Found item: {}", m_pHives->GetItemText(current_item)); + break; + } + + wxDataViewItem child = m_pHives->GetNthChild(wxDataViewItem(wxNullPtr), 0); + + while (row < (hive_count - 1)) + { + row ++; + + child = m_pHives->GetNthChild(wxDataViewItem(wxNullPtr), row); + nodes.push_back(child); + } + } + + nodes.clear(); + + if (found_item.IsOk()) + { + wxMessageBox(wxString::Format(_("Another hive by the name %s already exist. " + "Please try with a different name."), + hive_name), + _("Error!"), wxOK | wxCENTRE, this); + } + else + { + wxString selected_hive_name = m_pHives->GetItemText(selected_hive); + + int sample_count = m_pHives->GetChildCount(selected_hive); + + if (sample_count <= 0) + { + m_pHives->SetItemText(selected_hive, hive_name); + db.UpdateHive(selected_hive_name.ToStdString(), + hive_name.ToStdString()); + } + else + { + for (int i = 0; i < sample_count; i++) + { + wxDataViewItem sample_item = m_pHives->GetNthChild(selected_hive, i); + + wxString sample_name = serializer.DeserializeShowFileExtension() ? + m_pHives->GetItemText(sample_item).BeforeLast('.') : + m_pHives->GetItemText(sample_item); + + db.UpdateHiveName(sample_name.ToStdString(), + hive_name.ToStdString()); + db.UpdateHive(selected_hive_name.ToStdString(), + hive_name.ToStdString()); + + m_pHives->SetItemText(selected_hive, hive_name); + } + } + + msg = wxString::Format(_("Successfully changed hive name to %s."), hive_name); + } + } + break; + case wxID_CANCEL: + break; + default: + return; + } + + if (!msg.IsEmpty()) + SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); + // m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); + } + break; + case MN_DeleteHive: + { + wxString msg; + + wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to " + "delete %s from chives?"), + hive_name), + wxMessageBoxCaptionStr, + wxYES_NO | wxNO_DEFAULT | + wxICON_QUESTION | wxSTAY_ON_TOP); + + wxMessageDialog deleteFilledHiveDialog(this, wxString::Format(_("Are you sure you want to " + "delete %s and all samples " + "inside %s from chives?"), + hive_name, hive_name), + wxMessageBoxCaptionStr, + wxYES_NO | wxNO_DEFAULT | + wxICON_QUESTION | wxSTAY_ON_TOP); + + if (hive_name == m_pHives->GetItemText(m_FavoritesHive)) + { + wxMessageBox(wxString::Format(_("Error! Default hive %s cannot be deleted."), hive_name), + _("Error!"), wxOK | wxCENTRE, this); + return; + } + else if (!selected_hive.IsOk()) + { + wxMessageBox(_("No hive selected, try selecting a hive first"), _("Error!"), + wxOK | wxCENTRE, this); + return; + } + else if (selected_hive.IsOk() && !m_pHives->IsContainer(selected_hive)) + { + wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from chives."), + hive_name), + _("Error!"), wxOK | wxCENTRE, this); + return; + } + + if (m_pHives->GetChildCount(selected_hive) <= 0) + { + switch (deleteEmptyHiveDialog.ShowModal()) + { + case wxID_YES: + if (selected_hive.IsOk() && m_pHives->IsContainer(selected_hive) && + hive_name != m_pHives->GetItemText(m_FavoritesHive)) + { + m_pHives->DeleteItem(selected_hive); + + db.RemoveHiveFromDatabase(hive_name.ToStdString()); + + msg = wxString::Format(_("%s deleted from chives successfully."), hive_name); + } + break; + case wxID_NO: + break; + default: + return; + } + } + else + { + switch (deleteFilledHiveDialog.ShowModal()) + { + case wxID_YES: + if (selected_hive.IsOk() && m_pHives->IsContainer(selected_hive) && + hive_name != m_pHives->GetItemText(m_FavoritesHive)) + { + wxDataViewItem child_item; + + for (int i = 0; i < m_ListCtrl.GetItemCount(); i++) + // for (int i = 0; i < 1; i++) + { + wxString matched_sample = + serializer.DeserializeShowFileExtension() ? + m_ListCtrl.GetTextValue(i, 1).BeforeLast('.') : + m_ListCtrl.GetTextValue(i, 1); + + for (int j = 0; j < m_pHives->GetChildCount(selected_hive); j++) + { + child_item = m_pHives->GetNthChild(selected_hive, j); + + wxString child_name = + serializer.DeserializeShowFileExtension() ? + m_pHives->GetItemText(child_item).BeforeLast('.') : + m_pHives->GetItemText(child_item); + + if (child_name == matched_sample) + // if (child_name == "") + { + SH_LOG_DEBUG("Found match"); + + m_ListCtrl.SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); + + db.UpdateFavoriteColumn(matched_sample.ToStdString(), 0); + db.UpdateHiveName(matched_sample.ToStdString(), + m_pHives->GetItemText(m_FavoritesHive).ToStdString()); + + break; + } + else + SH_LOG_DEBUG("No match found"); + } + } + + m_pHives->DeleteChildren(selected_hive); + m_pHives->DeleteItem(selected_hive); + + db.RemoveHiveFromDatabase(hive_name.ToStdString()); + + msg = wxString::Format(_("%s and all samples inside %s " + "have been deleted from chives successfully."), + hive_name, hive_name); + } + break; + case wxID_NO: + break; + default: + return; + } + } + + if (!msg.IsEmpty()) + SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); + // m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); + } + break; + case MN_FilterLibrary: + { + if (!m_bFiltered) + { + try + { + const auto dataset = db.FilterDatabaseByHiveName(hive_name.ToStdString(), + serializer.DeserializeShowFileExtension(), + ICON_STAR_FILLED_16px, + ICON_STAR_EMPTY_16px); + + if (dataset.empty()) + { + wxMessageBox(_("Error! Database is empty."), _("Error!"), + wxOK | wxICON_ERROR | wxCENTRE, this); + return; + } + else + { + m_ListCtrl.DeleteAllItems(); + + for (auto data : dataset) + { + m_ListCtrl.AppendItem(data); + } + } + } + catch (...) + { + wxMessageBox(_("Error loading data, cannot filter sample view"), _("Error!"), + wxOK | wxICON_ERROR | wxCENTRE, this); + } + + m_bFiltered = true; + } + else + { + try + { + const auto dataset = db.FilterDatabaseBySampleName("", serializer.DeserializeShowFileExtension(), + ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); + + if (dataset.empty()) + { + wxMessageBox(_("Error! Database is empty."), _("Error!"), + wxOK | wxICON_ERROR | wxCENTRE, this); + } + else + { + m_ListCtrl.DeleteAllItems(); + + for (auto data : dataset) + { + m_ListCtrl.AppendItem(data); + } + } + } + catch (...) + { + wxMessageBox(_("Error loading data, cannot filter sample view"), _("Error!"), + wxOK | wxICON_ERROR | wxCENTRE, this); + } + + m_bFiltered = false; + } + } + break; + default: + return; + } + } + else if (selected_hive.IsOk() && !m_pHives->IsContainer(selected_hive)) + { + switch (m_pHives->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) + { + case MN_RemoveSample: + for(int i = 0; i < m_ListCtrl.GetItemCount(); i++) + // for(int i = 0; i < 1; i++) + { + wxString matched_sample = serializer.DeserializeShowFileExtension() ? + m_ListCtrl.GetTextValue(i, 1).BeforeLast('.') : + m_ListCtrl.GetTextValue(i, 1); + + wxString selected_sample_name = serializer.DeserializeShowFileExtension() ? + m_pHives->GetItemText(event.GetItem()).BeforeLast('.') : + m_pHives->GetItemText(event.GetItem()); + + if(selected_sample_name == matched_sample) + // if(selected_sample_name == "") + { + SH_LOG_DEBUG("Found match"); + + m_ListCtrl.SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); + + db.UpdateFavoriteColumn(matched_sample.ToStdString(), 0); + db.UpdateHiveName(matched_sample.ToStdString(), + m_pHives->GetItemText(m_FavoritesHive).ToStdString()); + + m_pHives->DeleteItem(selected_hive); + + break; + } + + wxString msg = wxString::Format(_("Removed %s from %s"), + m_pHives->GetItemText(event.GetItem()), + db.GetHiveByFilename(matched_sample.ToStdString())); + + // m_InfoBar->ShowMessage(wxString::Format(_("Removed %s from %s"), + // m_Hives->GetItemText(event.GetItem()), + // db.GetHiveByFilename(matched_sample.ToStdString())), + // wxICON_INFORMATION); + + SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); + } + break; + case MN_ShowInLibrary: + for(int i = 0; i < m_ListCtrl.GetItemCount(); i++) + // for(int i = 0; i < 1; i++) + { + wxString matched_sample = serializer.DeserializeShowFileExtension() ? + m_ListCtrl.GetTextValue(i, 1).BeforeLast('.') : + m_ListCtrl.GetTextValue(i, 1); + + wxString selected_sample_name = serializer.DeserializeShowFileExtension() ? + m_pHives->GetItemText(event.GetItem()).BeforeLast('.') : + m_pHives->GetItemText(event.GetItem()); + + if(selected_sample_name == matched_sample) + // if(selected_sample_name == "") + { + SH_LOG_DEBUG("Found match"); + + wxDataViewItem matched_item = m_ListCtrl.RowToItem(i); + + m_ListCtrl.UnselectAll(); + m_ListCtrl.SelectRow(i); + m_ListCtrl.EnsureVisible(matched_item); + + break; + } + } + break; + default: + return; + } + } +} + +void cHivesPanel::OnHiveStartEditing(wxDataViewEvent &event) +{ + SH_LOG_INFO("Right click on a hive and select rename to rename it.."); + event.Veto(); +} + +void cHivesPanel::OnClickAddHive(wxCommandEvent& event) +{ + Database db; + + std::deque nodes; + nodes.push_back(m_pHives->GetNthChild(wxDataViewItem(wxNullPtr), 0)); + + wxDataViewItem current_item, found_item; + + int row = 0; + int hive_count = m_pHives->GetChildCount(wxDataViewItem(wxNullPtr)); + + wxString msg; + + wxTextEntryDialog hiveEntry(this, _("Enter hive name"), _("Create new hive"), wxEmptyString, + wxTextEntryDialogStyle, wxDefaultPosition); + + hiveEntry.SetTextValidator(wxFILTER_EMPTY); + + switch (hiveEntry.ShowModal()) + { + case wxID_OK: + { + wxString hive_name = hiveEntry.GetValue(); + + while(!nodes.empty()) + { + current_item = nodes.front(); + nodes.pop_front(); + + if (m_pHives->GetItemText(current_item) == hive_name) + { + found_item = current_item; + SH_LOG_DEBUG("Found item: {}", m_pHives->GetItemText(current_item)); + break; + } + + wxDataViewItem child = m_pHives->GetNthChild(wxDataViewItem(wxNullPtr), 0); + + while (row < (hive_count - 1)) + { + row ++; + + child = m_pHives->GetNthChild(wxDataViewItem(wxNullPtr), row); + nodes.push_back(child); + } + } + + nodes.clear(); + + if (found_item.IsOk()) + { + wxMessageBox(wxString::Format(_("Another hive by the name %s already exist. " + "Please try with a different name."), + hive_name), + _("Error!"), wxOK | wxCENTRE, this); + } + else + { + m_pHives->AppendContainer(wxDataViewItem(wxNullPtr), hive_name); + db.InsertIntoHives(hive_name.ToStdString()); + + msg = wxString::Format(_("%s added to cHivesPanel."), hive_name); + } + break; + } + case wxID_CANCEL: + break; + default: + return; + } + + if (!msg.IsEmpty()) + SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); + // m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); +} + +void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event) +{ + Serializer serializer; + Database db; + // cListCtrl m_ListCtrl.m_pWindow); + + wxDataViewItem selected_item = m_pHives->GetSelection(); + wxString hive_name = m_pHives->GetItemText(selected_item); + + wxString msg; + + wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to delete " + "%s from chives?"), + hive_name), + wxMessageBoxCaptionStr, + wxYES_NO | wxNO_DEFAULT | + wxICON_QUESTION | wxSTAY_ON_TOP); + + wxMessageDialog deleteFilledHiveDialog(this, wxString::Format(_("Are you sure you want to delete " + "%s and all sample inside %s from chives?"), + hive_name, hive_name), + wxMessageBoxCaptionStr, + wxYES_NO | wxNO_DEFAULT | + wxICON_QUESTION | wxSTAY_ON_TOP); + + if (hive_name == m_pHives->GetItemText(m_FavoritesHive)) + { + wxMessageBox(wxString::Format(_("Error! Default hive %s cannot be deleted."), hive_name), + _("Error!"), wxOK | wxCENTRE, this); + return; + } + else if (!selected_item.IsOk()) + { + wxMessageBox(_("No hive selected, try selecting a hive first"), _("Error!"), wxOK | wxCENTRE, this); + return; + } + else if (selected_item.IsOk() && !m_pHives->IsContainer(selected_item)) + { + wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from chives."), hive_name), + _("Error!"), wxOK | wxCENTRE, this); + return; + } + + if (m_pHives->GetChildCount(selected_item) <= 0) + { + switch (deleteEmptyHiveDialog.ShowModal()) + { + case wxID_YES: + if (selected_item.IsOk() && m_pHives->IsContainer(selected_item) && + hive_name != m_pHives->GetItemText(m_FavoritesHive)) + { + m_pHives->DeleteItem(selected_item); + + db.RemoveHiveFromDatabase(hive_name.ToStdString()); + msg = wxString::Format(_("%s deleted from chives successfully."), hive_name); + } + break; + case wxID_NO: + break; + default: + return; + } + } + else + { + switch (deleteFilledHiveDialog.ShowModal()) + { + case wxID_YES: + if (selected_item.IsOk() && m_pHives->IsContainer(selected_item) && + hive_name != m_pHives->GetItemText(m_FavoritesHive)) + { + wxDataViewItem child_item; + + for (int i = 0; i < m_ListCtrl.GetItemCount(); i++) + // for (int i = 0; i < 1; i++) + { + wxString matched_sample = serializer.DeserializeShowFileExtension() ? + m_ListCtrl.GetTextValue(i, 1).BeforeLast('.') : + m_ListCtrl.GetTextValue(i, 1); + + for (int j = 0; j < m_pHives->GetChildCount(selected_item); j++) + { + child_item = m_pHives->GetNthChild(selected_item, j); + + wxString child_name = serializer.DeserializeShowFileExtension() ? + m_pHives->GetItemText(child_item).BeforeLast('.') : + m_pHives->GetItemText(child_item); + + if (child_name == matched_sample) + // if (child_name == "") + { + SH_LOG_DEBUG("Found match"); + + m_ListCtrl.SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); + + db.UpdateFavoriteColumn(matched_sample.ToStdString(), 0); + db.UpdateHiveName(matched_sample.ToStdString(), + m_pHives->GetItemText(m_FavoritesHive).ToStdString()); + + break; + } + else + SH_LOG_DEBUG("No match found"); + } + } + + m_pHives->DeleteChildren(selected_item); + m_pHives->DeleteItem(selected_item); + + db.RemoveHiveFromDatabase(hive_name.ToStdString()); + + msg = wxString::Format(_("%s and all samples inside %s have been deleted " + "from chives successfully."), + hive_name, hive_name); + } + break; + case wxID_NO: + break; + default: + return; + } + } + + if (!msg.IsEmpty()) + SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); + // m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); +} + +cHivesPanel::~cHivesPanel() +{ + +} diff --git a/src/GUI/Hives.hpp b/src/GUI/Hives.hpp new file mode 100644 index 0000000..fbbefba --- /dev/null +++ b/src/GUI/Hives.hpp @@ -0,0 +1,56 @@ +#pragma once + +#include "GUI/ListCtrl.hpp" + +#include +#include +#include +#include +#include + +class cHivesPanel : public wxPanel +{ + public: + // ------------------------------------------------------------------- + cHivesPanel(wxWindow* window, wxDataViewListCtrl& listCtrl); + ~cHivesPanel(); + + public: + // ------------------------------------------------------------------- + wxDataViewTreeCtrl* GetHivesObject() { return m_pHives; } + wxDataViewItem GetFavoritesHive() { return m_FavoritesHive; } + + bool IsLibraryFiltered() { return m_bFiltered; } + + private: + // ------------------------------------------------------------------- + // Hives panel button event handlers + void OnDragAndDropToHives(wxDropFilesEvent& event); + void OnClickAddHive(wxCommandEvent& event); + void OnClickRemoveHive(wxCommandEvent& event); + void OnShowHivesContextMenu(wxDataViewEvent& event); + void OnHiveStartEditing(wxDataViewEvent& event); + + private: + // ------------------------------------------------------------------- + wxDataViewItem m_FavoritesHive; + + wxDataViewTreeCtrl* m_pHives = nullptr; + wxButton* m_pAddHiveButton = nullptr; + wxButton* m_pRemoveHiveButton = nullptr; + wxBoxSizer* m_pMainSizer = nullptr; + wxBoxSizer* m_pHivesSizer = nullptr; + wxBoxSizer* m_pButtonSizer = nullptr; + + private: + // ------------------------------------------------------------------- + bool m_bFiltered = false; + + // ------------------------------------------------------------------- + wxWindow* m_pWindow = nullptr; + + wxDataViewListCtrl& m_ListCtrl; + + // ------------------------------------------------------------------- + // friend class cListCtrl; +}; diff --git a/src/GUI/InfoBar.cpp b/src/GUI/InfoBar.cpp new file mode 100644 index 0000000..60a37f1 --- /dev/null +++ b/src/GUI/InfoBar.cpp @@ -0,0 +1,12 @@ +#include "InfoBar.hpp" + +cInfoBar::cInfoBar(wxWindow* window) + : wxInfoBar(window) +{ + +} + +cInfoBar::~cInfoBar() +{ + +} diff --git a/src/GUI/InfoBar.hpp b/src/GUI/InfoBar.hpp new file mode 100644 index 0000000..7069dce --- /dev/null +++ b/src/GUI/InfoBar.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +class cInfoBar : public wxInfoBar +{ + public: + cInfoBar(wxWindow* window); + ~cInfoBar(); + + public: + wxInfoBar* GetInfoBarObject() { return this; } + + private: + wxWindow* m_pWindow; +}; diff --git a/src/GUI/Library.cpp b/src/GUI/Library.cpp new file mode 100644 index 0000000..0355b33 --- /dev/null +++ b/src/GUI/Library.cpp @@ -0,0 +1,29 @@ +#include "GUI/Library.hpp" +#include "Utility/Log.hpp" + +cLibrary::cLibrary(wxWindow* window, wxDataViewItem favHive, wxDataViewTreeCtrl& hives, + wxTreeItemId trashRoot, wxTreeCtrl& trash) + : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), + m_FavoritesHive(favHive), m_pHives(hives), m_pTrash(trash), m_TrashRoot(trashRoot) +{ + m_pSizer = new wxBoxSizer(wxVERTICAL); + + m_pSearchBar = new cSearchBar(this, *m_pListCtrl); + m_pInfoBar = new cInfoBar(this); + m_pListCtrl = new cListCtrl(this, m_FavoritesHive, hives, trashRoot, trash); + + m_pSizer->Add(m_pSearchBar, wxSizerFlags(1).Expand()); + m_pSizer->Add(m_pInfoBar, wxSizerFlags(0).Expand()); + m_pSizer->Add(m_pListCtrl, wxSizerFlags(1).Expand()); + + // Sizer for bottom right panel + this->SetSizer(m_pSizer); + m_pSizer->Fit(this); + m_pSizer->SetSizeHints(this); + m_pSizer->Layout(); +} + +cLibrary::~cLibrary() +{ + +} diff --git a/src/GUI/Library.hpp b/src/GUI/Library.hpp new file mode 100644 index 0000000..c957eca --- /dev/null +++ b/src/GUI/Library.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include "GUI/InfoBar.hpp" +#include "GUI/ListCtrl.hpp" +#include "GUI/SearchBar.hpp" + +#include +#include +#include +#include +#include + +class cLibrary : public wxPanel +{ + public: + cLibrary(wxWindow* window, wxDataViewItem favHive, wxDataViewTreeCtrl& hives, + wxTreeItemId trashRoot, wxTreeCtrl& trash); + ~cLibrary(); + + public: + wxSearchCtrl* GetSearchCtrlObject() const { return m_pSearchBar; } + wxInfoBar* GetInfoBarObject() const { return m_pInfoBar; } + wxDataViewListCtrl* GetListCtrlObject() const { return m_pListCtrl; } + + // void SetHivesObject(wxDataViewTreeCtrl& hives) { m_pHives = &hives;} + // void SetFavoritesHive(wxDataViewItem favHive) { m_FavoritesHive = favHive;} + // void SetTrashObject(wxTreeCtrl& trash) { m_pTrash = &trash;} + // void SetTrashRoot(wxTreeItemId trashRoot) { m_TrashRoot = trashRoot;} + + private: + cSearchBar* m_pSearchBar = nullptr; + cInfoBar* m_pInfoBar = nullptr; + cListCtrl* m_pListCtrl = nullptr; + wxBoxSizer* m_pSizer = nullptr; + + wxDataViewItem m_FavoritesHive; + wxDataViewTreeCtrl& m_pHives; + wxTreeCtrl& m_pTrash; + wxTreeItemId m_TrashRoot; +}; diff --git a/src/GUI/ListCtrl.cpp b/src/GUI/ListCtrl.cpp new file mode 100644 index 0000000..2579320 --- /dev/null +++ b/src/GUI/ListCtrl.cpp @@ -0,0 +1,935 @@ +#include "GUI/ListCtrl.hpp" +// #include "GUI/Hives.hpp" +// #include "GUI/Trash.hpp" +#include "GUI/Dialogs/TagEditor.hpp" +#include "Database/Database.hpp" +#include "GUI/Hives.hpp" +#include "Utility/ControlIDs.hpp" +#include "Utility/SH_Event.hpp" +#include "Utility/Signal.hpp" +#include "Utility/Serialize.hpp" +#include "Utility/Log.hpp" +#include "Utility/Paths.hpp" + +#include +#include +#include "wx/log.h" +#include +#include + +// cListCtrl::cListCtrl(wxWindow* window) +cListCtrl::cListCtrl(wxWindow* window, wxDataViewItem favHive, wxDataViewTreeCtrl& hives, + wxTreeItemId trashRoot, wxTreeCtrl& trash) + : wxDataViewListCtrl(window, BC_Library, wxDefaultPosition, wxDefaultSize, + wxDV_MULTIPLE | wxDV_HORIZ_RULES | wxDV_VERT_RULES | wxDV_ROW_LINES), + // m_pWindow(window) + m_pWindow(window), m_Hives(hives), m_FavoritesHive(favHive), m_TrashRoot(trashRoot), m_Trash(trash) +{ + // Adding columns to wxDataViewListCtrl. + AppendBitmapColumn(wxBitmap(ICON_STAR_FILLED_16px), + 0, + wxDATAVIEW_CELL_ACTIVATABLE, + 30, + wxALIGN_CENTER, + !wxDATAVIEW_COL_RESIZABLE); + AppendTextColumn(_("Filename"), + wxDATAVIEW_CELL_INERT, + 250, + wxALIGN_LEFT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + AppendTextColumn(_("Sample Pack"), + wxDATAVIEW_CELL_INERT, + 180, + wxALIGN_LEFT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + AppendTextColumn(_("Type"), + wxDATAVIEW_CELL_INERT, + 120, + wxALIGN_LEFT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + AppendTextColumn(_("Channels"), + wxDATAVIEW_CELL_INERT, + 90, + wxALIGN_RIGHT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + AppendTextColumn(_("Length"), + wxDATAVIEW_CELL_INERT, + 80, + wxALIGN_RIGHT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + AppendTextColumn(_("Sample Rate"), + wxDATAVIEW_CELL_INERT, + 120, + wxALIGN_RIGHT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + AppendTextColumn(_("Bitrate"), + wxDATAVIEW_CELL_INERT, + 80, + wxALIGN_RIGHT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + AppendTextColumn(_("Path"), + wxDATAVIEW_CELL_INERT, + 250, + wxALIGN_LEFT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + + // Enable cListCtrl to accept files to be dropped on it + this->DragAcceptFiles(true); + + // Enable dragging a file from cListCtrl + this->EnableDragSource(wxDF_FILENAME); + + Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &cListCtrl::OnClickLibrary, this, BC_Library); + Bind(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, &cListCtrl::OnDragFromLibrary, this); + this->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(cListCtrl::OnDragAndDropToLibrary), NULL, this); + Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &cListCtrl::OnShowLibraryContextMenu, this, BC_Library); + Bind(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, + &cListCtrl::OnShowLibraryColumnHeaderContextMenu, this, BC_Library); + + LoadDatabase(); +} + +void cListCtrl::OnClickLibrary(wxDataViewEvent& event) +{ + // cHivesPanel hives(m_pWindow); + Database db; + + int selected_row = this->ItemToRow(event.GetItem()); + int current_row = this->ItemToRow(this->GetCurrentItem()); + + if (selected_row < 0 || !event.GetItem().IsOk()) + return; + + if (selected_row != current_row) + { + this->SetCurrentItem(event.GetItem()); + return; + } + + // Update the waveform bitmap + SampleHive::Signal::SendWaveformUpdateStatus(*this); + // m_TopWaveformPanel->ResetDC(); + + // TODO + // SampleHive::Signal::SendSetLoopABButton(*this); + // m_LoopABButton->SetValue(false); + + SampleHive::Signal::SendTimerStopStatus(*this); + // if (m_Timer->IsRunning()) + // { + // m_Timer->Stop(); + // SH_LOG_DEBUG("TIMER STOPPED"); + // } + + wxString selection = this->GetTextValue(selected_row, 1); + + // Get curremt column + wxDataViewColumn* CurrentColumn = this->GetCurrentColumn(); + + // Get favorite column + wxDataViewColumn* FavoriteColumn = this->GetColumn(0); + + if (!CurrentColumn) + return; + + wxString sample_path = GetFilenamePathAndExtension(selection).Path; + std::string filename = GetFilenamePathAndExtension(selection).Filename; + std::string extension = GetFilenamePathAndExtension(selection).Extension; + + if (CurrentColumn != FavoriteColumn) + { + SampleHive::Signal::SendCallFunctionPlay(selection, *this); + + // TODO + // ClearLoopPoints(); + + // if (bAutoplay) + // { + // if (bLoopPointsSet && m_LoopABButton->GetValue()) + // PlaySample(sample_path.ToStdString(), selection.ToStdString(), + // true, m_LoopA.ToDouble(), wxFromStart); + // else + // PlaySample(sample_path.ToStdString(), selection.ToStdString()); + // } + // else + // m_MediaCtrl->Stop(); + } + else + { + wxString msg; + + // Get hive name and location + std::string hive_name = m_Hives.GetItemText(m_FavoritesHive).ToStdString(); + wxDataViewItem hive_selection = m_Hives.GetSelection(); + + SH_LOG_DEBUG("HIVE NAME: {}", hive_name); + + if (hive_selection.IsOk() && m_Hives.IsContainer(hive_selection)) + hive_name = m_Hives.GetItemText(hive_selection).ToStdString(); + + wxString name = this->GetTextValue(selected_row, 1); + + // Get root + wxDataViewItem root = wxDataViewItem(wxNullPtr); + wxDataViewItem container; + wxDataViewItem child; + + if (db.GetFavoriteColumnValueByFilename(filename) == 0) + { + SH_LOG_DEBUG("TRUE COND...."); + + this->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0); + + db.UpdateFavoriteColumn(filename, 1); + db.UpdateHiveName(filename, hive_name); + + for (int i = 0; i < m_Hives.GetChildCount(root); i++) + { + container = m_Hives.GetNthChild(root, i); + + if (m_Hives.GetItemText(container).ToStdString() == hive_name) + { + m_Hives.AppendItem(container, name); + break; + } + } + + msg = wxString::Format(_("Added %s to %s"), name, hive_name); + } + else + { + this->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0); + + db.UpdateFavoriteColumn(filename, 0); + db.UpdateHiveName(filename, m_Hives.GetItemText(m_FavoritesHive).ToStdString()); + + for (int i = 0; i < m_Hives.GetChildCount(root); i++) + { + container = m_Hives.GetNthChild(root, i); + + for (int j = 0; j < m_Hives.GetChildCount(container); j++) + { + child = m_Hives.GetNthChild(container, j); + + if (m_Hives.GetItemText(child) == name) + { + m_Hives.DeleteItem(child); + break; + } + } + } + + msg = wxString::Format(_("Removed %s from %s"), name, hive_name); + } + + if (!msg.IsEmpty()) + SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); + // m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); + } +} + +void cListCtrl::OnDragAndDropToLibrary(wxDropFilesEvent& event) +{ + SH_LOG_DEBUG("Start Inserting Samples"); + + if (event.GetNumberOfFiles() > 0) + { + wxString* dropped = event.GetFiles(); + wxASSERT(dropped); + + wxBusyCursor busy_cursor; + wxWindowDisabler window_disabler; + + wxString name; + wxString filepath; + wxArrayString filepath_array; + + wxProgressDialog* progressDialog = new wxProgressDialog(_("Reading files.."), + _("Reading files, please wait..."), + event.GetNumberOfFiles(), this, + wxPD_APP_MODAL | wxPD_SMOOTH | + wxPD_CAN_ABORT | wxPD_AUTO_HIDE); + + progressDialog->CenterOnParent(wxBOTH); + + wxYield(); + + for (int i = 0; i < event.GetNumberOfFiles(); i++) + { + filepath = dropped[i]; + + if (wxFileExists(filepath)) + { + filepath_array.push_back(filepath); + } + else if (wxDirExists(filepath)) + { + wxDir::GetAllFiles(filepath, &filepath_array); + } + + progressDialog->Pulse(_("Reading Samples"), NULL); + } + + progressDialog->Destroy(); + + AddSamples(filepath_array); + + SH_LOG_DEBUG("Done Inserting Samples"); + } +} + +void cListCtrl::OnDragFromLibrary(wxDataViewEvent& event) +{ + int selected_row = this->ItemToRow(event.GetItem()); + + if (selected_row < 0) + return; + + wxString selection = this->GetTextValue(selected_row, 1); + + wxString sample_path = GetFilenamePathAndExtension(selection).Path; + + wxFileDataObject* fileData = new wxFileDataObject(); + + fileData->AddFile(sample_path); + event.SetDataObject(fileData); + + SH_LOG_DEBUG("Started dragging '{}'.", sample_path); +} + +void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event) +{ + TagEditor* tagEditor; + Serializer serializer; + Database db; + // cHivesPanel hives(m_pWindow); + + wxString msg; + + wxDataViewItem item = event.GetItem(); + int selected_row; + + if (item.IsOk()) + selected_row = this->ItemToRow(item); + else + return; + + wxString selection = this->GetTextValue(selected_row, 1); + + wxString sample_path = GetFilenamePathAndExtension(selection).Path; + std::string filename = GetFilenamePathAndExtension(selection).Filename; + std::string extension = GetFilenamePathAndExtension(selection).Extension; + + wxMenu menu; + + //true = add false = remove + bool favorite_add = false; + + if (db.GetFavoriteColumnValueByFilename(filename) == 1) + menu.Append(MN_FavoriteSample, _("Remove from hive"), _("Remove the selected sample(s) from hive")); + else + { + menu.Append(MN_FavoriteSample, _("Add to hive"), _("Add selected sample(s) to hive")); + favorite_add = true; + } + + menu.Append(MN_DeleteSample, _("Delete"), _("Delete the selected sample(s) from database")); + menu.Append(MN_TrashSample, _("Trash"), _("Send the selected sample(s) to trash")); + + if (this->GetSelectedItemsCount() <= 1) + { + menu.Append(MN_EditTagSample, _("Edit tags"), + _("Edit the tags for the selected sample"))->Enable(true); + menu.Append(MN_OpenFile, _("Open in file manager"), + _("Open the selected sample in system's file manager"))->Enable(true); + } + else + { + menu.Append(MN_EditTagSample, _("Edit tags"), + _("Edit the tags for the selected sample"))->Enable(false); + menu.Append(MN_OpenFile, _("Open in file manager"), + _("Open the selected sample in system's file manager"))->Enable(false); + } + + switch (this->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) + { + case MN_FavoriteSample: + { + std::string hive_name = m_Hives.GetItemText(m_FavoritesHive).ToStdString(); + + wxDataViewItem hive_selection = m_Hives.GetSelection(); + + if (hive_selection.IsOk() && m_Hives.IsContainer(hive_selection)) + hive_name = m_Hives.GetItemText(hive_selection).ToStdString(); + + wxDataViewItem root = wxDataViewItem(wxNullPtr); + wxDataViewItem container; + wxDataViewItem child; + + wxDataViewItemArray samples; + int sample_count = this->GetSelections(samples); + int selected_row = 0; + int db_status = 0; + + for (int k = 0; k < sample_count; k++) + { + selected_row = this->ItemToRow(samples[k]); + + if (selected_row < 0) + continue; + + wxString name = this->GetTextValue(selected_row, 1); + + filename = serializer.DeserializeShowFileExtension() ? + name.BeforeLast('.').ToStdString() : name.ToStdString(); + + db_status = db.GetFavoriteColumnValueByFilename(filename); + + // Aleady Added, Do Nothing + if (favorite_add && db_status == 1) + continue; + + // Already Removed, Do Nothing + if (!favorite_add && db_status == 0) + continue; + + // Add To Favorites + if (favorite_add && db_status == 0) + { + this->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0); + + db.UpdateFavoriteColumn(filename, 1); + db.UpdateHiveName(filename, hive_name); + + for (int i = 0; i < m_Hives.GetChildCount(root); i++) + { + container = m_Hives.GetNthChild(root, i); + + if (m_Hives.GetItemText(container).ToStdString() == hive_name) + { + m_Hives.AppendItem(container, name); + + msg = wxString::Format(_("Added %s to %s"), name, hive_name); + break; + } + } + } + else + { + //Remove From Favorites + this->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0); + + db.UpdateFavoriteColumn(filename, 0); + db.UpdateHiveName(filename, + m_Hives.GetItemText(m_FavoritesHive).ToStdString()); + + for (int i = 0; i < m_Hives.GetChildCount(root); i++) + { + container = m_Hives.GetNthChild(root, i); + + for (int j = 0; j < m_Hives.GetChildCount(container); j++) + { + child = m_Hives.GetNthChild(container, j); + + if (m_Hives.GetItemText(child) == name) + { + m_Hives.DeleteItem(child); + + msg = wxString::Format(_("Removed %s from %s"), name, hive_name); + break; + } + } + } + } + } + break; + } + case MN_DeleteSample: + { + wxDataViewItemArray items; + int rows = this->GetSelections(items); + + wxMessageDialog singleMsgDialog(this, wxString::Format(_("Are you sure you want to delete " + "%s from database? " + "Warning this change is " + "permanent, and cannot be undone."), + sample_path.AfterLast('/')), + wxMessageBoxCaptionStr, + wxYES_NO | wxNO_DEFAULT | + wxICON_QUESTION | wxSTAY_ON_TOP | + wxCENTER); + + wxMessageDialog multipleMsgDialog(this, wxString::Format(_("Are you sure you want to delete " + "%d selected samples from database? " + "Warning this change is " + "permanent, and cannot be " + "undone."), rows), + wxMessageBoxCaptionStr, + wxYES_NO | wxNO_DEFAULT | + wxICON_QUESTION | wxSTAY_ON_TOP | + wxCENTER); + + wxDataViewItem root = wxDataViewItem(wxNullPtr); + wxDataViewItem container; + wxDataViewItem child; + + if (this->GetSelectedItemsCount() <= 1) + { + switch (singleMsgDialog.ShowModal()) + { + case wxID_YES: + { + db.RemoveSampleFromDatabase(filename); + this->DeleteItem(selected_row); + + for (int j = 0; j < m_Hives.GetChildCount(root); j++) + { + container = m_Hives.GetNthChild(root, j); + + for (int k = 0; k < m_Hives.GetChildCount(container); k++) + { + child = m_Hives.GetNthChild(container, k); + + wxString child_text = serializer.DeserializeShowFileExtension() ? + m_Hives.GetItemText(child).BeforeLast('.') : + m_Hives.GetItemText(child); + + if (child_text == filename) + { + m_Hives.DeleteItem(child); + + break; + } + } + } + + msg = wxString::Format(_("Deleted %s from database successfully"), selection); + } + break; + case wxID_NO: + msg = _("Cancel delete"); + break; + default: + wxMessageBox(_("Unexpected wxMessageDialog return code!"), _("Error!"), + wxOK | wxICON_ERROR | wxCENTRE, this); + } + } + else + { + switch (multipleMsgDialog.ShowModal()) + { + case wxID_YES: + { + for (int i = 0; i < rows; i++) + { + int row = this->ItemToRow(items[i]); + + wxString text_value = this->GetTextValue(row, 1); + + std::string multi_selection = serializer.DeserializeShowFileExtension() ? + text_value.BeforeLast('.').ToStdString() : text_value.ToStdString() ; + + db.RemoveSampleFromDatabase(multi_selection); + this->DeleteItem(row); + + for (int j = 0; j < m_Hives.GetChildCount(root); j++) + { + container = m_Hives.GetNthChild(root, j); + + for (int k = 0; k < m_Hives.GetChildCount(container); k++) + { + child = m_Hives.GetNthChild(container, k); + + wxString child_text = serializer.DeserializeShowFileExtension() ? + m_Hives.GetItemText(child).BeforeLast('.') : + m_Hives.GetItemText(child); + + if (child_text == multi_selection) + { + m_Hives.DeleteItem(child); + break; + } + } + } + + msg = wxString::Format(_("Deleted %s from database successfully"), text_value); + } + } + break; + case wxID_NO: + msg = _("Cancel delete"); + break; + default: + wxMessageBox(_("Unexpected wxMessageDialog return code!"), _("Error!"), + wxOK | wxICON_ERROR | wxCENTRE, this); + } + } + } + break; + case MN_TrashSample: + { + wxDataViewItem root = wxDataViewItem(wxNullPtr); + wxDataViewItem container, child; + + if (db.IsTrashed(filename)) + SH_LOG_INFO("{} already trashed", filename); + else + { + wxDataViewItemArray items; + int rows = this->GetSelections(items); + + wxString name; + wxFileDataObject file_data; + wxArrayString files; + + for (int i = 0; i < rows; i++) + { + int item_row = this->ItemToRow(items[i]); + + wxString text_value = this->GetTextValue(item_row, 1); + + std::string multi_selection = serializer.DeserializeShowFileExtension() ? + this->GetTextValue(item_row, 1).BeforeLast('.').ToStdString() : + this->GetTextValue(item_row, 1).ToStdString() ; + + file_data.AddFile(multi_selection); + + files = file_data.GetFilenames(); + + if (db.GetFavoriteColumnValueByFilename(files[i].ToStdString())) + { + this->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0); + + db.UpdateFavoriteColumn(files[i].ToStdString(), 0); + + for (int j = 0; j < m_Hives.GetChildCount(root); j++) + { + container = m_Hives.GetNthChild(root, j); + + for (int k = 0; k < m_Hives.GetChildCount(container); k++) + { + child = m_Hives.GetNthChild(container, k); + + wxString child_text = serializer.DeserializeShowFileExtension() ? + m_Hives.GetItemText(child).BeforeLast('.') : + m_Hives.GetItemText(child); + + if (child_text == files[i]) + { + m_Hives.DeleteItem(child); + break; + } + } + } + } + + m_Trash.AppendItem(m_TrashRoot, text_value); + + this->DeleteItem(item_row); + + db.UpdateTrashColumn(files[i].ToStdString(), 1); + db.UpdateHiveName(files[i].ToStdString(), + m_Hives.GetItemText(m_FavoritesHive).ToStdString()); + + msg = wxString::Format(_("%s sent to trash"), text_value); + } + } + } + break; + case MN_EditTagSample: + { + tagEditor = new TagEditor(this, static_cast(sample_path)); + + switch (tagEditor->ShowModal()) + { + case wxID_OK: + SH_LOG_DEBUG("tags dialog ok, Return code: {}", tagEditor->GetReturnCode()); + break; + case wxID_APPLY: + SH_LOG_DEBUG("tags dialog apply, Return code: {}", tagEditor->GetReturnCode()); + break; + case wxID_CANCEL: + SH_LOG_DEBUG("tags dialog cancel, Return code: {}", tagEditor->GetReturnCode()); + break; + default: + msg = _("Unexpected TagEditor return code!"); + } + } + break; + case MN_OpenFile: + wxExecute(wxString::Format("xdg-open '%s'", sample_path.BeforeLast('/'))); + break; + case wxID_NONE: + return; + default: + wxMessageBox(_("Unexpected wxMenu return code!"), _("Error!"), + wxOK | wxICON_ERROR | wxCENTRE, this); + break; + } + + if (!msg.IsEmpty()) + SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); + // m_InfoBar->ShowMessage(msg); +} + +void cListCtrl::OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event) +{ + wxMenu menu; + + wxDataViewColumn* FavoriteColumn = this->GetColumn(0); + wxDataViewColumn* FilenameColumn = this->GetColumn(1); + wxDataViewColumn* SamplePackColumn = this->GetColumn(2); + wxDataViewColumn* TypeColumn = this->GetColumn(3); + wxDataViewColumn* ChannelsColumn = this->GetColumn(4); + wxDataViewColumn* LengthColumn = this->GetColumn(5); + wxDataViewColumn* SampleRateColumn = this->GetColumn(6); + wxDataViewColumn* BitrateColumn = this->GetColumn(7); + wxDataViewColumn* PathColumn = this->GetColumn(8); + + menu.AppendCheckItem(MN_ColumnFavorite, _("Favorites"), + _("Toggle favorites column"))->Check(FavoriteColumn->IsShown()); + menu.AppendCheckItem(MN_ColumnFilename, _("Filename"), + _("Toggle filename column"))->Check(FilenameColumn->IsShown()); + menu.AppendCheckItem(MN_ColumnSamplePack, _("Sample Pack"), + _("Toggle sample pack column"))->Check(SamplePackColumn->IsShown()); + menu.AppendCheckItem(MN_ColumnType, _("Type"), + _("Toggle type column"))->Check(TypeColumn->IsShown()); + menu.AppendCheckItem(MN_ColumnChannels, _("Channels"), + _("Toggle channels column"))->Check(ChannelsColumn->IsShown()); + menu.AppendCheckItem(MN_ColumnLength, _("Length"), + _("Toggle length column"))->Check(LengthColumn->IsShown()); + menu.AppendCheckItem(MN_ColumnSampleRate, _("Sample Rate"), + _("Toggle sample rate column"))->Check(SampleRateColumn->IsShown()); + menu.AppendCheckItem(MN_ColumnBitrate, _("Bitrate"), + _("Toggle bitrate column"))->Check(BitrateColumn->IsShown()); + menu.AppendCheckItem(MN_ColumnPath, _("Path"), + _("Toggle path column"))->Check(PathColumn->IsShown()); + + switch (this->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) + { + case MN_ColumnFavorite: + FavoriteColumn->SetHidden(!menu.IsChecked(MN_ColumnFavorite)); + break; + case MN_ColumnFilename: + FilenameColumn->SetHidden(!menu.IsChecked(MN_ColumnFilename)); + break; + case MN_ColumnSamplePack: + SamplePackColumn->SetHidden(!menu.IsChecked(MN_ColumnSamplePack)); + break; + case MN_ColumnType: + TypeColumn->SetHidden(!menu.IsChecked(MN_ColumnType)); + break; + case MN_ColumnChannels: + ChannelsColumn->SetHidden(!menu.IsChecked(MN_ColumnChannels)); + break; + case MN_ColumnLength: + LengthColumn->SetHidden(!menu.IsChecked(MN_ColumnLength)); + break; + case MN_ColumnSampleRate: + SampleRateColumn->SetHidden(!menu.IsChecked(MN_ColumnSampleRate)); + break; + case MN_ColumnBitrate: + BitrateColumn->SetHidden(!menu.IsChecked(MN_ColumnBitrate)); + break; + case MN_ColumnPath: + PathColumn->SetHidden(!menu.IsChecked(MN_ColumnPath)); + break; + default: + break; + } +} + +void cListCtrl::AddSamples(wxArrayString& files) +{ + Serializer serializer; + Database db; + + wxBusyCursor busy_cursor; + wxWindowDisabler window_disabler; + + wxProgressDialog* progressDialog = new wxProgressDialog(_("Adding files.."), + _("Adding files, please wait..."), + static_cast(files.size()), this, + wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_CAN_ABORT | + wxPD_AUTO_HIDE); + progressDialog->CenterOnParent(wxBOTH); + + std::vector sample_array; + + std::string path; + std::string artist; + std::string filename_with_extension; + std::string filename_without_extension; + std::string extension; + std::string filename; + + //Check All Files At Once + wxArrayString sorted_files; + + sorted_files = db.CheckDuplicates(files); + files = sorted_files; + + if(files.size() < 1) + { + progressDialog->Destroy(); + return; + } + + progressDialog->SetRange(files.size()); + + for(unsigned int i = 0; i < files.size(); i++) + { + progressDialog->Update(i, wxString::Format(_("Getting Data For %s"), files[i].AfterLast('/'))); + + if(progressDialog->WasCancelled()) + { + progressDialog->Destroy(); + return; + } + + path = files[i].ToStdString(); + filename_with_extension = files[i].AfterLast('/').ToStdString(); + filename_without_extension = files[i].AfterLast('/').BeforeLast('.').ToStdString(); + extension = files[i].AfterLast('.').ToStdString(); + + filename = serializer.DeserializeShowFileExtension() ? + filename_with_extension : filename_without_extension; + + Sample sample; + + sample.SetPath(path); + sample.SetFilename(filename_without_extension); + sample.SetFileExtension(extension); + + Tags tags(path); + + artist = tags.GetAudioInfo().artist.ToStdString(); + + sample.SetSamplePack(artist); + sample.SetChannels(tags.GetAudioInfo().channels); + sample.SetLength(tags.GetAudioInfo().length); + sample.SetSampleRate(tags.GetAudioInfo().sample_rate); + sample.SetBitrate(tags.GetAudioInfo().bitrate); + + wxLongLong llLength = sample.GetLength(); + int total_min = static_cast((llLength / 60000).GetValue()); + int total_sec = static_cast(((llLength % 60000) / 1000).GetValue()); + + wxVector data; + + wxVariant icon = wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)); + + if (tags.IsFileValid()) + { + data.clear(); + data.push_back(icon); + data.push_back(filename); + data.push_back(sample.GetSamplePack()); + data.push_back(""); + data.push_back(wxString::Format("%d", sample.GetChannels())); + data.push_back(wxString::Format("%2i:%02i", total_min, total_sec)); + data.push_back(wxString::Format("%d", sample.GetSampleRate())); + data.push_back(wxString::Format("%d", sample.GetBitrate())); + data.push_back(path); + + SH_LOG_INFO("Adding file: {}, Extension: {}", sample.GetFilename(), sample.GetFileExtension()); + + this->AppendItem(data); + + sample_array.push_back(sample); + } + else + { + wxString msg = wxString::Format(_("Error! Cannot open %s, Invalid file type."), + filename_with_extension); + + SampleHive::Signal::SendInfoBarMessage(msg, wxICON_ERROR, *this); + // m_InfoBar->ShowMessage(msg, wxICON_ERROR); + } + } + + progressDialog->Pulse(_("Updating Database.."), NULL); + + db.InsertIntoSamples(sample_array); + + progressDialog->Destroy(); +} + +cListCtrl::FileInfo cListCtrl::GetFilenamePathAndExtension(const wxString& selected, + bool checkExtension, bool doGetFilename) const +{ + Serializer serializer; + Database db; + + wxString path; + std::string extension, filename; + + wxString filename_with_extension = db.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString()); + wxString filename_without_extension = db.GetSamplePathByFilename(selected.ToStdString()); + + if (checkExtension) + { + extension = serializer.DeserializeShowFileExtension() ? + db.GetSampleFileExtension(selected.ToStdString()) : + db.GetSampleFileExtension(selected.BeforeLast('.').ToStdString()); + } + + path = selected.Contains(wxString::Format(".%s", extension)) ? + filename_with_extension : filename_without_extension; + + if (doGetFilename) + filename = path.AfterLast('/').BeforeLast('.').ToStdString(); + + return { path, extension, filename }; +} + +void cListCtrl::LoadDatabase() +{ + Serializer serializer; + Database db; + // cHivesPanel hives(m_pWindow); + // cTrashPanel trash(m_pWindow); + + try + { + const auto dataset = db.LoadSamplesDatabase(m_Hives, m_FavoritesHive, + m_Trash, m_TrashRoot, + serializer.DeserializeShowFileExtension(), + ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); + + if (dataset.empty()) + SH_LOG_INFO("Error! Database is empty."); + else + { + for (auto data : dataset) + this->AppendItem(data); + } + + db.LoadHivesDatabase(m_Hives); + } + catch(...) + { + std::cerr << "Error loading data." << std::endl; + } +} + +cListCtrl::~cListCtrl() +{ + +} diff --git a/src/GUI/ListCtrl.hpp b/src/GUI/ListCtrl.hpp new file mode 100644 index 0000000..76adee5 --- /dev/null +++ b/src/GUI/ListCtrl.hpp @@ -0,0 +1,60 @@ +#pragma once + +#include +#include +#include + +class cListCtrl : public wxDataViewListCtrl +{ + + struct FileInfo + { + wxString Path; + std::string Extension; + std::string Filename; + }; + + public: + // ------------------------------------------------------------------- + // cListCtrl(wxWindow* window); + cListCtrl(wxWindow* window, wxDataViewItem favHive, wxDataViewTreeCtrl& hives, + wxTreeItemId trashRoot, wxTreeCtrl& trash); + ~cListCtrl(); + + public: + // ------------------------------------------------------------------- + wxDataViewListCtrl* GetListCtrlObject() { return this; } + + private: + // ------------------------------------------------------------------- + // Library event handlers + void OnClickLibrary(wxDataViewEvent& event); + void OnDragAndDropToLibrary(wxDropFilesEvent& event); + void OnDragFromLibrary(wxDataViewEvent& event); + void OnShowLibraryContextMenu(wxDataViewEvent& event); + void OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event); + + // ------------------------------------------------------------------- + void AddSamples(wxArrayString& files); + + // ------------------------------------------------------------------- + cListCtrl::FileInfo GetFilenamePathAndExtension(const wxString& selected, + bool checkExtension = true, + bool doGetFilename = true) const; + + // ------------------------------------------------------------------- + void LoadDatabase(); + + private: + // ------------------------------------------------------------------- + wxWindow* m_pWindow = nullptr; + + wxDataViewTreeCtrl& m_Hives; + wxDataViewItem m_FavoritesHive; + wxTreeItemId m_TrashRoot; + wxTreeCtrl& m_Trash; + + // ------------------------------------------------------------------- + // friend class cHives; + // friend class cTrash; +}; diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index d83d532..fe9b728 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -24,6 +24,7 @@ #include "Database/Database.hpp" #include "Utility/ControlIDs.hpp" #include "Utility/Paths.hpp" +#include "Utility/SH_Event.hpp" #include "Utility/Tags.hpp" #include "Utility/Sample.hpp" #include "Utility/Log.hpp" @@ -36,8 +37,6 @@ #include #include -#include - #include #include #include @@ -131,30 +130,35 @@ MainFrame::MainFrame() // Set the menu bar to use SetMenuBar(m_MenuBar); + // Load default yaml config file. + LoadConfigFile(); + + InitDatabase(); + // Initializing Sizers m_MainSizer = new wxBoxSizer(wxVERTICAL); - m_TopSizer = new wxBoxSizer(wxVERTICAL); + // m_TopSizer = new wxBoxSizer(wxVERTICAL); - m_BottomLeftPanelMainSizer = new wxBoxSizer(wxVERTICAL); + // m_BottomLeftPanelMainSizer = new wxBoxSizer(wxVERTICAL); m_TopPanelMainSizer = new wxBoxSizer(wxVERTICAL); - m_BottomRightPanelMainSizer = new wxBoxSizer(wxVERTICAL); + // m_BottomRightPanelMainSizer = new wxBoxSizer(wxVERTICAL); - m_WaveformDisplaySizer = new wxBoxSizer(wxHORIZONTAL); + // m_WaveformDisplaySizer = new wxBoxSizer(wxHORIZONTAL); - m_HivesMainSizer = new wxBoxSizer(wxVERTICAL); - m_HivesFavoritesSizer = new wxBoxSizer(wxVERTICAL); - m_HivesButtonSizer = new wxBoxSizer(wxHORIZONTAL); + // m_HivesMainSizer = new wxBoxSizer(wxVERTICAL); + // m_HivesFavoritesSizer = new wxBoxSizer(wxVERTICAL); + // m_HivesButtonSizer = new wxBoxSizer(wxHORIZONTAL); - m_TrashMainSizer = new wxBoxSizer(wxVERTICAL); - m_TrashItemSizer = new wxBoxSizer(wxVERTICAL); - m_TrashButtonSizer = new wxBoxSizer(wxHORIZONTAL); + // m_TrashMainSizer = new wxBoxSizer(wxVERTICAL); + // m_TrashItemSizer = new wxBoxSizer(wxVERTICAL); + // m_TrashButtonSizer = new wxBoxSizer(wxHORIZONTAL); // Main panel of the app - m_MainPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + // m_MainPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); // Creating top splitter window - m_TopSplitter = new wxSplitterWindow(m_MainPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, + m_TopSplitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_NOBORDER | wxSP_LIVE_UPDATE | wxSP_THIN_SASH); m_TopSplitter->SetMinimumPaneSize(200); m_TopSplitter->SetSashGravity(0); @@ -169,154 +173,166 @@ MainFrame::MainFrame() m_BottomSplitter->SetSashGravity(0); // Left half of the BottomSplitter window - m_BottomLeftPanel = new wxPanel(m_BottomSplitter, wxID_ANY, - wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + // m_BottomLeftPanel = new wxPanel(m_BottomSplitter, wxID_ANY, + // wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + + // m_Notebook = new cNotebook(m_BottomSplitter, *m_Library->GetListCtrlObject()); // Initializing wxNotebook - m_Notebook = new wxNotebook(m_BottomLeftPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP); + // m_Notebook = new wxNotebook(m_BottomLeftPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP); // Initializing wxGenericDirCtrl as one of the wxNotebook page. - m_DirCtrl = new wxGenericDirCtrl(m_Notebook, BC_DirCtrl, wxDirDialogDefaultFolderStr, wxDefaultPosition, - wxDefaultSize, wxDIRCTRL_SHOW_FILTERS, - _("All files|*|Ogg files (*.ogg)|*.ogg|Wav files (*.wav)|*.wav|" - "Flac files (*.flac)|*.flac"), 0); + // m_DirCtrl = new wxGenericDirCtrl(m_Notebook, BC_DirCtrl, wxDirDialogDefaultFolderStr, wxDefaultPosition, + // wxDefaultSize, wxDIRCTRL_SHOW_FILTERS, + // _("All files|*|Ogg files (*.ogg)|*.ogg|Wav files (*.wav)|*.wav|" + // "Flac files (*.flac)|*.flac"), 0); - m_DirCtrl->SetPath(USER_HOME_DIR); + // m_DirCtrl->SetPath(USER_HOME_DIR); - // This panel will hold 2nd page of wxNotebook - m_HivesPanel = new wxPanel(m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + // // This panel will hold 2nd page of wxNotebook + // m_HivesPanel = new wxPanel(m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); - m_AddHiveButton = new wxButton(m_HivesPanel, BC_HiveAdd, "+", wxDefaultPosition, wxDefaultSize, 0); - m_AddHiveButton->SetToolTip(_("Create new hive")); - m_RemoveHiveButton = new wxButton(m_HivesPanel, BC_HiveRemove, "-", wxDefaultPosition, wxDefaultSize, 0); - m_RemoveHiveButton->SetToolTip(_("Delete selected hive")); + // m_AddHiveButton = new wxButton(m_HivesPanel, BC_HiveAdd, "+", wxDefaultPosition, wxDefaultSize, 0); + // m_AddHiveButton->SetToolTip(_("Create new hive")); + // m_RemoveHiveButton = new wxButton(m_HivesPanel, BC_HiveRemove, "-", wxDefaultPosition, wxDefaultSize, 0); + // m_RemoveHiveButton->SetToolTip(_("Delete selected hive")); - // Initializing wxTreeCtrl as another page of wxNotebook - m_Hives = new wxDataViewTreeCtrl(m_HivesPanel, BC_Hives, wxDefaultPosition, wxDefaultSize, - wxDV_NO_HEADER | wxDV_SINGLE); + // // Initializing wxTreeCtrl as another page of wxNotebook + // m_Hives = new wxDataViewTreeCtrl(m_HivesPanel, BC_Hives, wxDefaultPosition, wxDefaultSize, + // wxDV_NO_HEADER | wxDV_SINGLE); - // Adding default hive - favorites_hive = m_Hives->AppendContainer(wxDataViewItem(wxNullPtr), _("Favorites")); + // // Adding default hive + // favorites_hive = m_Hives->AppendContainer(wxDataViewItem(wxNullPtr), _("Favorites")); - // Setting m_Hives to accept files to be dragged and dropped on it - m_Hives->DragAcceptFiles(true); + // // Setting m_Hives to accept files to be dragged and dropped on it + // m_Hives->DragAcceptFiles(true); - m_TrashPanel = new wxPanel(m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + // m_TrashPanel = new wxPanel(m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); - m_Trash = new wxTreeCtrl(m_TrashPanel, BC_Trash, wxDefaultPosition, wxDefaultSize, - wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_MULTIPLE); + // m_Trash = new wxTreeCtrl(m_TrashPanel, BC_Trash, wxDefaultPosition, wxDefaultSize, + // wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_MULTIPLE); - // Setting m_Trash to accept files to be dragged and dropped on it - m_Trash->DragAcceptFiles(true); + // // Setting m_Trash to accept files to be dragged and dropped on it + // m_Trash->DragAcceptFiles(true); - m_RestoreTrashedItemButton = new wxButton(m_TrashPanel, BC_RestoreTrashedItem, _("Restore sample"), - wxDefaultPosition, wxDefaultSize, 0); - m_RestoreTrashedItemButton->SetToolTip(_("Restore selected sample")); + // m_RestoreTrashedItemButton = new wxButton(m_TrashPanel, BC_RestoreTrashedItem, _("Restore sample"), + // wxDefaultPosition, wxDefaultSize, 0); + // m_RestoreTrashedItemButton->SetToolTip(_("Restore selected sample")); - // Addubg root to TrashedItems - trash_root = m_Trash->AddRoot("Trash"); + // // Addubg root to TrashedItems + // trash_root = m_Trash->AddRoot("Trash"); - // Adding the pages to wxNotebook - m_Notebook->AddPage(m_DirCtrl, _("Browse"), false); - m_Notebook->AddPage(m_HivesPanel, _("Hives"), false); - m_Notebook->AddPage(m_TrashPanel, _("Trash"), false); + // // Adding the pages to wxNotebook + // m_Notebook->AddPage(m_DirCtrl, _("Browse"), false); + // m_Notebook->AddPage(m_HivesPanel, _("Hives"), false); + // m_Notebook->AddPage(m_TrashPanel, _("Trash"), false); // Right half of BottomSlitter window - m_BottomRightPanel = new wxPanel(m_BottomSplitter, wxID_ANY, - wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + // m_BottomRightPanel = new wxPanel(m_BottomSplitter, wxID_ANY, + // wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + + m_Notebook = new cNotebook(m_BottomSplitter); + + m_Library = new cLibrary(m_BottomSplitter, + m_Notebook->GetHivesPanel()->GetFavoritesHive(), + *m_Notebook->GetHivesPanel()->GetHivesObject(), + m_Notebook->GetTrashPanel()->GetTrashRoot(), + *m_Notebook->GetTrashPanel()->GetTrashObject()); + + m_Notebook->SetListCtrlObject(*m_Library->GetListCtrlObject()); // Set split direction m_TopSplitter->SplitHorizontally(m_TopPanel, m_BottomSplitter); - m_BottomSplitter->SplitVertically(m_BottomLeftPanel, m_BottomRightPanel); + m_BottomSplitter->SplitVertically(m_Notebook, m_Library); // Initializing wxSearchCtrl on bottom panel. - m_SearchBox = new wxSearchCtrl(m_BottomRightPanel, BC_Search, _("Search for samples.."), - wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); + // m_SearchBox = new wxSearchCtrl(m_BottomRightPanel, BC_Search, _("Search for samples.."), + // wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); - // Set minimum and maximum size of m_SearchBox - // so it doesn't expand too wide when resizing the main frame. - m_SearchBox->SetMinSize(wxSize(-1, 38)); - m_SearchBox->SetMaxSize(wxSize(-1, 38)); + // // Set minimum and maximum size of m_SearchBox + // // so it doesn't expand too wide when resizing the main frame. + // m_SearchBox->SetMinSize(wxSize(-1, 38)); + // m_SearchBox->SetMaxSize(wxSize(-1, 38)); - m_SearchBox->ShowSearchButton(true); - m_SearchBox->ShowCancelButton(true); + // m_SearchBox->ShowSearchButton(true); + // m_SearchBox->ShowCancelButton(true); - // Initializing wxDataViewListCtrl on bottom panel. - m_Library = new wxDataViewListCtrl(m_BottomRightPanel, BC_Library, wxDefaultPosition, wxDefaultSize, - wxDV_MULTIPLE | wxDV_HORIZ_RULES | wxDV_VERT_RULES | wxDV_ROW_LINES); + // // Initializing wxDataViewListCtrl on bottom panel. + // m_Library = new wxDataViewListCtrl(m_BottomRightPanel, BC_Library, wxDefaultPosition, wxDefaultSize, + // wxDV_MULTIPLE | wxDV_HORIZ_RULES | wxDV_VERT_RULES | wxDV_ROW_LINES); - // Adding columns to wxDataViewListCtrl. - m_Library->AppendBitmapColumn(wxBitmap(ICON_STAR_FILLED_16px), - 0, - wxDATAVIEW_CELL_ACTIVATABLE, - 30, - wxALIGN_CENTER, - !wxDATAVIEW_COL_RESIZABLE); - m_Library->AppendTextColumn(_("Filename"), - wxDATAVIEW_CELL_INERT, - 250, - wxALIGN_LEFT, - wxDATAVIEW_COL_RESIZABLE | - wxDATAVIEW_COL_SORTABLE | - wxDATAVIEW_COL_REORDERABLE); - m_Library->AppendTextColumn(_("Sample Pack"), - wxDATAVIEW_CELL_INERT, - 180, - wxALIGN_LEFT, - wxDATAVIEW_COL_RESIZABLE | - wxDATAVIEW_COL_SORTABLE | - wxDATAVIEW_COL_REORDERABLE); - m_Library->AppendTextColumn(_("Type"), - wxDATAVIEW_CELL_INERT, - 120, - wxALIGN_LEFT, - wxDATAVIEW_COL_RESIZABLE | - wxDATAVIEW_COL_SORTABLE | - wxDATAVIEW_COL_REORDERABLE); - m_Library->AppendTextColumn(_("Channels"), - wxDATAVIEW_CELL_INERT, - 90, - wxALIGN_RIGHT, - wxDATAVIEW_COL_RESIZABLE | - wxDATAVIEW_COL_SORTABLE | - wxDATAVIEW_COL_REORDERABLE); - m_Library->AppendTextColumn(_("Length"), - wxDATAVIEW_CELL_INERT, - 80, - wxALIGN_RIGHT, - wxDATAVIEW_COL_RESIZABLE | - wxDATAVIEW_COL_SORTABLE | - wxDATAVIEW_COL_REORDERABLE); - m_Library->AppendTextColumn(_("Sample Rate"), - wxDATAVIEW_CELL_INERT, - 120, - wxALIGN_RIGHT, - wxDATAVIEW_COL_RESIZABLE | - wxDATAVIEW_COL_SORTABLE | - wxDATAVIEW_COL_REORDERABLE); - m_Library->AppendTextColumn(_("Bitrate"), - wxDATAVIEW_CELL_INERT, - 80, - wxALIGN_RIGHT, - wxDATAVIEW_COL_RESIZABLE | - wxDATAVIEW_COL_SORTABLE | - wxDATAVIEW_COL_REORDERABLE); - m_Library->AppendTextColumn(_("Path"), - wxDATAVIEW_CELL_INERT, - 250, - wxALIGN_LEFT, - wxDATAVIEW_COL_RESIZABLE | - wxDATAVIEW_COL_SORTABLE | - wxDATAVIEW_COL_REORDERABLE); + // // Adding columns to wxDataViewListCtrl. + // m_Library->AppendBitmapColumn(wxBitmap(ICON_STAR_FILLED_16px), + // 0, + // wxDATAVIEW_CELL_ACTIVATABLE, + // 30, + // wxALIGN_CENTER, + // !wxDATAVIEW_COL_RESIZABLE); + // m_Library->AppendTextColumn(_("Filename"), + // wxDATAVIEW_CELL_INERT, + // 250, + // wxALIGN_LEFT, + // wxDATAVIEW_COL_RESIZABLE | + // wxDATAVIEW_COL_SORTABLE | + // wxDATAVIEW_COL_REORDERABLE); + // m_Library->AppendTextColumn(_("Sample Pack"), + // wxDATAVIEW_CELL_INERT, + // 180, + // wxALIGN_LEFT, + // wxDATAVIEW_COL_RESIZABLE | + // wxDATAVIEW_COL_SORTABLE | + // wxDATAVIEW_COL_REORDERABLE); + // m_Library->AppendTextColumn(_("Type"), + // wxDATAVIEW_CELL_INERT, + // 120, + // wxALIGN_LEFT, + // wxDATAVIEW_COL_RESIZABLE | + // wxDATAVIEW_COL_SORTABLE | + // wxDATAVIEW_COL_REORDERABLE); + // m_Library->AppendTextColumn(_("Channels"), + // wxDATAVIEW_CELL_INERT, + // 90, + // wxALIGN_RIGHT, + // wxDATAVIEW_COL_RESIZABLE | + // wxDATAVIEW_COL_SORTABLE | + // wxDATAVIEW_COL_REORDERABLE); + // m_Library->AppendTextColumn(_("Length"), + // wxDATAVIEW_CELL_INERT, + // 80, + // wxALIGN_RIGHT, + // wxDATAVIEW_COL_RESIZABLE | + // wxDATAVIEW_COL_SORTABLE | + // wxDATAVIEW_COL_REORDERABLE); + // m_Library->AppendTextColumn(_("Sample Rate"), + // wxDATAVIEW_CELL_INERT, + // 120, + // wxALIGN_RIGHT, + // wxDATAVIEW_COL_RESIZABLE | + // wxDATAVIEW_COL_SORTABLE | + // wxDATAVIEW_COL_REORDERABLE); + // m_Library->AppendTextColumn(_("Bitrate"), + // wxDATAVIEW_CELL_INERT, + // 80, + // wxALIGN_RIGHT, + // wxDATAVIEW_COL_RESIZABLE | + // wxDATAVIEW_COL_SORTABLE | + // wxDATAVIEW_COL_REORDERABLE); + // m_Library->AppendTextColumn(_("Path"), + // wxDATAVIEW_CELL_INERT, + // 250, + // wxALIGN_LEFT, + // wxDATAVIEW_COL_RESIZABLE | + // wxDATAVIEW_COL_SORTABLE | + // wxDATAVIEW_COL_REORDERABLE); - // Enable Library to accept files to be dropped on it - m_Library->DragAcceptFiles(true); + // // Enable Library to accept files to be dropped on it + // m_Library->DragAcceptFiles(true); - // Enable dragging a file from Library - m_Library->EnableDragSource(wxDF_FILENAME); + // // Enable dragging a file from Library + // m_Library->EnableDragSource(wxDF_FILENAME); // Initialize wxInfoBar for showing information inside application - m_InfoBar = new wxInfoBar(m_BottomRightPanel); + // m_InfoBar = new wxInfoBar(m_BottomRightPanel); // Initializing wxMediaCtrl. m_MediaCtrl = new wxMediaCtrl(this, BC_MediaCtrl, wxEmptyString, wxDefaultPosition, @@ -325,23 +341,8 @@ MainFrame::MainFrame() // Intializing wxTimer m_Timer = new wxTimer(this); - // Load default yaml config file. - LoadConfigFile(); - - // Initialize the database - try - { - m_Database = std::make_unique(); - m_Database->CreateTableSamples(); - m_Database->CreateTableHives(); - } - catch (std::exception& e) - { - SH_LOG_ERROR("Error! Cannot initialize database {}", e.what()); - } - - m_TransportControls = new TransportControls(m_TopPanel, *m_Library, *m_MediaCtrl, *m_Timer); - m_WaveformViewer = new WaveformViewer(m_TopPanel, *m_Library, *m_MediaCtrl, *m_Database); + m_TransportControls = new cTransportControls(m_TopPanel, *m_Library->GetListCtrlObject(), *m_MediaCtrl, *m_Timer); + m_WaveformViewer = new cWaveformViewer(m_TopPanel, *m_Library->GetListCtrlObject(), *m_MediaCtrl, *m_Database); // Binding events. Bind(wxEVT_MENU, &MainFrame::OnSelectAddFile, this, MN_AddFile); @@ -362,37 +363,37 @@ MainFrame::MainFrame() this->Connect(wxEVT_SIZE, wxSizeEventHandler(MainFrame::OnResizeFrame), NULL, this); m_StatusBar->Connect(wxEVT_SIZE, wxSizeEventHandler(MainFrame::OnResizeStatusBar), NULL, this); - Bind(wxEVT_DIRCTRL_FILEACTIVATED, &MainFrame::OnClickDirCtrl, this, BC_DirCtrl); - Bind(wxEVT_TREE_BEGIN_DRAG, &MainFrame::OnDragFromDirCtrl, this, m_DirCtrl->GetTreeCtrl()->GetId()); + // Bind(wxEVT_DIRCTRL_FILEACTIVATED, &MainFrame::OnClickDirCtrl, this, BC_DirCtrl); + // Bind(wxEVT_TREE_BEGIN_DRAG, &MainFrame::OnDragFromDirCtrl, this, m_DirCtrl->GetTreeCtrl()->GetId()); - Bind(SampleHive::SH_EVT_CALL_FUNC_PLAY, &MainFrame::OnRecieveCallFunctionPlay, this); + // Bind(SampleHive::SH_EVT_CALL_FUNC_PLAY, &MainFrame::OnRecieveCallFunctionPlay, this); - Bind(wxEVT_MEDIA_FINISHED, &MainFrame::OnMediaFinished, this, BC_MediaCtrl); - Bind(wxEVT_BUTTON, &MainFrame::OnClickSettings, this, BC_Settings); + // Bind(wxEVT_MEDIA_FINISHED, &MainFrame::OnMediaFinished, this, BC_MediaCtrl); + // Bind(wxEVT_BUTTON, &MainFrame::OnClickSettings, this, BC_Settings); - Bind(wxEVT_TIMER, &MainFrame::UpdateElapsedTime, this); + // Bind(wxEVT_TIMER, &MainFrame::UpdateElapsedTime, this); - m_Trash->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(MainFrame::OnDragAndDropToTrash), NULL, this); - Bind(wxEVT_TREE_ITEM_RIGHT_CLICK, &MainFrame::OnShowTrashContextMenu, this, BC_Trash); - Bind(wxEVT_BUTTON, &MainFrame::OnClickRestoreTrashItem, this, BC_RestoreTrashedItem); + // m_Trash->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(MainFrame::OnDragAndDropToTrash), NULL, this); + // Bind(wxEVT_TREE_ITEM_RIGHT_CLICK, &MainFrame::OnShowTrashContextMenu, this, BC_Trash); + // Bind(wxEVT_BUTTON, &MainFrame::OnClickRestoreTrashItem, this, BC_RestoreTrashedItem); - Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &MainFrame::OnClickLibrary, this, BC_Library); - Bind(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, &MainFrame::OnDragFromLibrary, this); - m_Library->Connect(wxEVT_DROP_FILES, - wxDropFilesEventHandler(MainFrame::OnDragAndDropToLibrary), NULL, this); - Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &MainFrame::OnShowLibraryContextMenu, this, BC_Library); - Bind(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, - &MainFrame::OnShowLibraryColumnHeaderContextMenu, this, BC_Library); + // Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &MainFrame::OnClickLibrary, this, BC_Library); + // Bind(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, &MainFrame::OnDragFromLibrary, this); + // m_Library->Connect(wxEVT_DROP_FILES, + // wxDropFilesEventHandler(MainFrame::OnDragAndDropToLibrary), NULL, this); + // Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &MainFrame::OnShowLibraryContextMenu, this, BC_Library); + // Bind(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, + // &MainFrame::OnShowLibraryColumnHeaderContextMenu, this, BC_Library); - Bind(wxEVT_TEXT, &MainFrame::OnDoSearch, this, BC_Search); - Bind(wxEVT_SEARCHCTRL_SEARCH_BTN, &MainFrame::OnDoSearch, this, BC_Search); - Bind(wxEVT_SEARCHCTRL_CANCEL_BTN, &MainFrame::OnCancelSearch, this, BC_Search); + // Bind(wxEVT_TEXT, &MainFrame::OnDoSearch, this, BC_Search); + // Bind(wxEVT_SEARCHCTRL_SEARCH_BTN, &MainFrame::OnDoSearch, this, BC_Search); + // Bind(wxEVT_SEARCHCTRL_CANCEL_BTN, &MainFrame::OnCancelSearch, this, BC_Search); - m_Hives->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(MainFrame::OnDragAndDropToHives), NULL, this); - Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &MainFrame::OnShowHivesContextMenu, this, BC_Hives); - Bind(wxEVT_DATAVIEW_ITEM_START_EDITING, &MainFrame::OnHiveStartEditing, this, BC_Hives); - Bind(wxEVT_BUTTON, &MainFrame::OnClickAddHive, this, BC_HiveAdd); - Bind(wxEVT_BUTTON, &MainFrame::OnClickRemoveHive, this, BC_HiveRemove); + // m_Hives->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(MainFrame::OnDragAndDropToHives), NULL, this); + // Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &MainFrame::OnShowHivesContextMenu, this, BC_Hives); + // Bind(wxEVT_DATAVIEW_ITEM_START_EDITING, &MainFrame::OnHiveStartEditing, this, BC_Hives); + // Bind(wxEVT_BUTTON, &MainFrame::OnClickAddHive, this, BC_HiveAdd); + // Bind(wxEVT_BUTTON, &MainFrame::OnClickRemoveHive, this, BC_HiveRemove); Bind(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, &MainFrame::OnRecieveLoopPoints, this); Bind(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, &MainFrame::OnRecievePushStatusBarStatus, this); @@ -400,34 +401,36 @@ MainFrame::MainFrame() Bind(SampleHive::SH_EVT_STATUSBAR_STATUS_SET, &MainFrame::OnRecieveSetStatusBarStatus, this); Bind(SampleHive::SH_EVT_INFOBAR_MESSAGE_SHOW, &MainFrame::OnRecieveInfoBarStatus, this); Bind(SampleHive::SH_EVT_TIMER_STOP, &MainFrame::OnRecieveTimerStopStatus, this); + Bind(SampleHive::SH_EVT_UPDATE_WAVEFORM, &MainFrame::OnRecieveWaveformUpdateStatus, this); + Bind(SampleHive::SH_EVT_CALL_FUNC_PLAY, &MainFrame::OnRecieveCallFunctionPlay, this); // Adding widgets to their sizers - m_MainSizer->Add(m_MainPanel, 1, wxALL | wxEXPAND, 0); + m_MainSizer->Add(m_TopSplitter, 1, wxALL | wxEXPAND, 0); - m_TopSizer->Add(m_TopSplitter, 1, wxALL | wxEXPAND, 0); + // m_TopSizer->Add(m_TopSplitter, 1, wxALL | wxEXPAND, 0); m_TopPanelMainSizer->Add(m_WaveformViewer, 1, wxALL | wxEXPAND, 2); m_TopPanelMainSizer->Add(m_TransportControls, 0, wxALL | wxEXPAND, 2); - m_BottomLeftPanelMainSizer->Add(m_Notebook, 1, wxALL | wxEXPAND, 0); + // m_BottomLeftPanelMainSizer->Add(m_Notebook, 1, wxALL | wxEXPAND, 0); - m_HivesFavoritesSizer->Add(m_Hives, 1, wxALL | wxEXPAND, 0); + // m_HivesFavoritesSizer->Add(m_Hives, 1, wxALL | wxEXPAND, 0); - m_HivesButtonSizer->Add(m_AddHiveButton, 1, wxALL | wxEXPAND, 0); - m_HivesButtonSizer->Add(m_RemoveHiveButton, 1, wxALL | wxEXPAND, 0); + // m_HivesButtonSizer->Add(m_AddHiveButton, 1, wxALL | wxEXPAND, 0); + // m_HivesButtonSizer->Add(m_RemoveHiveButton, 1, wxALL | wxEXPAND, 0); - m_HivesMainSizer->Add(m_HivesFavoritesSizer, 1, wxALL | wxEXPAND, 0); - m_HivesMainSizer->Add(m_HivesButtonSizer, 0, wxALL | wxEXPAND, 0); + // m_HivesMainSizer->Add(m_HivesFavoritesSizer, 1, wxALL | wxEXPAND, 0); + // m_HivesMainSizer->Add(m_HivesButtonSizer, 0, wxALL | wxEXPAND, 0); - m_TrashItemSizer->Add(m_Trash, 1, wxALL | wxEXPAND, 0); - m_TrashButtonSizer->Add(m_RestoreTrashedItemButton, 1, wxALL | wxEXPAND, 0); + // m_TrashItemSizer->Add(m_Trash, 1, wxALL | wxEXPAND, 0); + // m_TrashButtonSizer->Add(m_RestoreTrashedItemButton, 1, wxALL | wxEXPAND, 0); - m_TrashMainSizer->Add(m_TrashItemSizer, 1, wxALL | wxEXPAND, 0); - m_TrashMainSizer->Add(m_TrashButtonSizer, 0, wxALL | wxEXPAND, 0); + // m_TrashMainSizer->Add(m_TrashItemSizer, 1, wxALL | wxEXPAND, 0); + // m_TrashMainSizer->Add(m_TrashButtonSizer, 0, wxALL | wxEXPAND, 0); - m_BottomRightPanelMainSizer->Add(m_SearchBox, 1, wxALL | wxEXPAND, 2); - m_BottomRightPanelMainSizer->Add(m_InfoBar, 0, wxALL | wxEXPAND, 0); - m_BottomRightPanelMainSizer->Add(m_Library, 1, wxALL | wxEXPAND, 0); + // m_BottomRightPanelMainSizer->Add(m_SearchBox, 1, wxALL | wxEXPAND, 2); + // m_BottomRightPanelMainSizer->Add(m_InfoBar, 0, wxALL | wxEXPAND, 0); + // m_BottomRightPanelMainSizer->Add(m_Library, 1, wxALL | wxEXPAND, 0); // Sizer for the frame this->SetSizer(m_MainSizer); @@ -435,15 +438,15 @@ MainFrame::MainFrame() this->Center(wxBOTH); // Sizer for the main panel - m_MainPanel->SetSizer(m_TopSizer); - m_TopSizer->Fit(m_MainPanel); - m_TopSizer->SetSizeHints(m_MainPanel); - m_TopSizer->Layout(); + // m_MainPanel->SetSizer(m_TopSizer); + // m_TopSizer->Fit(m_MainPanel); + // m_TopSizer->SetSizeHints(m_MainPanel); + // m_TopSizer->Layout(); - m_WaveformViewer->SetSizer(m_WaveformDisplaySizer); - m_WaveformDisplaySizer->Fit(m_WaveformViewer); - m_WaveformDisplaySizer->SetSizeHints(m_WaveformViewer); - m_WaveformDisplaySizer->Layout(); + // m_WaveformViewer->SetSizer(m_WaveformDisplaySizer); + // m_WaveformDisplaySizer->Fit(m_WaveformViewer); + // m_WaveformDisplaySizer->SetSizeHints(m_WaveformViewer); + // m_WaveformDisplaySizer->Layout(); // Sizer for TopPanel m_TopPanel->SetSizer(m_TopPanelMainSizer); @@ -452,396 +455,396 @@ MainFrame::MainFrame() m_TopPanelMainSizer->Layout(); // Sizer for bottom left panel - m_BottomLeftPanel->SetSizer(m_BottomLeftPanelMainSizer); - m_BottomLeftPanelMainSizer->Fit(m_BottomLeftPanel); - m_BottomLeftPanelMainSizer->SetSizeHints(m_BottomLeftPanel); - m_BottomLeftPanelMainSizer->Layout(); + // m_Notebook->SetSizer(m_BottomLeftPanelMainSizer); + // m_BottomLeftPanelMainSizer->Fit(m_Notebook); + // m_BottomLeftPanelMainSizer->SetSizeHints(m_Notebook); + // m_BottomLeftPanelMainSizer->Layout(); // Sizer for Hives page for wxNotebook - m_HivesPanel->SetSizer(m_HivesMainSizer); - m_HivesMainSizer->Fit(m_HivesPanel); - m_HivesMainSizer->SetSizeHints(m_HivesPanel); - m_HivesMainSizer->Layout(); + // m_HivesPanel->SetSizer(m_HivesMainSizer); + // m_HivesMainSizer->Fit(m_HivesPanel); + // m_HivesMainSizer->SetSizeHints(m_HivesPanel); + // m_HivesMainSizer->Layout(); // Sizer for trash pane - m_TrashPanel->SetSizer(m_TrashMainSizer); - m_TrashMainSizer->Fit(m_TrashPanel); - m_TrashMainSizer->SetSizeHints(m_TrashPanel); - m_TrashMainSizer->Layout(); + // m_TrashPanel->SetSizer(m_TrashMainSizer); + // m_TrashMainSizer->Fit(m_TrashPanel); + // m_TrashMainSizer->SetSizeHints(m_TrashPanel); + // m_TrashMainSizer->Layout(); // Sizer for bottom right panel - m_BottomRightPanel->SetSizer(m_BottomRightPanelMainSizer); - m_BottomRightPanelMainSizer->Fit(m_BottomRightPanel); - m_BottomRightPanelMainSizer->SetSizeHints(m_BottomRightPanel); - m_BottomRightPanelMainSizer->Layout(); + // m_BottomRightPanel->SetSizer(m_BottomRightPanelMainSizer); + // m_BottomRightPanelMainSizer->Fit(m_BottomRightPanel); + // m_BottomRightPanelMainSizer->SetSizeHints(m_BottomRightPanel); + // m_BottomRightPanelMainSizer->Layout(); // Restore the data previously added to Library - LoadDatabase(); + // LoadDatabase(); // Set some properites after the frame has been created CallAfter(&MainFrame::SetAfterFrameCreate); } -void MainFrame::OnClickSettings(wxCommandEvent& event) -{ - Settings* settings = new Settings(this); - - switch (settings->ShowModal()) - { - case wxID_OK: - if (settings->CanAutoImport()) - { - OnAutoImportDir(settings->GetImportDirPath()); - RefreshDatabase(); - } - if (settings->IsWaveformColourChanged()) - { - m_WaveformViewer->ResetDC(); - } - break; - case wxID_CANCEL: - break; - default: - return; - } -} - -void MainFrame::AddSamples(wxArrayString& files) -{ - Serializer serializer; - - wxBusyCursor busy_cursor; - wxWindowDisabler window_disabler; - - wxProgressDialog* progressDialog = new wxProgressDialog(_("Adding files.."), - _("Adding files, please wait..."), - static_cast(files.size()), this, - wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_CAN_ABORT | - wxPD_AUTO_HIDE); - progressDialog->CenterOnParent(wxBOTH); - - std::vector sample_array; - - std::string path; - std::string artist; - std::string filename_with_extension; - std::string filename_without_extension; - std::string extension; - std::string filename; - - //Check All Files At Once - wxArrayString sorted_files; - - sorted_files = m_Database->CheckDuplicates(files); - files = sorted_files; - - if(files.size() < 1) - { - progressDialog->Destroy(); - return; - } - - progressDialog->SetRange(files.size()); - - for(unsigned int i = 0; i < files.size(); i++) - { - progressDialog->Update(i, wxString::Format(_("Getting Data For %s"), files[i].AfterLast('/'))); - - if(progressDialog->WasCancelled()) - { - progressDialog->Destroy(); - return; - } - - path = files[i].ToStdString(); - filename_with_extension = files[i].AfterLast('/').ToStdString(); - filename_without_extension = files[i].AfterLast('/').BeforeLast('.').ToStdString(); - extension = files[i].AfterLast('.').ToStdString(); - - filename = serializer.DeserializeShowFileExtension() ? - filename_with_extension : filename_without_extension; - - Sample sample; - - sample.SetPath(path); - sample.SetFilename(filename_without_extension); - sample.SetFileExtension(extension); - - Tags tags(path); - - artist = tags.GetAudioInfo().artist.ToStdString(); - - sample.SetSamplePack(artist); - sample.SetChannels(tags.GetAudioInfo().channels); - sample.SetLength(tags.GetAudioInfo().length); - sample.SetSampleRate(tags.GetAudioInfo().sample_rate); - sample.SetBitrate(tags.GetAudioInfo().bitrate); - - wxLongLong llLength = sample.GetLength(); - int total_min = static_cast((llLength / 60000).GetValue()); - int total_sec = static_cast(((llLength % 60000) / 1000).GetValue()); - - wxVector data; - - wxVariant icon = wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)); - - if (tags.IsFileValid()) - { - data.clear(); - data.push_back(icon); - data.push_back(filename); - data.push_back(sample.GetSamplePack()); - data.push_back(""); - data.push_back(wxString::Format("%d", sample.GetChannels())); - data.push_back(wxString::Format("%2i:%02i", total_min, total_sec)); - data.push_back(wxString::Format("%d", sample.GetSampleRate())); - data.push_back(wxString::Format("%d", sample.GetBitrate())); - data.push_back(path); - - SH_LOG_INFO("Adding file: {}, Extension: {}", sample.GetFilename(), sample.GetFileExtension()); - - m_Library->AppendItem(data); - - sample_array.push_back(sample); - } - else - { - wxString msg = wxString::Format(_("Error! Cannot open %s, Invalid file type."), - filename_with_extension); - m_InfoBar->ShowMessage(msg, wxICON_ERROR); - } - } - - progressDialog->Pulse(_("Updating Database.."), NULL); - - m_Database->InsertIntoSamples(sample_array); - - progressDialog->Destroy(); -} - -void MainFrame::OnClickDirCtrl(wxCommandEvent& event) -{ - wxArrayString path; - path.push_back(m_DirCtrl->GetFilePath()); - - AddSamples(path); -} - -void MainFrame::OnDragAndDropToLibrary(wxDropFilesEvent& event) -{ - SH_LOG_DEBUG("Start Inserting Samples"); - - if (event.GetNumberOfFiles() > 0) - { - wxString* dropped = event.GetFiles(); - wxASSERT(dropped); - - wxBusyCursor busy_cursor; - wxWindowDisabler window_disabler; - - wxString name; - wxString filepath; - wxArrayString filepath_array; - - wxProgressDialog* progressDialog = new wxProgressDialog(_("Reading files.."), - _("Reading files, please wait..."), - event.GetNumberOfFiles(), this, - wxPD_APP_MODAL | wxPD_SMOOTH | - wxPD_CAN_ABORT | wxPD_AUTO_HIDE); - - progressDialog->CenterOnParent(wxBOTH); - - wxYield(); - - for (int i = 0; i < event.GetNumberOfFiles(); i++) - { - filepath = dropped[i]; - - if (wxFileExists(filepath)) - { - filepath_array.push_back(filepath); - } - else if (wxDirExists(filepath)) - { - wxDir::GetAllFiles(filepath, &filepath_array); - } - - progressDialog->Pulse(_("Reading Samples"), NULL); - } - - progressDialog->Destroy(); - - AddSamples(filepath_array); - - SH_LOG_DEBUG("Done Inserting Samples"); - } -} - -void MainFrame::OnDragAndDropToHives(wxDropFilesEvent& event) -{ - Serializer serializer; - - if (event.GetNumberOfFiles() > 0) - { - wxFileDataObject file_data; - wxArrayString files; - - wxDataViewItemArray items; - int rows = m_Library->GetSelections(items); - - wxDataViewItem drop_target;; - wxDataViewColumn* column; - wxPoint position = event.GetPosition(); - - m_Hives->HitTest(position, drop_target, column); - - wxString hive_name = m_Hives->GetItemText(drop_target); - - wxString msg; - - for (int i = 0; i < rows; i++) - { - int row = m_Library->ItemToRow(items[i]); - - wxString name = m_Library->GetTextValue(row, 1); - - file_data.AddFile(name); - - files = file_data.GetFilenames(); - - wxString file_name = serializer.DeserializeShowFileExtension() ? - files[i].BeforeLast('.') : files[i]; - - SH_LOG_DEBUG("Dropping {} file(s) {} on {}", rows - i, files[i], m_Hives->GetItemText(drop_target)); - - if (drop_target.IsOk() && m_Hives->IsContainer(drop_target) && - m_Database->GetFavoriteColumnValueByFilename(file_name.ToStdString()) == 0) - { - m_Hives->AppendItem(drop_target, files[i]); - - m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), row, 0); - - m_Database->UpdateFavoriteColumn(file_name.ToStdString(), 1); - m_Database->UpdateHiveName(file_name.ToStdString(), hive_name.ToStdString()); - - msg = wxString::Format(_("%s added to %s."), files[i], hive_name); - } - else - { - if (m_Database->GetFavoriteColumnValueByFilename(file_name.ToStdString()) == 1) - { - wxMessageBox(wxString::Format(_("%s is already added to %s hive"), files[i], - m_Database->GetHiveByFilename(file_name.ToStdString())), - _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this); - } - else - { - if (m_Hives->GetItemText(drop_target) == "") - wxMessageBox(_("Cannot drop item outside of a hive, try dropping on a hive."), - _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this); - else - wxMessageBox(wxString::Format(_("%s is not a hive, try dropping on a hive."), - m_Hives->GetItemText(drop_target)), _("Error!"), - wxOK | wxICON_ERROR | wxCENTRE, this); - } - } +// void MainFrame::OnClickSettings(wxCommandEvent& event) +// { +// Settings* settings = new Settings(this); + +// switch (settings->ShowModal()) +// { +// case wxID_OK: +// if (settings->CanAutoImport()) +// { +// OnAutoImportDir(settings->GetImportDirPath()); +// RefreshDatabase(); +// } +// if (settings->IsWaveformColourChanged()) +// { +// m_WaveformViewer->ResetDC(); +// } +// break; +// case wxID_CANCEL: +// break; +// default: +// return; +// } +// } + +// void MainFrame::AddSamples(wxArrayString& files) +// { +// Serializer serializer; + +// wxBusyCursor busy_cursor; +// wxWindowDisabler window_disabler; + +// wxProgressDialog* progressDialog = new wxProgressDialog(_("Adding files.."), +// _("Adding files, please wait..."), +// static_cast(files.size()), this, +// wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_CAN_ABORT | +// wxPD_AUTO_HIDE); +// progressDialog->CenterOnParent(wxBOTH); + +// std::vector sample_array; + +// std::string path; +// std::string artist; +// std::string filename_with_extension; +// std::string filename_without_extension; +// std::string extension; +// std::string filename; + +// //Check All Files At Once +// wxArrayString sorted_files; + +// sorted_files = m_Database->CheckDuplicates(files); +// files = sorted_files; + +// if(files.size() < 1) +// { +// progressDialog->Destroy(); +// return; +// } + +// progressDialog->SetRange(files.size()); + +// for(unsigned int i = 0; i < files.size(); i++) +// { +// progressDialog->Update(i, wxString::Format(_("Getting Data For %s"), files[i].AfterLast('/'))); + +// if(progressDialog->WasCancelled()) +// { +// progressDialog->Destroy(); +// return; +// } + +// path = files[i].ToStdString(); +// filename_with_extension = files[i].AfterLast('/').ToStdString(); +// filename_without_extension = files[i].AfterLast('/').BeforeLast('.').ToStdString(); +// extension = files[i].AfterLast('.').ToStdString(); + +// filename = serializer.DeserializeShowFileExtension() ? +// filename_with_extension : filename_without_extension; + +// Sample sample; + +// sample.SetPath(path); +// sample.SetFilename(filename_without_extension); +// sample.SetFileExtension(extension); + +// Tags tags(path); + +// artist = tags.GetAudioInfo().artist.ToStdString(); + +// sample.SetSamplePack(artist); +// sample.SetChannels(tags.GetAudioInfo().channels); +// sample.SetLength(tags.GetAudioInfo().length); +// sample.SetSampleRate(tags.GetAudioInfo().sample_rate); +// sample.SetBitrate(tags.GetAudioInfo().bitrate); + +// wxLongLong llLength = sample.GetLength(); +// int total_min = static_cast((llLength / 60000).GetValue()); +// int total_sec = static_cast(((llLength % 60000) / 1000).GetValue()); + +// wxVector data; + +// wxVariant icon = wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)); + +// if (tags.IsFileValid()) +// { +// data.clear(); +// data.push_back(icon); +// data.push_back(filename); +// data.push_back(sample.GetSamplePack()); +// data.push_back(""); +// data.push_back(wxString::Format("%d", sample.GetChannels())); +// data.push_back(wxString::Format("%2i:%02i", total_min, total_sec)); +// data.push_back(wxString::Format("%d", sample.GetSampleRate())); +// data.push_back(wxString::Format("%d", sample.GetBitrate())); +// data.push_back(path); - if (!msg.IsEmpty()) - m_InfoBar->ShowMessage(msg, wxICON_ERROR); - } - } -} +// SH_LOG_INFO("Adding file: {}, Extension: {}", sample.GetFilename(), sample.GetFileExtension()); -void MainFrame::OnAutoImportDir(const wxString& pathToDirectory) -{ - SH_LOG_DEBUG("Start Importing Samples"); +// m_Library->AppendItem(data); - wxBusyCursor busy_cursor; - wxWindowDisabler window_disabler; +// sample_array.push_back(sample); +// } +// else +// { +// wxString msg = wxString::Format(_("Error! Cannot open %s, Invalid file type."), +// filename_with_extension); +// m_InfoBar->ShowMessage(msg, wxICON_ERROR); +// } +// } - wxString filepath; - wxArrayString filepath_array; +// progressDialog->Pulse(_("Updating Database.."), NULL); - size_t number_of_files = wxDir::GetAllFiles(pathToDirectory, &filepath_array, - wxEmptyString, wxDIR_DEFAULT); +// m_Database->InsertIntoSamples(sample_array); - wxProgressDialog* progressDialog = new wxProgressDialog(_("Adding files.."), - _("Adding files, please wait..."), - static_cast(number_of_files), this, - wxPD_APP_MODAL | wxPD_SMOOTH | - wxPD_CAN_ABORT | wxPD_AUTO_HIDE); +// progressDialog->Destroy(); +// } - progressDialog->CenterOnParent(wxBOTH); +// void MainFrame::OnClickDirCtrl(wxCommandEvent& event) +// { +// wxArrayString path; +// path.push_back(m_DirCtrl->GetFilePath()); - for (size_t i = 0; i < number_of_files; i++) - { - filepath = filepath_array[i]; +// AddSamples(path); +// } - if (wxFileExists(filepath)) - { - filepath_array.push_back(filepath); - } - else if (wxDirExists(filepath)) - { - wxDir::GetAllFiles(filepath, &filepath_array); - } +// void MainFrame::OnDragAndDropToLibrary(wxDropFilesEvent& event) +// { +// SH_LOG_DEBUG("Start Inserting Samples"); - progressDialog->Pulse(_("Reading Samples"), NULL); - } +// if (event.GetNumberOfFiles() > 0) +// { +// wxString* dropped = event.GetFiles(); +// wxASSERT(dropped); - progressDialog->Destroy(); +// wxBusyCursor busy_cursor; +// wxWindowDisabler window_disabler; - AddSamples(filepath_array); +// wxString name; +// wxString filepath; +// wxArrayString filepath_array; - SH_LOG_DEBUG("Done Importing Samples"); -} +// wxProgressDialog* progressDialog = new wxProgressDialog(_("Reading files.."), +// _("Reading files, please wait..."), +// event.GetNumberOfFiles(), this, +// wxPD_APP_MODAL | wxPD_SMOOTH | +// wxPD_CAN_ABORT | wxPD_AUTO_HIDE); -// Temporary function to check drag and drop result -void LogDragResult(wxDragResult result) -{ - wxString msg; - switch (result) - { - case wxDragError: msg = "Error!"; break; - case wxDragNone: msg = "Nothing"; break; - case wxDragCopy: msg = "Copied"; break; - case wxDragMove: msg = "Moved"; break; - case wxDragCancel: msg = "Cancelled"; break; - default: msg = "Huh?"; break; - } - - SH_LOG_DEBUG("Drag result: {}", msg); -} - -void MainFrame::OnDragFromDirCtrl(wxTreeEvent& event) -{ - wxFileDataObject file_data; - file_data.AddFile(m_DirCtrl->GetPath(event.GetItem())); - - wxDropSource drop_source(this); - drop_source.SetData(file_data); - - LogDragResult(drop_source.DoDragDrop()); -} - -void MainFrame::OnDragFromLibrary(wxDataViewEvent& event) -{ - int selected_row = m_Library->ItemToRow(event.GetItem()); - - if (selected_row < 0) - return; - - wxString selection = m_Library->GetTextValue(selected_row, 1); - - wxString sample_path = GetFilenamePathAndExtension(selection).Path; - - wxFileDataObject* fileData = new wxFileDataObject(); - - fileData->AddFile(sample_path); - event.SetDataObject(fileData); +// progressDialog->CenterOnParent(wxBOTH); - SH_LOG_DEBUG("Started dragging '{}'.", sample_path); -} +// wxYield(); + +// for (int i = 0; i < event.GetNumberOfFiles(); i++) +// { +// filepath = dropped[i]; + +// if (wxFileExists(filepath)) +// { +// filepath_array.push_back(filepath); +// } +// else if (wxDirExists(filepath)) +// { +// wxDir::GetAllFiles(filepath, &filepath_array); +// } + +// progressDialog->Pulse(_("Reading Samples"), NULL); +// } + +// progressDialog->Destroy(); + +// AddSamples(filepath_array); + +// SH_LOG_DEBUG("Done Inserting Samples"); +// } +// } + +// void MainFrame::OnDragAndDropToHives(wxDropFilesEvent& event) +// { +// Serializer serializer; + +// if (event.GetNumberOfFiles() > 0) +// { +// wxFileDataObject file_data; +// wxArrayString files; + +// wxDataViewItemArray items; +// int rows = m_Library->GetSelections(items); + +// wxDataViewItem drop_target;; +// wxDataViewColumn* column; +// wxPoint position = event.GetPosition(); + +// m_Hives->HitTest(position, drop_target, column); + +// wxString hive_name = m_Hives->GetItemText(drop_target); + +// wxString msg; + +// for (int i = 0; i < rows; i++) +// { +// int row = m_Library->ItemToRow(items[i]); + +// wxString name = m_Library->GetTextValue(row, 1); + +// file_data.AddFile(name); + +// files = file_data.GetFilenames(); + +// wxString file_name = serializer.DeserializeShowFileExtension() ? +// files[i].BeforeLast('.') : files[i]; + +// SH_LOG_DEBUG("Dropping {} file(s) {} on {}", rows - i, files[i], m_Hives->GetItemText(drop_target)); + +// if (drop_target.IsOk() && m_Hives->IsContainer(drop_target) && +// m_Database->GetFavoriteColumnValueByFilename(file_name.ToStdString()) == 0) +// { +// m_Hives->AppendItem(drop_target, files[i]); + +// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), row, 0); + +// m_Database->UpdateFavoriteColumn(file_name.ToStdString(), 1); +// m_Database->UpdateHiveName(file_name.ToStdString(), hive_name.ToStdString()); + +// msg = wxString::Format(_("%s added to %s."), files[i], hive_name); +// } +// else +// { +// if (m_Database->GetFavoriteColumnValueByFilename(file_name.ToStdString()) == 1) +// { +// wxMessageBox(wxString::Format(_("%s is already added to %s hive"), files[i], +// m_Database->GetHiveByFilename(file_name.ToStdString())), +// _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this); +// } +// else +// { +// if (m_Hives->GetItemText(drop_target) == "") +// wxMessageBox(_("Cannot drop item outside of a hive, try dropping on a hive."), +// _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this); +// else +// wxMessageBox(wxString::Format(_("%s is not a hive, try dropping on a hive."), +// m_Hives->GetItemText(drop_target)), _("Error!"), +// wxOK | wxICON_ERROR | wxCENTRE, this); +// } +// } + +// if (!msg.IsEmpty()) +// m_InfoBar->ShowMessage(msg, wxICON_ERROR); +// } +// } +// } + +// void MainFrame::OnAutoImportDir(const wxString& pathToDirectory) +// { +// SH_LOG_DEBUG("Start Importing Samples"); + +// wxBusyCursor busy_cursor; +// wxWindowDisabler window_disabler; + +// wxString filepath; +// wxArrayString filepath_array; + +// size_t number_of_files = wxDir::GetAllFiles(pathToDirectory, &filepath_array, +// wxEmptyString, wxDIR_DEFAULT); + +// wxProgressDialog* progressDialog = new wxProgressDialog(_("Adding files.."), +// _("Adding files, please wait..."), +// static_cast(number_of_files), this, +// wxPD_APP_MODAL | wxPD_SMOOTH | +// wxPD_CAN_ABORT | wxPD_AUTO_HIDE); + +// progressDialog->CenterOnParent(wxBOTH); + +// for (size_t i = 0; i < number_of_files; i++) +// { +// filepath = filepath_array[i]; + +// if (wxFileExists(filepath)) +// { +// filepath_array.push_back(filepath); +// } +// else if (wxDirExists(filepath)) +// { +// wxDir::GetAllFiles(filepath, &filepath_array); +// } + +// progressDialog->Pulse(_("Reading Samples"), NULL); +// } + +// progressDialog->Destroy(); + +// AddSamples(filepath_array); + +// SH_LOG_DEBUG("Done Importing Samples"); +// } + +// // Temporary function to check drag and drop result +// void LogDragResult(wxDragResult result) +// { +// wxString msg; +// switch (result) +// { +// case wxDragError: msg = "Error!"; break; +// case wxDragNone: msg = "Nothing"; break; +// case wxDragCopy: msg = "Copied"; break; +// case wxDragMove: msg = "Moved"; break; +// case wxDragCancel: msg = "Cancelled"; break; +// default: msg = "Huh?"; break; +// } + +// SH_LOG_DEBUG("Drag result: {}", msg); +// } + +// void MainFrame::OnDragFromDirCtrl(wxTreeEvent& event) +// { +// wxFileDataObject file_data; +// file_data.AddFile(m_DirCtrl->GetPath(event.GetItem())); + +// wxDropSource drop_source(this); +// drop_source.SetData(file_data); + +// LogDragResult(drop_source.DoDragDrop()); +// } + +// void MainFrame::OnDragFromLibrary(wxDataViewEvent& event) +// { +// int selected_row = m_Library->ItemToRow(event.GetItem()); + +// if (selected_row < 0) +// return; + +// wxString selection = m_Library->GetTextValue(selected_row, 1); + +// wxString sample_path = GetFilenamePathAndExtension(selection).Path; + +// wxFileDataObject* fileData = new wxFileDataObject(); + +// fileData->AddFile(sample_path); +// event.SetDataObject(fileData); + +// SH_LOG_DEBUG("Started dragging '{}'.", sample_path); +// } void MainFrame::OnMediaFinished(wxMediaEvent& event) { @@ -888,8 +891,9 @@ void MainFrame::UpdateElapsedTime(wxTimerEvent& event) position.Printf(wxT("%2i:%02i"), current_min, current_sec); m_TransportControls->SetSamplePositionText(wxString::Format(wxT("%s/%s"), - position.c_str(), duration.c_str())); + position.c_str(), duration.c_str())); + this->Refresh(); m_TransportControls->Refresh(); m_WaveformViewer->Refresh(); @@ -898,1455 +902,1455 @@ void MainFrame::UpdateElapsedTime(wxTimerEvent& event) m_MediaCtrl->Seek(m_LoopA.ToDouble(), wxFromStart); } -void MainFrame::OnClickLibrary(wxDataViewEvent& event) -{ - int selected_row = m_Library->ItemToRow(event.GetItem()); - int current_row = m_Library->ItemToRow(m_Library->GetCurrentItem()); - - if (selected_row < 0 || !event.GetItem().IsOk()) - return; - - if (selected_row != current_row) - { - m_Library->SetCurrentItem(event.GetItem()); - return; - } - - // Update the waveform bitmap - m_WaveformViewer->ResetDC(); - - m_TransportControls->SetLoopABValue(false); - - if (m_Timer->IsRunning()) - { - m_Timer->Stop(); - SH_LOG_DEBUG("TIMER STOPPED"); - } - - wxString selection = m_Library->GetTextValue(selected_row, 1); - - // Get curremt column - wxDataViewColumn* CurrentColumn = m_Library->GetCurrentColumn(); - - // Get favorite column - wxDataViewColumn* FavoriteColumn = m_Library->GetColumn(0); - - if (!CurrentColumn) - return; - - wxString sample_path = GetFilenamePathAndExtension(selection).Path; - std::string filename = GetFilenamePathAndExtension(selection).Filename; - std::string extension = GetFilenamePathAndExtension(selection).Extension; - - if (CurrentColumn != FavoriteColumn) - { - ClearLoopPoints(); - - if (m_TransportControls->CanAutoplay()) - { - if (bLoopPointsSet && m_TransportControls->IsLoopABOn()) - PlaySample(sample_path.ToStdString(), selection.ToStdString(), - true, m_LoopA.ToDouble(), wxFromStart); - else - PlaySample(sample_path.ToStdString(), selection.ToStdString()); - } - else - m_MediaCtrl->Stop(); - } - else - { - wxString msg; - - // Get hive name and location - std::string hive_name = m_Hives->GetItemText(favorites_hive).ToStdString(); - wxDataViewItem hive_selection = m_Hives->GetSelection(); - - if (hive_selection.IsOk() && m_Hives->IsContainer(hive_selection)) - hive_name = m_Hives->GetItemText(hive_selection).ToStdString(); - - wxString name = m_Library->GetTextValue(selected_row, 1); - - // Get root - wxDataViewItem root = wxDataViewItem(wxNullPtr); - wxDataViewItem container; - wxDataViewItem child; - - if (m_Database->GetFavoriteColumnValueByFilename(filename) == 0) - { - m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0); - - m_Database->UpdateFavoriteColumn(filename, 1); - m_Database->UpdateHiveName(filename, hive_name); - - for (int i = 0; i < m_Hives->GetChildCount(root); i++) - { - container = m_Hives->GetNthChild(root, i); - - if (m_Hives->GetItemText(container).ToStdString() == hive_name) - { - m_Hives->AppendItem(container, name); - break; - } - } - - msg = wxString::Format(_("Added %s to %s"), name, hive_name); - } - else - { - m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0); - - m_Database->UpdateFavoriteColumn(filename, 0); - m_Database->UpdateHiveName(filename, m_Hives->GetItemText(favorites_hive).ToStdString()); - - for (int i = 0; i < m_Hives->GetChildCount(root); i++) - { - container = m_Hives->GetNthChild(root, i); - - for (int j = 0; j < m_Hives->GetChildCount(container); j++) - { - child = m_Hives->GetNthChild(container, j); - - if (m_Hives->GetItemText(child) == name) - { - m_Hives->DeleteItem(child); - break; - } - } - } - - msg = wxString::Format(_("Removed %s from %s"), name, hive_name); - } - - if (!msg.IsEmpty()) - m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); - } -} - -void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) -{ - Serializer serializer; - - wxDataViewItem selected_hive = event.GetItem(); - - wxString hive_name = m_Hives->GetItemText(selected_hive); - - wxMenu menu; - - if (m_Hives->IsContainer(selected_hive)) - { - // Container menu items - menu.Append(MN_RenameHive, _("Rename hive"), _("Rename selected hive")); - menu.Append(MN_DeleteHive, _("Delete hive"), _("Delete selected hive")); - - if (!bFiltered) - menu.Append(MN_FilterLibrary, _("Filter library"), - _("Show only samples from current hive in library")); - else - menu.Append(MN_FilterLibrary, _("Clear filter"), _("Clear the filter")); - } - else - { - // Child menu items - menu.Append(MN_RemoveSample, _("Remove sample"), _("Remove the selected sample(s)")); - menu.Append(MN_ShowInLibrary, _("Show sample in library"), _("Show the selected in library")); - } - - if (selected_hive.IsOk() && m_Hives->IsContainer(selected_hive)) - { - switch (m_Hives->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) - { - case MN_RenameHive: - { - std::deque nodes; - nodes.push_back(m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0)); - - wxDataViewItem current_item, found_item; - - int row = 0; - int hive_count = m_Hives->GetChildCount(wxDataViewItem(wxNullPtr)); - - wxString msg; - - wxTextEntryDialog renameEntry(this, _("Enter new name"), wxGetTextFromUserPromptStr, - wxEmptyString, wxTextEntryDialogStyle, wxDefaultPosition); - - renameEntry.SetTextValidator(wxFILTER_EMPTY); - - switch (renameEntry.ShowModal()) - { - case wxID_OK: - { - wxString hive_name = renameEntry.GetValue(); - - while(!nodes.empty()) - { - current_item = nodes.front(); - nodes.pop_front(); - - if (m_Hives->GetItemText(current_item) == hive_name) - { - found_item = current_item; - SH_LOG_DEBUG("Found item: {}", m_Hives->GetItemText(current_item)); - break; - } - - wxDataViewItem child = m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0); - - while (row < (hive_count - 1)) - { - row ++; - - child = m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), row); - nodes.push_back(child); - } - } - - nodes.clear(); - - if (found_item.IsOk()) - { - wxMessageBox(wxString::Format(_("Another hive by the name %s already exist. " - "Please try with a different name."), - hive_name), - _("Error!"), wxOK | wxCENTRE, this); - } - else - { - wxString selected_hive_name = m_Hives->GetItemText(selected_hive); - - int sample_count = m_Hives->GetChildCount(selected_hive); - - if (sample_count <= 0) - { - m_Hives->SetItemText(selected_hive, hive_name); - m_Database->UpdateHive(selected_hive_name.ToStdString(), - hive_name.ToStdString()); - } - else - { - for (int i = 0; i < sample_count; i++) - { - wxDataViewItem sample_item = m_Hives->GetNthChild(selected_hive, i); - - wxString sample_name = serializer.DeserializeShowFileExtension() ? - m_Hives->GetItemText(sample_item).BeforeLast('.') : - m_Hives->GetItemText(sample_item); - - m_Database->UpdateHiveName(sample_name.ToStdString(), - hive_name.ToStdString()); - m_Database->UpdateHive(selected_hive_name.ToStdString(), - hive_name.ToStdString()); - - m_Hives->SetItemText(selected_hive, hive_name); - } - } - - msg = wxString::Format(_("Successfully changed hive name to %s."), hive_name); - } - } - break; - case wxID_CANCEL: - break; - default: - return; - } - - if (!msg.IsEmpty()) - m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); - } - break; - case MN_DeleteHive: - { - wxString msg; - - wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to " - "delete %s from hives?"), - hive_name), - wxMessageBoxCaptionStr, - wxYES_NO | wxNO_DEFAULT | - wxICON_QUESTION | wxSTAY_ON_TOP); - - wxMessageDialog deleteFilledHiveDialog(this, wxString::Format(_("Are you sure you want to " - "delete %s and all samples " - "inside %s from hives?"), - hive_name, hive_name), - wxMessageBoxCaptionStr, - wxYES_NO | wxNO_DEFAULT | - wxICON_QUESTION | wxSTAY_ON_TOP); - - if (hive_name == m_Hives->GetItemText(favorites_hive)) - { - wxMessageBox(wxString::Format(_("Error! Default hive %s cannot be deleted."), hive_name), - _("Error!"), wxOK | wxCENTRE, this); - return; - } - else if (!selected_hive.IsOk()) - { - wxMessageBox(_("No hive selected, try selecting a hive first"), _("Error!"), - wxOK | wxCENTRE, this); - return; - } - else if (selected_hive.IsOk() && !m_Hives->IsContainer(selected_hive)) - { - wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from hives."), - hive_name), - _("Error!"), wxOK | wxCENTRE, this); - return; - } - - if(m_Hives->GetChildCount(selected_hive) <= 0) - { - switch (deleteEmptyHiveDialog.ShowModal()) - { - case wxID_YES: - if (selected_hive.IsOk() && m_Hives->IsContainer(selected_hive) && - hive_name != m_Hives->GetItemText(favorites_hive)) - { - m_Hives->DeleteItem(selected_hive); - - m_Database->RemoveHiveFromDatabase(hive_name.ToStdString()); - - msg = wxString::Format(_("%s deleted from hives successfully."), hive_name); - } - break; - case wxID_NO: - break; - default: - return; - } - } - else - { - switch (deleteFilledHiveDialog.ShowModal()) - { - case wxID_YES: - if (selected_hive.IsOk() && m_Hives->IsContainer(selected_hive) && - hive_name != m_Hives->GetItemText(favorites_hive)) - { - wxDataViewItem child_item; - - for (int i = 0; i < m_Library->GetItemCount(); i++) - { - wxString matched_sample = - serializer.DeserializeShowFileExtension() ? - m_Library->GetTextValue(i, 1).BeforeLast('.') : - m_Library->GetTextValue(i, 1); - - for (int j = 0; j < m_Hives->GetChildCount(selected_hive); j++) - { - child_item = m_Hives->GetNthChild(selected_hive, j); - - wxString child_name = - serializer.DeserializeShowFileExtension() ? - m_Hives->GetItemText(child_item).BeforeLast('.') : - m_Hives->GetItemText(child_item); - - if (child_name == matched_sample) - { - SH_LOG_DEBUG("Found match"); - - m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), - i, 0); - - m_Database->UpdateFavoriteColumn(matched_sample.ToStdString(), 0); - m_Database->UpdateHiveName(matched_sample.ToStdString(), - m_Hives->GetItemText(favorites_hive).ToStdString()); - - break; - } - else - SH_LOG_DEBUG("No match found"); - } - } - - m_Hives->DeleteChildren(selected_hive); - m_Hives->DeleteItem(selected_hive); - - m_Database->RemoveHiveFromDatabase(hive_name.ToStdString()); - - msg = wxString::Format(_("%s and all samples inside %s " - "have been deleted from hives successfully."), - hive_name, hive_name); - } - break; - case wxID_NO: - break; - default: - return; - } - } - - if (!msg.IsEmpty()) - m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); - } - break; - case MN_FilterLibrary: - { - if (!bFiltered) - { - try - { - const auto dataset = m_Database->FilterDatabaseByHiveName(hive_name.ToStdString(), - serializer.DeserializeShowFileExtension(), - ICON_STAR_FILLED_16px, - ICON_STAR_EMPTY_16px); - - if (dataset.empty()) - { - wxMessageBox(_("Error! Database is empty."), _("Error!"), - wxOK | wxICON_ERROR | wxCENTRE, this); - return; - } - else - { - m_Library->DeleteAllItems(); - - for (auto data : dataset) - { - m_Library->AppendItem(data); - } - } - } - catch (...) - { - wxMessageBox(_("Error loading data, cannot filter sample view"), _("Error!"), - wxOK | wxICON_ERROR | wxCENTRE, this); - } - - bFiltered = true; - } - else - { - try - { - const auto dataset = m_Database->FilterDatabaseBySampleName("", serializer.DeserializeShowFileExtension(), - ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); - - if (dataset.empty()) - { - wxMessageBox(_("Error! Database is empty."), _("Error!"), - wxOK | wxICON_ERROR | wxCENTRE, this); - } - else - { - m_Library->DeleteAllItems(); - - for (auto data : dataset) - { - m_Library->AppendItem(data); - } - } - } - catch (...) - { - wxMessageBox(_("Error loading data, cannot filter sample view"), _("Error!"), - wxOK | wxICON_ERROR | wxCENTRE, this); - } - - bFiltered = false; - } - } - break; - default: - return; - } - } - else if (selected_hive.IsOk() && !m_Hives->IsContainer(selected_hive)) - { - switch (m_Hives->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) - { - case MN_RemoveSample: - for(int i = 0; i < m_Library->GetItemCount(); i++) - { - wxString matched_sample = serializer.DeserializeShowFileExtension() ? - m_Library->GetTextValue(i, 1).BeforeLast('.') : - m_Library->GetTextValue(i, 1); - - wxString selected_sample_name = serializer.DeserializeShowFileExtension() ? - m_Hives->GetItemText(event.GetItem()).BeforeLast('.') : - m_Hives->GetItemText(event.GetItem()); - - if(selected_sample_name == matched_sample) - { - SH_LOG_DEBUG("Found match"); - - m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); - - m_Database->UpdateFavoriteColumn(matched_sample.ToStdString(), 0); - m_Database->UpdateHiveName(matched_sample.ToStdString(), - m_Hives->GetItemText(favorites_hive).ToStdString()); - - m_Hives->DeleteItem(selected_hive); - - break; - } - - m_InfoBar->ShowMessage(wxString::Format(_("Removed %s from %s"), - m_Hives->GetItemText(event.GetItem()), - m_Database->GetHiveByFilename(matched_sample.ToStdString())), - wxICON_INFORMATION); - } - break; - case MN_ShowInLibrary: - for(int i = 0; i < m_Library->GetItemCount(); i++) - { - wxString matched_sample = serializer.DeserializeShowFileExtension() ? - m_Library->GetTextValue(i, 1).BeforeLast('.') : - m_Library->GetTextValue(i, 1); - - wxString selected_sample_name = serializer.DeserializeShowFileExtension() ? - m_Hives->GetItemText(event.GetItem()).BeforeLast('.') : - m_Hives->GetItemText(event.GetItem()); - - if(selected_sample_name == matched_sample) - { - SH_LOG_DEBUG("Found match"); - - wxDataViewItem matched_item = m_Library->RowToItem(i); - - m_Library->UnselectAll(); - m_Library->SelectRow(i); - m_Library->EnsureVisible(matched_item); - - break; - } - } - break; - default: - return; - } - } -} - -void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event) -{ - TagEditor* tagEditor; - Serializer serializer; - - wxString msg; - - wxDataViewItem item = event.GetItem(); - int selected_row; - - if (item.IsOk()) - selected_row = m_Library->ItemToRow(item); - else - return; - - wxString selection = m_Library->GetTextValue(selected_row, 1); - - wxString sample_path = GetFilenamePathAndExtension(selection).Path; - std::string filename = GetFilenamePathAndExtension(selection).Filename; - std::string extension = GetFilenamePathAndExtension(selection).Extension; - - wxMenu menu; - - //true = add false = remove - bool favorite_add = false; - - if (m_Database->GetFavoriteColumnValueByFilename(filename) == 1) - menu.Append(MN_FavoriteSample, _("Remove from hive"), _("Remove the selected sample(s) from hive")); - else - { - menu.Append(MN_FavoriteSample, _("Add to hive"), _("Add selected sample(s) to hive")); - favorite_add = true; - } - - menu.Append(MN_DeleteSample, _("Delete"), _("Delete the selected sample(s) from database")); - menu.Append(MN_TrashSample, _("Trash"), _("Send the selected sample(s) to trash")); - - if (m_Library->GetSelectedItemsCount() <= 1) - { - menu.Append(MN_EditTagSample, _("Edit tags"), - _("Edit the tags for the selected sample"))->Enable(true); - menu.Append(MN_OpenFile, _("Open in file manager"), - _("Open the selected sample in system's file manager"))->Enable(true); - } - else - { - menu.Append(MN_EditTagSample, _("Edit tags"), - _("Edit the tags for the selected sample"))->Enable(false); - menu.Append(MN_OpenFile, _("Open in file manager"), - _("Open the selected sample in system's file manager"))->Enable(false); - } - - switch (m_Library->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) - { - case MN_FavoriteSample: - { - std::string hive_name = m_Hives->GetItemText(favorites_hive).ToStdString(); - - wxDataViewItem hive_selection = m_Hives->GetSelection(); - - if (hive_selection.IsOk() && m_Hives->IsContainer(hive_selection)) - hive_name = m_Hives->GetItemText(hive_selection).ToStdString(); - - wxDataViewItem root = wxDataViewItem(wxNullPtr); - wxDataViewItem container; - wxDataViewItem child; - - wxDataViewItemArray samples; - int sample_count = m_Library->GetSelections(samples); - int selected_row = 0; - int db_status = 0; - - for (int k = 0; k < sample_count; k++) - { - selected_row = m_Library->ItemToRow(samples[k]); - - if (selected_row < 0) - continue; - - wxString name = m_Library->GetTextValue(selected_row, 1); - - filename = serializer.DeserializeShowFileExtension() ? - name.BeforeLast('.').ToStdString() : name.ToStdString(); - - db_status = m_Database->GetFavoriteColumnValueByFilename(filename); - - // Aleady Added, Do Nothing - if (favorite_add && db_status == 1) - continue; - - // Already Removed, Do Nothing - if (!favorite_add && db_status == 0) - continue; - - // Add To Favorites - if (favorite_add && db_status == 0) - { - m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0); - - m_Database->UpdateFavoriteColumn(filename, 1); - m_Database->UpdateHiveName(filename, hive_name); - - for (int i = 0; i < m_Hives->GetChildCount(root); i++) - { - container = m_Hives->GetNthChild(root, i); - - if (m_Hives->GetItemText(container).ToStdString() == hive_name) - { - m_Hives->AppendItem(container, name); - - msg = wxString::Format(_("Added %s to %s"), name, hive_name); - break; - } - } - } - else - { - //Remove From Favorites - m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0); - - m_Database->UpdateFavoriteColumn(filename, 0); - m_Database->UpdateHiveName(filename, - m_Hives->GetItemText(favorites_hive).ToStdString()); - - for (int i = 0; i < m_Hives->GetChildCount(root); i++) - { - container = m_Hives->GetNthChild(root, i); - - for (int j = 0; j < m_Hives->GetChildCount(container); j++) - { - child = m_Hives->GetNthChild(container, j); - - if (m_Hives->GetItemText(child) == name) - { - m_Hives->DeleteItem(child); - - msg = wxString::Format(_("Removed %s from %s"), name, hive_name); - break; - } - } - } - } - } - break; - } - case MN_DeleteSample: - { - wxDataViewItemArray items; - int rows = m_Library->GetSelections(items); - - wxMessageDialog singleMsgDialog(this, wxString::Format(_("Are you sure you want to delete " - "%s from database? " - "Warning this change is " - "permanent, and cannot be undone."), - sample_path.AfterLast('/')), - wxMessageBoxCaptionStr, - wxYES_NO | wxNO_DEFAULT | - wxICON_QUESTION | wxSTAY_ON_TOP | - wxCENTER); - - wxMessageDialog multipleMsgDialog(this, wxString::Format(_("Are you sure you want to delete " - "%d selected samples from database? " - "Warning this change is " - "permanent, and cannot be " - "undone."), rows), - wxMessageBoxCaptionStr, - wxYES_NO | wxNO_DEFAULT | - wxICON_QUESTION | wxSTAY_ON_TOP | - wxCENTER); - - wxDataViewItem root = wxDataViewItem(wxNullPtr); - wxDataViewItem container; - wxDataViewItem child; - - if (m_Library->GetSelectedItemsCount() <= 1) - { - switch (singleMsgDialog.ShowModal()) - { - case wxID_YES: - { - m_Database->RemoveSampleFromDatabase(filename); - m_Library->DeleteItem(selected_row); - - for (int j = 0; j < m_Hives->GetChildCount(root); j++) - { - container = m_Hives->GetNthChild(root, j); - - for (int k = 0; k < m_Hives->GetChildCount(container); k++) - { - child = m_Hives->GetNthChild(container, k); - - wxString child_text = serializer.DeserializeShowFileExtension() ? - m_Hives->GetItemText(child).BeforeLast('.') : - m_Hives->GetItemText(child); - - if (child_text == filename) - { - m_Hives->DeleteItem(child); - - break; - } - } - } - - msg = wxString::Format(_("Deleted %s from database successfully"), selection); - } - break; - case wxID_NO: - msg = _("Cancel delete"); - break; - default: - wxMessageBox(_("Unexpected wxMessageDialog return code!"), _("Error!"), - wxOK | wxICON_ERROR | wxCENTRE, this); - } - } - else - { - switch (multipleMsgDialog.ShowModal()) - { - case wxID_YES: - { - for (int i = 0; i < rows; i++) - { - int row = m_Library->ItemToRow(items[i]); - - wxString text_value = m_Library->GetTextValue(row, 1); - - std::string multi_selection = serializer.DeserializeShowFileExtension() ? - text_value.BeforeLast('.').ToStdString() : text_value.ToStdString() ; - - m_Database->RemoveSampleFromDatabase(multi_selection); - m_Library->DeleteItem(row); - - for (int j = 0; j < m_Hives->GetChildCount(root); j++) - { - container = m_Hives->GetNthChild(root, j); - - for (int k = 0; k < m_Hives->GetChildCount(container); k++) - { - child = m_Hives->GetNthChild(container, k); - - wxString child_text = serializer.DeserializeShowFileExtension() ? - m_Hives->GetItemText(child).BeforeLast('.') : - m_Hives->GetItemText(child); - - if (child_text == multi_selection) - { - m_Hives->DeleteItem(child); - break; - } - } - } - - msg = wxString::Format(_("Deleted %s from database successfully"), text_value); - } - } - break; - case wxID_NO: - msg = _("Cancel delete"); - break; - default: - wxMessageBox(_("Unexpected wxMessageDialog return code!"), _("Error!"), - wxOK | wxICON_ERROR | wxCENTRE, this); - } - } - } - break; - case MN_TrashSample: - { - wxDataViewItem root = wxDataViewItem(wxNullPtr); - wxDataViewItem container, child; - - if (m_Database->IsTrashed(filename)) - SH_LOG_INFO("{} already trashed", filename); - else - { - wxDataViewItemArray items; - int rows = m_Library->GetSelections(items); - - wxString name; - wxFileDataObject file_data; - wxArrayString files; - - for (int i = 0; i < rows; i++) - { - int item_row = m_Library->ItemToRow(items[i]); - - wxString text_value = m_Library->GetTextValue(item_row, 1); - - std::string multi_selection = serializer.DeserializeShowFileExtension() ? - m_Library->GetTextValue(item_row, 1).BeforeLast('.').ToStdString() : - m_Library->GetTextValue(item_row, 1).ToStdString() ; - - file_data.AddFile(multi_selection); - - files = file_data.GetFilenames(); - - if (m_Database->GetFavoriteColumnValueByFilename(files[i].ToStdString())) - { - m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0); - - m_Database->UpdateFavoriteColumn(files[i].ToStdString(), 0); - - for (int j = 0; j < m_Hives->GetChildCount(root); j++) - { - container = m_Hives->GetNthChild(root, j); - - for (int k = 0; k < m_Hives->GetChildCount(container); k++) - { - child = m_Hives->GetNthChild(container, k); - - wxString child_text = serializer.DeserializeShowFileExtension() ? - m_Hives->GetItemText(child).BeforeLast('.') : - m_Hives->GetItemText(child); - - if (child_text == files[i]) - { - m_Hives->DeleteItem(child); - break; - } - } - } - } - - m_Database->UpdateTrashColumn(files[i].ToStdString(), 1); - m_Database->UpdateHiveName(files[i].ToStdString(), - m_Hives->GetItemText(favorites_hive).ToStdString()); - - m_Trash->AppendItem(trash_root, text_value); - - m_Library->DeleteItem(item_row); - - msg = wxString::Format(_("%s sent to trash"), text_value); - } - } - } - break; - case MN_EditTagSample: - { - tagEditor = new TagEditor(this, static_cast(sample_path)); - - switch (tagEditor->ShowModal()) - { - case wxID_OK: - SH_LOG_DEBUG("tags dialog ok, Return code: {}", tagEditor->GetReturnCode()); - break; - case wxID_APPLY: - SH_LOG_DEBUG("tags dialog apply, Return code: {}", tagEditor->GetReturnCode()); - break; - case wxID_CANCEL: - SH_LOG_DEBUG("tags dialog cancel, Return code: {}", tagEditor->GetReturnCode()); - break; - default: - msg = _("Unexpected TagEditor return code!"); - } - } - break; - case MN_OpenFile: - wxExecute(wxString::Format("xdg-open '%s'", sample_path.BeforeLast('/'))); - break; - case wxID_NONE: - return; - default: - wxMessageBox(_("Unexpected wxMenu return code!"), _("Error!"), - wxOK | wxICON_ERROR | wxCENTRE, this); - break; - } - - if(!msg.IsEmpty()) - m_InfoBar->ShowMessage(msg); -} - -void MainFrame::OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event) -{ - wxMenu menu; - - wxDataViewColumn* FavoriteColumn = m_Library->GetColumn(0); - wxDataViewColumn* FilenameColumn = m_Library->GetColumn(1); - wxDataViewColumn* SamplePackColumn = m_Library->GetColumn(2); - wxDataViewColumn* TypeColumn = m_Library->GetColumn(3); - wxDataViewColumn* ChannelsColumn = m_Library->GetColumn(4); - wxDataViewColumn* LengthColumn = m_Library->GetColumn(5); - wxDataViewColumn* SampleRateColumn = m_Library->GetColumn(6); - wxDataViewColumn* BitrateColumn = m_Library->GetColumn(7); - wxDataViewColumn* PathColumn = m_Library->GetColumn(8); - - menu.AppendCheckItem(MN_ColumnFavorite, _("Favorites"), - _("Toggle favorites column"))->Check(FavoriteColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnFilename, _("Filename"), - _("Toggle filename column"))->Check(FilenameColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnSamplePack, _("Sample Pack"), - _("Toggle sample pack column"))->Check(SamplePackColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnType, _("Type"), - _("Toggle type column"))->Check(TypeColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnChannels, _("Channels"), - _("Toggle channels column"))->Check(ChannelsColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnLength, _("Length"), - _("Toggle length column"))->Check(LengthColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnSampleRate, _("Sample Rate"), - _("Toggle sample rate column"))->Check(SampleRateColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnBitrate, _("Bitrate"), - _("Toggle bitrate column"))->Check(BitrateColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnPath, _("Path"), - _("Toggle path column"))->Check(PathColumn->IsShown()); - - switch (m_Library->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) - { - case MN_ColumnFavorite: - FavoriteColumn->SetHidden(!menu.IsChecked(MN_ColumnFavorite)); - break; - case MN_ColumnFilename: - FilenameColumn->SetHidden(!menu.IsChecked(MN_ColumnFilename)); - break; - case MN_ColumnSamplePack: - SamplePackColumn->SetHidden(!menu.IsChecked(MN_ColumnSamplePack)); - break; - case MN_ColumnType: - TypeColumn->SetHidden(!menu.IsChecked(MN_ColumnType)); - break; - case MN_ColumnChannels: - ChannelsColumn->SetHidden(!menu.IsChecked(MN_ColumnChannels)); - break; - case MN_ColumnLength: - LengthColumn->SetHidden(!menu.IsChecked(MN_ColumnLength)); - break; - case MN_ColumnSampleRate: - SampleRateColumn->SetHidden(!menu.IsChecked(MN_ColumnSampleRate)); - break; - case MN_ColumnBitrate: - BitrateColumn->SetHidden(!menu.IsChecked(MN_ColumnBitrate)); - break; - case MN_ColumnPath: - PathColumn->SetHidden(!menu.IsChecked(MN_ColumnPath)); - break; - default: - break; - } -} - -void MainFrame::LoadDatabase() -{ - Serializer serializer; - - try - { - const auto dataset = m_Database->LoadSamplesDatabase(*m_Hives, favorites_hive, - *m_Trash, trash_root, - serializer.DeserializeShowFileExtension(), - ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); - - if (dataset.empty()) - SH_LOG_INFO("Error! Database is empty."); - else - { - for (auto data : dataset) - m_Library->AppendItem(data); - } - - m_Database->LoadHivesDatabase(*m_Hives); - } - catch(...) - { - std::cerr << "Error loading data." << std::endl; - } -} - -void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event) -{ - Serializer serializer; - - wxTreeItemId selected_trashed_item = event.GetItem(); - - wxMenu menu; - - menu.Append(MN_DeleteTrash, _("Delete from database"), _("Delete the selected sample(s) from database")); - menu.Append(MN_RestoreTrashedItem, _("Restore sample"), _("Restore the selected sample(s) back to library")); - - if (selected_trashed_item.IsOk()) - { - switch (m_Trash->GetPopupMenuSelectionFromUser(menu, event.GetPoint())) - { - case MN_DeleteTrash: - { - wxString trashed_item_name = serializer.DeserializeShowFileExtension() ? - m_Trash->GetItemText(selected_trashed_item).BeforeLast('.') : - m_Trash->GetItemText(selected_trashed_item); - - m_Database->RemoveSampleFromDatabase(trashed_item_name.ToStdString()); - - m_Trash->Delete(selected_trashed_item); - - SH_LOG_INFO("{} deleted from trash and databse", trashed_item_name); - } - break; - case MN_RestoreTrashedItem: - { - wxArrayTreeItemIds selected_item_ids; - m_Trash->GetSelections(selected_item_ids); - - wxFileDataObject file_data; - wxArrayString files; - - wxString selected_item_text; - std::string filename; - - for (size_t i = 0; i < selected_item_ids.GetCount(); i++) - { - selected_item_text = m_Trash->GetItemText(selected_item_ids[i]); - - filename = GetFilenamePathAndExtension(selected_item_text).Filename; - - file_data.AddFile(filename); - - files = file_data.GetFilenames(); - - m_Database->UpdateTrashColumn(files[i].ToStdString(), 0); - - try - { - wxVector> dataset; - - if (m_Database->RestoreFromTrashByFilename(files[i].ToStdString(), - dataset, - serializer.DeserializeShowFileExtension(), - ICON_STAR_FILLED_16px, - ICON_STAR_EMPTY_16px).empty()) - { - SH_LOG_INFO("Error! Database is empty."); - } - else - { - for (auto data : dataset) - { - m_Library->AppendItem(data); - } - } - } - catch (...) - { - std::cerr << "Error loading data." << std::endl; - } - - m_Trash->Delete(selected_item_ids[i]); - - SH_LOG_INFO("{} restored from trash", files[i]); - } - } - break; - default: - break; - } - } -} - -void MainFrame::OnDragAndDropToTrash(wxDropFilesEvent& event) -{ - Serializer serializer; +// void MainFrame::OnClickLibrary(wxDataViewEvent& event) +// { +// int selected_row = m_Library->ItemToRow(event.GetItem()); +// int current_row = m_Library->ItemToRow(m_Library->GetCurrentItem()); + +// if (selected_row < 0 || !event.GetItem().IsOk()) +// return; + +// if (selected_row != current_row) +// { +// m_Library->SetCurrentItem(event.GetItem()); +// return; +// } + +// // Update the waveform bitmap +// m_WaveformViewer->ResetDC(); + +// m_TransportControls->SetLoopABValue(false); + +// if (m_Timer->IsRunning()) +// { +// m_Timer->Stop(); +// SH_LOG_DEBUG("TIMER STOPPED"); +// } + +// wxString selection = m_Library->GetTextValue(selected_row, 1); + +// // Get curremt column +// wxDataViewColumn* CurrentColumn = m_Library->GetCurrentColumn(); + +// // Get favorite column +// wxDataViewColumn* FavoriteColumn = m_Library->GetColumn(0); + +// if (!CurrentColumn) +// return; + +// wxString sample_path = GetFilenamePathAndExtension(selection).Path; +// std::string filename = GetFilenamePathAndExtension(selection).Filename; +// std::string extension = GetFilenamePathAndExtension(selection).Extension; + +// if (CurrentColumn != FavoriteColumn) +// { +// ClearLoopPoints(); + +// if (m_TransportControls->CanAutoplay()) +// { +// if (bLoopPointsSet && m_TransportControls->IsLoopABOn()) +// PlaySample(sample_path.ToStdString(), selection.ToStdString(), +// true, m_LoopA.ToDouble(), wxFromStart); +// else +// PlaySample(sample_path.ToStdString(), selection.ToStdString()); +// } +// else +// m_MediaCtrl->Stop(); +// } +// else +// { +// wxString msg; + +// // Get hive name and location +// std::string hive_name = m_Hives->GetItemText(favorites_hive).ToStdString(); +// wxDataViewItem hive_selection = m_Hives->GetSelection(); + +// if (hive_selection.IsOk() && m_Hives->IsContainer(hive_selection)) +// hive_name = m_Hives->GetItemText(hive_selection).ToStdString(); + +// wxString name = m_Library->GetTextValue(selected_row, 1); + +// // Get root +// wxDataViewItem root = wxDataViewItem(wxNullPtr); +// wxDataViewItem container; +// wxDataViewItem child; + +// if (m_Database->GetFavoriteColumnValueByFilename(filename) == 0) +// { +// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0); + +// m_Database->UpdateFavoriteColumn(filename, 1); +// m_Database->UpdateHiveName(filename, hive_name); + +// for (int i = 0; i < m_Hives->GetChildCount(root); i++) +// { +// container = m_Hives->GetNthChild(root, i); + +// if (m_Hives->GetItemText(container).ToStdString() == hive_name) +// { +// m_Hives->AppendItem(container, name); +// break; +// } +// } + +// msg = wxString::Format(_("Added %s to %s"), name, hive_name); +// } +// else +// { +// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0); + +// m_Database->UpdateFavoriteColumn(filename, 0); +// m_Database->UpdateHiveName(filename, m_Hives->GetItemText(favorites_hive).ToStdString()); + +// for (int i = 0; i < m_Hives->GetChildCount(root); i++) +// { +// container = m_Hives->GetNthChild(root, i); + +// for (int j = 0; j < m_Hives->GetChildCount(container); j++) +// { +// child = m_Hives->GetNthChild(container, j); + +// if (m_Hives->GetItemText(child) == name) +// { +// m_Hives->DeleteItem(child); +// break; +// } +// } +// } + +// msg = wxString::Format(_("Removed %s from %s"), name, hive_name); +// } + +// if (!msg.IsEmpty()) +// m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); +// } +// } + +// void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) +// { +// Serializer serializer; + +// wxDataViewItem selected_hive = event.GetItem(); + +// wxString hive_name = m_Hives->GetItemText(selected_hive); + +// wxMenu menu; + +// if (m_Hives->IsContainer(selected_hive)) +// { +// // Container menu items +// menu.Append(MN_RenameHive, _("Rename hive"), _("Rename selected hive")); +// menu.Append(MN_DeleteHive, _("Delete hive"), _("Delete selected hive")); + +// if (!bFiltered) +// menu.Append(MN_FilterLibrary, _("Filter library"), +// _("Show only samples from current hive in library")); +// else +// menu.Append(MN_FilterLibrary, _("Clear filter"), _("Clear the filter")); +// } +// else +// { +// // Child menu items +// menu.Append(MN_RemoveSample, _("Remove sample"), _("Remove the selected sample(s)")); +// menu.Append(MN_ShowInLibrary, _("Show sample in library"), _("Show the selected in library")); +// } + +// if (selected_hive.IsOk() && m_Hives->IsContainer(selected_hive)) +// { +// switch (m_Hives->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) +// { +// case MN_RenameHive: +// { +// std::deque nodes; +// nodes.push_back(m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0)); + +// wxDataViewItem current_item, found_item; + +// int row = 0; +// int hive_count = m_Hives->GetChildCount(wxDataViewItem(wxNullPtr)); + +// wxString msg; + +// wxTextEntryDialog renameEntry(this, _("Enter new name"), wxGetTextFromUserPromptStr, +// wxEmptyString, wxTextEntryDialogStyle, wxDefaultPosition); + +// renameEntry.SetTextValidator(wxFILTER_EMPTY); + +// switch (renameEntry.ShowModal()) +// { +// case wxID_OK: +// { +// wxString hive_name = renameEntry.GetValue(); + +// while(!nodes.empty()) +// { +// current_item = nodes.front(); +// nodes.pop_front(); + +// if (m_Hives->GetItemText(current_item) == hive_name) +// { +// found_item = current_item; +// SH_LOG_DEBUG("Found item: {}", m_Hives->GetItemText(current_item)); +// break; +// } + +// wxDataViewItem child = m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0); + +// while (row < (hive_count - 1)) +// { +// row ++; + +// child = m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), row); +// nodes.push_back(child); +// } +// } + +// nodes.clear(); + +// if (found_item.IsOk()) +// { +// wxMessageBox(wxString::Format(_("Another hive by the name %s already exist. " +// "Please try with a different name."), +// hive_name), +// _("Error!"), wxOK | wxCENTRE, this); +// } +// else +// { +// wxString selected_hive_name = m_Hives->GetItemText(selected_hive); + +// int sample_count = m_Hives->GetChildCount(selected_hive); + +// if (sample_count <= 0) +// { +// m_Hives->SetItemText(selected_hive, hive_name); +// m_Database->UpdateHive(selected_hive_name.ToStdString(), +// hive_name.ToStdString()); +// } +// else +// { +// for (int i = 0; i < sample_count; i++) +// { +// wxDataViewItem sample_item = m_Hives->GetNthChild(selected_hive, i); + +// wxString sample_name = serializer.DeserializeShowFileExtension() ? +// m_Hives->GetItemText(sample_item).BeforeLast('.') : +// m_Hives->GetItemText(sample_item); + +// m_Database->UpdateHiveName(sample_name.ToStdString(), +// hive_name.ToStdString()); +// m_Database->UpdateHive(selected_hive_name.ToStdString(), +// hive_name.ToStdString()); + +// m_Hives->SetItemText(selected_hive, hive_name); +// } +// } + +// msg = wxString::Format(_("Successfully changed hive name to %s."), hive_name); +// } +// } +// break; +// case wxID_CANCEL: +// break; +// default: +// return; +// } + +// if (!msg.IsEmpty()) +// m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); +// } +// break; +// case MN_DeleteHive: +// { +// wxString msg; + +// wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to " +// "delete %s from hives?"), +// hive_name), +// wxMessageBoxCaptionStr, +// wxYES_NO | wxNO_DEFAULT | +// wxICON_QUESTION | wxSTAY_ON_TOP); + +// wxMessageDialog deleteFilledHiveDialog(this, wxString::Format(_("Are you sure you want to " +// "delete %s and all samples " +// "inside %s from hives?"), +// hive_name, hive_name), +// wxMessageBoxCaptionStr, +// wxYES_NO | wxNO_DEFAULT | +// wxICON_QUESTION | wxSTAY_ON_TOP); + +// if (hive_name == m_Hives->GetItemText(favorites_hive)) +// { +// wxMessageBox(wxString::Format(_("Error! Default hive %s cannot be deleted."), hive_name), +// _("Error!"), wxOK | wxCENTRE, this); +// return; +// } +// else if (!selected_hive.IsOk()) +// { +// wxMessageBox(_("No hive selected, try selecting a hive first"), _("Error!"), +// wxOK | wxCENTRE, this); +// return; +// } +// else if (selected_hive.IsOk() && !m_Hives->IsContainer(selected_hive)) +// { +// wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from hives."), +// hive_name), +// _("Error!"), wxOK | wxCENTRE, this); +// return; +// } + +// if(m_Hives->GetChildCount(selected_hive) <= 0) +// { +// switch (deleteEmptyHiveDialog.ShowModal()) +// { +// case wxID_YES: +// if (selected_hive.IsOk() && m_Hives->IsContainer(selected_hive) && +// hive_name != m_Hives->GetItemText(favorites_hive)) +// { +// m_Hives->DeleteItem(selected_hive); + +// m_Database->RemoveHiveFromDatabase(hive_name.ToStdString()); + +// msg = wxString::Format(_("%s deleted from hives successfully."), hive_name); +// } +// break; +// case wxID_NO: +// break; +// default: +// return; +// } +// } +// else +// { +// switch (deleteFilledHiveDialog.ShowModal()) +// { +// case wxID_YES: +// if (selected_hive.IsOk() && m_Hives->IsContainer(selected_hive) && +// hive_name != m_Hives->GetItemText(favorites_hive)) +// { +// wxDataViewItem child_item; + +// for (int i = 0; i < m_Library->GetItemCount(); i++) +// { +// wxString matched_sample = +// serializer.DeserializeShowFileExtension() ? +// m_Library->GetTextValue(i, 1).BeforeLast('.') : +// m_Library->GetTextValue(i, 1); + +// for (int j = 0; j < m_Hives->GetChildCount(selected_hive); j++) +// { +// child_item = m_Hives->GetNthChild(selected_hive, j); + +// wxString child_name = +// serializer.DeserializeShowFileExtension() ? +// m_Hives->GetItemText(child_item).BeforeLast('.') : +// m_Hives->GetItemText(child_item); + +// if (child_name == matched_sample) +// { +// SH_LOG_DEBUG("Found match"); + +// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), +// i, 0); + +// m_Database->UpdateFavoriteColumn(matched_sample.ToStdString(), 0); +// m_Database->UpdateHiveName(matched_sample.ToStdString(), +// m_Hives->GetItemText(favorites_hive).ToStdString()); + +// break; +// } +// else +// SH_LOG_DEBUG("No match found"); +// } +// } + +// m_Hives->DeleteChildren(selected_hive); +// m_Hives->DeleteItem(selected_hive); + +// m_Database->RemoveHiveFromDatabase(hive_name.ToStdString()); + +// msg = wxString::Format(_("%s and all samples inside %s " +// "have been deleted from hives successfully."), +// hive_name, hive_name); +// } +// break; +// case wxID_NO: +// break; +// default: +// return; +// } +// } + +// if (!msg.IsEmpty()) +// m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); +// } +// break; +// case MN_FilterLibrary: +// { +// if (!bFiltered) +// { +// try +// { +// const auto dataset = m_Database->FilterDatabaseByHiveName(hive_name.ToStdString(), +// serializer.DeserializeShowFileExtension(), +// ICON_STAR_FILLED_16px, +// ICON_STAR_EMPTY_16px); + +// if (dataset.empty()) +// { +// wxMessageBox(_("Error! Database is empty."), _("Error!"), +// wxOK | wxICON_ERROR | wxCENTRE, this); +// return; +// } +// else +// { +// m_Library->DeleteAllItems(); + +// for (auto data : dataset) +// { +// m_Library->AppendItem(data); +// } +// } +// } +// catch (...) +// { +// wxMessageBox(_("Error loading data, cannot filter sample view"), _("Error!"), +// wxOK | wxICON_ERROR | wxCENTRE, this); +// } + +// bFiltered = true; +// } +// else +// { +// try +// { +// const auto dataset = m_Database->FilterDatabaseBySampleName("", serializer.DeserializeShowFileExtension(), +// ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); + +// if (dataset.empty()) +// { +// wxMessageBox(_("Error! Database is empty."), _("Error!"), +// wxOK | wxICON_ERROR | wxCENTRE, this); +// } +// else +// { +// m_Library->DeleteAllItems(); + +// for (auto data : dataset) +// { +// m_Library->AppendItem(data); +// } +// } +// } +// catch (...) +// { +// wxMessageBox(_("Error loading data, cannot filter sample view"), _("Error!"), +// wxOK | wxICON_ERROR | wxCENTRE, this); +// } + +// bFiltered = false; +// } +// } +// break; +// default: +// return; +// } +// } +// else if (selected_hive.IsOk() && !m_Hives->IsContainer(selected_hive)) +// { +// switch (m_Hives->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) +// { +// case MN_RemoveSample: +// for(int i = 0; i < m_Library->GetItemCount(); i++) +// { +// wxString matched_sample = serializer.DeserializeShowFileExtension() ? +// m_Library->GetTextValue(i, 1).BeforeLast('.') : +// m_Library->GetTextValue(i, 1); + +// wxString selected_sample_name = serializer.DeserializeShowFileExtension() ? +// m_Hives->GetItemText(event.GetItem()).BeforeLast('.') : +// m_Hives->GetItemText(event.GetItem()); + +// if(selected_sample_name == matched_sample) +// { +// SH_LOG_DEBUG("Found match"); + +// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); + +// m_Database->UpdateFavoriteColumn(matched_sample.ToStdString(), 0); +// m_Database->UpdateHiveName(matched_sample.ToStdString(), +// m_Hives->GetItemText(favorites_hive).ToStdString()); + +// m_Hives->DeleteItem(selected_hive); + +// break; +// } + +// m_InfoBar->ShowMessage(wxString::Format(_("Removed %s from %s"), +// m_Hives->GetItemText(event.GetItem()), +// m_Database->GetHiveByFilename(matched_sample.ToStdString())), +// wxICON_INFORMATION); +// } +// break; +// case MN_ShowInLibrary: +// for(int i = 0; i < m_Library->GetItemCount(); i++) +// { +// wxString matched_sample = serializer.DeserializeShowFileExtension() ? +// m_Library->GetTextValue(i, 1).BeforeLast('.') : +// m_Library->GetTextValue(i, 1); + +// wxString selected_sample_name = serializer.DeserializeShowFileExtension() ? +// m_Hives->GetItemText(event.GetItem()).BeforeLast('.') : +// m_Hives->GetItemText(event.GetItem()); + +// if(selected_sample_name == matched_sample) +// { +// SH_LOG_DEBUG("Found match"); + +// wxDataViewItem matched_item = m_Library->RowToItem(i); + +// m_Library->UnselectAll(); +// m_Library->SelectRow(i); +// m_Library->EnsureVisible(matched_item); + +// break; +// } +// } +// break; +// default: +// return; +// } +// } +// } + +// void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event) +// { +// TagEditor* tagEditor; +// Serializer serializer; + +// wxString msg; + +// wxDataViewItem item = event.GetItem(); +// int selected_row; + +// if (item.IsOk()) +// selected_row = m_Library->ItemToRow(item); +// else +// return; + +// wxString selection = m_Library->GetTextValue(selected_row, 1); + +// wxString sample_path = GetFilenamePathAndExtension(selection).Path; +// std::string filename = GetFilenamePathAndExtension(selection).Filename; +// std::string extension = GetFilenamePathAndExtension(selection).Extension; + +// wxMenu menu; + +// //true = add false = remove +// bool favorite_add = false; + +// if (m_Database->GetFavoriteColumnValueByFilename(filename) == 1) +// menu.Append(MN_FavoriteSample, _("Remove from hive"), _("Remove the selected sample(s) from hive")); +// else +// { +// menu.Append(MN_FavoriteSample, _("Add to hive"), _("Add selected sample(s) to hive")); +// favorite_add = true; +// } + +// menu.Append(MN_DeleteSample, _("Delete"), _("Delete the selected sample(s) from database")); +// menu.Append(MN_TrashSample, _("Trash"), _("Send the selected sample(s) to trash")); + +// if (m_Library->GetSelectedItemsCount() <= 1) +// { +// menu.Append(MN_EditTagSample, _("Edit tags"), +// _("Edit the tags for the selected sample"))->Enable(true); +// menu.Append(MN_OpenFile, _("Open in file manager"), +// _("Open the selected sample in system's file manager"))->Enable(true); +// } +// else +// { +// menu.Append(MN_EditTagSample, _("Edit tags"), +// _("Edit the tags for the selected sample"))->Enable(false); +// menu.Append(MN_OpenFile, _("Open in file manager"), +// _("Open the selected sample in system's file manager"))->Enable(false); +// } + +// switch (m_Library->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) +// { +// case MN_FavoriteSample: +// { +// std::string hive_name = m_Hives->GetItemText(favorites_hive).ToStdString(); + +// wxDataViewItem hive_selection = m_Hives->GetSelection(); + +// if (hive_selection.IsOk() && m_Hives->IsContainer(hive_selection)) +// hive_name = m_Hives->GetItemText(hive_selection).ToStdString(); + +// wxDataViewItem root = wxDataViewItem(wxNullPtr); +// wxDataViewItem container; +// wxDataViewItem child; + +// wxDataViewItemArray samples; +// int sample_count = m_Library->GetSelections(samples); +// int selected_row = 0; +// int db_status = 0; + +// for (int k = 0; k < sample_count; k++) +// { +// selected_row = m_Library->ItemToRow(samples[k]); + +// if (selected_row < 0) +// continue; + +// wxString name = m_Library->GetTextValue(selected_row, 1); + +// filename = serializer.DeserializeShowFileExtension() ? +// name.BeforeLast('.').ToStdString() : name.ToStdString(); + +// db_status = m_Database->GetFavoriteColumnValueByFilename(filename); + +// // Aleady Added, Do Nothing +// if (favorite_add && db_status == 1) +// continue; + +// // Already Removed, Do Nothing +// if (!favorite_add && db_status == 0) +// continue; + +// // Add To Favorites +// if (favorite_add && db_status == 0) +// { +// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0); + +// m_Database->UpdateFavoriteColumn(filename, 1); +// m_Database->UpdateHiveName(filename, hive_name); + +// for (int i = 0; i < m_Hives->GetChildCount(root); i++) +// { +// container = m_Hives->GetNthChild(root, i); + +// if (m_Hives->GetItemText(container).ToStdString() == hive_name) +// { +// m_Hives->AppendItem(container, name); + +// msg = wxString::Format(_("Added %s to %s"), name, hive_name); +// break; +// } +// } +// } +// else +// { +// //Remove From Favorites +// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0); + +// m_Database->UpdateFavoriteColumn(filename, 0); +// m_Database->UpdateHiveName(filename, +// m_Hives->GetItemText(favorites_hive).ToStdString()); + +// for (int i = 0; i < m_Hives->GetChildCount(root); i++) +// { +// container = m_Hives->GetNthChild(root, i); + +// for (int j = 0; j < m_Hives->GetChildCount(container); j++) +// { +// child = m_Hives->GetNthChild(container, j); + +// if (m_Hives->GetItemText(child) == name) +// { +// m_Hives->DeleteItem(child); + +// msg = wxString::Format(_("Removed %s from %s"), name, hive_name); +// break; +// } +// } +// } +// } +// } +// break; +// } +// case MN_DeleteSample: +// { +// wxDataViewItemArray items; +// int rows = m_Library->GetSelections(items); + +// wxMessageDialog singleMsgDialog(this, wxString::Format(_("Are you sure you want to delete " +// "%s from database? " +// "Warning this change is " +// "permanent, and cannot be undone."), +// sample_path.AfterLast('/')), +// wxMessageBoxCaptionStr, +// wxYES_NO | wxNO_DEFAULT | +// wxICON_QUESTION | wxSTAY_ON_TOP | +// wxCENTER); + +// wxMessageDialog multipleMsgDialog(this, wxString::Format(_("Are you sure you want to delete " +// "%d selected samples from database? " +// "Warning this change is " +// "permanent, and cannot be " +// "undone."), rows), +// wxMessageBoxCaptionStr, +// wxYES_NO | wxNO_DEFAULT | +// wxICON_QUESTION | wxSTAY_ON_TOP | +// wxCENTER); + +// wxDataViewItem root = wxDataViewItem(wxNullPtr); +// wxDataViewItem container; +// wxDataViewItem child; + +// if (m_Library->GetSelectedItemsCount() <= 1) +// { +// switch (singleMsgDialog.ShowModal()) +// { +// case wxID_YES: +// { +// m_Database->RemoveSampleFromDatabase(filename); +// m_Library->DeleteItem(selected_row); + +// for (int j = 0; j < m_Hives->GetChildCount(root); j++) +// { +// container = m_Hives->GetNthChild(root, j); + +// for (int k = 0; k < m_Hives->GetChildCount(container); k++) +// { +// child = m_Hives->GetNthChild(container, k); + +// wxString child_text = serializer.DeserializeShowFileExtension() ? +// m_Hives->GetItemText(child).BeforeLast('.') : +// m_Hives->GetItemText(child); + +// if (child_text == filename) +// { +// m_Hives->DeleteItem(child); + +// break; +// } +// } +// } + +// msg = wxString::Format(_("Deleted %s from database successfully"), selection); +// } +// break; +// case wxID_NO: +// msg = _("Cancel delete"); +// break; +// default: +// wxMessageBox(_("Unexpected wxMessageDialog return code!"), _("Error!"), +// wxOK | wxICON_ERROR | wxCENTRE, this); +// } +// } +// else +// { +// switch (multipleMsgDialog.ShowModal()) +// { +// case wxID_YES: +// { +// for (int i = 0; i < rows; i++) +// { +// int row = m_Library->ItemToRow(items[i]); + +// wxString text_value = m_Library->GetTextValue(row, 1); + +// std::string multi_selection = serializer.DeserializeShowFileExtension() ? +// text_value.BeforeLast('.').ToStdString() : text_value.ToStdString() ; + +// m_Database->RemoveSampleFromDatabase(multi_selection); +// m_Library->DeleteItem(row); + +// for (int j = 0; j < m_Hives->GetChildCount(root); j++) +// { +// container = m_Hives->GetNthChild(root, j); + +// for (int k = 0; k < m_Hives->GetChildCount(container); k++) +// { +// child = m_Hives->GetNthChild(container, k); + +// wxString child_text = serializer.DeserializeShowFileExtension() ? +// m_Hives->GetItemText(child).BeforeLast('.') : +// m_Hives->GetItemText(child); + +// if (child_text == multi_selection) +// { +// m_Hives->DeleteItem(child); +// break; +// } +// } +// } + +// msg = wxString::Format(_("Deleted %s from database successfully"), text_value); +// } +// } +// break; +// case wxID_NO: +// msg = _("Cancel delete"); +// break; +// default: +// wxMessageBox(_("Unexpected wxMessageDialog return code!"), _("Error!"), +// wxOK | wxICON_ERROR | wxCENTRE, this); +// } +// } +// } +// break; +// case MN_TrashSample: +// { +// wxDataViewItem root = wxDataViewItem(wxNullPtr); +// wxDataViewItem container, child; + +// if (m_Database->IsTrashed(filename)) +// SH_LOG_INFO("{} already trashed", filename); +// else +// { +// wxDataViewItemArray items; +// int rows = m_Library->GetSelections(items); + +// wxString name; +// wxFileDataObject file_data; +// wxArrayString files; + +// for (int i = 0; i < rows; i++) +// { +// int item_row = m_Library->ItemToRow(items[i]); + +// wxString text_value = m_Library->GetTextValue(item_row, 1); + +// std::string multi_selection = serializer.DeserializeShowFileExtension() ? +// m_Library->GetTextValue(item_row, 1).BeforeLast('.').ToStdString() : +// m_Library->GetTextValue(item_row, 1).ToStdString() ; + +// file_data.AddFile(multi_selection); + +// files = file_data.GetFilenames(); + +// if (m_Database->GetFavoriteColumnValueByFilename(files[i].ToStdString())) +// { +// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0); + +// m_Database->UpdateFavoriteColumn(files[i].ToStdString(), 0); + +// for (int j = 0; j < m_Hives->GetChildCount(root); j++) +// { +// container = m_Hives->GetNthChild(root, j); + +// for (int k = 0; k < m_Hives->GetChildCount(container); k++) +// { +// child = m_Hives->GetNthChild(container, k); + +// wxString child_text = serializer.DeserializeShowFileExtension() ? +// m_Hives->GetItemText(child).BeforeLast('.') : +// m_Hives->GetItemText(child); + +// if (child_text == files[i]) +// { +// m_Hives->DeleteItem(child); +// break; +// } +// } +// } +// } + +// m_Database->UpdateTrashColumn(files[i].ToStdString(), 1); +// m_Database->UpdateHiveName(files[i].ToStdString(), +// m_Hives->GetItemText(favorites_hive).ToStdString()); + +// m_Trash->AppendItem(trash_root, text_value); + +// m_Library->DeleteItem(item_row); + +// msg = wxString::Format(_("%s sent to trash"), text_value); +// } +// } +// } +// break; +// case MN_EditTagSample: +// { +// tagEditor = new TagEditor(this, static_cast(sample_path)); + +// switch (tagEditor->ShowModal()) +// { +// case wxID_OK: +// SH_LOG_DEBUG("tags dialog ok, Return code: {}", tagEditor->GetReturnCode()); +// break; +// case wxID_APPLY: +// SH_LOG_DEBUG("tags dialog apply, Return code: {}", tagEditor->GetReturnCode()); +// break; +// case wxID_CANCEL: +// SH_LOG_DEBUG("tags dialog cancel, Return code: {}", tagEditor->GetReturnCode()); +// break; +// default: +// msg = _("Unexpected TagEditor return code!"); +// } +// } +// break; +// case MN_OpenFile: +// wxExecute(wxString::Format("xdg-open '%s'", sample_path.BeforeLast('/'))); +// break; +// case wxID_NONE: +// return; +// default: +// wxMessageBox(_("Unexpected wxMenu return code!"), _("Error!"), +// wxOK | wxICON_ERROR | wxCENTRE, this); +// break; +// } + +// if(!msg.IsEmpty()) +// m_InfoBar->ShowMessage(msg); +// } + +// void MainFrame::OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event) +// { +// wxMenu menu; + +// wxDataViewColumn* FavoriteColumn = m_Library->GetColumn(0); +// wxDataViewColumn* FilenameColumn = m_Library->GetColumn(1); +// wxDataViewColumn* SamplePackColumn = m_Library->GetColumn(2); +// wxDataViewColumn* TypeColumn = m_Library->GetColumn(3); +// wxDataViewColumn* ChannelsColumn = m_Library->GetColumn(4); +// wxDataViewColumn* LengthColumn = m_Library->GetColumn(5); +// wxDataViewColumn* SampleRateColumn = m_Library->GetColumn(6); +// wxDataViewColumn* BitrateColumn = m_Library->GetColumn(7); +// wxDataViewColumn* PathColumn = m_Library->GetColumn(8); + +// menu.AppendCheckItem(MN_ColumnFavorite, _("Favorites"), +// _("Toggle favorites column"))->Check(FavoriteColumn->IsShown()); +// menu.AppendCheckItem(MN_ColumnFilename, _("Filename"), +// _("Toggle filename column"))->Check(FilenameColumn->IsShown()); +// menu.AppendCheckItem(MN_ColumnSamplePack, _("Sample Pack"), +// _("Toggle sample pack column"))->Check(SamplePackColumn->IsShown()); +// menu.AppendCheckItem(MN_ColumnType, _("Type"), +// _("Toggle type column"))->Check(TypeColumn->IsShown()); +// menu.AppendCheckItem(MN_ColumnChannels, _("Channels"), +// _("Toggle channels column"))->Check(ChannelsColumn->IsShown()); +// menu.AppendCheckItem(MN_ColumnLength, _("Length"), +// _("Toggle length column"))->Check(LengthColumn->IsShown()); +// menu.AppendCheckItem(MN_ColumnSampleRate, _("Sample Rate"), +// _("Toggle sample rate column"))->Check(SampleRateColumn->IsShown()); +// menu.AppendCheckItem(MN_ColumnBitrate, _("Bitrate"), +// _("Toggle bitrate column"))->Check(BitrateColumn->IsShown()); +// menu.AppendCheckItem(MN_ColumnPath, _("Path"), +// _("Toggle path column"))->Check(PathColumn->IsShown()); + +// switch (m_Library->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) +// { +// case MN_ColumnFavorite: +// FavoriteColumn->SetHidden(!menu.IsChecked(MN_ColumnFavorite)); +// break; +// case MN_ColumnFilename: +// FilenameColumn->SetHidden(!menu.IsChecked(MN_ColumnFilename)); +// break; +// case MN_ColumnSamplePack: +// SamplePackColumn->SetHidden(!menu.IsChecked(MN_ColumnSamplePack)); +// break; +// case MN_ColumnType: +// TypeColumn->SetHidden(!menu.IsChecked(MN_ColumnType)); +// break; +// case MN_ColumnChannels: +// ChannelsColumn->SetHidden(!menu.IsChecked(MN_ColumnChannels)); +// break; +// case MN_ColumnLength: +// LengthColumn->SetHidden(!menu.IsChecked(MN_ColumnLength)); +// break; +// case MN_ColumnSampleRate: +// SampleRateColumn->SetHidden(!menu.IsChecked(MN_ColumnSampleRate)); +// break; +// case MN_ColumnBitrate: +// BitrateColumn->SetHidden(!menu.IsChecked(MN_ColumnBitrate)); +// break; +// case MN_ColumnPath: +// PathColumn->SetHidden(!menu.IsChecked(MN_ColumnPath)); +// break; +// default: +// break; +// } +// } + +// void MainFrame::LoadDatabase() +// { +// Serializer serializer; + +// try +// { +// const auto dataset = m_Database->LoadSamplesDatabase(*m_Hives, favorites_hive, +// *m_Trash, trash_root, +// serializer.DeserializeShowFileExtension(), +// ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); + +// if (dataset.empty()) +// SH_LOG_INFO("Error! Database is empty."); +// else +// { +// for (auto data : dataset) +// m_Library->AppendItem(data); +// } + +// m_Database->LoadHivesDatabase(*m_Hives); +// } +// catch(...) +// { +// std::cerr << "Error loading data." << std::endl; +// } +// } + +// void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event) +// { +// Serializer serializer; + +// wxTreeItemId selected_trashed_item = event.GetItem(); + +// wxMenu menu; + +// menu.Append(MN_DeleteTrash, _("Delete from database"), _("Delete the selected sample(s) from database")); +// menu.Append(MN_RestoreTrashedItem, _("Restore sample"), _("Restore the selected sample(s) back to library")); + +// if (selected_trashed_item.IsOk()) +// { +// switch (m_Trash->GetPopupMenuSelectionFromUser(menu, event.GetPoint())) +// { +// case MN_DeleteTrash: +// { +// wxString trashed_item_name = serializer.DeserializeShowFileExtension() ? +// m_Trash->GetItemText(selected_trashed_item).BeforeLast('.') : +// m_Trash->GetItemText(selected_trashed_item); + +// m_Database->RemoveSampleFromDatabase(trashed_item_name.ToStdString()); + +// m_Trash->Delete(selected_trashed_item); + +// SH_LOG_INFO("{} deleted from trash and databse", trashed_item_name); +// } +// break; +// case MN_RestoreTrashedItem: +// { +// wxArrayTreeItemIds selected_item_ids; +// m_Trash->GetSelections(selected_item_ids); + +// wxFileDataObject file_data; +// wxArrayString files; + +// wxString selected_item_text; +// std::string filename; + +// for (size_t i = 0; i < selected_item_ids.GetCount(); i++) +// { +// selected_item_text = m_Trash->GetItemText(selected_item_ids[i]); + +// filename = GetFilenamePathAndExtension(selected_item_text).Filename; + +// file_data.AddFile(filename); + +// files = file_data.GetFilenames(); + +// m_Database->UpdateTrashColumn(files[i].ToStdString(), 0); + +// try +// { +// wxVector> dataset; + +// if (m_Database->RestoreFromTrashByFilename(files[i].ToStdString(), +// dataset, +// serializer.DeserializeShowFileExtension(), +// ICON_STAR_FILLED_16px, +// ICON_STAR_EMPTY_16px).empty()) +// { +// SH_LOG_INFO("Error! Database is empty."); +// } +// else +// { +// for (auto data : dataset) +// { +// m_Library->AppendItem(data); +// } +// } +// } +// catch (...) +// { +// std::cerr << "Error loading data." << std::endl; +// } + +// m_Trash->Delete(selected_item_ids[i]); + +// SH_LOG_INFO("{} restored from trash", files[i]); +// } +// } +// break; +// default: +// break; +// } +// } +// } + +// void MainFrame::OnDragAndDropToTrash(wxDropFilesEvent& event) +// { +// Serializer serializer; - if (event.GetNumberOfFiles() > 0) - { - wxFileDataObject file_data; - wxArrayString files; +// if (event.GetNumberOfFiles() > 0) +// { +// wxFileDataObject file_data; +// wxArrayString files; - wxDataViewItemArray items; - int rows = m_Library->GetSelections(items); +// wxDataViewItemArray items; +// int rows = m_Library->GetSelections(items); - wxString msg; +// wxString msg; - wxDataViewItem root = wxDataViewItem(wxNullPtr); - wxDataViewItem container, child; +// wxDataViewItem root = wxDataViewItem(wxNullPtr); +// wxDataViewItem container, child; - for (int i = 0; i < rows; i++) - { - int item_row = m_Library->ItemToRow(items[i]); - - wxString text_value = m_Library->GetTextValue(item_row, 1); +// for (int i = 0; i < rows; i++) +// { +// int item_row = m_Library->ItemToRow(items[i]); + +// wxString text_value = m_Library->GetTextValue(item_row, 1); - std::string multi_selection = serializer.DeserializeShowFileExtension() ? - m_Library->GetTextValue(item_row, 1).BeforeLast('.').ToStdString() : - m_Library->GetTextValue(item_row, 1).ToStdString() ; - - file_data.AddFile(multi_selection); - - files = file_data.GetFilenames(); - - if (m_Database->GetFavoriteColumnValueByFilename(files[i].ToStdString())) - { - m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0); - - m_Database->UpdateFavoriteColumn(files[i].ToStdString(), 0); - - for (int j = 0; j < m_Hives->GetChildCount(root); j++) - { - container = m_Hives->GetNthChild(root, j); - - for (int k = 0; k < m_Hives->GetChildCount(container); k++) - { - child = m_Hives->GetNthChild(container, k); - - wxString child_text = serializer.DeserializeShowFileExtension() ? - m_Hives->GetItemText(child).BeforeLast('.') : - m_Hives->GetItemText(child); - - if (child_text == files[i]) - { - m_Hives->DeleteItem(child); - break; - } - } - } - } - - m_Database->UpdateTrashColumn(files[i].ToStdString(), 1); - m_Database->UpdateHiveName(files[i].ToStdString(), - m_Hives->GetItemText(favorites_hive).ToStdString()); - - m_Trash->AppendItem(trash_root, text_value); - - m_Library->DeleteItem(item_row); - - msg = wxString::Format(_("%s sent to trash"), text_value); - } - - if (!msg.IsEmpty()) - m_InfoBar->ShowMessage(msg, wxICON_ERROR); - } -} - -void MainFrame::OnClickAddHive(wxCommandEvent& event) -{ - std::deque nodes; - nodes.push_back(m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0)); - - wxDataViewItem current_item, found_item; - - int row = 0; - int hive_count = m_Hives->GetChildCount(wxDataViewItem(wxNullPtr)); - - wxString msg; - - wxTextEntryDialog hiveEntry(this, _("Enter hive name"), _("Create new hive"), wxEmptyString, - wxTextEntryDialogStyle, wxDefaultPosition); - - hiveEntry.SetTextValidator(wxFILTER_EMPTY); - - switch (hiveEntry.ShowModal()) - { - case wxID_OK: - { - wxString hive_name = hiveEntry.GetValue(); - - while(!nodes.empty()) - { - current_item = nodes.front(); - nodes.pop_front(); - - if (m_Hives->GetItemText(current_item) == hive_name) - { - found_item = current_item; - SH_LOG_DEBUG("Found item: {}", m_Hives->GetItemText(current_item)); - break; - } - - wxDataViewItem child = m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0); - - while (row < (hive_count - 1)) - { - row ++; - - child = m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), row); - nodes.push_back(child); - } - } - - nodes.clear(); - - if (found_item.IsOk()) - { - wxMessageBox(wxString::Format(_("Another hive by the name %s already exist. " - "Please try with a different name."), - hive_name), - _("Error!"), wxOK | wxCENTRE, this); - } - else - { - m_Hives->AppendContainer(wxDataViewItem(wxNullPtr), hive_name); - m_Database->InsertIntoHives(hive_name.ToStdString()); - - msg = wxString::Format(_("%s added to Hives."), hive_name); - } - break; - } - case wxID_CANCEL: - break; - default: - return; - } - - if (!msg.IsEmpty()) - m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); -} - -void MainFrame::OnClickRemoveHive(wxCommandEvent& event) -{ - Serializer serializer; - - wxDataViewItem selected_item = m_Hives->GetSelection(); - wxString hive_name = m_Hives->GetItemText(selected_item); - - wxString msg; - - wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to delete " - "%s from hives?"), - hive_name), - wxMessageBoxCaptionStr, - wxYES_NO | wxNO_DEFAULT | - wxICON_QUESTION | wxSTAY_ON_TOP); - - wxMessageDialog deleteFilledHiveDialog(this, wxString::Format(_("Are you sure you want to delete " - "%s and all sample inside %s from hives?"), - hive_name, hive_name), - wxMessageBoxCaptionStr, - wxYES_NO | wxNO_DEFAULT | - wxICON_QUESTION | wxSTAY_ON_TOP); - - if (hive_name == m_Hives->GetItemText(favorites_hive)) - { - wxMessageBox(wxString::Format(_("Error! Default hive %s cannot be deleted."), hive_name), - _("Error!"), wxOK | wxCENTRE, this); - return; - } - else if (!selected_item.IsOk()) - { - wxMessageBox(_("No hive selected, try selecting a hive first"), _("Error!"), wxOK | wxCENTRE, this); - return; - } - else if (selected_item.IsOk() && !m_Hives->IsContainer(selected_item)) - { - wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from hives."), hive_name), - _("Error!"), wxOK | wxCENTRE, this); - return; - } - - if (m_Hives->GetChildCount(selected_item) <= 0) - { - switch (deleteEmptyHiveDialog.ShowModal()) - { - case wxID_YES: - if (selected_item.IsOk() && m_Hives->IsContainer(selected_item) && - hive_name != m_Hives->GetItemText(favorites_hive)) - { - m_Hives->DeleteItem(selected_item); - - m_Database->RemoveHiveFromDatabase(hive_name.ToStdString()); - msg = wxString::Format(_("%s deleted from hives successfully."), hive_name); - } - break; - case wxID_NO: - break; - default: - return; - } - } - else - { - switch (deleteFilledHiveDialog.ShowModal()) - { - case wxID_YES: - if (selected_item.IsOk() && m_Hives->IsContainer(selected_item) && - hive_name != m_Hives->GetItemText(favorites_hive)) - { - wxDataViewItem child_item; - - for (int i = 0; i < m_Library->GetItemCount(); i++) - { - wxString matched_sample = serializer.DeserializeShowFileExtension() ? - m_Library->GetTextValue(i, 1).BeforeLast('.') : - m_Library->GetTextValue(i, 1); - - for (int j = 0; j < m_Hives->GetChildCount(selected_item); j++) - { - child_item = m_Hives->GetNthChild(selected_item, j); - - wxString child_name = serializer.DeserializeShowFileExtension() ? - m_Hives->GetItemText(child_item).BeforeLast('.') : - m_Hives->GetItemText(child_item); - - if (child_name == matched_sample) - { - SH_LOG_DEBUG("Found match"); - - m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); - - m_Database->UpdateFavoriteColumn(matched_sample.ToStdString(), 0); - m_Database->UpdateHiveName(matched_sample.ToStdString(), - m_Hives->GetItemText(favorites_hive).ToStdString()); - - break; - } - else - SH_LOG_DEBUG("No match found"); - } - } - - m_Hives->DeleteChildren(selected_item); - m_Hives->DeleteItem(selected_item); - - m_Database->RemoveHiveFromDatabase(hive_name.ToStdString()); - - msg = wxString::Format(_("%s and all samples inside %s have been deleted " - "from hives successfully."), - hive_name, hive_name); - } - break; - case wxID_NO: - break; - default: - return; - } - } - - if (!msg.IsEmpty()) - m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); -} - -void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event) -{ - Serializer serializer; - - wxArrayTreeItemIds selected_item_ids; - m_Trash->GetSelections(selected_item_ids); - - wxFileDataObject file_data; - wxArrayString files; - - wxString selected_item_text; - std::string filename; - - if (m_Trash->GetChildrenCount(trash_root) == 0) - { - wxMessageBox(_("Trash is empty, nothing to restore!"), wxMessageBoxCaptionStr, wxOK | wxCENTRE, this); - return; - } - - if (selected_item_ids.IsEmpty()) - { - wxMessageBox(_("No item selected, try selected a item first."), wxMessageBoxCaptionStr, - wxOK | wxCENTRE, this); - return; - } - - for (size_t i = 0; i < selected_item_ids.GetCount(); i++) - { - selected_item_text = m_Trash->GetItemText(selected_item_ids[i]); - - filename = GetFilenamePathAndExtension(selected_item_text).Filename; - - file_data.AddFile(filename); - - files = file_data.GetFilenames(); - - m_Database->UpdateTrashColumn(files[i].ToStdString(), 0); - - try - { - wxVector> dataset; - - if (m_Database->RestoreFromTrashByFilename(files[i].ToStdString(), dataset, - serializer.DeserializeShowFileExtension(), - ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty()) - { - SH_LOG_INFO("Error! Database is empty."); - } - else - { - for (auto data : dataset) - { - m_Library->AppendItem(data); - } - } - } - catch (...) - { - std::cerr << "Error loading data." << std::endl; - } - - m_Trash->Delete(selected_item_ids[i]); - } -} - -void MainFrame::OnDoSearch(wxCommandEvent& event) -{ - Serializer serializer; - - const auto search = m_SearchBox->GetValue().ToStdString(); - - try - { - const auto dataset = m_Database->FilterDatabaseBySampleName(search, - serializer.DeserializeShowFileExtension(), - ICON_STAR_FILLED_16px, - ICON_STAR_EMPTY_16px); - - if (dataset.empty()) - { - SH_LOG_INFO("Error! Database is empty."); - } - else - { - m_Library->DeleteAllItems(); - - std::cout << search << std::endl; - - for (const auto& data : dataset) - { - m_Library->AppendItem(data); - } - } - } - catch (...) - { - std::cerr << "Error loading data." << std::endl; - } -} - -void MainFrame::OnCancelSearch(wxCommandEvent& event) -{ - m_SearchBox->Clear(); -} +// std::string multi_selection = serializer.DeserializeShowFileExtension() ? +// m_Library->GetTextValue(item_row, 1).BeforeLast('.').ToStdString() : +// m_Library->GetTextValue(item_row, 1).ToStdString() ; + +// file_data.AddFile(multi_selection); + +// files = file_data.GetFilenames(); + +// if (m_Database->GetFavoriteColumnValueByFilename(files[i].ToStdString())) +// { +// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0); + +// m_Database->UpdateFavoriteColumn(files[i].ToStdString(), 0); + +// for (int j = 0; j < m_Hives->GetChildCount(root); j++) +// { +// container = m_Hives->GetNthChild(root, j); + +// for (int k = 0; k < m_Hives->GetChildCount(container); k++) +// { +// child = m_Hives->GetNthChild(container, k); + +// wxString child_text = serializer.DeserializeShowFileExtension() ? +// m_Hives->GetItemText(child).BeforeLast('.') : +// m_Hives->GetItemText(child); + +// if (child_text == files[i]) +// { +// m_Hives->DeleteItem(child); +// break; +// } +// } +// } +// } + +// m_Database->UpdateTrashColumn(files[i].ToStdString(), 1); +// m_Database->UpdateHiveName(files[i].ToStdString(), +// m_Hives->GetItemText(favorites_hive).ToStdString()); + +// m_Trash->AppendItem(trash_root, text_value); + +// m_Library->DeleteItem(item_row); + +// msg = wxString::Format(_("%s sent to trash"), text_value); +// } + +// if (!msg.IsEmpty()) +// m_InfoBar->ShowMessage(msg, wxICON_ERROR); +// } +// } + +// void MainFrame::OnClickAddHive(wxCommandEvent& event) +// { +// std::deque nodes; +// nodes.push_back(m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0)); + +// wxDataViewItem current_item, found_item; + +// int row = 0; +// int hive_count = m_Hives->GetChildCount(wxDataViewItem(wxNullPtr)); + +// wxString msg; + +// wxTextEntryDialog hiveEntry(this, _("Enter hive name"), _("Create new hive"), wxEmptyString, +// wxTextEntryDialogStyle, wxDefaultPosition); + +// hiveEntry.SetTextValidator(wxFILTER_EMPTY); + +// switch (hiveEntry.ShowModal()) +// { +// case wxID_OK: +// { +// wxString hive_name = hiveEntry.GetValue(); + +// while(!nodes.empty()) +// { +// current_item = nodes.front(); +// nodes.pop_front(); + +// if (m_Hives->GetItemText(current_item) == hive_name) +// { +// found_item = current_item; +// SH_LOG_DEBUG("Found item: {}", m_Hives->GetItemText(current_item)); +// break; +// } + +// wxDataViewItem child = m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0); + +// while (row < (hive_count - 1)) +// { +// row ++; + +// child = m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), row); +// nodes.push_back(child); +// } +// } + +// nodes.clear(); + +// if (found_item.IsOk()) +// { +// wxMessageBox(wxString::Format(_("Another hive by the name %s already exist. " +// "Please try with a different name."), +// hive_name), +// _("Error!"), wxOK | wxCENTRE, this); +// } +// else +// { +// m_Hives->AppendContainer(wxDataViewItem(wxNullPtr), hive_name); +// m_Database->InsertIntoHives(hive_name.ToStdString()); + +// msg = wxString::Format(_("%s added to Hives."), hive_name); +// } +// break; +// } +// case wxID_CANCEL: +// break; +// default: +// return; +// } + +// if (!msg.IsEmpty()) +// m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); +// } + +// void MainFrame::OnClickRemoveHive(wxCommandEvent& event) +// { +// Serializer serializer; + +// wxDataViewItem selected_item = m_Hives->GetSelection(); +// wxString hive_name = m_Hives->GetItemText(selected_item); + +// wxString msg; + +// wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to delete " +// "%s from hives?"), +// hive_name), +// wxMessageBoxCaptionStr, +// wxYES_NO | wxNO_DEFAULT | +// wxICON_QUESTION | wxSTAY_ON_TOP); + +// wxMessageDialog deleteFilledHiveDialog(this, wxString::Format(_("Are you sure you want to delete " +// "%s and all sample inside %s from hives?"), +// hive_name, hive_name), +// wxMessageBoxCaptionStr, +// wxYES_NO | wxNO_DEFAULT | +// wxICON_QUESTION | wxSTAY_ON_TOP); + +// if (hive_name == m_Hives->GetItemText(favorites_hive)) +// { +// wxMessageBox(wxString::Format(_("Error! Default hive %s cannot be deleted."), hive_name), +// _("Error!"), wxOK | wxCENTRE, this); +// return; +// } +// else if (!selected_item.IsOk()) +// { +// wxMessageBox(_("No hive selected, try selecting a hive first"), _("Error!"), wxOK | wxCENTRE, this); +// return; +// } +// else if (selected_item.IsOk() && !m_Hives->IsContainer(selected_item)) +// { +// wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from hives."), hive_name), +// _("Error!"), wxOK | wxCENTRE, this); +// return; +// } + +// if (m_Hives->GetChildCount(selected_item) <= 0) +// { +// switch (deleteEmptyHiveDialog.ShowModal()) +// { +// case wxID_YES: +// if (selected_item.IsOk() && m_Hives->IsContainer(selected_item) && +// hive_name != m_Hives->GetItemText(favorites_hive)) +// { +// m_Hives->DeleteItem(selected_item); + +// m_Database->RemoveHiveFromDatabase(hive_name.ToStdString()); +// msg = wxString::Format(_("%s deleted from hives successfully."), hive_name); +// } +// break; +// case wxID_NO: +// break; +// default: +// return; +// } +// } +// else +// { +// switch (deleteFilledHiveDialog.ShowModal()) +// { +// case wxID_YES: +// if (selected_item.IsOk() && m_Hives->IsContainer(selected_item) && +// hive_name != m_Hives->GetItemText(favorites_hive)) +// { +// wxDataViewItem child_item; + +// for (int i = 0; i < m_Library->GetItemCount(); i++) +// { +// wxString matched_sample = serializer.DeserializeShowFileExtension() ? +// m_Library->GetTextValue(i, 1).BeforeLast('.') : +// m_Library->GetTextValue(i, 1); + +// for (int j = 0; j < m_Hives->GetChildCount(selected_item); j++) +// { +// child_item = m_Hives->GetNthChild(selected_item, j); + +// wxString child_name = serializer.DeserializeShowFileExtension() ? +// m_Hives->GetItemText(child_item).BeforeLast('.') : +// m_Hives->GetItemText(child_item); + +// if (child_name == matched_sample) +// { +// SH_LOG_DEBUG("Found match"); + +// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); + +// m_Database->UpdateFavoriteColumn(matched_sample.ToStdString(), 0); +// m_Database->UpdateHiveName(matched_sample.ToStdString(), +// m_Hives->GetItemText(favorites_hive).ToStdString()); + +// break; +// } +// else +// SH_LOG_DEBUG("No match found"); +// } +// } + +// m_Hives->DeleteChildren(selected_item); +// m_Hives->DeleteItem(selected_item); + +// m_Database->RemoveHiveFromDatabase(hive_name.ToStdString()); + +// msg = wxString::Format(_("%s and all samples inside %s have been deleted " +// "from hives successfully."), +// hive_name, hive_name); +// } +// break; +// case wxID_NO: +// break; +// default: +// return; +// } +// } + +// if (!msg.IsEmpty()) +// m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); +// } + +// void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event) +// { +// Serializer serializer; + +// wxArrayTreeItemIds selected_item_ids; +// m_Trash->GetSelections(selected_item_ids); + +// wxFileDataObject file_data; +// wxArrayString files; + +// wxString selected_item_text; +// std::string filename; + +// if (m_Trash->GetChildrenCount(trash_root) == 0) +// { +// wxMessageBox(_("Trash is empty, nothing to restore!"), wxMessageBoxCaptionStr, wxOK | wxCENTRE, this); +// return; +// } + +// if (selected_item_ids.IsEmpty()) +// { +// wxMessageBox(_("No item selected, try selected a item first."), wxMessageBoxCaptionStr, +// wxOK | wxCENTRE, this); +// return; +// } + +// for (size_t i = 0; i < selected_item_ids.GetCount(); i++) +// { +// selected_item_text = m_Trash->GetItemText(selected_item_ids[i]); + +// filename = GetFilenamePathAndExtension(selected_item_text).Filename; + +// file_data.AddFile(filename); + +// files = file_data.GetFilenames(); + +// m_Database->UpdateTrashColumn(files[i].ToStdString(), 0); + +// try +// { +// wxVector> dataset; + +// if (m_Database->RestoreFromTrashByFilename(files[i].ToStdString(), dataset, +// serializer.DeserializeShowFileExtension(), +// ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty()) +// { +// SH_LOG_INFO("Error! Database is empty."); +// } +// else +// { +// for (auto data : dataset) +// { +// m_Library->AppendItem(data); +// } +// } +// } +// catch (...) +// { +// std::cerr << "Error loading data." << std::endl; +// } + +// m_Trash->Delete(selected_item_ids[i]); +// } +// } + +// void MainFrame::OnDoSearch(wxCommandEvent& event) +// { +// Serializer serializer; + +// const auto search = m_SearchBox->GetValue().ToStdString(); + +// try +// { +// const auto dataset = m_Database->FilterDatabaseBySampleName(search, +// serializer.DeserializeShowFileExtension(), +// ICON_STAR_FILLED_16px, +// ICON_STAR_EMPTY_16px); + +// if (dataset.empty()) +// { +// SH_LOG_INFO("Error! Database is empty."); +// } +// else +// { +// m_Library->DeleteAllItems(); + +// std::cout << search << std::endl; + +// for (const auto& data : dataset) +// { +// m_Library->AppendItem(data); +// } +// } +// } +// catch (...) +// { +// std::cerr << "Error loading data." << std::endl; +// } +// } + +// void MainFrame::OnCancelSearch(wxCommandEvent& event) +// { +// m_SearchBox->Clear(); +// } void MainFrame::LoadConfigFile() { @@ -2413,20 +2417,20 @@ void MainFrame::LoadConfigFile() this->SetStatusText(_("Stopped"), 1); } -void MainFrame::RefreshDatabase() -{ - m_Library->DeleteAllItems(); +// void MainFrame::RefreshDatabase() +// { +// m_Library->DeleteAllItems(); - if (m_Hives->GetChildCount(wxDataViewItem(wxNullPtr)) < 1 && - m_Hives->GetItemText(wxDataViewItem(wxNullPtr)) == m_Hives->GetItemText(favorites_hive)) - return; - else - m_Hives->DeleteAllItems(); +// if (m_Hives->GetChildCount(wxDataViewItem(wxNullPtr)) < 1 && +// m_Hives->GetItemText(wxDataViewItem(wxNullPtr)) == m_Hives->GetItemText(favorites_hive)) +// return; +// else +// m_Hives->DeleteAllItems(); - m_Trash->DeleteAllItems(); +// m_Trash->DeleteAllItems(); - LoadDatabase(); -} +// LoadDatabase(); +// } bool MainFrame::CreateWatcherIfNecessary() { @@ -2530,7 +2534,7 @@ void MainFrame::OnFileSystemEvent(wxFileSystemWatcherEvent& event) { case wxFSW_EVENT_CREATE: SH_LOG_INFO("NEW FILES DETECTED, ADDING: {}", path); - AddSamples(files); + // AddSamples(files); break; case wxFSW_EVENT_ACCESS: SH_LOG_INFO("ACCESSING DIRECTORY: {}", path); @@ -2555,38 +2559,38 @@ void MainFrame::OnFileSystemEvent(wxFileSystemWatcherEvent& event) } } -FileInfo MainFrame::GetFilenamePathAndExtension(const wxString& selected, - bool checkExtension, bool doGetFilename) const -{ - Serializer serializer; +// FileInfo MainFrame::GetFilenamePathAndExtension(const wxString& selected, +// bool checkExtension, bool doGetFilename) const +// { +// Serializer serializer; - wxString path; - std::string extension, filename; +// wxString path; +// std::string extension, filename; - wxString filename_with_extension = m_Database->GetSamplePathByFilename(selected.BeforeLast('.').ToStdString()); - wxString filename_without_extension = m_Database->GetSamplePathByFilename(selected.ToStdString()); +// wxString filename_with_extension = m_Database->GetSamplePathByFilename(selected.BeforeLast('.').ToStdString()); +// wxString filename_without_extension = m_Database->GetSamplePathByFilename(selected.ToStdString()); - if (checkExtension) - { - extension = serializer.DeserializeShowFileExtension() ? - m_Database->GetSampleFileExtension(selected.ToStdString()) : - m_Database->GetSampleFileExtension(selected.BeforeLast('.').ToStdString()); - } +// if (checkExtension) +// { +// extension = serializer.DeserializeShowFileExtension() ? +// m_Database->GetSampleFileExtension(selected.ToStdString()) : +// m_Database->GetSampleFileExtension(selected.BeforeLast('.').ToStdString()); +// } - path = selected.Contains(wxString::Format(".%s", extension)) ? - filename_with_extension : filename_without_extension; +// path = selected.Contains(wxString::Format(".%s", extension)) ? +// filename_with_extension : filename_without_extension; - if (doGetFilename) - filename = path.AfterLast('/').BeforeLast('.').ToStdString(); +// if (doGetFilename) +// filename = path.AfterLast('/').BeforeLast('.').ToStdString(); - return { path, extension, filename }; -} +// return { path, extension, filename }; +// } -void MainFrame::OnHiveStartEditing(wxDataViewEvent &event) -{ - SH_LOG_INFO("Right click on a hive and select rename to rename it.."); - event.Veto(); -} +// void MainFrame::OnHiveStartEditing(wxDataViewEvent &event) +// { +// SH_LOG_INFO("Right click on a hive and select rename to rename it.."); +// event.Veto(); +// } void MainFrame::OnSelectAddFile(wxCommandEvent& event) { @@ -2602,8 +2606,8 @@ void MainFrame::OnSelectAddFile(wxCommandEvent& event) wxArrayString paths; file_dialog.GetPaths(paths); - for (size_t i = 0; i < (size_t)paths.size(); i++) - AddSamples(paths); + // for (size_t i = 0; i < (size_t)paths.size(); i++) + // AddSamples(paths); } break; default: @@ -2622,7 +2626,7 @@ void MainFrame::OnSelectAddDirectory(wxCommandEvent& event) { wxString path = dir_dialog.GetPath(); - OnAutoImportDir(path); + // OnAutoImportDir(path); } break; default: @@ -2637,14 +2641,14 @@ void MainFrame::OnSelectToggleExtension(wxCommandEvent& event) if (m_ToggleExtension->IsChecked()) { serializer.SerializeShowFileExtension(true); - m_InfoBar->ShowMessage(_("Extension showing, restart the application to view changes " - "or press CTRL+E to toggle show/hide."), wxICON_INFORMATION); + // m_InfoBar->ShowMessage(_("Extension showing, restart the application to view changes " + // "or press CTRL+E to toggle show/hide."), wxICON_INFORMATION); } else { serializer.SerializeShowFileExtension(false); - m_InfoBar->ShowMessage(_("Extension hidden, restart the application to view changes " - "or press CTRL+E to toggle show/hide."), wxICON_INFORMATION); + // m_InfoBar->ShowMessage(_("Extension hidden, restart the application to view changes " + // "or press CTRL+E to toggle show/hide."), wxICON_INFORMATION); } } @@ -2655,7 +2659,7 @@ void MainFrame::OnSelectToggleMenuBar(wxCommandEvent& event) if (m_ToggleMenuBar->IsChecked()) { m_MenuBar->Show(); - m_InfoBar->ShowMessage(_("MenuBar showing, press CTRL+M to toggle show/hide."), wxICON_INFORMATION); + // m_InfoBar->ShowMessage(_("MenuBar showing, press CTRL+M to toggle show/hide."), wxICON_INFORMATION); bShowMenuBar = true; @@ -2664,7 +2668,7 @@ void MainFrame::OnSelectToggleMenuBar(wxCommandEvent& event) else { m_MenuBar->Hide(); - m_InfoBar->ShowMessage(_("MenuBar hidden, press CTRL+M to toggle show/hide."), wxICON_INFORMATION); + // m_InfoBar->ShowMessage(_("MenuBar hidden, press CTRL+M to toggle show/hide."), wxICON_INFORMATION); bShowMenuBar = false; @@ -2679,7 +2683,7 @@ void MainFrame::OnSelectToggleStatusBar(wxCommandEvent& event) if (m_ToggleStatusBar->IsChecked()) { m_StatusBar->Show(); - m_InfoBar->ShowMessage(_("StatusBar showing, press CTRL+B to toggle show/hide."), wxICON_INFORMATION); + // m_InfoBar->ShowMessage(_("StatusBar showing, press CTRL+B to toggle show/hide."), wxICON_INFORMATION); bShowStatusBar = true; @@ -2688,7 +2692,7 @@ void MainFrame::OnSelectToggleStatusBar(wxCommandEvent& event) else { m_StatusBar->Hide(); - m_InfoBar->ShowMessage(_("StatusBar hidden, press CTRL+B to toggle show/hide."), wxICON_INFORMATION); + // m_InfoBar->ShowMessage(_("StatusBar hidden, press CTRL+B to toggle show/hide."), wxICON_INFORMATION); bShowStatusBar = false; @@ -2710,8 +2714,8 @@ void MainFrame::OnSelectPreferences(wxCommandEvent& event) case wxID_OK: if (settings->CanAutoImport()) { - OnAutoImportDir(settings->GetImportDirPath()); - RefreshDatabase(); + // OnAutoImportDir(settings->GetImportDirPath()); + // RefreshDatabase(); } if (settings->IsWaveformColourChanged()) { @@ -2770,7 +2774,8 @@ void MainFrame::OnSelectResetAppData(wxCommandEvent& event) SH_LOG_ERROR("Could not delete {}", DATABASE_FILEPATH); if (config_is_deleted && db_is_deleted) - m_InfoBar->ShowMessage(_("Successfully cleared app data"), wxICON_INFORMATION); + // m_InfoBar->ShowMessage(_("Successfully cleared app data"), wxICON_INFORMATION); + SH_LOG_INFO("Cleared app data successfully"); else wxMessageBox(_("Error! Could not clear app data"), _("Error!"), wxOK | wxCENTRE | wxICON_ERROR, this); @@ -2865,9 +2870,16 @@ void MainFrame::SetAfterFrameCreate() m_TopSplitter->SetSashPosition(serializer.DeserializeSplitterSashPos("top")); m_BottomSplitter->SetSashPosition(serializer.DeserializeSplitterSashPos("bottom")); + + // m_Notebook->SetListCtrlObject(*m_Library->GetListCtrlObject()); + + // m_Library->SetHivesObject(*m_Notebook->GetHivesPanel()->GetHivesObject()); + // m_Library->SetFavoritesHive(m_Notebook->GetHivesPanel()->GetFavoritesHive()); + // m_Library->SetTrashObject(*m_Notebook->GetTrashPanel()->GetTrashObject()); + // m_Library->SetTrashRoot(m_Notebook->GetTrashPanel()->GetTrashRoot()); } -void MainFrame::OnRecieveLoopPoints(SampleHive::SH_LoopPointsEvent& event) +void MainFrame::OnRecieveLoopPoints(SampleHive::LoopPointsEvent& event) { std::pair loop_points = event.GetLoopPoints(); @@ -2880,54 +2892,59 @@ void MainFrame::OnRecieveLoopPoints(SampleHive::SH_LoopPointsEvent& event) int loopB_sec = static_cast(((m_LoopB % 60000) / 1000).GetValue()); SH_LOG_INFO(wxString::Format(_("Loop points set: A: %2i:%02i, B: %2i:%02i"), - loopA_min, loopA_sec, loopB_min, loopB_sec)); + loopA_min, loopA_sec, loopB_min, loopB_sec)); m_TransportControls->SetLoopABValue(true); bLoopPointsSet = true; } -void MainFrame::OnRecievePushStatusBarStatus(SampleHive::SH_StatusBarStatusEvent& event) +void MainFrame::OnRecievePushStatusBarStatus(SampleHive::StatusBarStatusEvent& event) { std::pair status = event.GetPushMessageAndSection(); m_StatusBar->PushStatusText(status.first, status.second); } -void MainFrame::OnRecievePopStatusBarStatus(SampleHive::SH_StatusBarStatusEvent& event) +void MainFrame::OnRecievePopStatusBarStatus(SampleHive::StatusBarStatusEvent& event) { m_StatusBar->PopStatusText(event.GetPopMessageSection()); } -void MainFrame::OnRecieveSetStatusBarStatus(SampleHive::SH_StatusBarStatusEvent& event) +void MainFrame::OnRecieveSetStatusBarStatus(SampleHive::StatusBarStatusEvent& event) { std::pair status = event.GetStatusTextAndSection(); m_StatusBar->SetStatusText(status.first, status.second); } -void MainFrame::OnRecieveInfoBarStatus(SampleHive::SH_InfoBarMessageEvent& event) +void MainFrame::OnRecieveInfoBarStatus(SampleHive::InfoBarMessageEvent& event) { SH_LOG_INFO("{} called..", __FUNCTION__); std::pair info = event.GetInfoBarMessage(); - m_InfoBar->ShowMessage(info.first, info.second); + // m_InfoBar->ShowMessage(info.first, info.second); SH_LOG_INFO("{} event processed", __FUNCTION__); } -void MainFrame::OnRecieveTimerStopStatus(SampleHive::SH_TimerEvent& event) +void MainFrame::OnRecieveTimerStopStatus(SampleHive::TimerEvent& event) { if (m_Timer->IsRunning()) m_Timer->Stop(); } -void MainFrame::OnRecieveCallFunctionPlay(SampleHive::SH_CallFunctionEvent& event) +void MainFrame::OnRecieveCallFunctionPlay(SampleHive::CallFunctionEvent& event) { + Serializer serializer; + wxString selection = event.GetSlection(); - wxString sample_path = GetFilenamePathAndExtension(selection).Path; + // wxString sample_path = GetFilenamePathAndExtension(selection).Path; + wxString sample_path = serializer.DeserializeShowFileExtension() ? + m_Database->GetSamplePathByFilename(selection.BeforeLast('.').ToStdString()) : + m_Database->GetSamplePathByFilename(selection.ToStdString()); if (bLoopPointsSet && m_TransportControls->IsLoopABOn()) PlaySample(sample_path.ToStdString(), selection.ToStdString(), true, m_LoopA.ToDouble(), wxFromStart); @@ -2935,6 +2952,11 @@ void MainFrame::OnRecieveCallFunctionPlay(SampleHive::SH_CallFunctionEvent& even PlaySample(sample_path.ToStdString(), selection.ToStdString()); } +void MainFrame::OnRecieveWaveformUpdateStatus(SampleHive::WaveformUpdateEvent& event) +{ + m_WaveformViewer->ResetDC(); +} + void MainFrame::ClearLoopPoints() { m_LoopA = 0; @@ -2963,6 +2985,21 @@ void MainFrame::PlaySample(const std::string& filepath, const std::string& sampl SH_LOG_ERROR("Error! Cannot load sample."); } +void MainFrame::InitDatabase() +{ + // Initialize the database + try + { + m_Database = std::make_unique(); + m_Database->CreateTableSamples(); + m_Database->CreateTableHives(); + } + catch (std::exception& e) + { + SH_LOG_ERROR("Error! Cannot initialize database {}", e.what()); + } +} + MainFrame::~MainFrame() { // Delete wxTimer diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index 8737582..fdf57a0 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -21,11 +21,13 @@ #pragma once #include "Database/Database.hpp" +#include "GUI/Library.hpp" #include "GUI/TransportControls.hpp" #include "GUI/WaveformViewer.hpp" -#include "SampleHiveConfig.hpp" +#include "GUI/Notebook.hpp" #include "Utility/Serialize.hpp" #include "Utility/SH_Event.hpp" +#include "SampleHiveConfig.hpp" #include #include @@ -85,7 +87,7 @@ class MainFrame : public wxFrame private: // ------------------------------------------------------------------- // Main Panel - wxPanel* m_MainPanel; + // wxPanel* m_MainPanel; wxBoxSizer* m_MainSizer; // ------------------------------------------------------------------- @@ -120,41 +122,43 @@ class MainFrame : public wxFrame // ------------------------------------------------------------------- // Top panel controls wxPanel* m_TopPanel; - TransportControls* m_TransportControls; - WaveformViewer* m_WaveformViewer; - wxBoxSizer* m_TopSizer; + cTransportControls* m_TransportControls; + cWaveformViewer* m_WaveformViewer; + // wxBoxSizer* m_TopSizer; wxBoxSizer* m_TopPanelMainSizer; - wxBoxSizer* m_WaveformDisplaySizer; + // wxBoxSizer* m_WaveformDisplaySizer; // ------------------------------------------------------------------- // Left panel controls - wxPanel* m_BottomLeftPanel; - wxPanel* m_HivesPanel; - wxPanel* m_TrashPanel; - wxNotebook* m_Notebook; - wxBoxSizer* m_BottomLeftPanelMainSizer; - wxBoxSizer* m_HivesMainSizer; - wxBoxSizer* m_HivesFavoritesSizer; - wxBoxSizer* m_HivesButtonSizer; - wxBoxSizer* m_TrashMainSizer; - wxBoxSizer* m_TrashItemSizer; - wxBoxSizer* m_TrashButtonSizer; - wxGenericDirCtrl* m_DirCtrl; - wxDataViewTreeCtrl* m_Hives; - wxDataViewItem favorites_hive; - wxTreeItemId trash_root; - wxTreeCtrl* m_Trash; - wxButton* m_AddHiveButton; - wxButton* m_RemoveHiveButton; - wxButton* m_RestoreTrashedItemButton; + // wxPanel* m_BottomLeftPanel; + cNotebook* m_Notebook; + // wxPanel* m_HivesPanel; + // wxPanel* m_TrashPanel; + // wxNotebook* m_Notebook; + // wxBoxSizer* m_BottomLeftPanelMainSizer; + // wxBoxSizer* m_HivesMainSizer; + // wxBoxSizer* m_HivesFavoritesSizer; + // wxBoxSizer* m_HivesButtonSizer; + // wxBoxSizer* m_TrashMainSizer; + // wxBoxSizer* m_TrashItemSizer; + // wxBoxSizer* m_TrashButtonSizer; + // wxGenericDirCtrl* m_DirCtrl; + // wxDataViewTreeCtrl* m_Hives; + // wxDataViewItem favorites_hive; + // wxTreeItemId trash_root; + // wxTreeCtrl* m_Trash; + // wxButton* m_AddHiveButton; + // wxButton* m_RemoveHiveButton; + // wxButton* m_RestoreTrashedItemButton; // ------------------------------------------------------------------- // Right panel controls - wxPanel* m_BottomRightPanel; - wxBoxSizer* m_BottomRightPanelMainSizer; - wxSearchCtrl* m_SearchBox; - wxInfoBar* m_InfoBar; - wxDataViewListCtrl* m_Library; + cLibrary* m_Library; + // wxPanel* m_BottomRightPanel; + // wxBoxSizer* m_BottomRightPanelMainSizer; + // wxSearchCtrl* m_SearchBox; + // wxInfoBar* m_InfoBar; + // wxDataViewListCtrl* m_Library; // ------------------------------------------------------------------- // MediaCtrl @@ -175,7 +179,7 @@ class MainFrame : public wxFrame wxLongLong m_LoopA, m_LoopB; // ------------------------------------------------------------------- - wxSystemAppearance m_Theme = wxSystemSettings::GetAppearance(); + // wxSystemAppearance m_Theme = wxSystemSettings::GetAppearance(); private: // ------------------------------------------------------------------- @@ -188,39 +192,39 @@ class MainFrame : public wxFrame // ------------------------------------------------------------------- // Top panel control handlers void OnMediaFinished(wxMediaEvent& event); - void OnClickSettings(wxCommandEvent& event); + // void OnClickSettings(wxCommandEvent& event); // ------------------------------------------------------------------- // DirCtrl event handlers - void OnClickDirCtrl(wxCommandEvent& event); - void OnDragFromDirCtrl(wxTreeEvent& event); + // void OnClickDirCtrl(wxCommandEvent& event); + // void OnDragFromDirCtrl(wxTreeEvent& event); // ------------------------------------------------------------------- // TrashPane event handlers - void OnShowTrashContextMenu(wxTreeEvent& event); - void OnClickRestoreTrashItem(wxCommandEvent& event); - void OnDragAndDropToTrash(wxDropFilesEvent& event); + // void OnShowTrashContextMenu(wxTreeEvent& event); + // void OnClickRestoreTrashItem(wxCommandEvent& event); + // void OnDragAndDropToTrash(wxDropFilesEvent& event); // ------------------------------------------------------------------- // Hives panel button event handlers - void OnDragAndDropToHives(wxDropFilesEvent& event); - void OnClickAddHive(wxCommandEvent& event); - void OnClickRemoveHive(wxCommandEvent& event); - void OnShowHivesContextMenu(wxDataViewEvent& event); - void OnHiveStartEditing(wxDataViewEvent& event); + // void OnDragAndDropToHives(wxDropFilesEvent& event); + // void OnClickAddHive(wxCommandEvent& event); + // void OnClickRemoveHive(wxCommandEvent& event); + // void OnShowHivesContextMenu(wxDataViewEvent& event); + // void OnHiveStartEditing(wxDataViewEvent& event); // ------------------------------------------------------------------- // SearchCtrl event handlers - void OnDoSearch(wxCommandEvent& event); - void OnCancelSearch(wxCommandEvent& event); + // void OnDoSearch(wxCommandEvent& event); + // void OnCancelSearch(wxCommandEvent& event); // ------------------------------------------------------------------- // Library event handlers - void OnClickLibrary(wxDataViewEvent& event); - void OnDragAndDropToLibrary(wxDropFilesEvent& event); - void OnDragFromLibrary(wxDataViewEvent& event); - void OnShowLibraryContextMenu(wxDataViewEvent& event); - void OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event); + // void OnClickLibrary(wxDataViewEvent& event); + // void OnDragAndDropToLibrary(wxDropFilesEvent& event); + // void OnDragFromLibrary(wxDataViewEvent& event); + // void OnShowLibraryContextMenu(wxDataViewEvent& event); + // void OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event); // ------------------------------------------------------------------- // App menu items event handlers @@ -251,8 +255,8 @@ class MainFrame : public wxFrame void UpdateElapsedTime(wxTimerEvent& event); // ------------------------------------------------------------------- - void AddSamples(wxArrayString& files); - void OnAutoImportDir(const wxString& pathToDirectory); + // void AddSamples(wxArrayString& files); + // void OnAutoImportDir(const wxString& pathToDirectory); // ------------------------------------------------------------------- void PlaySample(const std::string& filepath, const std::string& sample, bool seek = false, @@ -260,23 +264,24 @@ class MainFrame : public wxFrame // Recieve custom events // ------------------------------------------------------------------- - void OnRecieveLoopPoints(SampleHive::SH_LoopPointsEvent& event); - void OnRecievePushStatusBarStatus(SampleHive::SH_StatusBarStatusEvent& event); - void OnRecievePopStatusBarStatus(SampleHive::SH_StatusBarStatusEvent& event); - void OnRecieveSetStatusBarStatus(SampleHive::SH_StatusBarStatusEvent& event); - void OnRecieveInfoBarStatus(SampleHive::SH_InfoBarMessageEvent& event); - void OnRecieveTimerStopStatus(SampleHive::SH_TimerEvent& event); - void OnRecieveCallFunctionPlay(SampleHive::SH_CallFunctionEvent& event); + void OnRecieveLoopPoints(SampleHive::LoopPointsEvent& event); + void OnRecievePushStatusBarStatus(SampleHive::StatusBarStatusEvent& event); + void OnRecievePopStatusBarStatus(SampleHive::StatusBarStatusEvent& event); + void OnRecieveSetStatusBarStatus(SampleHive::StatusBarStatusEvent& event); + void OnRecieveInfoBarStatus(SampleHive::InfoBarMessageEvent& event); + void OnRecieveTimerStopStatus(SampleHive::TimerEvent& event); + void OnRecieveCallFunctionPlay(SampleHive::CallFunctionEvent& event); + void OnRecieveWaveformUpdateStatus(SampleHive::WaveformUpdateEvent& event); // ------------------------------------------------------------------- - void LoadDatabase(); - void RefreshDatabase(); + // void LoadDatabase(); + // void RefreshDatabase(); void LoadConfigFile(); // ------------------------------------------------------------------- // Getters - FileInfo GetFilenamePathAndExtension(const wxString& selected, - bool checkExtension = true, bool doGetFilename = true) const; + // FileInfo GetFilenamePathAndExtension(const wxString& selected, + // bool checkExtension = true, bool doGetFilename = true) const; // ------------------------------------------------------------------- // Directory watchers @@ -294,6 +299,8 @@ class MainFrame : public wxFrame // ------------------------------------------------------------------- void ClearLoopPoints(); + void InitDatabase(); + // ------------------------------------------------------------------- friend class App; }; diff --git a/src/GUI/Notebook.cpp b/src/GUI/Notebook.cpp new file mode 100644 index 0000000..d9a7983 --- /dev/null +++ b/src/GUI/Notebook.cpp @@ -0,0 +1,33 @@ +#include "GUI/Notebook.hpp" +#include "GUI/DirectoryBrowser.hpp" +#include "GUI/Hives.hpp" +#include "GUI/Trash.hpp" + +cNotebook::cNotebook(wxWindow* window) + : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL) +{ + m_pNotebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP); + + m_DirectoryBrowser = new cDirectoryBrowser(m_pNotebook); + m_HivesPanel = new cHivesPanel(m_pNotebook, *m_pListCtrl); + m_TrashPanel = new cTrashPanel(m_pNotebook, *m_pListCtrl); + + // Adding the pages to wxNotebook + m_pNotebook->AddPage(m_DirectoryBrowser, _("Browse"), false); + m_pNotebook->AddPage(m_HivesPanel, _("Hives"), false); + m_pNotebook->AddPage(m_TrashPanel, _("Trash"), false); + + m_pSizer = new wxBoxSizer(wxVERTICAL); + + m_pSizer->Add(m_pNotebook, wxSizerFlags(1).Expand()); + + this->SetSizer(m_pSizer); + m_pSizer->Fit(this); + m_pSizer->SetSizeHints(this); + m_pSizer->Layout(); +} + +cNotebook::~cNotebook() +{ + +} diff --git a/src/GUI/Notebook.hpp b/src/GUI/Notebook.hpp new file mode 100644 index 0000000..df5f57f --- /dev/null +++ b/src/GUI/Notebook.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include "GUI/DirectoryBrowser.hpp" +#include "GUI/Hives.hpp" +#include "GUI/Trash.hpp" + +#include +#include +#include +#include + +class cNotebook : public wxPanel +{ + public: + // ------------------------------------------------------------------- + cNotebook(wxWindow* window); + ~cNotebook(); + + // ------------------------------------------------------------------- + cDirectoryBrowser* GetDirectoryBrowser() const { return m_DirectoryBrowser; } + cHivesPanel* GetHivesPanel() const { return m_HivesPanel; } + cTrashPanel* GetTrashPanel() const { return m_TrashPanel; } + + void SetListCtrlObject(wxDataViewListCtrl& listCtrl) { m_pListCtrl = &listCtrl; } + + private: + // ------------------------------------------------------------------- + wxNotebook* m_pNotebook = nullptr; + wxBoxSizer* m_pSizer = nullptr; + + // ------------------------------------------------------------------- + cDirectoryBrowser* m_DirectoryBrowser = nullptr; + cHivesPanel* m_HivesPanel = nullptr; + cTrashPanel* m_TrashPanel = nullptr; + + wxDataViewListCtrl* m_pListCtrl; +}; diff --git a/src/GUI/SearchBar.cpp b/src/GUI/SearchBar.cpp new file mode 100644 index 0000000..2c9592d --- /dev/null +++ b/src/GUI/SearchBar.cpp @@ -0,0 +1,70 @@ +#include "GUI/SearchBar.hpp" +#include "GUI/ListCtrl.hpp" +#include "Database/Database.hpp" +#include "Utility/ControlIDs.hpp" +#include "Utility/Serialize.hpp" +#include "Utility/Paths.hpp" +#include "Utility/Log.hpp" + +cSearchBar::cSearchBar(wxWindow* window, wxDataViewListCtrl& listCtrl) + : wxSearchCtrl(window, BC_Search, _("Search for samples.."), + wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER), + m_pWindow(window), m_ListCtrl(listCtrl) +{ + // Set minimum and maximum size of m_SearchBox + // so it doesn't expand too wide when resizing the main frame. + SetMinSize(wxSize(-1, 38)); + SetMaxSize(wxSize(-1, 38)); + + ShowSearchButton(true); + ShowCancelButton(true); + + Bind(wxEVT_TEXT, &cSearchBar::OnDoSearch, this, BC_Search); + Bind(wxEVT_SEARCHCTRL_SEARCH_BTN, &cSearchBar::OnDoSearch, this, BC_Search); + Bind(wxEVT_SEARCHCTRL_CANCEL_BTN, &cSearchBar::OnCancelSearch, this, BC_Search); +} + +void cSearchBar::OnDoSearch(wxCommandEvent& event) +{ + Serializer serializer; + Database db; + // cListCtrl m_ListCtrl(m_pWindow); + + const auto search = this->GetValue().ToStdString(); + + try + { + const auto dataset = db.FilterDatabaseBySampleName(search, serializer.DeserializeShowFileExtension(), + ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); + + if (dataset.empty()) + { + SH_LOG_INFO("Error! Database is empty."); + } + else + { + m_ListCtrl.DeleteAllItems(); + + std::cout << search << std::endl; + + for (const auto& data : dataset) + { + m_ListCtrl.AppendItem(data); + } + } + } + catch (...) + { + std::cerr << "Error loading data." << std::endl; + } +} + +void cSearchBar::OnCancelSearch(wxCommandEvent& event) +{ + this->Clear(); +} + +cSearchBar::~cSearchBar() +{ + +} diff --git a/src/GUI/SearchBar.hpp b/src/GUI/SearchBar.hpp new file mode 100644 index 0000000..ec4e521 --- /dev/null +++ b/src/GUI/SearchBar.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +class cSearchBar : public wxSearchCtrl +{ + public: + cSearchBar(wxWindow* window, wxDataViewListCtrl& listCtrl); + ~cSearchBar(); + + public: + wxSearchCtrl* GetSearchCtrlObject() { return this; } + + private: + // ------------------------------------------------------------------- + // SearchCtrl event handlers + void OnDoSearch(wxCommandEvent& event); + void OnCancelSearch(wxCommandEvent& event); + + private: + // ------------------------------------------------------------------- + wxWindow* m_pWindow = nullptr; + + wxDataViewListCtrl& m_ListCtrl; +}; diff --git a/src/GUI/TransportControls.cpp b/src/GUI/TransportControls.cpp index 1c6dadf..dd49cd4 100644 --- a/src/GUI/TransportControls.cpp +++ b/src/GUI/TransportControls.cpp @@ -1,12 +1,13 @@ #include "GUI/TransportControls.hpp" #include "Utility/ControlIDs.hpp" #include "Utility/SH_Event.hpp" +#include "Utility/Signal.hpp" #include "Utility/Serialize.hpp" #include "Utility/Log.hpp" #include "Utility/Paths.hpp" -TransportControls::TransportControls(wxWindow* window, wxDataViewListCtrl& library, - wxMediaCtrl& mediaCtrl, wxTimer& timer) +cTransportControls::cTransportControls(wxWindow* window, wxDataViewListCtrl& library, + wxMediaCtrl& mediaCtrl, wxTimer& timer) : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxNO_BORDER), m_Library(library), m_MediaCtrl(mediaCtrl), m_Timer(timer) { @@ -21,6 +22,7 @@ TransportControls::TransportControls(wxWindow* window, wxDataViewListCtrl& libra m_pLoopABButton = new wxBitmapToggleButton(this, BC_LoopABButton, static_cast(ICON_AB_DARK_16px), wxDefaultPosition, wxDefaultSize, 0); + m_pLoopABButton->SetToolTip(_("Loop selected region")); // Autoplay checkbox @@ -101,20 +103,20 @@ TransportControls::TransportControls(wxWindow* window, wxDataViewListCtrl& libra m_pMainSizer->SetSizeHints(this); m_pMainSizer->Layout(); - Bind(wxEVT_BUTTON, &TransportControls::OnClickPlay, this, BC_Play); - Bind(wxEVT_TOGGLEBUTTON, &TransportControls::OnClickLoop, this, BC_Loop); - Bind(wxEVT_BUTTON, &TransportControls::OnClickStop, this, BC_Stop); - Bind(wxEVT_TOGGLEBUTTON, &TransportControls::OnClickMute, this, BC_Mute); + Bind(wxEVT_BUTTON, &cTransportControls::OnClickPlay, this, BC_Play); + Bind(wxEVT_TOGGLEBUTTON, &cTransportControls::OnClickLoop, this, BC_Loop); + Bind(wxEVT_BUTTON, &cTransportControls::OnClickStop, this, BC_Stop); + Bind(wxEVT_TOGGLEBUTTON, &cTransportControls::OnClickMute, this, BC_Mute); // Bind(wxEVT_BUTTON, &Controls::OnClickSettings, this, BC_Settings); - Bind(wxEVT_CHECKBOX, &TransportControls::OnCheckAutoplay, this, BC_Autoplay); - Bind(wxEVT_SCROLL_THUMBTRACK, &TransportControls::OnSlideVolume, this, BC_Volume); - Bind(wxEVT_SCROLL_THUMBRELEASE, &TransportControls::OnReleaseVolumeSlider, this, BC_Volume); + Bind(wxEVT_CHECKBOX, &cTransportControls::OnCheckAutoplay, this, BC_Autoplay); + Bind(wxEVT_SCROLL_THUMBTRACK, &cTransportControls::OnSlideVolume, this, BC_Volume); + Bind(wxEVT_SCROLL_THUMBRELEASE, &cTransportControls::OnReleaseVolumeSlider, this, BC_Volume); // Load control values from config file LoadConfigFile(); } -void TransportControls::OnClickPlay(wxCommandEvent& event) +void cTransportControls::OnClickPlay(wxCommandEvent& event) { m_bStopped = false; @@ -126,10 +128,10 @@ void TransportControls::OnClickPlay(wxCommandEvent& event) wxString selection = m_Library.GetTextValue(selected_row, 1); // Send custom event to MainFrame to play the sample - SendCallFunctionPlay(selection); + SampleHive::Signal::SendCallFunctionPlay(selection, *this); } -void TransportControls::OnClickLoop(wxCommandEvent& event) +void cTransportControls::OnClickLoop(wxCommandEvent& event) { Serializer serializer; @@ -138,7 +140,7 @@ void TransportControls::OnClickLoop(wxCommandEvent& event) serializer.SerializeMediaOptions("loop", m_bLoop); } -void TransportControls::OnClickStop(wxCommandEvent& event) +void cTransportControls::OnClickStop(wxCommandEvent& event) { if (!m_MediaCtrl.Stop()) SH_LOG_ERROR("Error! Unable to stop media."); @@ -146,15 +148,15 @@ void TransportControls::OnClickStop(wxCommandEvent& event) m_bStopped = true; // Send custom event to MainFrame to stop the timer - SendTimerStopStatus(); + SampleHive::Signal::SendTimerStopStatus(*this); m_pSamplePosition->SetLabel("--:--/--:--"); // Send custom event to MainFrame to set the statusbar status - SendSetStatusBarStatus(_("Stopped"), 1); + SampleHive::Signal::SendSetStatusBarStatus(_("Stopped"), 1, *this); } -void TransportControls::OnClickMute(wxCommandEvent& event) +void cTransportControls::OnClickMute(wxCommandEvent& event) { Serializer serializer; @@ -174,7 +176,7 @@ void TransportControls::OnClickMute(wxCommandEvent& event) } } -void TransportControls::OnCheckAutoplay(wxCommandEvent& event) +void cTransportControls::OnCheckAutoplay(wxCommandEvent& event) { Serializer serializer; @@ -192,15 +194,16 @@ void TransportControls::OnCheckAutoplay(wxCommandEvent& event) } } -void TransportControls::OnSlideVolume(wxScrollEvent& event) +void cTransportControls::OnSlideVolume(wxScrollEvent& event) { m_MediaCtrl.SetVolume(double(m_pVolumeSlider->GetValue()) / 100); // Send custom event to MainFrame to push status to statusbar - SendPushStatusBarStatus(wxString::Format(_("Volume: %d"), m_pVolumeSlider->GetValue()), 1); + SampleHive::Signal::SendPushStatusBarStatus(wxString::Format(_("Volume: %d"), + m_pVolumeSlider->GetValue()), 1, *this); } -void TransportControls::OnReleaseVolumeSlider(wxScrollEvent& event) +void cTransportControls::OnReleaseVolumeSlider(wxScrollEvent& event) { Serializer serializer; @@ -217,15 +220,16 @@ void TransportControls::OnReleaseVolumeSlider(wxScrollEvent& event) wxSleep(1); // Send custom event to MainFrame to pop status from statusbar - SendPopStatusBarStatus(1); + SampleHive::Signal::SendPopStatusBarStatus(1, *this); if (m_MediaCtrl.GetState() == wxMEDIASTATE_STOPPED) - SendSetStatusBarStatus(_("Stopped"), 1); + SampleHive::Signal::SendSetStatusBarStatus(_("Stopped"), 1, *this); else - SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selection), 1); + SampleHive::Signal::SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selection), + 1, *this); } -void TransportControls::LoadConfigFile() +void cTransportControls::LoadConfigFile() { Serializer serializer; @@ -247,55 +251,7 @@ void TransportControls::LoadConfigFile() m_MediaCtrl.SetVolume(0.0); } -void TransportControls::SendPushStatusBarStatus(const wxString& msg, int section) -{ - SampleHive::SH_StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, this->GetId()); - event.SetEventObject(this); - - event.SetPushMessageAndSection({ msg, section }); - - HandleWindowEvent(event); -} - -void TransportControls::SendPopStatusBarStatus(int section) -{ - SampleHive::SH_StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_POP, this->GetId()); - event.SetEventObject(this); - - event.SetPopMessageSection(section); - - HandleWindowEvent(event); -} - -void TransportControls::SendSetStatusBarStatus(const wxString& text, int section) -{ - SampleHive::SH_StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_SET, this->GetId()); - event.SetEventObject(this); - - event.SetStatusTextAndSection({ text, section }); - - HandleWindowEvent(event); -} - -void TransportControls::SendCallFunctionPlay(const wxString& selection) -{ - SampleHive::SH_CallFunctionEvent event(SampleHive::SH_EVT_CALL_FUNC_PLAY, this->GetId()); - event.SetEventObject(this); - - event.SetSelection(selection); - - HandleWindowEvent(event); -} - -void TransportControls::SendTimerStopStatus() -{ - SampleHive::SH_TimerEvent event(SampleHive::SH_EVT_TIMER_STOP, this->GetId()); - event.SetEventObject(this); - - HandleWindowEvent(event); -} - -TransportControls::~TransportControls() +cTransportControls::~cTransportControls() { } diff --git a/src/GUI/TransportControls.hpp b/src/GUI/TransportControls.hpp index 1a71e7b..ffee40b 100644 --- a/src/GUI/TransportControls.hpp +++ b/src/GUI/TransportControls.hpp @@ -1,26 +1,27 @@ #pragma once -#include "wx/bmpbuttn.h" -#include "wx/button.h" -#include "wx/checkbox.h" -#include "wx/dataview.h" -#include "wx/event.h" -#include "wx/mediactrl.h" -#include "wx/settings.h" -#include "wx/sizer.h" -#include "wx/slider.h" -#include "wx/stattext.h" -#include "wx/tglbtn.h" -#include "wx/panel.h" -#include "wx/timer.h" -#include "wx/window.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -class TransportControls : public wxPanel +class cTransportControls : public wxPanel { public: // ------------------------------------------------------------------- - TransportControls(wxWindow* window, wxDataViewListCtrl& library, wxMediaCtrl& mediaCtrl, wxTimer& timer); - ~TransportControls(); + cTransportControls(wxWindow* window, wxDataViewListCtrl& library, wxMediaCtrl& mediaCtrl, wxTimer& timer); + ~cTransportControls(); public: // ------------------------------------------------------------------- @@ -59,15 +60,6 @@ class TransportControls : public wxPanel void OnSlideVolume(wxScrollEvent& event); void OnReleaseVolumeSlider(wxScrollEvent& event); - private: - // ------------------------------------------------------------------- - // Custom events for sending infomation to MainFrame - void SendPushStatusBarStatus(const wxString& msg, int section); - void SendSetStatusBarStatus(const wxString& msg, int section); - void SendPopStatusBarStatus(int section); - void SendCallFunctionPlay(const wxString& selection); - void SendTimerStopStatus(); - private: // ------------------------------------------------------------------- // Load control values from config file diff --git a/src/GUI/Trash.cpp b/src/GUI/Trash.cpp new file mode 100644 index 0000000..47da61b --- /dev/null +++ b/src/GUI/Trash.cpp @@ -0,0 +1,292 @@ +#include "GUI/Trash.hpp" +#include "GUI/Hives.hpp" +#include "GUI/ListCtrl.hpp" +#include "Database/Database.hpp" +#include "Utility/ControlIDs.hpp" +#include "Utility/Log.hpp" +#include "Utility/Paths.hpp" +#include "Utility/Signal.hpp" +#include "Utility/Serialize.hpp" + +#include +#include + +cTrashPanel::cTrashPanel(wxWindow* window, wxDataViewListCtrl& listCtrl) + : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), + m_pWindow(window), m_ListCtrl(listCtrl) +{ + m_pMainSizer = new wxBoxSizer(wxVERTICAL); + m_pTrashSizer = new wxBoxSizer(wxVERTICAL); + m_pButtonSizer = new wxBoxSizer(wxHORIZONTAL); + + m_pTrash = new wxTreeCtrl(this, BC_Trash, wxDefaultPosition, wxDefaultSize, + wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_MULTIPLE); + + // Setting m_Trash to accept files to be dragged and dropped on it + m_pTrash->DragAcceptFiles(true); + + m_pTrashSizer->Add(m_pTrash, wxSizerFlags(1).Expand()); + + m_pRestoreTrashedItemButton = new wxButton(this, BC_RestoreTrashedItem, _("Restore sample"), + wxDefaultPosition, wxDefaultSize, 0); + m_pRestoreTrashedItemButton->SetToolTip(_("Restore selected sample")); + + m_pButtonSizer->Add(m_pRestoreTrashedItemButton, wxSizerFlags(1).Expand()); + + // Addubg root to TrashedItems + m_TrashRoot = m_pTrash->AddRoot("Trash"); + + m_pTrash->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(cTrashPanel::OnDragAndDropToTrash), NULL, this); + Bind(wxEVT_TREE_ITEM_RIGHT_CLICK, &cTrashPanel::OnShowTrashContextMenu, this, BC_Trash); + Bind(wxEVT_BUTTON, &cTrashPanel::OnClickRestoreTrashItem, this, BC_RestoreTrashedItem); + + m_pMainSizer->Add(m_pTrashSizer, wxSizerFlags(1).Expand()); + m_pMainSizer->Add(m_pButtonSizer, wxSizerFlags(0).Expand()); + + // Sizer for trash pane + this->SetSizer(m_pMainSizer); + m_pMainSizer->Fit(this); + m_pMainSizer->SetSizeHints(this); + m_pMainSizer->Layout(); +} + +void cTrashPanel::OnDragAndDropToTrash(wxDropFilesEvent& event) +{ + Serializer serializer; + Database db; + cHivesPanel hives(m_pWindow, m_ListCtrl); + // cListCtrl m_ListCtrl.m_pWindow); + + if (event.GetNumberOfFiles() > 0) + { + wxFileDataObject file_data; + wxArrayString files; + + wxDataViewItemArray items; + int rows = m_ListCtrl.GetSelections(items); + // int rows = 2; + + wxString msg; + + wxDataViewItem root = wxDataViewItem(wxNullPtr); + wxDataViewItem container, child; + + for (int i = 0; i < rows; i++) + { + int item_row = m_ListCtrl.ItemToRow(items[i]); + + wxString text_value = m_ListCtrl.GetTextValue(item_row, 1); + + std::string multi_selection = serializer.DeserializeShowFileExtension() ? + m_ListCtrl.GetTextValue(item_row, 1).BeforeLast('.').ToStdString() : + m_ListCtrl.GetTextValue(item_row, 1).ToStdString() ; + + file_data.AddFile(multi_selection); + + files = file_data.GetFilenames(); + + if (db.GetFavoriteColumnValueByFilename(files[i].ToStdString())) + { + m_ListCtrl.SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0); + + db.UpdateFavoriteColumn(files[i].ToStdString(), 0); + + for (int j = 0; j < hives.GetHivesObject()->GetChildCount(root); j++) + { + container = hives.GetHivesObject()->GetNthChild(root, j); + + for (int k = 0; k < hives.GetHivesObject()->GetChildCount(container); k++) + { + child = hives.GetHivesObject()->GetNthChild(container, k); + + wxString child_text = serializer.DeserializeShowFileExtension() ? + hives.GetHivesObject()->GetItemText(child).BeforeLast('.') : + hives.GetHivesObject()->GetItemText(child); + + if (child_text == files[i]) + { + hives.GetHivesObject()->DeleteItem(child); + break; + } + } + } + } + + db.UpdateTrashColumn(files[i].ToStdString(), 1); + db.UpdateHiveName(files[i].ToStdString(), + hives.GetHivesObject()->GetItemText(hives.GetFavoritesHive()).ToStdString()); + + m_pTrash->AppendItem(m_TrashRoot, text_value); + + m_ListCtrl.DeleteItem(item_row); + + msg = wxString::Format(_("%s sent to trash"), text_value); + } + + if (!msg.IsEmpty()) + SampleHive::Signal::SendInfoBarMessage(msg, wxICON_ERROR, *this); + // m_InfoBar->ShowMessage(msg, wxICON_ERROR); + } +} + +void cTrashPanel::OnShowTrashContextMenu(wxTreeEvent& event) +{ + Serializer serializer; + Database db; + // cListCtrl m_ListCtrl.m_pWindow); + + wxTreeItemId selected_trashed_item = event.GetItem(); + + wxMenu menu; + + menu.Append(MN_DeleteTrash, _("Delete from database"), _("Delete the selected sample(s) from database")); + menu.Append(MN_RestoreTrashedItem, _("Restore sample"), _("Restore the selected sample(s) back to library")); + + if (selected_trashed_item.IsOk()) + { + switch (m_pTrash->GetPopupMenuSelectionFromUser(menu, event.GetPoint())) + { + case MN_DeleteTrash: + { + wxString trashed_item_name = serializer.DeserializeShowFileExtension() ? + m_pTrash->GetItemText(selected_trashed_item).BeforeLast('.') : + m_pTrash->GetItemText(selected_trashed_item); + + db.RemoveSampleFromDatabase(trashed_item_name.ToStdString()); + + m_pTrash->Delete(selected_trashed_item); + + SH_LOG_INFO("{} deleted from trash and databse", trashed_item_name); + } + break; + case MN_RestoreTrashedItem: + { + wxArrayTreeItemIds selected_item_ids; + m_pTrash->GetSelections(selected_item_ids); + + wxFileDataObject file_data; + wxArrayString files; + + wxString selected_item_text; + std::string filename; + + for (size_t i = 0; i < selected_item_ids.GetCount(); i++) + { + selected_item_text = m_pTrash->GetItemText(selected_item_ids[i]); + + // filename = GetFilenamePathAndExtension(selected_item_text).Filename; + + file_data.AddFile(filename); + + files = file_data.GetFilenames(); + + db.UpdateTrashColumn(files[i].ToStdString(), 0); + + try + { + wxVector> dataset; + + if (db.RestoreFromTrashByFilename(files[i].ToStdString(), + dataset, + serializer.DeserializeShowFileExtension(), + ICON_STAR_FILLED_16px, + ICON_STAR_EMPTY_16px).empty()) + { + SH_LOG_INFO("Error! Database is empty."); + } + else + { + for (auto data : dataset) + { + m_ListCtrl.AppendItem(data); + } + } + } + catch (...) + { + std::cerr << "Error loading data." << std::endl; + } + + m_pTrash->Delete(selected_item_ids[i]); + + SH_LOG_INFO("{} restored from trash", files[i]); + } + } + break; + default: + break; + } + } +} + +void cTrashPanel::OnClickRestoreTrashItem(wxCommandEvent& event) +{ + Serializer serializer; + Database db; + // cListCtrl m_ListCtrl.m_pWindow); + + wxArrayTreeItemIds selected_item_ids; + m_pTrash->GetSelections(selected_item_ids); + + wxFileDataObject file_data; + wxArrayString files; + + wxString selected_item_text; + std::string filename; + + if (m_pTrash->GetChildrenCount(m_TrashRoot) == 0) + { + wxMessageBox(_("Trash is empty, nothing to restore!"), wxMessageBoxCaptionStr, wxOK | wxCENTRE, this); + return; + } + + if (selected_item_ids.IsEmpty()) + { + wxMessageBox(_("No item selected, try selected a item first."), wxMessageBoxCaptionStr, + wxOK | wxCENTRE, this); + return; + } + + for (size_t i = 0; i < selected_item_ids.GetCount(); i++) + { + selected_item_text = m_pTrash->GetItemText(selected_item_ids[i]); + + // filename = GetFilenamePathAndExtension(selected_item_text).Filename; + + file_data.AddFile(filename); + + files = file_data.GetFilenames(); + + db.UpdateTrashColumn(files[i].ToStdString(), 0); + + try + { + wxVector> dataset; + + if (db.RestoreFromTrashByFilename(files[i].ToStdString(), dataset, + serializer.DeserializeShowFileExtension(), + ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty()) + { + SH_LOG_INFO("Error! Database is empty."); + } + else + { + for (auto data : dataset) + { + m_ListCtrl.AppendItem(data); + } + } + } + catch (...) + { + std::cerr << "Error loading data." << std::endl; + } + + m_pTrash->Delete(selected_item_ids[i]); + } +} + +cTrashPanel::~cTrashPanel() +{ + +} diff --git a/src/GUI/Trash.hpp b/src/GUI/Trash.hpp new file mode 100644 index 0000000..170b1da --- /dev/null +++ b/src/GUI/Trash.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +class cTrashPanel : public wxPanel +{ + public: + cTrashPanel(wxWindow* window, wxDataViewListCtrl& listCtrl); + ~cTrashPanel(); + + public: + wxTreeCtrl* GetTrashObject() { return m_pTrash; } + wxTreeItemId GetTrashRoot() { return m_TrashRoot; } + + private: + // ------------------------------------------------------------------- + // TrashPane event handlers + void OnShowTrashContextMenu(wxTreeEvent& event); + void OnClickRestoreTrashItem(wxCommandEvent& event); + void OnDragAndDropToTrash(wxDropFilesEvent& event); + + private: + wxTreeItemId m_TrashRoot; + wxTreeCtrl* m_pTrash = nullptr; + wxButton* m_pRestoreTrashedItemButton = nullptr; + wxBoxSizer* m_pMainSizer = nullptr; + wxBoxSizer* m_pTrashSizer = nullptr; + wxBoxSizer* m_pButtonSizer = nullptr; + + private: + wxWindow* m_pWindow = nullptr; + wxDataViewListCtrl& m_ListCtrl; + // friend class cListCtrl; +}; diff --git a/src/GUI/WaveformViewer.cpp b/src/GUI/WaveformViewer.cpp index 4d29650..8234bce 100644 --- a/src/GUI/WaveformViewer.cpp +++ b/src/GUI/WaveformViewer.cpp @@ -20,6 +20,7 @@ #include "GUI/WaveformViewer.hpp" #include "Utility/Serialize.hpp" +#include "Utility/Signal.hpp" #include "Utility/Tags.hpp" #include "Utility/SH_Event.hpp" #include "Utility/Log.hpp" @@ -37,7 +38,7 @@ #include -WaveformViewer::WaveformViewer(wxWindow* window, wxDataViewListCtrl& library, +cWaveformViewer::cWaveformViewer(wxWindow* window, wxDataViewListCtrl& library, wxMediaCtrl& mediaCtrl, Database& database) : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxNO_BORDER | wxFULL_REPAINT_ON_RESIZE), @@ -45,20 +46,27 @@ WaveformViewer::WaveformViewer(wxWindow* window, wxDataViewListCtrl& library, { this->SetDoubleBuffered(true); - Bind(wxEVT_PAINT, &WaveformViewer::OnPaint, this); - Bind(wxEVT_MOTION, &WaveformViewer::OnMouseMotion, this); - Bind(wxEVT_LEFT_DOWN, &WaveformViewer::OnMouseLeftButtonDown, this); - Bind(wxEVT_LEFT_UP, &WaveformViewer::OnMouseLeftButtonUp, this); - // Bind(wxEVT_KEY_DOWN, &WaveformViewer::OnControlKeyDown, this); - Bind(wxEVT_KEY_UP, &WaveformViewer::OnControlKeyUp, this); + Bind(wxEVT_PAINT, &cWaveformViewer::OnPaint, this); + Bind(wxEVT_MOTION, &cWaveformViewer::OnMouseMotion, this); + Bind(wxEVT_LEFT_DOWN, &cWaveformViewer::OnMouseLeftButtonDown, this); + Bind(wxEVT_LEFT_UP, &cWaveformViewer::OnMouseLeftButtonUp, this); + // Bind(wxEVT_KEY_DOWN, &cWaveformViewer::OnControlKeyDown, this); + Bind(wxEVT_KEY_UP, &cWaveformViewer::OnControlKeyUp, this); + + m_Sizer = new wxBoxSizer(wxVERTICAL); + + this->SetSizer(m_Sizer); + m_Sizer->Fit(this); + m_Sizer->SetSizeHints(this); + m_Sizer->Layout(); } -WaveformViewer::~WaveformViewer() +cWaveformViewer::~cWaveformViewer() { } -void WaveformViewer::OnPaint(wxPaintEvent& event) +void cWaveformViewer::OnPaint(wxPaintEvent& event) { wxPaintDC dc(this); @@ -101,13 +109,14 @@ void WaveformViewer::OnPaint(wxPaintEvent& event) this->GetSize().GetHeight() + 5)); bAreaSelected = true; - SendLoopPoints(); + // SendLoopPoints(); + SampleHive::Signal::SendLoopPoints(CalculateLoopPoints(), *this); } else bAreaSelected = false; } -void WaveformViewer::RenderPlayhead(wxDC& dc) +void cWaveformViewer::RenderPlayhead(wxDC& dc) { int selected_row = m_Library.GetSelectedRow(); @@ -145,7 +154,7 @@ void WaveformViewer::RenderPlayhead(wxDC& dc) line_pos, this->GetSize().GetHeight() - 1); } -void WaveformViewer::UpdateWaveformBitmap() +void cWaveformViewer::UpdateWaveformBitmap() { Serializer serializer; @@ -251,7 +260,7 @@ void WaveformViewer::UpdateWaveformBitmap() SH_LOG_DEBUG("Done drawing bitmap.."); } -void WaveformViewer::OnControlKeyDown(wxKeyEvent &event) +void cWaveformViewer::OnControlKeyDown(wxKeyEvent &event) { switch (event.GetKeyCode()) { @@ -266,7 +275,7 @@ void WaveformViewer::OnControlKeyDown(wxKeyEvent &event) event.Skip(); } -void WaveformViewer::OnControlKeyUp(wxKeyEvent &event) +void cWaveformViewer::OnControlKeyUp(wxKeyEvent &event) { switch (event.GetKeyCode()) { @@ -287,7 +296,7 @@ void WaveformViewer::OnControlKeyUp(wxKeyEvent &event) event.Skip(); } -void WaveformViewer::OnMouseMotion(wxMouseEvent& event) +void cWaveformViewer::OnMouseMotion(wxMouseEvent& event) { int selected_row = m_Library.GetSelectedRow(); @@ -327,7 +336,7 @@ void WaveformViewer::OnMouseMotion(wxMouseEvent& event) return; } -void WaveformViewer::OnMouseLeftButtonDown(wxMouseEvent& event) +void cWaveformViewer::OnMouseLeftButtonDown(wxMouseEvent& event) { int selected_row = m_Library.GetSelectedRow(); @@ -376,7 +385,7 @@ void WaveformViewer::OnMouseLeftButtonDown(wxMouseEvent& event) event.Skip(); } -void WaveformViewer::OnMouseLeftButtonUp(wxMouseEvent& event) +void cWaveformViewer::OnMouseLeftButtonUp(wxMouseEvent& event) { int selected_row = m_Library.GetSelectedRow(); @@ -427,12 +436,13 @@ void WaveformViewer::OnMouseLeftButtonUp(wxMouseEvent& event) SetCursor(wxCURSOR_ARROW); m_MediaCtrl.Seek(seek_to, wxFromStart); - SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selected), 1); + // SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selected), 1); + SampleHive::Signal::SendInfoBarMessage(wxString::Format(_("Now playing: %s"), selected), 1, *this); m_MediaCtrl.Play(); } } -void WaveformViewer::ResetDC() +void cWaveformViewer::ResetDC() { bBitmapDirty = true; bSelectRange = false; @@ -441,17 +451,12 @@ void WaveformViewer::ResetDC() Refresh(); } -void WaveformViewer::SendLoopPoints() +std::pair cWaveformViewer::CalculateLoopPoints() { - SH_LOG_DEBUG("{} Called", __FUNCTION__); - - SampleHive::SH_LoopPointsEvent event(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, this->GetId()); - event.SetEventObject(this); - int selected_row = m_Library.GetSelectedRow(); if (selected_row < 0) - return; + return { 0.0, 0.0 }; wxString selected = m_Library.GetTextValue(selected_row, 1); std::string path = m_Database.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString()); @@ -467,19 +472,15 @@ void WaveformViewer::SendLoopPoints() double loopA = ((double)a / panel_width) * length; double loopB = ((double)b / panel_width) * length; - event.SetLoopPoints({ loopA, loopB }); - - HandleWindowEvent(event); - - SH_LOG_DEBUG("{} processed event, sending loop points..", __FUNCTION__); + return { loopA, loopB }; } -void WaveformViewer::SendPushStatusBarStatus(const wxString& msg, int section) -{ - SampleHive::SH_StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, this->GetId()); - event.SetEventObject(this); +// void cWaveformViewer::SendPushStatusBarStatus(const wxString& msg, int section) +// { +// SampleHive::SH_StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, this->GetId()); +// event.SetEventObject(this); - event.SetPushMessageAndSection({ msg, section }); +// event.SetPushMessageAndSection({ msg, section }); - HandleWindowEvent(event); -} +// HandleWindowEvent(event); +// } diff --git a/src/GUI/WaveformViewer.hpp b/src/GUI/WaveformViewer.hpp index cd6276d..0a38a93 100644 --- a/src/GUI/WaveformViewer.hpp +++ b/src/GUI/WaveformViewer.hpp @@ -35,17 +35,19 @@ #include #include -class WaveformViewer : public wxPanel +class cWaveformViewer : public wxPanel { public: - WaveformViewer(wxWindow* window, wxDataViewListCtrl& library, - wxMediaCtrl& mediaCtrl, Database& database); - ~WaveformViewer(); + cWaveformViewer(wxWindow* window, wxDataViewListCtrl& library, + wxMediaCtrl& mediaCtrl, Database& database); + ~cWaveformViewer(); private: // ------------------------------------------------------------------- wxWindow* m_Window; + wxBoxSizer* m_Sizer; + // ------------------------------------------------------------------- Database& m_Database; wxDataViewListCtrl& m_Library; @@ -84,10 +86,13 @@ class WaveformViewer : public wxPanel void OnControlKeyUp(wxKeyEvent& event); void OnControlKeyDown(wxKeyEvent& event); + // ------------------------------------------------------------------- + std::pair CalculateLoopPoints(); + // ------------------------------------------------------------------- // Send custom events - void SendLoopPoints(); - void SendPushStatusBarStatus(const wxString& msg, int section); + // void SendLoopPoints(); + // void SendPushStatusBarStatus(const wxString& msg, int section); public: // ------------------------------------------------------------------- diff --git a/src/Utility/SH_Event.cpp b/src/Utility/SH_Event.cpp index bf8bd52..3f6ba23 100644 --- a/src/Utility/SH_Event.cpp +++ b/src/Utility/SH_Event.cpp @@ -22,96 +22,109 @@ namespace SampleHive { - SH_LoopPointsEvent::SH_LoopPointsEvent(wxEventType eventType, int winId) + LoopPointsEvent::LoopPointsEvent(wxEventType eventType, int winId) : wxCommandEvent(eventType, winId) { } - SH_LoopPointsEvent::~SH_LoopPointsEvent() + LoopPointsEvent::~LoopPointsEvent() { } - wxDEFINE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, SH_LoopPointsEvent); + wxDEFINE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, LoopPointsEvent); - // SH_AddSampleEvent::SH_AddSampleEvent(wxEventType eventType, int winId) + // AddSampleEvent::AddSampleEvent(wxEventType eventType, int winId) // : wxCommandEvent(eventType, winId) // { // } - // SH_AddSampleEvent::~SH_AddSampleEvent() + // AddSampleEvent::~AddSampleEvent() // { // } - // wxDEFINE_EVENT(SH_EVT_STATUS_ADD_SAMPLE, SH_AddSampleEvent); + // wxDEFINE_EVENT(SH_EVT_STATUS_ADD_SAMPLE, AddSampleEvent); - // SH_MediaEvent::SH_MediaEvent(wxEventType eventType, int winId) + // MediaEvent::MediaEvent(wxEventType eventType, int winId) // : wxCommandEvent(eventType, winId) // { // } - // SH_MediaEvent::~SH_MediaEvent() + // MediaEvent::~MediaEvent() // { // } - // wxDEFINE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, SH_MediaEvent); + // wxDEFINE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, MediaEvent); - SH_StatusBarStatusEvent::SH_StatusBarStatusEvent(wxEventType eventType, int winId) + StatusBarStatusEvent::StatusBarStatusEvent(wxEventType eventType, int winId) : wxCommandEvent(eventType, winId) { } - SH_StatusBarStatusEvent::~SH_StatusBarStatusEvent() + StatusBarStatusEvent::~StatusBarStatusEvent() { } - wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_PUSH, SH_StatusBarStatusEvent); - wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_POP, SH_StatusBarStatusEvent); - wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_SET, SH_StatusBarStatusEvent); + wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_PUSH, StatusBarStatusEvent); + wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_POP, StatusBarStatusEvent); + wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_SET, StatusBarStatusEvent); - SH_InfoBarMessageEvent::SH_InfoBarMessageEvent(wxEventType eventType, int winId) + InfoBarMessageEvent::InfoBarMessageEvent(wxEventType eventType, int winId) : wxCommandEvent(eventType, winId) { } - SH_InfoBarMessageEvent::~SH_InfoBarMessageEvent() + InfoBarMessageEvent::~InfoBarMessageEvent() { } - wxDEFINE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, SH_InfoBarMessageEvent); + wxDEFINE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, InfoBarMessageEvent); - SH_TimerEvent::SH_TimerEvent(wxEventType eventType, int winId) + TimerEvent::TimerEvent(wxEventType eventType, int winId) : wxCommandEvent(eventType, winId) { } - SH_TimerEvent::~SH_TimerEvent() + TimerEvent::~TimerEvent() { } - wxDEFINE_EVENT(SH_EVT_TIMER_STOP, SH_TimerEvent); + wxDEFINE_EVENT(SH_EVT_TIMER_STOP, TimerEvent); - SH_CallFunctionEvent::SH_CallFunctionEvent(wxEventType eventType, int winId) + CallFunctionEvent::CallFunctionEvent(wxEventType eventType, int winId) : wxCommandEvent(eventType, winId) { } - SH_CallFunctionEvent::~SH_CallFunctionEvent() + CallFunctionEvent::~CallFunctionEvent() { } - wxDEFINE_EVENT(SH_EVT_CALL_FUNC_PLAY, SH_CallFunctionEvent); + wxDEFINE_EVENT(SH_EVT_CALL_FUNC_PLAY, CallFunctionEvent); + + WaveformUpdateEvent::WaveformUpdateEvent(wxEventType eventType, int winId) + : wxCommandEvent(eventType, winId) + { + + } + + WaveformUpdateEvent::~WaveformUpdateEvent() + { + + } + + wxDEFINE_EVENT(SH_EVT_UPDATE_WAVEFORM, WaveformUpdateEvent); } diff --git a/src/Utility/SH_Event.hpp b/src/Utility/SH_Event.hpp index 1d26635..207ccf7 100644 --- a/src/Utility/SH_Event.hpp +++ b/src/Utility/SH_Event.hpp @@ -26,14 +26,14 @@ namespace SampleHive { - class SH_LoopPointsEvent : public wxCommandEvent + class LoopPointsEvent : public wxCommandEvent { public: - SH_LoopPointsEvent(wxEventType eventType, int winId); - ~SH_LoopPointsEvent(); + LoopPointsEvent(wxEventType eventType, int winId); + ~LoopPointsEvent(); public: - virtual wxEvent* Clone() const { return new SH_LoopPointsEvent(*this); } + virtual wxEvent* Clone() const { return new LoopPointsEvent(*this); } public: std::pair GetLoopPoints() const { return { m_LoopA, m_LoopB }; }; @@ -44,16 +44,16 @@ namespace SampleHive double m_LoopA, m_LoopB; }; - wxDECLARE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, SH_LoopPointsEvent); + wxDECLARE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, LoopPointsEvent); - // class SH_AddSampleEvent : public wxCommandEvent + // class AddSampleEvent : public wxCommandEvent // { // public: - // SH_AddSampleEvent(wxEventType eventType, int winId); - // ~SH_AddSampleEvent(); + // AddSampleEvent(wxEventType eventType, int winId); + // ~AddSampleEvent(); // public: - // virtual wxEvent* Clone() const { return new SH_AddSampleEvent(*this); } + // virtual wxEvent* Clone() const { return new AddSampleEvent(*this); } // public: // wxArrayString GetArrayString() const { return m_Files; }; @@ -63,16 +63,16 @@ namespace SampleHive // wxArrayString m_Files; // }; - // wxDECLARE_EVENT(SH_EVT_STATUS_ADD_SAMPLE, SH_AddSampleEvent); + // wxDECLARE_EVENT(SH_EVT_STATUS_ADD_SAMPLE, AddSampleEvent); - // class SH_MediaEvent : public wxCommandEvent + // class MediaEvent : public wxCommandEvent // { // public: - // SH_MediaEvent(wxEventType eventType, int winId); - // ~SH_MediaEvent(); + // MediaEvent(wxEventType eventType, int winId); + // ~MediaEvent(); // public: - // virtual wxEvent* Clone() const { return new SH_MediaEvent(*this); } + // virtual wxEvent* Clone() const { return new MediaEvent(*this); } // public: // void SetPath(const wxString& path) { m_Path = path; } @@ -82,16 +82,16 @@ namespace SampleHive // wxString m_Path; // }; - // wxDECLARE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, SH_MediaEvent); + // wxDECLARE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, MediaEvent); - class SH_StatusBarStatusEvent : public wxCommandEvent + class StatusBarStatusEvent : public wxCommandEvent { public: - SH_StatusBarStatusEvent(wxEventType eventType, int winId); - ~SH_StatusBarStatusEvent(); + StatusBarStatusEvent(wxEventType eventType, int winId); + ~StatusBarStatusEvent(); public: - virtual wxEvent* Clone() const { return new SH_StatusBarStatusEvent(*this); } + virtual wxEvent* Clone() const { return new StatusBarStatusEvent(*this); } public: std::pair GetPushMessageAndSection() const { return { m_Msg, m_PushSection }; } @@ -110,18 +110,18 @@ namespace SampleHive int m_PushSection, m_PopSection, m_SetSection; }; - wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_PUSH, SH_StatusBarStatusEvent); - wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_POP, SH_StatusBarStatusEvent); - wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_SET, SH_StatusBarStatusEvent); + wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_PUSH, StatusBarStatusEvent); + wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_POP, StatusBarStatusEvent); + wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_SET, StatusBarStatusEvent); - class SH_InfoBarMessageEvent : public wxCommandEvent + class InfoBarMessageEvent : public wxCommandEvent { public: - SH_InfoBarMessageEvent(wxEventType eventType, int winId); - ~SH_InfoBarMessageEvent(); + InfoBarMessageEvent(wxEventType eventType, int winId); + ~InfoBarMessageEvent(); public: - virtual wxEvent* Clone() const { return new SH_InfoBarMessageEvent(*this); } + virtual wxEvent* Clone() const { return new InfoBarMessageEvent(*this); } public: std::pair GetInfoBarMessage() const { return { m_Msg, m_Mode }; } @@ -133,28 +133,28 @@ namespace SampleHive int m_Mode; }; - wxDECLARE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, SH_InfoBarMessageEvent); + wxDECLARE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, InfoBarMessageEvent); - class SH_TimerEvent : public wxCommandEvent + class TimerEvent : public wxCommandEvent { public: - SH_TimerEvent(wxEventType eventType, int winId); - ~SH_TimerEvent(); + TimerEvent(wxEventType eventType, int winId); + ~TimerEvent(); public: - virtual wxEvent* Clone() const { return new SH_TimerEvent(*this); } + virtual wxEvent* Clone() const { return new TimerEvent(*this); } }; - wxDECLARE_EVENT(SH_EVT_TIMER_STOP, SH_TimerEvent); + wxDECLARE_EVENT(SH_EVT_TIMER_STOP, TimerEvent); - class SH_CallFunctionEvent : public wxCommandEvent + class CallFunctionEvent : public wxCommandEvent { public: - SH_CallFunctionEvent(wxEventType eventType, int winId); - ~SH_CallFunctionEvent(); + CallFunctionEvent(wxEventType eventType, int winId); + ~CallFunctionEvent(); public: - virtual wxEvent* Clone() const { return new SH_CallFunctionEvent(*this); } + virtual wxEvent* Clone() const { return new CallFunctionEvent(*this); } public: wxString GetSlection() { return m_Selection; } @@ -164,5 +164,18 @@ namespace SampleHive wxString m_Selection; }; - wxDECLARE_EVENT(SH_EVT_CALL_FUNC_PLAY, SH_CallFunctionEvent); + wxDECLARE_EVENT(SH_EVT_CALL_FUNC_PLAY, CallFunctionEvent); + + class WaveformUpdateEvent : public wxCommandEvent + { + public: + WaveformUpdateEvent(wxEventType eventType, int winId); + ~WaveformUpdateEvent(); + + public: + virtual wxEvent* Clone() const { return new WaveformUpdateEvent(*this); } + }; + + wxDECLARE_EVENT(SH_EVT_UPDATE_WAVEFORM, WaveformUpdateEvent); + } diff --git a/src/Utility/Signal.cpp b/src/Utility/Signal.cpp new file mode 100644 index 0000000..d0cdefa --- /dev/null +++ b/src/Utility/Signal.cpp @@ -0,0 +1,104 @@ +#include "Utility/Signal.hpp" +#include "Utility/Log.hpp" +#include "Utility/SH_Event.hpp" + +namespace SampleHive { + + void Signal::SendInfoBarMessage(const wxString& msg, int mode, wxWindow& window, bool isDialog) + { + SampleHive::InfoBarMessageEvent event(SampleHive::SH_EVT_INFOBAR_MESSAGE_SHOW, window.GetId()); + event.SetEventObject(&window); + + event.SetInfoBarMessage({ msg, mode }); + + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + + void Signal::SendPushStatusBarStatus(const wxString& msg, int section, wxWindow& window, bool isDialog) + { + SampleHive::StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, window.GetId()); + event.SetEventObject(&window); + + event.SetPushMessageAndSection({ msg, section }); + + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + + void Signal::SendPopStatusBarStatus(int section, wxWindow& window, bool isDialog) + { + SampleHive::StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_POP, window.GetId()); + event.SetEventObject(&window); + + event.SetPopMessageSection(section); + + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + + void Signal::SendSetStatusBarStatus(const wxString& text, int section, wxWindow& window, bool isDialog) + { + SampleHive::StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_SET, window.GetId()); + event.SetEventObject(&window); + + event.SetStatusTextAndSection({ text, section }); + + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + + void Signal::SendCallFunctionPlay(const wxString& selection, wxWindow& window, bool isDialog) + { + SampleHive::CallFunctionEvent event(SampleHive::SH_EVT_CALL_FUNC_PLAY, window.GetId()); + event.SetEventObject(&window); + + event.SetSelection(selection); + + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + + void Signal::SendTimerStopStatus(wxWindow& window, bool isDialog) + { + SampleHive::TimerEvent event(SampleHive::SH_EVT_TIMER_STOP, window.GetId()); + event.SetEventObject(&window); + + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + + void Signal::SendLoopPoints(std::pair loopPoint, wxWindow& window, bool isDialog) + { + SampleHive::LoopPointsEvent event(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, window.GetId()); + event.SetEventObject(&window); + + event.SetLoopPoints({loopPoint.first, loopPoint.second}); + + window.HandleWindowEvent(event); + } + + void Signal::SendWaveformUpdateStatus(wxWindow& window, bool isDialog) + { + SampleHive::WaveformUpdateEvent event(SampleHive::SH_EVT_UPDATE_WAVEFORM, window.GetId()); + event.SetEventObject(&window); + + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + +} diff --git a/src/Utility/Signal.hpp b/src/Utility/Signal.hpp new file mode 100644 index 0000000..c0563dc --- /dev/null +++ b/src/Utility/Signal.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +namespace SampleHive { + + class Signal + { + public: + Signal(); + ~Signal(); + + public: + static void SendInfoBarMessage(const wxString& msg, int mode, wxWindow& window, bool isDialog = false); + static void SendPushStatusBarStatus(const wxString& msg, int section, wxWindow& window, bool isDialog = false); + static void SendSetStatusBarStatus(const wxString& msg, int section, wxWindow& window, bool isDialog = false); + static void SendPopStatusBarStatus(int section, wxWindow& window, bool isDialog = false); + static void SendCallFunctionPlay(const wxString& selection, wxWindow& window, bool isDialog = false); + static void SendTimerStopStatus(wxWindow& window, bool isDialog = false); + static void SendLoopPoints(std::pair loopPoint, wxWindow& window, bool isDialog = false); + static void SendWaveformUpdateStatus(wxWindow& window, bool isDialog = false); + + }; + +}