|
From: Lasse Kärkkäi. <tr...@us...> - 2010-01-18 07:48:22
|
Module: performous
Branch: master
Commit: fd3f1695d2ac2cd10888e1cba8c72b4657a868aa
Author: Lasse Karkkainen <tro...@tr...>
Date: Mon Jan 18 09:48:13 2010 +0200
A quick hack to allow filtering by instrument type (keys F5-F8 in song selector)
---
game/screen_songs.cc | 6 +++++-
game/song.hh | 1 +
game/songs.cc | 15 +++++++++++++--
game/songs.hh | 5 +++++
4 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/game/screen_songs.cc b/game/screen_songs.cc
index 901c313..1effacc 100644
--- a/game/screen_songs.cc
+++ b/game/screen_songs.cc
@@ -104,6 +104,10 @@ void ScreenSongs::manageEvent(SDL_Event event) {
ss->setSong(m_songs.currentPtr());
sm->activateScreen("Hiscore");
}
+ else if (key == SDLK_F5) m_songs.setTypeFilter(m_songs.getTypeFilter() ^ 8); // Vocals
+ else if (key == SDLK_F6) m_songs.setTypeFilter(m_songs.getTypeFilter() ^ 4); // Guitars
+ else if (key == SDLK_F7) m_songs.setTypeFilter(m_songs.getTypeFilter() ^ 2); // Drums
+ else if (key == SDLK_F8) m_songs.setTypeFilter(m_songs.getTypeFilter() ^ 1); // Dance
}
}
@@ -259,7 +263,7 @@ void ScreenSongs::drawInstruments(Song const& song, Dimensions const& dim, float
float xincr = 0.2f;
{
// vocals
- float a = alpha * (!song.notes.empty() ? 1.00 : 0.25);
+ float a = alpha * (song.hasVocals() ? 1.00 : 0.25);
bool karaoke = (song.music.find("vocals") != song.music.end());
glutil::Begin block(GL_TRIANGLE_STRIP);
glColor4f(1.0f, 1.0f, karaoke ? 0.25f : 1.0f, a);
diff --git a/game/song.hh b/game/song.hh
index 6d817c9..f99a778 100644
--- a/game/song.hh
+++ b/game/song.hh
@@ -46,6 +46,7 @@ class Song: boost::noncopyable {
bool hasDance() const { return !danceTracks.empty(); }
bool hasDrums() const { return track_map.find("drums") != track_map.end(); }
bool hasGuitars() const { return track_map.size() - hasDrums(); }
+ bool hasVocals() const { return !notes.empty(); }
int noteMin, ///< lowest note
noteMax; ///< highest note
std::string path; ///< path of songfile
diff --git a/game/songs.cc b/game/songs.cc
index eb1ced2..99fece7 100644
--- a/game/songs.cc
+++ b/game/songs.cc
@@ -16,7 +16,7 @@
#include <stdexcept>
#include <cstdlib>
-Songs::Songs(Database & database, std::string const& songlist): m_songlist(songlist), math_cover(), m_database(database), m_order(), m_dirty(false), m_loading(false) {
+Songs::Songs(Database & database, std::string const& songlist): m_songlist(songlist), math_cover(), m_typeFilter(), m_database(database), m_order(), m_dirty(false), m_loading(false) {
reload();
}
@@ -120,6 +120,12 @@ void Songs::setFilter(std::string const& val) {
filter_internal();
}
+void Songs::setTypeFilter(unsigned char filter) {
+ if (m_typeFilter == filter) return;
+ m_typeFilter = filter;
+ filter_internal();
+}
+
void Songs::filter_internal() {
boost::mutex::scoped_lock l(m_mutex);
// Print messages when loading has finished
@@ -132,7 +138,12 @@ void Songs::filter_internal() {
try {
SongVector filtered;
for (SongVector::const_iterator it = m_songs.begin(); it != m_songs.end(); ++it) {
- if (regex_search(it->get()->strFull(), boost::regex(m_filter, boost::regex_constants::icase))) filtered.push_back(*it);
+ Song& s = **it;
+ if ((m_typeFilter & 1) && !s.hasDance()) continue;
+ if ((m_typeFilter & 2) && !s.hasDrums()) continue;
+ if ((m_typeFilter & 4) && !s.hasGuitars()) continue;
+ if ((m_typeFilter & 8) && !s.hasVocals()) continue;
+ if (regex_search(s.strFull(), boost::regex(m_filter, boost::regex_constants::icase))) filtered.push_back(*it);
}
m_filtered.swap(filtered);
} catch (...) {
diff --git a/game/songs.hh b/game/songs.hh
index c49deac..d403139 100644
--- a/game/songs.hh
+++ b/game/songs.hh
@@ -53,6 +53,10 @@ class Songs: boost::noncopyable {
Song const& current() const { return *m_filtered[math_cover.getTarget()]; }
/// filters songlist by regular expression
void setFilter(std::string const& regex);
+ /// filters songlist by instrument type (bitmask)
+ void setTypeFilter(unsigned char filter);
+ /// get current type filter (bitmask)
+ unsigned char getTypeFilter() const { return m_typeFilter; }
/// sort descending
std::string sortDesc() const;
/// changes sorting
@@ -67,6 +71,7 @@ class Songs: boost::noncopyable {
SongVector m_songs, m_filtered;
AnimAcceleration math_cover;
std::string m_filter;
+ unsigned char m_typeFilter;
Database & m_database;
int m_order;
void dumpSongs_internal() const;
|