From f40f514912662fb1c9555252f2d3b00bf589d22b Mon Sep 17 00:00:00 2001 From: apoorv569 Date: Mon, 8 Nov 2021 13:22:03 +0530 Subject: [PATCH] Add new custom events. --- src/App.cpp | 1 - src/GUI/Dialogs/TagEditor.cpp | 2 +- src/GUI/MainFrame.cpp | 33 ++++++++++++++++---- src/GUI/MainFrame.hpp | 5 ++- src/GUI/WaveformViewer.cpp | 8 ++--- src/GUI/WaveformViewer.hpp | 2 +- src/Utility/Paths.hpp | 2 ++ src/Utility/SH_Event.cpp | 26 ++++++++-------- src/Utility/SH_Event.hpp | 57 ++++++++++++++++++----------------- src/Utility/Sample.hpp | 1 - 10 files changed, 82 insertions(+), 55 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index e138687..f8a4485 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -19,7 +19,6 @@ */ #include "App.hpp" -#include "SampleHiveConfig.hpp" #include "Utility/Paths.hpp" #include "Utility/Log.hpp" diff --git a/src/GUI/Dialogs/TagEditor.cpp b/src/GUI/Dialogs/TagEditor.cpp index 3f5907e..df73d47 100644 --- a/src/GUI/Dialogs/TagEditor.cpp +++ b/src/GUI/Dialogs/TagEditor.cpp @@ -319,7 +319,7 @@ void TagEditor::SendInfoBarMessage(const wxString& msg, int mode) { SH_LOG_INFO("{} called..", __FUNCTION__); - SampleHive::SH_InfoBarMessageEvent event(SampleHive::SH_EVT_INFOBAR_MESSAGE_UPDATED, this->GetId()); + SampleHive::SH_InfoBarMessageEvent event(SampleHive::SH_EVT_INFOBAR_MESSAGE_SHOW, this->GetId()); event.SetEventObject(this); event.SetInfoBarMessage({ msg, mode }); diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 65f25a3..5730f35 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -459,8 +459,11 @@ MainFrame::MainFrame() Bind(wxEVT_BUTTON, &MainFrame::OnClickRemoveHive, this, BC_HiveRemove); Bind(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, &MainFrame::OnRecieveLoopPoints, this); - Bind(SampleHive::SH_EVT_STATUSBAR_MESSAGE_UPDATED, &MainFrame::OnRecieveStatusBarStatus, this); - Bind(SampleHive::SH_EVT_INFOBAR_MESSAGE_UPDATED, &MainFrame::OnRecieveInfoBarStatus, this); + Bind(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, &MainFrame::OnRecievePushStatusBarStatus, this); + Bind(SampleHive::SH_EVT_STATUSBAR_STATUS_POP, &MainFrame::OnRecievePopStatusBarStatus, this); + 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); // Adding widgets to their sizers m_MainSizer->Add(m_MainPanel, 1, wxALL | wxEXPAND, 0); @@ -3012,21 +3015,33 @@ void MainFrame::OnRecieveLoopPoints(SampleHive::SH_LoopPointsEvent& event) int loopB_min = static_cast((m_LoopB / 60000).GetValue()); 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)); + SH_LOG_INFO(wxString::Format(_("Loop points set: A: %2i:%02i, B: %2i:%02i"), + loopA_min, loopA_sec, loopB_min, loopB_sec)); m_LoopABButton->SetValue(true); bLoopPointsSet = true; } -void MainFrame::OnRecieveStatusBarStatus(SampleHive::SH_StatusBarMessageEvent& event) +void MainFrame::OnRecievePushStatusBarStatus(SampleHive::SH_StatusBarStatusEvent& event) { - std::pair status = event.GetMessageAndSection(); + std::pair status = event.GetPushMessageAndSection(); m_StatusBar->PushStatusText(status.first, status.second); } +void MainFrame::OnRecievePopStatusBarStatus(SampleHive::SH_StatusBarStatusEvent& event) +{ + m_StatusBar->PopStatusText(event.GetPopMessageSection()); +} + +void MainFrame::OnRecieveSetStatusBarStatus(SampleHive::SH_StatusBarStatusEvent& event) +{ + std::pair status = event.GetStatusTextAndSection(); + + m_StatusBar->SetStatusText(status.first, status.second); +} + void MainFrame::OnRecieveInfoBarStatus(SampleHive::SH_InfoBarMessageEvent& event) { SH_LOG_INFO("{} called..", __FUNCTION__); @@ -3038,6 +3053,12 @@ void MainFrame::OnRecieveInfoBarStatus(SampleHive::SH_InfoBarMessageEvent& event SH_LOG_INFO("{} event processed", __FUNCTION__); } +void MainFrame::OnRecieveTimerStopStatus(SampleHive::SH_TimerEvent& event) +{ + if (m_Timer->IsRunning()) + m_Timer->Stop(); +} + void MainFrame::ClearLoopPoints() { m_LoopA = 0; diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index c7311c5..4e7583b 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -273,8 +273,11 @@ class MainFrame : public wxFrame // Recieve custom events // ------------------------------------------------------------------- void OnRecieveLoopPoints(SampleHive::SH_LoopPointsEvent& event); - void OnRecieveStatusBarStatus(SampleHive::SH_StatusBarMessageEvent& 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 LoadDatabase(); diff --git a/src/GUI/WaveformViewer.cpp b/src/GUI/WaveformViewer.cpp index 17ae61f..ea4bc88 100644 --- a/src/GUI/WaveformViewer.cpp +++ b/src/GUI/WaveformViewer.cpp @@ -427,7 +427,7 @@ void WaveformViewer::OnMouseLeftButtonUp(wxMouseEvent& event) SetCursor(wxCURSOR_ARROW); m_MediaCtrl.Seek(seek_to, wxFromStart); - SendStatusBarStatus(wxString::Format(_("Now playing: %s"), selected), 1); + SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selected), 1); m_MediaCtrl.Play(); } } @@ -474,12 +474,12 @@ void WaveformViewer::SendLoopPoints() SH_LOG_DEBUG("{} processed event, sending loop points..", __FUNCTION__); } -void WaveformViewer::SendStatusBarStatus(const wxString& msg, int section) +void WaveformViewer::SendPushStatusBarStatus(const wxString& msg, int section) { - SampleHive::SH_StatusBarMessageEvent event(SampleHive::SH_EVT_STATUSBAR_MESSAGE_UPDATED, this->GetId()); + SampleHive::SH_StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, this->GetId()); event.SetEventObject(this); - event.SetMessageAndSection({ msg, section }); + event.SetPushMessageAndSection({ msg, section }); HandleWindowEvent(event); } diff --git a/src/GUI/WaveformViewer.hpp b/src/GUI/WaveformViewer.hpp index dd3e5bf..cd6276d 100644 --- a/src/GUI/WaveformViewer.hpp +++ b/src/GUI/WaveformViewer.hpp @@ -87,7 +87,7 @@ class WaveformViewer : public wxPanel // ------------------------------------------------------------------- // Send custom events void SendLoopPoints(); - void SendStatusBarStatus(const wxString& msg, int section); + void SendPushStatusBarStatus(const wxString& msg, int section); public: // ------------------------------------------------------------------- diff --git a/src/Utility/Paths.hpp b/src/Utility/Paths.hpp index 2b72df7..8bda7e2 100644 --- a/src/Utility/Paths.hpp +++ b/src/Utility/Paths.hpp @@ -1,5 +1,7 @@ #pragma once +#include "SampleHiveConfig.hpp" + // Path to all the assets #define ICON_HIVE_16px SAMPLEHIVE_DATADIR "/icons/icon-hive_16x16.png" #define ICON_HIVE_24px SAMPLEHIVE_DATADIR "/icons/icon-hive_24x24.png" diff --git a/src/Utility/SH_Event.cpp b/src/Utility/SH_Event.cpp index 463e19b..6c62342 100644 --- a/src/Utility/SH_Event.cpp +++ b/src/Utility/SH_Event.cpp @@ -61,18 +61,20 @@ namespace SampleHive // wxDEFINE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, SH_MediaEvent); - SH_StatusBarMessageEvent::SH_StatusBarMessageEvent(wxEventType eventType, int winId) + SH_StatusBarStatusEvent::SH_StatusBarStatusEvent(wxEventType eventType, int winId) : wxCommandEvent(eventType, winId) { } - SH_StatusBarMessageEvent::~SH_StatusBarMessageEvent() + SH_StatusBarStatusEvent::~SH_StatusBarStatusEvent() { } - wxDEFINE_EVENT(SH_EVT_STATUSBAR_MESSAGE_UPDATED, SH_StatusBarMessageEvent); + 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); SH_InfoBarMessageEvent::SH_InfoBarMessageEvent(wxEventType eventType, int winId) : wxCommandEvent(eventType, winId) @@ -85,18 +87,18 @@ namespace SampleHive } - wxDEFINE_EVENT(SH_EVT_INFOBAR_MESSAGE_UPDATED, SH_InfoBarMessageEvent); + wxDEFINE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, SH_InfoBarMessageEvent); - // SH_TimerEvent::SH_TimerEvent(wxEventType eventType, int winId) - // : wxCommandEvent(eventType, winId) - // { + SH_TimerEvent::SH_TimerEvent(wxEventType eventType, int winId) + : wxCommandEvent(eventType, winId) + { - // } + } - // SH_TimerEvent::~SH_TimerEvent() - // { + SH_TimerEvent::~SH_TimerEvent() + { - // } + } - // wxDEFINE_EVENT(SH_EVT_TIMER_STATUS_UPDATED, SH_TimerEvent); + wxDEFINE_EVENT(SH_EVT_TIMER_STOP, SH_TimerEvent); } diff --git a/src/Utility/SH_Event.hpp b/src/Utility/SH_Event.hpp index d8eb27e..d2baf58 100644 --- a/src/Utility/SH_Event.hpp +++ b/src/Utility/SH_Event.hpp @@ -84,26 +84,35 @@ namespace SampleHive // wxDECLARE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, SH_MediaEvent); - class SH_StatusBarMessageEvent : public wxCommandEvent + class SH_StatusBarStatusEvent : public wxCommandEvent { public: - SH_StatusBarMessageEvent(wxEventType eventType, int winId); - ~SH_StatusBarMessageEvent(); + SH_StatusBarStatusEvent(wxEventType eventType, int winId); + ~SH_StatusBarStatusEvent(); public: - virtual wxEvent* Clone() const { return new SH_StatusBarMessageEvent(*this); } + virtual wxEvent* Clone() const { return new SH_StatusBarStatusEvent(*this); } public: - std::pair GetMessageAndSection() const { return { m_Msg, m_Section }; } - void SetMessageAndSection(std::pair status) - { m_Msg = status.first; m_Section = status.second; } + std::pair GetPushMessageAndSection() const { return { m_Msg, m_PushSection }; } + void SetPushMessageAndSection(std::pair status) + { m_Msg = status.first; m_PushSection = status.second; } + + std::pair GetStatusTextAndSection() const { return { m_Text, m_SetSection }; } + void SetStatusTextAndSection(std::pair status) + { m_Text = status.first, m_SetSection = status.second; } + + int GetPopMessageSection() const { return m_PopSection; } + void SetPopMessageSection(int section) { m_PopSection = section; } private: - wxString m_Msg; - int m_Section; + wxString m_Msg, m_Text; + int m_PushSection, m_PopSection, m_SetSection; }; - wxDECLARE_EVENT(SH_EVT_STATUSBAR_MESSAGE_UPDATED, SH_StatusBarMessageEvent); + 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); class SH_InfoBarMessageEvent : public wxCommandEvent { @@ -124,25 +133,17 @@ namespace SampleHive int m_Mode; }; - wxDECLARE_EVENT(SH_EVT_INFOBAR_MESSAGE_UPDATED, SH_InfoBarMessageEvent); + wxDECLARE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, SH_InfoBarMessageEvent); - // class SH_TimerEvent : public wxCommandEvent - // { - // public: - // SH_TimerEvent(wxEventType eventType, int winId); - // ~SH_TimerEvent(); + class SH_TimerEvent : public wxCommandEvent + { + public: + SH_TimerEvent(wxEventType eventType, int winId); + ~SH_TimerEvent(); - // public: - // virtual wxEvent* Clone() const { return new SH_TimerEvent(*this); } + public: + virtual wxEvent* Clone() const { return new SH_TimerEvent(*this); } + }; - // public: - // std::pair GetSecondsAndMode() const { return { m_Seconds, m_Mode }; } - // void SetSecondsAndMode(std::pair timerStatus) { m_Seconds = timerStatus.first; m_Mode = timerStatus.second; } - - // private: - // int m_Seconds; - // bool m_Mode; - // }; - - // wxDECLARE_EVENT(SH_EVT_TIMER_STATUS_UPDATED, SH_TimerEvent); + wxDECLARE_EVENT(SH_EVT_TIMER_STOP, SH_TimerEvent); } diff --git a/src/Utility/Sample.hpp b/src/Utility/Sample.hpp index ac3bd9f..1cffc60 100644 --- a/src/Utility/Sample.hpp +++ b/src/Utility/Sample.hpp @@ -39,7 +39,6 @@ class Sample { public: Sample(); - Sample(int favorite, const std::string& filename, const std::string& fileExtension, const std::string& samplePack, const std::string& type, int channels, int length, int sampleRate, int bitrate, const std::string& path, int trashed);