Skip to content

Commit

Permalink
add artist and simfile author search capability
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed Dec 14, 2016
1 parent 43d3392 commit 4599f9f
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ local function searchInput(event)
searchstring = searchstring:sub(1, -2) -- remove the last element of the string
elseif event.DeviceInput.button == "DeviceButton_delete" then
searchstring = ""
elseif event.DeviceInput.button == "DeviceButton_=" then
searchstring = searchstring.."="
else
for i=1,#englishes do -- add standard characters to string
if event.DeviceInput.button == "DeviceButton_"..englishes[i] then
Expand Down
62 changes: 57 additions & 5 deletions src/MusicWheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,65 @@ void MusicWheel::GetSongList( vector<Song*> &arraySongs, SortOrder so )
}

void MusicWheel::FilterBySearch(vector<Song*>& inv, RString findme) {
// uhh ok yeah come back to this mess later - mina
bool super_search = false;
size_t fart = findme.find("artist=");
size_t faux = findme.find("author=");
size_t fitty = findme.find("title=");
RString findfart = "";
RString findfaux = "";
RString findfitty = "";

if (fart != findme.npos || faux != findme.npos || fitty != findme.npos) {
super_search = true;
if (fart != findme.npos)
findfart = findme.substr(fart + 7, findme.find(fart, ';') - fart);
if (faux != findme.npos)
findfaux = findme.substr(faux + 7, findme.find(faux, ';') - faux);
if (fitty != findme.npos)
findfitty = findme.substr(fitty + 6, findme.find(fitty, ';') - fitty);
}

vector<Song*> tmp;
for (size_t i = 0; i < inv.size(); i++) {
RString scoot = inv[i]->GetDisplayMainTitle().MakeLower();
size_t res = scoot.find(findme);
if (res != string::npos)
tmp.push_back(inv[i]);
if (super_search == false) {
for (size_t i = 0; i < inv.size(); i++) {
RString scoot = inv[i]->GetDisplayMainTitle().MakeLower();
size_t res = scoot.find(findme);
if (res != string::npos)
tmp.emplace_back(inv[i]);
}
} else {
for (size_t i = 0; i < inv.size(); i++) {
RString fartS = inv[i]->GetDisplayArtist().MakeLower();
RString fauxS = inv[i]->GetOrTryAtLeastToGetSimfileAuthor().MakeLower();
RString fittyS = inv[i]->GetDisplayMainTitle().MakeLower();

size_t smells = -1;
size_t bs = -1;
size_t gimmie = -1;

if (findfart != "") {
smells = fartS.find(findfart);
if (smells != fartS.npos)
tmp.emplace_back(inv[i]);
}

if (findfaux != "") {
bs = fauxS.find(findfaux);
if (bs != fauxS.npos)
tmp.emplace_back(inv[i]);
}

if (findfitty != "") {
gimmie = fittyS.find(findfitty);
if (gimmie != fittyS.npos)
tmp.emplace_back(inv[i]);
}

}
}


if (tmp.size() > 0) {
lastvalidsearch = findme;
inv.swap(tmp);
Expand Down
44 changes: 23 additions & 21 deletions src/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,27 @@ void Song::InitSteps(Steps *pSteps)
pSteps->SetMaxBPM(this->m_fSpecifiedBPMMax);
}

RString Song::GetOrTryAtLeastToGetSimfileAuthor() {
size_t begin = 0;
size_t end = 0;

RString o = GetSongDir();
o = o.substr(0, o.size() - 1);
o = o.substr(o.find_last_of('/') + 1);

/* Conform to current standard credit placement in songs folders,
for those of you who don't follow convention - too bad. - mina */
end = o.find_last_of(")");
if (end != o.npos) {
begin = o.find_last_of("(");
if (begin != o.npos) {
o = o.substr(begin + 1, end - begin - 1);
return o;
}
}
return "Author Unknown";
}

void Song::GetDisplayBpms( DisplayBpms &AddTo ) const
{
if( m_DisplayBPMType == DISPLAY_BPM_SPECIFIED )
Expand Down Expand Up @@ -2305,27 +2326,8 @@ class LunaSong: public Luna<Song>
COMMON_RETURN_SELF;
}

static int GetOrTryAtLeastToGetSimfileAuthor(T* p, lua_State* L)
{
size_t begin = 0;
size_t end = 0;

RString path = p->GetSongDir();
path = path.substr(0, path.size() - 1);
path = path.substr(path.find_last_of('/') + 1);

/* Conform to current standard credit placement in songs folders,
for those of you who don't follow convention - too bad. - mina */
end = path.find_last_of(")");
if (end != path.npos) {
begin = path.find_last_of("(");
if (begin != path.npos)
path = path.substr(begin + 1, end - begin - 1);
}
else
path = "Author Unknown";

lua_pushstring(L, path);
static int GetOrTryAtLeastToGetSimfileAuthor(T* p, lua_State* L){
lua_pushstring(L, p->GetOrTryAtLeastToGetSimfileAuthor());
return 1;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Song.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ class Song
Steps *CreateSteps();
void InitSteps(Steps *pSteps);

RString GetOrTryAtLeastToGetSimfileAuthor();

/* [splittiming]
float SongGetBeatFromElapsedTime( float fElapsedTime ) const
{
Expand Down

0 comments on commit 4599f9f

Please sign in to comment.