From 0eaf78923cfa2569cc16ca4f12ebd5c86e47d1e2 Mon Sep 17 00:00:00 2001 From: apoorv569 Date: Sun, 5 Sep 2021 03:27:18 +0530 Subject: [PATCH] Can loop a region now. --- src/MainFrame.cpp | 53 ++++++++++++++++++++++++++++++++---------- src/MainFrame.hpp | 5 ++++ src/WaveformViewer.cpp | 13 +++++++---- src/WaveformViewer.hpp | 2 +- 4 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/MainFrame.cpp b/src/MainFrame.cpp index 5c842de..4006583 100644 --- a/src/MainFrame.cpp +++ b/src/MainFrame.cpp @@ -557,7 +557,7 @@ void MainFrame::OnClickSettings(wxCommandEvent& event) } if (settings->IsWaveformColourChanged()) { - m_TopWaveformPanel->ResetDC(); + m_TopWaveformPanel->ResetDC(m_MediaCtrl->GetState() == wxMEDIASTATE_PLAYING); } break; case wxID_CANCEL: @@ -948,9 +948,15 @@ void MainFrame::OnClickPlay(wxCommandEvent& event) PushStatusText(wxString::Format(_("Now playing: %s"), selection), 1); // Update waveform bitmap - m_TopWaveformPanel->ResetDC(); + // m_TopWaveformPanel->ResetDC(); - m_MediaCtrl->Play(); + if (bLoop && m_LoopPointAButton->GetValue() && m_LoopPointAButton->GetValue()) + { + m_MediaCtrl->Seek(m_LoopA.GetValue(), wxFromStart); + m_MediaCtrl->Play(); + } + else + m_MediaCtrl->Play(); m_Timer->Start(100, wxTIMER_CONTINUOUS); } @@ -1099,7 +1105,7 @@ void MainFrame::OnClickLibrary(wxDataViewEvent& event) } // Update the waveform bitmap - m_TopWaveformPanel->ResetDC(); + m_TopWaveformPanel->ResetDC(m_MediaCtrl->GetState() == wxMEDIASTATE_PLAYING); wxString selection = m_Library->GetTextValue(selected_row, 1); @@ -1138,13 +1144,22 @@ void MainFrame::OnClickLibrary(wxDataViewEvent& event) if (CurrentColumn != FavoriteColumn) { + ClearLoopPoints(); + m_MediaCtrl->Load(sample_path); if (bAutoplay) { PushStatusText(wxString::Format(_("Now playing: %s"), selection), 1); - m_MediaCtrl->Play(); + if (bLoop && m_LoopPointAButton->GetValue() && m_LoopPointAButton->GetValue()) + { + m_MediaCtrl->Seek(m_LoopA.GetValue(), wxFromStart); + m_MediaCtrl->Play(); + } + else + m_MediaCtrl->Play(); + m_Timer->Start(100, wxTIMER_CONTINUOUS); } } @@ -2949,13 +2964,13 @@ void MainFrame::OnRecieveLoopPoints(SampleHive::SH_LoopPointsEvent& event) std::pair loop_points = event.GetLoopPoints(); - wxLongLong loopA = loop_points.first; - wxLongLong loopB = loop_points.second; + m_LoopA = wxLongLong(loop_points.first); + m_LoopB = wxLongLong(loop_points.second); - int loopA_min = static_cast((loopA / 60000).GetValue()); - int loopA_sec = static_cast(((loopA % 60000) / 1000).GetValue()); - int loopB_min = static_cast((loopB / 60000).GetValue()); - int loopB_sec = static_cast(((loopB % 60000) / 1000).GetValue()); + int loopA_min = static_cast((m_LoopA / 60000).GetValue()); + int loopA_sec = static_cast(((m_LoopA % 60000) / 1000).GetValue()); + int loopB_min = static_cast((m_LoopB / 60000).GetValue()); + int loopB_sec = static_cast(((m_LoopB % 60000) / 1000).GetValue()); wxLogDebug(wxString::Format("LoopA: %2i:%02i, LoopB: %2i:%02i", loopA_min, loopA_sec, loopB_min, loopB_sec)); @@ -2963,7 +2978,9 @@ void MainFrame::OnRecieveLoopPoints(SampleHive::SH_LoopPointsEvent& event) m_LoopPointAText->SetValue(wxString::Format("%2i:%02i", loopA_min, loopA_sec)); m_LoopPointBText->SetValue(wxString::Format("%2i:%02i", loopB_min, loopB_sec)); - // TODO Looping the selected section + if (bLoop && m_LoopPointAButton->GetValue() && m_LoopPointAButton->GetValue()) + if (static_cast(m_MediaCtrl->Tell()) >= static_cast(m_LoopB.GetValue())) + m_MediaCtrl->Seek(m_LoopA.GetValue(), wxFromStart); wxLogDebug("%s Event processed successfully..", __FUNCTION__); } @@ -2975,4 +2992,16 @@ void MainFrame::OnRecieveStatusBarStatus(SampleHive::SH_SetStatusBarMessageEvent m_StatusBar->PushStatusText(status.first, status.second); } +void MainFrame::ClearLoopPoints() +{ + m_LoopPointAText->SetValue("00:00"); + m_LoopPointBText->SetValue("00:00"); + + m_LoopPointAButton->Disable(); + m_LoopPointBButton->Disable(); + + m_LoopA = 0; + m_LoopB = 0; +} + MainFrame::~MainFrame(){} diff --git a/src/MainFrame.hpp b/src/MainFrame.hpp index 335db69..f8810f0 100644 --- a/src/MainFrame.hpp +++ b/src/MainFrame.hpp @@ -170,6 +170,8 @@ class MainFrame : public wxFrame // FileSystemWatcher wxFileSystemWatcher* m_FsWatcher; + wxLongLong m_LoopA, m_LoopB; + private: // ------------------------------------------------------------------- bool bAutoplay = false; @@ -277,6 +279,9 @@ class MainFrame : public wxFrame // Call after frame creation void SetAfterFrameCreate(); + // ------------------------------------------------------------------- + void ClearLoopPoints(); + // ------------------------------------------------------------------- friend class App; }; diff --git a/src/WaveformViewer.cpp b/src/WaveformViewer.cpp index cee2b2b..2fd836b 100644 --- a/src/WaveformViewer.cpp +++ b/src/WaveformViewer.cpp @@ -420,13 +420,16 @@ void WaveformViewer::OnMouseLeftButtonUp(wxMouseEvent& event) } } -void WaveformViewer::ResetDC() +void WaveformViewer::ResetDC(bool playing) { - bBitmapDirty = true; - bSelectRange = false; - bDrawSelectedArea = false; + if (!playing) + { + bBitmapDirty = true; + bSelectRange = false; + bDrawSelectedArea = false; - Refresh(); + Refresh(); + } } void WaveformViewer::SendLoopPoints() diff --git a/src/WaveformViewer.hpp b/src/WaveformViewer.hpp index 50c2931..6247132 100644 --- a/src/WaveformViewer.hpp +++ b/src/WaveformViewer.hpp @@ -94,5 +94,5 @@ class WaveformViewer : public wxPanel public: // ------------------------------------------------------------------- - void ResetDC(); + void ResetDC(bool playing); };