Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
Added history of played tracks (available only with Random Track enab…
Browse files Browse the repository at this point in the history
…led).
  • Loading branch information
Flone-dnb committed Nov 2, 2019
1 parent 27af4e9 commit 49b481c
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 8 deletions.
3 changes: 1 addition & 2 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
- Add a history of played tracks so the 'prev' button will get back to actually previous track even if 'random track' function is selected.
- Speed up the process of adding the tracks.
- Speed up the process of adding the tracks.
- When adding music, we need to add it in the same order in which it was in the folder.
- Do something with color banding.
- Seems like with 'speed (by pitch)' effect we also need to increase mid-high frequencies on like 3-4 dB and maybe do the same thing with the low and the mid-low.
Expand Down
72 changes: 67 additions & 5 deletions src/Model/AudioService/audioservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,23 @@ void AudioService::playTrack(size_t iTrackIndex, bool bDontLockMutex)
pMainWindow->removePlayingOnTrack(iCurrentlyPlayingTrackIndex);
}


// Play track
if ( tracks[iTrackIndex]->playTrack(fCurrentVolume) )
{
bIsSomeTrackPlaying = true;
bCurrentTrackPaused = false;
iCurrentlyPlayingTrackIndex = iTrackIndex;

if (bRandomNextTrack)
{
vTracksHistory.push_back(tracks[iTrackIndex]);

if (vTracksHistory.size() > MAX_HISTORY_SIZE)
{
vTracksHistory.erase( vTracksHistory.begin() );
}
}
}
else
{
Expand Down Expand Up @@ -614,17 +625,52 @@ void AudioService::prevTrack()

if ( tracks.size() > 0 )
{
if (iCurrentlyPlayingTrackIndex == 0)
if (bRandomNextTrack)
{
mtxTracksVec.unlock();
if (vTracksHistory.size() > 1)
{
size_t iTrackIndex = 0;

Track* pPrevTrack = vTracksHistory[ vTracksHistory.size() - 2 ];

playTrack( tracks.size() - 1 );
for (size_t i = 0; i < tracks.size(); i++)
{
if (pPrevTrack == tracks[i])
{
iTrackIndex = i;
break;
}
}


mtxTracksVec.unlock();

vTracksHistory.pop_back();
vTracksHistory.pop_back();

playTrack ( iTrackIndex );
}
else
{
mtxTracksVec.unlock();

playTrack( iCurrentlyPlayingTrackIndex );
}
}
else
{
mtxTracksVec.unlock();
if (iCurrentlyPlayingTrackIndex == 0)
{
mtxTracksVec.unlock();

playTrack( tracks.size() - 1 );
}
else
{
mtxTracksVec.unlock();

playTrack(iCurrentlyPlayingTrackIndex - 1);
playTrack(iCurrentlyPlayingTrackIndex - 1);
}
}
}
else
Expand Down Expand Up @@ -678,6 +724,17 @@ void AudioService::removeTrack(size_t iTrackIndex)
}
}


// Erase from vTracksHistory
for (size_t i = 0; i < vTracksHistory.size(); i++)
{
if (vTracksHistory[i] == tracks[iTrackIndex])
{
vTracksHistory.erase ( vTracksHistory.begin() + i );
break;
}
}

delete tracks[iTrackIndex];
tracks.erase( tracks.begin() + iTrackIndex );

Expand Down Expand Up @@ -719,6 +776,9 @@ void AudioService::clearPlaylist()

fCurrentVolume = DEFAULT_VOLUME;


vTracksHistory.clear();

mtxTracksVec.unlock();
}

Expand Down Expand Up @@ -1216,6 +1276,8 @@ void AudioService::randomNextTrack()
bRepeatTrack = false;
pMainWindow->uncheckRepeatTrackButton();
}

vTracksHistory.clear();
}

void AudioService::setVolume(float fNewVolume)
Expand Down
4 changes: 3 additions & 1 deletion src/Model/AudioService/audioservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,13 @@ class AudioService
bool bMonitorTracks;


// Searcy
// Search
std::vector<size_t> vSearchResult;
size_t iCurrentPosInSearchVec;
bool bFirstSearchAfterKeyChange;


// Tracks
std::vector<Track*> tracks;
std::vector<Track*> vTracksHistory;
};
2 changes: 2 additions & 0 deletions src/globalparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
#define MONITOR_TRACK_INTERVAL_MS 200
#define MAX_TIME_ERROR_MS 50

#define MAX_HISTORY_SIZE 50

// graph
#define MAX_X_AXIS_VALUE 1000

0 comments on commit 49b481c

Please sign in to comment.