From 6d0f66d14447dfb6d1e2c461626faebbe4d46fe3 Mon Sep 17 00:00:00 2001 From: apoorv569 Date: Sun, 27 Mar 2022 15:29:09 +0530 Subject: [PATCH] Show milliseconds in addition to minutes and seconds for the length of a sample in the ISO 8601 standard. --- src/Database/Database.cpp | 25 +++++++++---------------- src/GUI/MainFrame.cpp | 15 +++------------ src/GUI/TransportControls.cpp | 6 +++--- src/Utility/Utils.cpp | 25 +++++++++++++++++++++---- src/Utility/Utils.hpp | 1 + 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/Database/Database.cpp b/src/Database/Database.cpp index b09012e..ad5c721 100644 --- a/src/Database/Database.cpp +++ b/src/Database/Database.cpp @@ -22,6 +22,7 @@ #include "Utility/Log.hpp" #include "Utility/Paths.hpp" #include "Utility/Serialize.hpp" +#include "Utility/Utils.hpp" #include #include @@ -610,9 +611,7 @@ wxVector> cDatabase::LoadSamplesDatabase(wxDataViewTreeCtrl int trashed = sqlite3_column_int(statement.stmt, 10); wxString hive_name = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 11))); - wxLongLong llLength = length; - int total_min = static_cast((llLength / 60000).GetValue()); - int total_sec = static_cast(((llLength % 60000) / 1000).GetValue()); + wxString len = SampleHive::cUtils::Get().CalculateAndGetISOStandardTime(length); wxVector vec; vec.reserve(12); @@ -685,7 +684,7 @@ wxVector> cDatabase::LoadSamplesDatabase(wxDataViewTreeCtrl vec.push_back(sample_pack); vec.push_back(sample_type); vec.push_back(wxString::Format("%d", channels)); - vec.push_back(wxString::Format("%2i:%02i", total_min, total_sec)); + vec.push_back(len); vec.push_back(wxString::Format("%d", sample_rate)); vec.push_back(wxString::Format("%d", bitrate)); vec.push_back(path); @@ -738,9 +737,7 @@ wxVector>cDatabase::FilterDatabaseBySampleName(const std::st int bitrate = sqlite3_column_int(statement.stmt, 7); wxString path = wxString(std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 8)))); - wxLongLong llLength = length; - int total_min = static_cast((llLength / 60000).GetValue()); - int total_sec = static_cast(((llLength % 60000) / 1000).GetValue()); + wxString len = SampleHive::cUtils::Get().CalculateAndGetISOStandardTime(length); wxVector vec; @@ -761,7 +758,7 @@ wxVector>cDatabase::FilterDatabaseBySampleName(const std::st vec.push_back(sample_pack); vec.push_back(sample_type); vec.push_back(wxString::Format("%d", channels)); - vec.push_back(wxString::Format("%2i:%02i", total_min, total_sec)); + vec.push_back(len); vec.push_back(wxString::Format("%d", sample_rate)); vec.push_back(wxString::Format("%d", bitrate)); vec.push_back(path); @@ -813,9 +810,7 @@ wxVector>cDatabase::FilterDatabaseByHiveName(const std::stri int bitrate = sqlite3_column_int(statement.stmt, 7); wxString path = wxString(std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 8)))); - wxLongLong llLength = length; - int total_min = static_cast((llLength / 60000).GetValue()); - int total_sec = static_cast(((llLength % 60000) / 1000).GetValue()); + wxString len = SampleHive::cUtils::Get().CalculateAndGetISOStandardTime(length); wxVector vec; @@ -832,7 +827,7 @@ wxVector>cDatabase::FilterDatabaseByHiveName(const std::stri vec.push_back(sample_pack); vec.push_back(sample_type); vec.push_back(wxString::Format("%d", channels)); - vec.push_back(wxString::Format("%2i:%02i", total_min, total_sec)); + vec.push_back(len); vec.push_back(wxString::Format("%d", sample_rate)); vec.push_back(wxString::Format("%d", bitrate)); vec.push_back(path); @@ -996,9 +991,7 @@ wxVector>cDatabase::RestoreFromTrashByFilename(const std::st int trashed = sqlite3_column_int(statement.stmt, 10); wxString hive_name = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 11))); - wxLongLong llLength = length; - int total_min = static_cast((llLength / 60000).GetValue()); - int total_sec = static_cast(((llLength % 60000) / 1000).GetValue()); + wxString len = SampleHive::cUtils::Get().CalculateAndGetISOStandardTime(length); wxVector vec; @@ -1017,7 +1010,7 @@ wxVector>cDatabase::RestoreFromTrashByFilename(const std::st vec.push_back(sample_pack); vec.push_back(sample_type); vec.push_back(wxString::Format("%d", channels)); - vec.push_back(wxString::Format("%2i:%02i", total_min, total_sec)); + vec.push_back(len); vec.push_back(wxString::Format("%d", sample_rate)); vec.push_back(wxString::Format("%d", bitrate)); vec.push_back(path); diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 5eaec42..cb6a5d6 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -230,7 +230,7 @@ void cMainFrame::OnMediaFinished(wxMediaEvent& event) SH_LOG_DEBUG("Stopping timer."); } - m_pTransportControls->SetSamplePositionText("--:--/--:--"); + m_pTransportControls->SetSamplePositionText("--:--.---/--:--.---"); PopStatusText(1); this->SetStatusText(_("Stopped"), 1); } @@ -239,18 +239,9 @@ void cMainFrame::OnMediaFinished(wxMediaEvent& event) void cMainFrame::UpdateElapsedTime(wxTimerEvent& event) { wxString duration, position; - wxLongLong llLength, llTell; - llLength = m_pMediaCtrl->Length(); - int total_min = static_cast((llLength / 60000).GetValue()); - int total_sec = static_cast(((llLength % 60000) / 1000).GetValue()); - - llTell = m_pMediaCtrl->Tell(); - int current_min = static_cast((llTell / 60000).GetValue()); - int current_sec = static_cast(((llTell % 60000) / 1000).GetValue()); - - duration.Printf(wxT("%2i:%02i"), total_min, total_sec); - position.Printf(wxT("%2i:%02i"), current_min, current_sec); + duration = SampleHive::cUtils::Get().CalculateAndGetISOStandardTime(m_pMediaCtrl->Length()); + position = SampleHive::cUtils::Get().CalculateAndGetISOStandardTime(m_pMediaCtrl->Tell()); m_pTransportControls->SetSamplePositionText(wxString::Format(wxT("%s/%s"), position.c_str(), duration.c_str())); diff --git a/src/GUI/TransportControls.cpp b/src/GUI/TransportControls.cpp index 0417a39..fc8dbf3 100644 --- a/src/GUI/TransportControls.cpp +++ b/src/GUI/TransportControls.cpp @@ -62,7 +62,7 @@ cTransportControls::cTransportControls(wxWindow* window, wxMediaCtrl& mediaCtrl) m_pVolumeSlider->SetMaxSize(wxSize(120, -1)); // Sample position static text - m_pSamplePosition = new wxStaticText(this, SampleHive::ID::BC_SamplePosition, "--:--/--:--", + m_pSamplePosition = new wxStaticText(this, SampleHive::ID::BC_SamplePosition, "--:--.---/--:--.---", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL); // Transport control buttons @@ -112,7 +112,7 @@ cTransportControls::cTransportControls(wxWindow* window, wxMediaCtrl& mediaCtrl) m_pMainSizer->Add(m_pSettingsButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); m_pMainSizer->Add(0,0,1, wxALL | wxEXPAND, 0); m_pMainSizer->Add(m_pSamplePosition, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_pMainSizer->Add(30,0,0, wxALL | wxEXPAND, 0); + m_pMainSizer->Add(60,0,0, wxALL | wxEXPAND, 0); m_pMainSizer->Add(m_pMuteButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); m_pMainSizer->Add(m_pVolumeSlider, 1, wxALL | wxALIGN_CENTER_VERTICAL, 2); m_pMainSizer->Add(m_pAutoPlayCheck, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); @@ -193,7 +193,7 @@ void cTransportControls::OnClickStop(wxCommandEvent& event) // Send custom event to MainFrame to stop the timer SampleHive::cSignal::SendTimerStopStatus(*this); - m_pSamplePosition->SetLabel("--:--/--:--"); + m_pSamplePosition->SetLabel("--:--.---/--:--.---"); // Send custom event to MainFrame to set the statusbar status SampleHive::cSignal::SendSetStatusBarStatus(_("Stopped"), 1, *this); diff --git a/src/Utility/Utils.cpp b/src/Utility/Utils.cpp index 299403f..aa91885 100644 --- a/src/Utility/Utils.cpp +++ b/src/Utility/Utils.cpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace SampleHive { @@ -125,9 +126,7 @@ namespace SampleHive { 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()); + wxString length = CalculateAndGetISOStandardTime(sample.GetLength()); wxVector data; @@ -141,7 +140,7 @@ namespace SampleHive { 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(length); data.push_back(wxString::Format("%d", sample.GetSampleRate())); data.push_back(wxString::Format("%d", sample.GetBitrate())); data.push_back(path); @@ -232,4 +231,22 @@ namespace SampleHive { return sample_path.ToStdString(); } + wxString cUtils::CalculateAndGetISOStandardTime(wxLongLong length) + { + const int min_digits = 2; + const size_t max_digits = 2; + wxString iso_length; + + int min = static_cast((length / 60000).GetValue()); + int sec = static_cast(((length % 60000) / 1000).GetValue()); + int ms = static_cast((length % 1000).GetValue()); + + iso_length = wxString::Format("%s:%s.%s", + wxString::Format("%0*i", min_digits, min).Left(max_digits), + wxString::Format("%0*i", min_digits, sec).Left(max_digits), + wxString::Format("%0*i", min_digits + 1, ms).Left(max_digits + 1)); + + return iso_length; + } + } diff --git a/src/Utility/Utils.hpp b/src/Utility/Utils.hpp index e457c6c..9fcf38a 100644 --- a/src/Utility/Utils.hpp +++ b/src/Utility/Utils.hpp @@ -59,6 +59,7 @@ namespace SampleHive { bool doGetFilename = true); void AddSamples(wxArrayString& files, wxWindow* parent); void OnAutoImportDir(const wxString& pathToDirectory, wxWindow* parent); + wxString CalculateAndGetISOStandardTime(wxLongLong length); private: // -------------------------------------------------------------------