Show milliseconds in addition to minutes and seconds for the length of a sample in the ISO 8601 standard.

This commit is contained in:
apoorv569 2022-03-27 15:29:09 +05:30
parent 293c12a7e0
commit 6d0f66d144
5 changed files with 37 additions and 35 deletions

View File

@ -22,6 +22,7 @@
#include "Utility/Log.hpp"
#include "Utility/Paths.hpp"
#include "Utility/Serialize.hpp"
#include "Utility/Utils.hpp"
#include <deque>
#include <exception>
@ -610,9 +611,7 @@ wxVector<wxVector<wxVariant>> cDatabase::LoadSamplesDatabase(wxDataViewTreeCtrl
int trashed = sqlite3_column_int(statement.stmt, 10);
wxString hive_name = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 11)));
wxLongLong llLength = length;
int total_min = static_cast<int>((llLength / 60000).GetValue());
int total_sec = static_cast<int>(((llLength % 60000) / 1000).GetValue());
wxString len = SampleHive::cUtils::Get().CalculateAndGetISOStandardTime(length);
wxVector<wxVariant> vec;
vec.reserve(12);
@ -685,7 +684,7 @@ wxVector<wxVector<wxVariant>> 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<wxVector<wxVariant>>cDatabase::FilterDatabaseBySampleName(const std::st
int bitrate = sqlite3_column_int(statement.stmt, 7);
wxString path = wxString(std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 8))));
wxLongLong llLength = length;
int total_min = static_cast<int>((llLength / 60000).GetValue());
int total_sec = static_cast<int>(((llLength % 60000) / 1000).GetValue());
wxString len = SampleHive::cUtils::Get().CalculateAndGetISOStandardTime(length);
wxVector<wxVariant> vec;
@ -761,7 +758,7 @@ wxVector<wxVector<wxVariant>>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<wxVector<wxVariant>>cDatabase::FilterDatabaseByHiveName(const std::stri
int bitrate = sqlite3_column_int(statement.stmt, 7);
wxString path = wxString(std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 8))));
wxLongLong llLength = length;
int total_min = static_cast<int>((llLength / 60000).GetValue());
int total_sec = static_cast<int>(((llLength % 60000) / 1000).GetValue());
wxString len = SampleHive::cUtils::Get().CalculateAndGetISOStandardTime(length);
wxVector<wxVariant> vec;
@ -832,7 +827,7 @@ wxVector<wxVector<wxVariant>>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<wxVector<wxVariant>>cDatabase::RestoreFromTrashByFilename(const std::st
int trashed = sqlite3_column_int(statement.stmt, 10);
wxString hive_name = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 11)));
wxLongLong llLength = length;
int total_min = static_cast<int>((llLength / 60000).GetValue());
int total_sec = static_cast<int>(((llLength % 60000) / 1000).GetValue());
wxString len = SampleHive::cUtils::Get().CalculateAndGetISOStandardTime(length);
wxVector<wxVariant> vec;
@ -1017,7 +1010,7 @@ wxVector<wxVector<wxVariant>>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);

View File

@ -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<int>((llLength / 60000).GetValue());
int total_sec = static_cast<int>(((llLength % 60000) / 1000).GetValue());
llTell = m_pMediaCtrl->Tell();
int current_min = static_cast<int>((llTell / 60000).GetValue());
int current_sec = static_cast<int>(((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()));

View File

@ -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);

View File

@ -30,6 +30,7 @@
#include <wx/dir.h>
#include <wx/gdicmn.h>
#include <wx/progdlg.h>
#include <wx/string.h>
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<int>((llLength / 60000).GetValue());
int total_sec = static_cast<int>(((llLength % 60000) / 1000).GetValue());
wxString length = CalculateAndGetISOStandardTime(sample.GetLength());
wxVector<wxVariant> 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<int>((length / 60000).GetValue());
int sec = static_cast<int>(((length % 60000) / 1000).GetValue());
int ms = static_cast<int>((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;
}
}

View File

@ -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:
// -------------------------------------------------------------------