libsaria: Remove the old remove_track_it() function
I can make this simplier by simply passing the index into the vector, rather than needing to calculate the iterator and pass the index. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
52c09ddb12
commit
d345d3211f
|
@ -44,7 +44,7 @@ namespace libsaria
|
|||
void add_track(Track *, unsigned int);
|
||||
void insert_sorted(Track *);
|
||||
void do_remove_tracks(list<Track *> &);
|
||||
unsigned int remove_track_it(vector<Track *>::iterator it, unsigned int);
|
||||
void remove_index(unsigned int);
|
||||
void do_sort();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -27,64 +27,40 @@ namespace libsaria
|
|||
cur = 0;
|
||||
}
|
||||
|
||||
unsigned int Playlist::remove_track_it(vector<Track *>::iterator it,
|
||||
unsigned int rm_index)
|
||||
void Playlist::remove_index(unsigned int rm_index)
|
||||
{
|
||||
index.remove_track(*it);
|
||||
(*it)->rm_playlist(this);
|
||||
it = plist.erase(it);
|
||||
notify_ui(PLAYLIST_RM, (*it), rm_index);
|
||||
if (rm_index >= plist.size())
|
||||
return;
|
||||
|
||||
Track *track = plist[rm_index];
|
||||
index.remove_track(track);
|
||||
track->rm_playlist(this);
|
||||
plist.erase(plist.begin() + rm_index);
|
||||
if (cur > rm_index)
|
||||
cur -= 1;
|
||||
if (cur >= plist.size())
|
||||
cur = 0;
|
||||
notify_ui(PLAYLIST_RM, track, rm_index);
|
||||
notify_ui(PLAYLIST_SIZE, NULL, 0);
|
||||
if (rm_index != 0) {
|
||||
rm_index--;
|
||||
it--;
|
||||
} else
|
||||
it = plist.begin();
|
||||
data_state = DIRTY;
|
||||
return rm_index;
|
||||
schedule_save();
|
||||
}
|
||||
|
||||
void Playlist::remove_track(Track *track)
|
||||
{
|
||||
vector<Track *>::iterator it;
|
||||
unsigned int index = 0;
|
||||
|
||||
for (it = plist.begin(); it != plist.end(); it++) {
|
||||
if (*it == track) {
|
||||
remove_track_it(it, index);
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
schedule_save();
|
||||
remove_index(find_index(track));
|
||||
}
|
||||
|
||||
void Playlist::remove_indices(list<unsigned int> &indices)
|
||||
{
|
||||
vector<Track *>::iterator to_rm, tmp;
|
||||
list<unsigned int>::iterator it;
|
||||
unsigned int index, removed;
|
||||
|
||||
if (is_static())
|
||||
return;
|
||||
indices.sort();
|
||||
|
||||
if (indices.back() >= plist.size())
|
||||
return;
|
||||
|
||||
index = 0;
|
||||
removed = 0;
|
||||
to_rm = plist.begin();
|
||||
for (it = indices.begin(); it != indices.end(); it++) {
|
||||
for (unsigned int i = 0; i < (*it - index); i++)
|
||||
to_rm++;
|
||||
remove_track_it(to_rm, (*it) - removed);
|
||||
index = *it;
|
||||
removed++;
|
||||
}
|
||||
|
||||
schedule_save();
|
||||
for (it = indices.begin(); it != indices.end(); it++)
|
||||
remove_index(*it);
|
||||
}
|
||||
|
||||
void Playlist::add_sorted(list<Track *> &tracks)
|
||||
|
|
|
@ -11,6 +11,8 @@ namespace libsaria
|
|||
|
||||
Track *Playlist::next()
|
||||
{
|
||||
Track *track;
|
||||
|
||||
if (get_size() == 0)
|
||||
return NULL;
|
||||
|
||||
|
@ -22,14 +24,13 @@ namespace libsaria
|
|||
if (cur >= plist.size())
|
||||
cur -= plist.size();
|
||||
|
||||
if (!(flags & PL_NO_DRAIN)) {
|
||||
remove_track_it(plist.begin() + cur, cur);
|
||||
schedule_save();
|
||||
}
|
||||
track = plist[cur];
|
||||
if (!(flags & PL_NO_DRAIN))
|
||||
remove_index(cur);
|
||||
|
||||
if (get_size() != 0)
|
||||
notify_ui(PLAYLIST_GOTO, plist[cur], cur);
|
||||
return plist[cur];
|
||||
notify_ui(PLAYLIST_GOTO, track, cur);
|
||||
return track;
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
||||
|
|
|
@ -130,15 +130,11 @@ namespace libsaria
|
|||
|
||||
unsigned int Playlist::find_index(Track *track)
|
||||
{
|
||||
vector<Track *>::iterator it;
|
||||
unsigned int index = 0;
|
||||
|
||||
for (it = plist.begin(); it != plist.end(); it++) {
|
||||
if (*it == track)
|
||||
return index;
|
||||
index++;
|
||||
for (unsigned int i = 0; i < plist.size(); i++) {
|
||||
if (plist[i] == track)
|
||||
return i;
|
||||
}
|
||||
return index;
|
||||
return plist.size();
|
||||
}
|
||||
|
||||
void Playlist::notify_ui(notify_t type, Track *track, unsigned int index)
|
||||
|
|
Loading…
Reference in New Issue