Refactoring, organizing files in directories. Add directory watcher, removed unnecessary calls to settings dialog.

This commit is contained in:
apoorv569
2021-11-04 19:16:58 +05:30
parent 5714beab03
commit c52d7708d8
22 changed files with 861 additions and 601 deletions
+116
View File
@@ -0,0 +1,116 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <wx/defs.h>
enum ControlIDs
{
/*
** BC = Browser control
** SD = Settings dialog
** MN = Popup menu
** ET = Edit tag dialog
*/
// -------------------------------------------------------------------
// Browser controls
BC_Play = wxID_HIGHEST + 1,
BC_Settings,
BC_Loop,
BC_Stop,
BC_LoopABButton,
BC_Mute,
BC_Autoplay,
BC_Volume,
BC_SamplePosition,
BC_Hives,
BC_DirCtrl,
BC_Library,
BC_Search,
BC_MediaCtrl,
BC_Trash,
BC_RestoreTrashedItem,
BC_HiveAdd,
BC_HiveRemove,
// -------------------------------------------------------------------
// Setting dialog controls
SD_BrowseConfigDir,
SD_BrowseDatabaseDir,
SD_AutoImport,
SD_FollowSymLinks,
SD_ShowFileExtension,
SD_BrowseAutoImportDir,
SD_FontType,
SD_FontSize,
SD_FontBrowseButton,
SD_WaveformColourPickerCtrl,
// -------------------------------------------------------------------
// App Menu items
MN_AddFile,
MN_AddDirectory,
MN_ToggleExtension,
MN_ToggleMenuBar,
MN_ToggleStatusBar,
// -------------------------------------------------------------------
// Library Menu items
MN_FavoriteSample,
MN_DeleteSample,
MN_TrashSample,
MN_EditTagSample,
MN_OpenFile,
// -------------------------------------------------------------------
// Library Column Header Menu items
MN_ColumnFavorite,
MN_ColumnFilename,
MN_ColumnSamplePack,
MN_ColumnType,
MN_ColumnChannels,
MN_ColumnLength,
MN_ColumnSampleRate,
MN_ColumnBitrate,
MN_ColumnPath,
// -------------------------------------------------------------------
// Hives Menu items
MN_RenameHive,
MN_DeleteHive,
MN_RemoveSample,
MN_FilterLibrary,
MN_ShowInLibrary,
// -------------------------------------------------------------------
// Trash Menu items
MN_DeleteTrash,
MN_RestoreTrashedItem,
// -------------------------------------------------------------------
// Edit tags dialog controls
ET_TitleCheck,
ET_ArtistCheck,
ET_AlbumCheck,
ET_GenreCheck,
ET_CommentsCheck,
ET_TypeCheck,
ET_CustomTag,
};
+102
View File
@@ -0,0 +1,102 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Utility/SH_Event.hpp"
namespace SampleHive
{
SH_LoopPointsEvent::SH_LoopPointsEvent(wxEventType eventType, int winId)
: wxCommandEvent(eventType, winId)
{
}
SH_LoopPointsEvent::~SH_LoopPointsEvent()
{
}
wxDEFINE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, SH_LoopPointsEvent);
// SH_AddSampleEvent::SH_AddSampleEvent(wxEventType eventType, int winId)
// : wxCommandEvent(eventType, winId)
// {
// }
// SH_AddSampleEvent::~SH_AddSampleEvent()
// {
// }
// wxDEFINE_EVENT(SH_EVT_STATUS_ADD_SAMPLE, SH_AddSampleEvent);
// SH_MediaEvent::SH_MediaEvent(wxEventType eventType, int winId)
// : wxCommandEvent(eventType, winId)
// {
// }
// SH_MediaEvent::~SH_MediaEvent()
// {
// }
// wxDEFINE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, SH_MediaEvent);
SH_StatusBarMessageEvent::SH_StatusBarMessageEvent(wxEventType eventType, int winId)
: wxCommandEvent(eventType, winId)
{
}
SH_StatusBarMessageEvent::~SH_StatusBarMessageEvent()
{
}
wxDEFINE_EVENT(SH_EVT_STATUSBAR_MESSAGE_UPDATED, SH_StatusBarMessageEvent);
// SH_InfoBarMessageEvent::SH_InfoBarMessageEvent(wxEventType eventType, int winId)
// : wxCommandEvent(eventType, winId)
// {
// }
// SH_InfoBarMessageEvent::~SH_InfoBarMessageEvent()
// {
// }
// wxDEFINE_EVENT(SH_EVT_INFOBAR_MESSAGE_UPDATED, SH_InfoBarMessageEvent);
// SH_TimerEvent::SH_TimerEvent(wxEventType eventType, int winId)
// : wxCommandEvent(eventType, winId)
// {
// }
// SH_TimerEvent::~SH_TimerEvent()
// {
// }
// wxDEFINE_EVENT(SH_EVT_TIMER_STATUS_UPDATED, SH_TimerEvent);
}
+146
View File
@@ -0,0 +1,146 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <utility>
#include <wx/event.h>
namespace SampleHive
{
class SH_LoopPointsEvent : public wxCommandEvent
{
public:
SH_LoopPointsEvent(wxEventType eventType, int winId);
~SH_LoopPointsEvent();
public:
virtual wxEvent* Clone() const { return new SH_LoopPointsEvent(*this); }
public:
std::pair<double, double> GetLoopPoints() const { return { m_LoopA, m_LoopB }; };
void SetLoopPoints(std::pair<double&, double&> loopPoints)
{ m_LoopA = loopPoints.first; m_LoopB = loopPoints.second; };
private:
double m_LoopA, m_LoopB;
};
wxDECLARE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, SH_LoopPointsEvent);
// class SH_AddSampleEvent : public wxCommandEvent
// {
// public:
// SH_AddSampleEvent(wxEventType eventType, int winId);
// ~SH_AddSampleEvent();
// public:
// virtual wxEvent* Clone() const { return new SH_AddSampleEvent(*this); }
// public:
// wxArrayString GetArrayString() const { return m_Files; };
// void SetArrayString(const wxArrayString& files) { m_Files = files; };
// private:
// wxArrayString m_Files;
// };
// wxDECLARE_EVENT(SH_EVT_STATUS_ADD_SAMPLE, SH_AddSampleEvent);
// class SH_MediaEvent : public wxCommandEvent
// {
// public:
// SH_MediaEvent(wxEventType eventType, int winId);
// ~SH_MediaEvent();
// public:
// virtual wxEvent* Clone() const { return new SH_MediaEvent(*this); }
// public:
// void SetPath(const wxString& path) { m_Path = path; }
// wxString GetPath() const { return m_Path; }
// private:
// wxString m_Path;
// };
// wxDECLARE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, SH_MediaEvent);
class SH_StatusBarMessageEvent : public wxCommandEvent
{
public:
SH_StatusBarMessageEvent(wxEventType eventType, int winId);
~SH_StatusBarMessageEvent();
public:
virtual wxEvent* Clone() const { return new SH_StatusBarMessageEvent(*this); }
public:
std::pair<wxString, int> GetMessageAndSection() const { return { m_Msg, m_Section }; }
void SetMessageAndSection(std::pair<const wxString&, int> status) { m_Msg = status.first; m_Section = status.second; }
private:
wxString m_Msg;
int m_Section;
};
wxDECLARE_EVENT(SH_EVT_STATUSBAR_MESSAGE_UPDATED, SH_StatusBarMessageEvent);
// class SH_InfoBarMessageEvent : public wxCommandEvent
// {
// public:
// SH_InfoBarMessageEvent(wxEventType eventType, int winId);
// ~SH_InfoBarMessageEvent();
// public:
// virtual wxEvent* Clone() const { return new SH_InfoBarMessageEvent(*this); }
// public:
// std::pair<wxString, int> GetInfoBarMessage() const { return { m_Msg, m_Mode }; }
// void SetInfoBarMessage(std::pair<wxString, int> infoBarMessageEvent) { m_Msg = infoBarMessageEvent.first; m_Mode = infoBarMessageEvent.second; }
// private:
// wxString m_Msg;
// int m_Mode;
// };
// wxDECLARE_EVENT(SH_EVT_INFOBAR_MESSAGE_UPDATED, SH_InfoBarMessageEvent);
// 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:
// std::pair<int, bool> GetSecondsAndMode() const { return { m_Seconds, m_Mode }; }
// void SetSecondsAndMode(std::pair<int, bool> 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);
}
+77
View File
@@ -0,0 +1,77 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* @file Sample.hpp
* @brief Defines Sample
* @author mill-j
* @date 04/28/2021
* @copyright GNU GPL v3
*/
#include "Utility/Sample.hpp"
///Default Constructor, Creates an empty sample profile
Sample::Sample()
{
}
///Overloaded Constructor, Creates a sample profile with supplied data. @see Set()
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)
{
Set(favorite, filename, fileExtension, samplePack, type,
channels, length, sampleRate, bitrate, path, trashed);
}
///Clears all sample data
void Sample::Clear()
{
m_Favorite = 0;
m_Channels = 0;
m_Length = 0;
m_SampleRate = 0;
m_Bitrate = 0;
m_Trashed = 0;
m_Filename = "";
m_FileExtension = "";
m_SamplePack = "";
m_Type = "";
m_Path = "";
}
void Sample::Set(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)
{
m_Favorite = favorite;
m_Filename = filename;
m_FileExtension = fileExtension;
m_SamplePack = samplePack;
m_Type = type;
m_Channels = channels;
m_Length = length;
m_SampleRate = sampleRate;
m_Bitrate = bitrate;
m_Path = path;
m_Trashed = trashed;
}
+97
View File
@@ -0,0 +1,97 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* @file Sample.hpp
* @brief Declares Sample
* @author mill-j
* @date 04/28/2021
* @copyright GNU GPL v3
*/
#pragma once
#include <string>
/**
* @class Sample
* @brief This class holds data for one sample.
*/
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);
private:
// -------------------------------------------------------------------
int m_Favorite = 0;
int m_Channels = 0;
int m_Length = 0;
int m_SampleRate = 0;
int m_Bitrate = 0;
int m_Trashed = 0;
std::string m_Filename;
std::string m_FileExtension;
std::string m_SamplePack;
std::string m_Type;
std::string m_Path;
public:
// -------------------------------------------------------------------
// Getters
int GetFavorite() const { return m_Favorite; }
int GetChannels() const { return m_Channels; }
int GetLength() const { return m_Length; }
int GetSampleRate() const { return m_SampleRate; }
int GetBitrate() const { return m_Bitrate; }
int GetTrashed() const { return m_Trashed; }
std::string GetFilename() const { return m_Filename; }
std::string GetFileExtension() const { return m_FileExtension; }
std::string GetSamplePack() const { return m_SamplePack; }
std::string GetType() const { return m_Type; }
std::string GetPath() const { return m_Path; }
// -------------------------------------------------------------------
// Setters
void Set(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);
void SetFavorite(int favorite) { m_Favorite = favorite; }
void SetChannels(int channels) { m_Channels = channels; }
void SetLength(int length) { m_Length = length; }
void SetSampleRate(int sampleRate) { m_SampleRate = sampleRate; }
void SetBitrate(int bitrate) { m_Bitrate = bitrate; }
void SetTrashed(int trashed) { m_Trashed = trashed; }
void SetFilename(const std::string& filename) { m_Filename = filename; }
void SetFileExtension(const std::string& fileExtension) { m_FileExtension = fileExtension; }
void SetSamplePack(const std::string& samplePack) { m_SamplePack = samplePack; }
void SetType(const std::string& type) { m_Type = type; }
void SetPath(const std::string& path) { m_Path = path; }
// -------------------------------------------------------------------
// Clear sample data
void Clear();
};
+547
View File
@@ -0,0 +1,547 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Utility/Serialize.hpp"
#include <fstream>
#include <sstream>
#include <wx/colour.h>
#include <wx/log.h>
#include <wx/filename.h>
#include <yaml-cpp/emittermanip.h>
#include <yaml-cpp/node/parse.h>
Serializer::Serializer(const std::string& filepath)
: m_Filepath(filepath)
{
std::ifstream ifstrm(m_Filepath);
wxFont font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT);
std::string system_font_face = font.GetFaceName().ToStdString();
int system_font_size = font.GetPointSize();
wxColour colour = "#FE9647";
std::string dir = wxGetHomeDir().ToStdString();
if (!ifstrm)
{
wxLogDebug("Genrating configuration file..");
m_Emitter << YAML::Comment("This is the configuration file for SampleHive,"
"feel free to edit the file as needed");
m_Emitter << YAML::Newline;
m_Emitter << YAML::BeginMap;
m_Emitter << YAML::Newline << YAML::Key << "Window";
m_Emitter << YAML::BeginMap;
m_Emitter << YAML::Key << "Width" << YAML::Value << 1280;
m_Emitter << YAML::Key << "Height" << YAML::Value << 720;
m_Emitter << YAML::Key << "ShowMenuBar" << YAML::Value << true;
m_Emitter << YAML::Key << "ShowStatusBar" << YAML::Value << true;
m_Emitter << YAML::EndMap << YAML::Newline;
m_Emitter << YAML::Newline << YAML::Key << "Media";
m_Emitter << YAML::BeginMap;
m_Emitter << YAML::Key << "Autoplay" << YAML::Value << false;
m_Emitter << YAML::Key << "Loop" << YAML::Value << false;
m_Emitter << YAML::Key << "Muted" << YAML::Value << false;
m_Emitter << YAML::EndMap << YAML::Newline;
m_Emitter << YAML::Newline << YAML::Key << "Display";
m_Emitter << YAML::BeginMap;
m_Emitter << YAML::Key << "Font";
m_Emitter << YAML::BeginMap;
m_Emitter << YAML::Key << "Family" << YAML::Value << system_font_face;
m_Emitter << YAML::Key << "Size" << YAML::Value << system_font_size;
m_Emitter << YAML::EndMap;
m_Emitter << YAML::Key << "Waveform";
m_Emitter << YAML::BeginMap;
m_Emitter << YAML::Key << "Colour" << YAML::Value << colour.GetAsString().ToStdString();
m_Emitter << YAML::EndMap;
m_Emitter << YAML::EndMap << YAML::Newline;
m_Emitter << YAML::Newline << YAML::Key << "Collection";
m_Emitter << YAML::BeginMap;
m_Emitter << YAML::Key << "AutoImport" << YAML::Value << false;
m_Emitter << YAML::Key << "Directory" << YAML::Value << dir;
m_Emitter << YAML::Key << "FollowSymLink" << YAML::Value << false;
m_Emitter << YAML::Key << "ShowFileExtension" << YAML::Value << true;
m_Emitter << YAML::EndMap << YAML::Newline;
m_Emitter << YAML::EndMap;
std::ofstream ofstrm(m_Filepath);
ofstrm << m_Emitter.c_str();
wxLogDebug("Generated %s successfully!", m_Filepath);
}
}
Serializer::~Serializer()
{
}
WindowSize Serializer::DeserializeWinSize() const
{
int width = 800, height = 600;
try
{
YAML::Node config = YAML::LoadFile(m_Filepath);
if (!config["Window"])
{
return { width, height };
}
if (auto win = config["Window"])
{
height = win["Height"].as<int>();
width = win["Width"].as<int>();
}
}
catch(const YAML::ParserException& ex)
{
std::cout << ex.what() << std::endl;
}
wxLogDebug("Window size: %d, %d", width, height);
return { width, height };
}
void Serializer::SerializeShowMenuAndStatusBar(std::string key, bool value)
{
YAML::Emitter out;
try
{
YAML::Node config = YAML::LoadFile(m_Filepath);
if (auto bar = config["Window"])
{
if (key == "menubar")
bar["ShowMenuBar"] = value;
if (key == "statusbar")
bar["ShowStatusBar"] = value;
out << config;
std::ofstream ofstrm(m_Filepath);
ofstrm << out.c_str();
}
else
wxLogDebug("Error! Cannot store show bar values.");
}
catch(const YAML::ParserException& ex)
{
std::cout << ex.what() << std::endl;
}
}
bool Serializer::DeserializeShowMenuAndStatusBar(std::string key) const
{
bool show = false;
try
{
YAML::Node config = YAML::LoadFile(m_Filepath);
if (auto bar = config["Window"])
{
if (key == "menubar")
show = bar["ShowMenuBar"].as<bool>();
if (key == "statusbar")
show = bar["ShowStatusBar"].as<bool>();
}
else
{
wxLogDebug("Error! Cannot fetch show bar values.");
}
}
catch(const YAML::ParserException& ex)
{
std::cout << ex.what() << std::endl;
}
return show;
}
void Serializer::SerializeBrowserControls(std::string key, bool value)
{
YAML::Emitter out;
try
{
YAML::Node config = YAML::LoadFile(m_Filepath);
if (auto media = config["Media"])
{
if (key == "autoplay")
media["Autoplay"] = value;
if (key == "loop")
media["Loop"] = value;
if (key == "muted")
media["Muted"] = value;
out << config;
std::ofstream ofstrm(m_Filepath);
ofstrm << out.c_str();
}
else
wxLogDebug("Error! Cannot store media values.");
}
catch(const YAML::ParserException& ex)
{
std::cout << ex.what() << std::endl;
}
}
bool Serializer::DeserializeBrowserControls(std::string key) const
{
bool control = false;
try
{
YAML::Node config = YAML::LoadFile(m_Filepath);
if (auto media = config["Media"])
{
if (key == "autoplay")
control = media["Autoplay"].as<bool>();
if (key == "loop")
control = media["Loop"].as<bool>();
if (key == "muted")
control = media["Muted"].as<bool>();
}
else
wxLogDebug("Error! Cannot fetch values.");
}
catch(const YAML::ParserException& ex)
{
std::cout << ex.what() << std::endl;
}
wxLogDebug("%s: %s", key, control ? "enabled" : "disabled");
return control;
}
void Serializer::SerializeDisplaySettings(wxFont& font)
{
YAML::Emitter out;
std::string font_face = font.GetFaceName().ToStdString();
int font_size = font.GetPointSize();
try
{
YAML::Node config = YAML::LoadFile(m_Filepath);
auto display = config["Display"];
if (auto fontSetting = display["Font"])
{
fontSetting["Family"] = font_face;
fontSetting["Size"] = font_size;
out << config;
std::ofstream ofstrm(m_Filepath);
ofstrm << out.c_str();
}
else
{
wxLogDebug("Error! Cannot store font values.");
}
}
catch(const YAML::ParserException& ex)
{
std::cout << ex.what() << std::endl;
}
}
wxFont Serializer::DeserializeDisplaySettings() const
{
wxFont font;
wxString face;
int size = 0 ;
try
{
YAML::Node config = YAML::LoadFile(m_Filepath);
auto display = config["Display"];
if (auto font_setting = display["Font"])
{
face = font_setting["Family"].as<std::string>();
size = font_setting["Size"].as<int>();
font.SetFaceName(face);
font.SetPointSize(size);
}
else
{
wxLogDebug("Error! Cannot fetch font values.");
}
}
catch(const YAML::ParserException& ex)
{
std::cout << ex.what() << std::endl;
}
return font;
}
void Serializer::SerializeWaveformColour(wxColour& colour)
{
YAML::Emitter out;
std::string colour_string = colour.GetAsString(wxC2S_HTML_SYNTAX).ToStdString();
try
{
YAML::Node config = YAML::LoadFile(m_Filepath);
auto display = config["Display"];
if (auto waveform = display["Waveform"])
{
waveform["Colour"] = colour_string;
out << config;
std::ofstream ofstrm(m_Filepath);
ofstrm << out.c_str();
}
else
{
wxLogDebug("Error! Cannot store waveform colour.");
}
}
catch(const YAML::ParserException& ex)
{
std::cout << ex.what() << std::endl;
}
}
wxColour Serializer::DeserializeWaveformColour() const
{
std::string colour;
try
{
YAML::Node config = YAML::LoadFile(m_Filepath);
auto display = config["Display"];
if (auto waveform = display["Waveform"])
{
colour = waveform["Colour"].as<std::string>();
}
else
{
wxLogDebug("Error! Cannot fetch waveform colour.");
}
}
catch(const YAML::ParserException& ex)
{
std::cout << ex.what() << std::endl;
}
return static_cast<wxString>(colour);
}
void Serializer::SerializeAutoImportSettings(bool autoImport, const std::string& importDir)
{
YAML::Emitter out;
try
{
YAML::Node config = YAML::LoadFile(m_Filepath);
if (auto autoImportInfo = config["Collection"])
{
autoImportInfo["AutoImport"] = autoImport;
autoImportInfo["Directory"] = importDir;
out << config;
std::ofstream ofstrm(m_Filepath);
ofstrm << out.c_str();
}
else
{
wxLogDebug("Error! Cannot store import dir values.");
}
}
catch(const YAML::ParserException& ex)
{
std::cout << ex.what() << std::endl;
}
}
ImportDirInfo Serializer::DeserializeAutoImportSettings() const
{
wxString dir;
bool auto_import = false;
try
{
YAML::Node config = YAML::LoadFile(m_Filepath);
if (auto autoImportInfo = config["Collection"])
{
auto_import = autoImportInfo["AutoImport"].as<bool>();
dir = autoImportInfo["Directory"].as<std::string>();
}
else
{
wxLogDebug("Error! Cannot fetch import dir values.");
}
}
catch (const YAML::ParserException& ex)
{
std::cout << ex.what() << std::endl;
}
return { auto_import, dir };
}
void Serializer::SerializeFollowSymLink(bool followSymLinks)
{
YAML::Emitter out;
try
{
YAML::Node config = YAML::LoadFile(m_Filepath);
if (auto followSymLinks = config["Collection"])
{
followSymLinks["FollowSymLinks"] = followSymLinks;
out << config;
std::ofstream ofstrm(m_Filepath);
ofstrm << out.c_str();
}
else
{
wxLogDebug("Error! Cannot store follow symbolic links value.");
}
}
catch(const YAML::ParserException& ex)
{
std::cout << ex.what() << std::endl;
}
}
bool Serializer::DeserializeFollowSymLink() const
{
bool follow_sym_links = false;
try
{
YAML::Node config = YAML::LoadFile(m_Filepath);
if (auto followSymLinks = config["Collection"])
{
follow_sym_links = followSymLinks["FollowSymLinks"].as<bool>();
}
else
{
wxLogDebug("Error! Cannot fetch follow symbolic links value.");
}
}
catch(const YAML::ParserException& ex)
{
std::cout << ex.what() << std::endl;
}
return follow_sym_links;
}
void Serializer::SerializeShowFileExtensionSetting(bool showExtension)
{
YAML::Emitter out;
try
{
YAML::Node config = YAML::LoadFile(m_Filepath);
if (auto fileExtensionInfo = config["Collection"])
{
fileExtensionInfo["ShowFileExtension"] = showExtension;
out << config;
std::ofstream ofstrm(m_Filepath);
ofstrm << out.c_str();
}
else
{
wxLogDebug("Error! Cannot store show file extension value.");
}
}
catch(const YAML::ParserException& ex)
{
std::cout << ex.what() << std::endl;
}
}
bool Serializer::DeserializeShowFileExtensionSetting() const
{
bool show_extension = false;
try
{
YAML::Node config = YAML::LoadFile(m_Filepath);
if (auto fileExtensionInfo = config["Collection"])
{
show_extension = fileExtensionInfo["ShowFileExtension"].as<bool>();
}
else
{
wxLogDebug("Error! Cannot fetch show file extension value.");
}
}
catch(const YAML::ParserException& ex)
{
std::cout << ex.what() << std::endl;
}
return show_extension;
}
+97
View File
@@ -0,0 +1,97 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <string>
#include <wx/checkbox.h>
#include <wx/dataview.h>
#include <wx/font.h>
#include <wx/string.h>
#include <wx/settings.h>
#include <wx/textctrl.h>
#include <wx/treebase.h>
#include <wx/treectrl.h>
#include <yaml-cpp/yaml.h>
#include <yaml-cpp/emitter.h>
#include <yaml-cpp/emittermanip.h>
#include <yaml-cpp/exceptions.h>
#include <yaml-cpp/node/node.h>
#include <yaml-cpp/node/parse.h>
#include <yaml-cpp/null.h>
#include <yaml-cpp/emittermanip.h>
typedef std::pair<int, int> WindowSize;
// typedef std::pair<wxString, int> FontType;
typedef std::pair<bool, wxString> ImportDirInfo;
class Serializer
{
public:
Serializer(const std::string& filepath);
~Serializer();
private:
// -------------------------------------------------------------------
const std::string& m_Filepath;
// -------------------------------------------------------------------
YAML::Emitter m_Emitter;
public:
// -------------------------------------------------------------------
// Window size
WindowSize DeserializeWinSize() const;
// -------------------------------------------------------------------
// Menu and status bar
void SerializeShowMenuAndStatusBar(std::string key, bool value);
bool DeserializeShowMenuAndStatusBar(std::string key) const;
// -------------------------------------------------------------------
// Browser controls
void SerializeBrowserControls(std::string key, bool value);
bool DeserializeBrowserControls(std::string key) const;
// -------------------------------------------------------------------
// Display settings
void SerializeDisplaySettings(wxFont& font);
wxFont DeserializeDisplaySettings() const;
// -------------------------------------------------------------------
// Waveform colour
void SerializeWaveformColour(wxColour& colour);
wxColour DeserializeWaveformColour() const;
// -------------------------------------------------------------------
// Auto import settings
void SerializeAutoImportSettings(bool autoImport, const std::string& importDir);
ImportDirInfo DeserializeAutoImportSettings() const;
// -------------------------------------------------------------------
// Follow symbolic links
void SerializeFollowSymLink(bool followSymLink);
bool DeserializeFollowSymLink() const;
// -------------------------------------------------------------------
// Show file extension
void SerializeShowFileExtensionSetting(bool showExtension);
bool DeserializeShowFileExtensionSetting() const;
};
+150
View File
@@ -0,0 +1,150 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Utility/Tags.hpp"
#include "SampleHiveConfig.hpp"
#include <taglib/tag.h>
#include <taglib/fileref.h>
#ifndef USE_SYSTEM_INCLUDE_PATH
#include <taglib/toolkit/tstring.h>
#else
#include <taglib/tstring.h>
#endif
Tags::Tags(const std::string& filename)
: m_Filepath(filename)
{
}
Tags::~Tags()
{
}
AudioInfo Tags::GetAudioInfo()
{
wxString artist, album, genre, title, comment;
int channels = 0, length = 0, sample_rate = 0, bitrate = 0;
TagLib::FileRef f (static_cast<const char*>(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::String Title = tag->title();
TagLib::String Artist = tag->artist();
TagLib::String Album = tag->album();
TagLib::String Genre = tag->genre();
TagLib::String Comment = tag->comment();
int seconds = properties->length() % 60;
int minutes = (properties->length() - seconds) / 60;
bitrate = properties->bitrate();
channels = properties->channels();
length = properties->lengthInMilliseconds();
int length_sec = properties->lengthInSeconds();
sample_rate = properties->sampleRate();
title = wxString::FromUTF8(Title.toCString(true));
artist = wxString::FromUTF8(Artist.toCString(true));
album = wxString::FromUTF8(Album.toCString(true));
genre = wxString::FromUTF8(Genre.toCString(true));
comment = wxString::FromUTF8(Comment.toCString(true));
bValid = true;
}
else
{
bValid = false;
}
return { title, artist, album, genre, comment, channels, length, sample_rate, bitrate };
}
void Tags::SetTitle(std::string title)
{
TagLib::FileRef f (static_cast<const char*>(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average);
if (!f.isNull() && f.tag() && f.audioProperties())
{
TagLib::Tag* tag = f.tag();
tag->setTitle(title);
f.save();
}
}
void Tags::SetArtist(std::string artist)
{
TagLib::FileRef f (static_cast<const char*>(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average);
if (!f.isNull() && f.tag() && f.audioProperties())
{
TagLib::Tag* tag = f.tag();
tag->setArtist(artist);
f.save();
}
}
void Tags::SetAlbum(std::string album)
{
TagLib::FileRef f (static_cast<const char*>(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average);
if (!f.isNull() && f.tag() && f.audioProperties())
{
TagLib::Tag* tag = f.tag();
tag->setAlbum(album);
f.save();
}
}
void Tags::SetGenre(std::string genre)
{
TagLib::FileRef f (static_cast<const char*>(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average);
if (!f.isNull() && f.tag() && f.audioProperties())
{
TagLib::Tag* tag = f.tag();
tag->setGenre(genre);
f.save();
}
}
void Tags::SetComment(std::string comment)
{
TagLib::FileRef f (static_cast<const char*>(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average);
if (!f.isNull() && f.tag() && f.audioProperties())
{
TagLib::Tag* tag = f.tag();
tag->setComment(comment);
f.save();
}
}
+65
View File
@@ -0,0 +1,65 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#include <wx/string.h>
struct AudioInfo
{
wxString title;
wxString artist;
wxString album;
wxString genre;
wxString comment;
int channels;
int length;
int sample_rate;
int bitrate;
};
class Tags
{
public:
Tags(const std::string& filepath);
~Tags();
private:
// -------------------------------------------------------------------
const std::string& m_Filepath;
bool bValid = false;
public:
// -------------------------------------------------------------------
AudioInfo GetAudioInfo();
void SetTitle(std::string artist);
void SetArtist(std::string artist);
void SetAlbum(std::string album);
void SetGenre(std::string genre);
void SetComment(std::string comment);
public:
// -------------------------------------------------------------------
inline bool IsFileValid() { return bValid; }
};