Skip to content

Commit

Permalink
Merge pull request #315 from Chrezm/0/demote_audiotrack_filename_to_key
Browse files Browse the repository at this point in the history
Change syntax of audio track loop points files so file name is a key
  • Loading branch information
Chrezm authored Jun 7, 2022
2 parents b4b4b1a + 4322c6c commit e31577f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/courtroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,9 @@ void Courtroom::list_music()
{
DRAudiotrackMetadata l_track(i_song);
QListWidgetItem *l_item = new QListWidgetItem(l_track.title(), ui_music_list);
l_item->setData(Qt::UserRole, l_track.file_name());
if (l_track.title() != l_track.file_name())
l_item->setToolTip(l_track.file_name());
l_item->setData(Qt::UserRole, l_track.filename());
if (l_track.title() != l_track.filename())
l_item->setToolTip(l_track.filename());
const QString l_song_path = ao_app->find_asset_path({ao_app->get_music_path(i_song)}, audio_extensions());
l_item->setBackground(l_song_path.isEmpty() ? l_missing_song_brush : l_song_brush);
}
Expand Down Expand Up @@ -1603,7 +1603,7 @@ void Courtroom::handle_song(QStringList p_contents)

if (ao_config->log_is_recording_enabled())
{
save_textlog(l_showname + " has played a song: " + l_song_meta.file_name());
save_textlog(l_showname + " has played a song: " + l_song_meta.filename());
}
}

Expand Down
44 changes: 25 additions & 19 deletions src/draudiotrackmetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,38 @@ void DRAudiotrackMetadata::update_cache()
qDebug() << "reading audiotrack metadata" << l_ini_path;
utils::QSettingsKeyFetcher l_fetcher(l_settings);

const QStringList l_audiotrack_name_list = l_settings.childGroups();
for (const QString &i_track_name : l_audiotrack_name_list)
const QStringList l_group_list = l_settings.childGroups();
for (const QString &i_group : l_group_list)
{
if (!QFileInfo::exists(ao_app->get_music_path(i_track_name)))
l_settings.beginGroup(i_group);
DRAudiotrackMetadata l_audiotrack;
l_audiotrack.m_title = l_settings.value(l_fetcher.lookup_value("title")).toString();
l_audiotrack.m_filename = l_settings.value(l_fetcher.lookup_value("filename")).toString();
l_audiotrack.m_play_once = l_settings.value(l_fetcher.lookup_value("play_once")).toBool();
l_audiotrack.m_loop_start = l_settings.value(l_fetcher.lookup_value("loop_start")).toULongLong();
l_audiotrack.m_loop_end = l_settings.value(l_fetcher.lookup_value("loop_end")).toULongLong();
l_settings.endGroup();

const QString l_track_name = l_audiotrack.m_filename;
if (l_track_name.isEmpty())
{
qWarning() << "error: audiotrack not found" << i_track_name;
qWarning() << "error: empty file name in section" << i_group;
continue;
}
else if (!QFileInfo::exists(ao_app->get_music_path(l_track_name)))
{
qWarning() << "error: audiotrack not found" << l_track_name;
continue;
}

const QString l_lower_track_name = i_track_name.toLower();
const QString l_lower_track_name = l_track_name.toLower();
if (l_new_audiotrack_origin.contains(l_lower_track_name))
{
qWarning() << "warning: replacing track" << i_track_name << "; previously defined in"
qWarning() << "warning: replacing track" << l_track_name << "; previously defined in"
<< l_new_audiotrack_origin[l_lower_track_name];
}
l_new_audiotrack_origin.insert(l_lower_track_name, l_ini_path);

l_settings.beginGroup(i_track_name);
DRAudiotrackMetadata l_audiotrack;
l_audiotrack.m_file_name = i_track_name;
l_audiotrack.m_title = l_settings.value(l_fetcher.lookup_value("title")).toString();
l_audiotrack.m_play_once = l_settings.value(l_fetcher.lookup_value("play_once")).toBool();
l_audiotrack.m_loop_start = l_settings.value(l_fetcher.lookup_value("loop_start")).toULongLong();
l_audiotrack.m_loop_end = l_settings.value(l_fetcher.lookup_value("loop_end")).toULongLong();
l_new_audiotrack_cache.insert(l_lower_track_name, std::move(l_audiotrack));
l_settings.endGroup();
}
}
s_audiotrack_cache = std::move(l_new_audiotrack_cache);
Expand All @@ -82,7 +88,7 @@ void DRAudiotrackMetadata::update_cache()
DRAudiotrackMetadata::DRAudiotrackMetadata()
{}

DRAudiotrackMetadata::DRAudiotrackMetadata(QString p_file_name) : m_file_name(p_file_name)
DRAudiotrackMetadata::DRAudiotrackMetadata(QString p_file_name) : m_filename(p_file_name)
{
const QString l_lower_file_name = p_file_name.toLower();
if (s_audiotrack_cache.contains(l_lower_file_name))
Expand All @@ -94,14 +100,14 @@ DRAudiotrackMetadata::DRAudiotrackMetadata(QString p_file_name) : m_file_name(p_
DRAudiotrackMetadata::~DRAudiotrackMetadata()
{}

QString DRAudiotrackMetadata::file_name()
QString DRAudiotrackMetadata::filename()
{
return m_file_name;
return m_filename;
}

QString DRAudiotrackMetadata::title()
{
return m_title.isEmpty() ? m_file_name : m_title;
return m_title.isEmpty() ? m_filename : m_title;
}

bool DRAudiotrackMetadata::play_once()
Expand Down
4 changes: 2 additions & 2 deletions src/draudiotrackmetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class DRAudiotrackMetadata
DRAudiotrackMetadata(QString file_name);
~DRAudiotrackMetadata();

QString file_name();
QString filename();
QString title();
bool play_once();
quint64 loop_start();
quint64 loop_end();

private:
QString m_file_name;
QString m_filename;
QString m_title;
bool m_play_once = false;
quint64 m_loop_start = 0;
Expand Down

0 comments on commit e31577f

Please sign in to comment.