diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index eb53aa2..3c474a9 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -183,9 +183,6 @@ class MainFrame : public wxFrame // ------------------------------------------------------------------- wxLongLong m_LoopA, m_LoopB; - // ------------------------------------------------------------------- - wxSystemAppearance m_Theme = wxSystemSettings::GetAppearance(); - private: // ------------------------------------------------------------------- bool bAutoplay = false; @@ -262,10 +259,6 @@ class MainFrame : public wxFrame // Frame resize event handler void OnResizeFrame(wxSizeEvent& event); - // Splitter window sash pos event handler - void OnTopSplitterSashPosChanged(wxSplitterEvent& event); - void OnBottomSplitterSashPosChanged(wxSplitterEvent& event); - // ------------------------------------------------------------------- // Timer update event handler void UpdateElapsedTime(wxTimerEvent& event); diff --git a/src/GUI/WaveformViewer.cpp b/src/GUI/WaveformViewer.cpp index 4d29650..5174c4e 100644 --- a/src/GUI/WaveformViewer.cpp +++ b/src/GUI/WaveformViewer.cpp @@ -25,6 +25,7 @@ #include "Utility/Log.hpp" #include "Utility/Paths.hpp" +#include #include #include @@ -35,6 +36,7 @@ #include #include +#include #include WaveformViewer::WaveformViewer(wxWindow* window, wxDataViewListCtrl& library, @@ -178,77 +180,85 @@ void WaveformViewer::UpdateWaveformBitmap() std::vector waveform; - // TODO, FIXME: Don't reload file on every window resize - snd_file.read(&sample.at(0), frames * channels); - - float display_width = this->GetSize().GetWidth(); - float display_height = this->GetSize().GetHeight(); - - SH_LOG_INFO("Calculating Waveform bars RMS.."); - - float chunk_size = (float)(frames) / (float)display_width; - int number_of_chunks = static_cast(static_cast(frames) / chunk_size); - - // Start with low non-zero value - float normalize = 0.00001; - - for (int i = 0; i < number_of_chunks; i++) + try { - double sum = 0, mono = 0; + // TODO, FIXME: Don't reload file on every window resize + snd_file.read(&sample.at(0), frames * channels); - int start_point = static_cast(i * chunk_size * channels); + float display_width = this->GetSize().GetWidth(); + float display_height = this->GetSize().GetHeight(); - // Iterate on the chunk, get the square of sum of monos - for (int j = 0; j < chunk_size; j++) + SH_LOG_INFO("Calculating Waveform bars RMS.."); + + float chunk_size = (float)(frames) / (float)display_width; + int number_of_chunks = static_cast(static_cast(frames) / chunk_size); + + // Start with low non-zero value + float normalize = 0.00001; + + for (int i = 0; i < number_of_chunks; i++) { - if (channels == 2) - mono = 0.5f * (sample[start_point + (2 * j)] + sample[start_point + (2 * j) + 1]); - else - mono = sample[start_point + j]; + double sum = 0, mono = 0; - sum += mono * mono; // Square + int start_point = static_cast(i * chunk_size * channels); + + // Iterate on the chunk, get the square of sum of monos + for (int j = 0; j < chunk_size; j++) + { + if (channels == 2) + mono = 0.5f * (sample[start_point + (2 * j)] + sample[start_point + (2 * j) + 1]); + else + mono = sample[start_point + j]; + + sum += mono * mono; // Square + } + + sum /= chunk_size; // Mean + sum = pow(sum, 0.5); // Root + + // We might bleed a bit on the end and get some near infs, dunno + // what is causing astronomically big numbers from sample[] + if ((sum < 200.0) && (sum > normalize)) + normalize = sum; + + waveform.push_back(sum); } - sum /= chunk_size; // Mean - sum = pow(sum, 0.5); // Root + // Actually normalize + for (int i = 0; i < waveform.size(); i++) + waveform[i] /= normalize; - // We might bleed a bit on the end and get some near infs, dunno - // what is causing astronomically big numbers from sample[] - if ((sum < 200.0) && (sum > normalize)) - normalize = sum; + // Draw code + wxMemoryDC mdc(m_WaveformBitmap); - waveform.push_back(sum); + mdc.SetBackground(wxBrush(wxColour(0, 0, 0, 150), wxBRUSHSTYLE_SOLID)); + mdc.Clear(); + + m_WaveformColour = serializer.DeserializeWaveformColour(); + + mdc.SetPen(wxPen(wxColour(m_WaveformColour), 2, wxPENSTYLE_SOLID)); + + SH_LOG_DEBUG("Drawing bitmap.."); + + for (int i = 0; i < waveform.size() - 1; i++) + { + float half_display_height = static_cast(display_height) / 2.0f; + + // X is percentage of i relative to waveform.size() multiplied by + // the width, Y is the half height times the value up or down + float X = display_width * ((float)i / waveform.size()); + float Y = waveform[i] * half_display_height; + + mdc.DrawLine(X, half_display_height + Y, X, half_display_height - Y); + } + + SH_LOG_DEBUG("Done drawing bitmap.."); } - - // Actually normalize - for (int i = 0; i < waveform.size(); i++) - waveform[i] /= normalize; - - // Draw code - wxMemoryDC mdc(m_WaveformBitmap); - - mdc.SetBackground(wxBrush(wxColour(0, 0, 0, 150), wxBRUSHSTYLE_SOLID)); - mdc.Clear(); - - m_WaveformColour = serializer.DeserializeWaveformColour(); - - mdc.SetPen(wxPen(wxColour(m_WaveformColour), 2, wxPENSTYLE_SOLID)); - - SH_LOG_DEBUG("Drawing bitmap.."); - - for (int i = 0; i < waveform.size() - 1; i++) + catch (std::exception& e) { - float half_display_height = static_cast(display_height) / 2.0f; - - // X is percentage of i relative to waveform.size() multiplied by - // the width, Y is the half height times the value up or down - float X = display_width * ((float)i / waveform.size()); - float Y = waveform[i] * half_display_height; - - mdc.DrawLine(X, half_display_height + Y, X, half_display_height - Y); + SH_LOG_ERROR("Error! SNDFILE {}", e.what()); + SH_LOG_ERROR("Error! SNDFILE {}", sf_strerror(snd_file.rawHandle())); } - - SH_LOG_DEBUG("Done drawing bitmap.."); } void WaveformViewer::OnControlKeyDown(wxKeyEvent &event) diff --git a/src/Utility/Tags.cpp b/src/Utility/Tags.cpp index bdf33ef..acb5a99 100644 --- a/src/Utility/Tags.cpp +++ b/src/Utility/Tags.cpp @@ -21,8 +21,11 @@ #include "Utility/Tags.hpp" #include "SampleHiveConfig.hpp" +// #include + #include #include +// #include #ifndef USE_SYSTEM_INCLUDE_PATH #include @@ -44,14 +47,15 @@ Tags::~Tags() AudioInfo Tags::GetAudioInfo() { wxString artist, album, genre, title, comment; - int channels = 0, length = 0, sample_rate = 0, bitrate = 0; + int channels = 0, length_ms = 0, length_s = 0, sample_rate = 0, bitrate = 0; - TagLib::FileRef f (static_cast(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average); + TagLib::FileRef f(static_cast(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average); if (!f.isNull() && f.tag() && f.audioProperties()) { TagLib::Tag* tag = f.tag(); TagLib::AudioProperties* properties = f.audioProperties(); + // TagLib::PropertyMap property_map = f.file()->properties(); TagLib::String Title = tag->title(); TagLib::String Artist = tag->artist(); @@ -64,8 +68,8 @@ AudioInfo Tags::GetAudioInfo() bitrate = properties->bitrate(); channels = properties->channels(); - length = properties->lengthInMilliseconds(); - int length_sec = properties->lengthInSeconds(); + length_ms = properties->lengthInMilliseconds(); + length_s = properties->lengthInSeconds(); sample_rate = properties->sampleRate(); title = wxString::FromUTF8(Title.toCString(true)); @@ -75,13 +79,33 @@ AudioInfo Tags::GetAudioInfo() comment = wxString::FromUTF8(Comment.toCString(true)); bValid = true; + + // unsigned int longest = 0; + + // for(TagLib::PropertyMap::ConstIterator i = property_map.begin(); i != property_map.end(); ++i) + // { + // if (i->first.size() > longest) + // { + // longest = i->first.size(); + // } + // } + + // std::cout << "-- TAG (properties) --" << std::endl; + + // for(TagLib::PropertyMap::ConstIterator i = property_map.begin(); i != property_map.end(); ++i) + // { + // for(TagLib::StringList::ConstIterator j = i->second.begin(); j != i->second.end(); ++j) + // { + // std::cout << std::left << std::setw(longest) << i->first << " - " << '"' << *j << '"' << std::endl; + // } + // } } else { bValid = false; } - return { title, artist, album, genre, comment, channels, length, sample_rate, bitrate }; + return { title, artist, album, genre, comment, channels, length_ms, sample_rate, bitrate }; } void Tags::SetTitle(std::string title)