Skip to content

Commit 7debfd1

Browse files
Merge pull request #125 from marcel-licence/124-track-selection-starts-with-second-track
start with first or last track when try to play prev or next track th…
2 parents d500ce8 + 05cdf29 commit 7debfd1

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/ml_track_selector.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ enum fileLoadStatus
6161
};
6262

6363

64-
enum fileLoadStatus LoadFileFromIdx(int fileIdx);
64+
static enum fileLoadStatus LoadFileFromIdx(int fileIdx);
6565

6666

6767
static uint8_t g_fileIdx = 0;
6868
static uint8_t g_totalFilesFound = 0;
69-
static bool auto_reload = true;
69+
static bool g_auto_reload = true;
70+
static bool g_is_first_loaded_file = true;
7071

7172

7273
void TrackSelector_Setup(const char *filter)
@@ -76,6 +77,8 @@ void TrackSelector_Setup(const char *filter)
7677
FS_Setup();
7778

7879
g_totalFilesFound = getFileCount(s_filter);
80+
g_is_first_loaded_file = true;
81+
7982
TrackSelector_DebugPrintf("Found %u %s files\n", g_totalFilesFound, s_filter);
8083
}
8184

@@ -92,13 +95,13 @@ void TrackSelector_Autostart(void)
9295

9396
void TrackSelector_Process(void)
9497
{
95-
if (auto_reload == true)
98+
if (g_auto_reload)
9699
{
97100
TrackSelector_Autostart();
98101
}
99102
}
100103

101-
enum fileLoadStatus LoadFileFromIdx(int fileIdx)
104+
static enum fileLoadStatus LoadFileFromIdx(int fileIdx)
102105
{
103106
TrackSelector_DebugPrintf("LoadFileFromIdx(%d)\n", fileIdx);
104107

@@ -170,7 +173,14 @@ void TrackSelector_LoadFileNext(void)
170173

171174
do
172175
{
173-
g_fileIdx = (g_fileIdx + 1) % g_totalFilesFound;
176+
if (!g_is_first_loaded_file)
177+
{
178+
g_fileIdx = (g_fileIdx + 1) % g_totalFilesFound;
179+
}
180+
else
181+
{
182+
g_is_first_loaded_file = false;
183+
}
174184
}
175185
while (LoadFileFromIdx(g_fileIdx) != fls_ok && g_fileIdx != startIdx);
176186
}
@@ -184,7 +194,14 @@ void TrackSelector_LoadFilePrev(void)
184194

185195
do
186196
{
187-
g_fileIdx = (g_fileIdx == 0) ? (g_totalFilesFound - 1) : (g_fileIdx - 1);
197+
if (!g_is_first_loaded_file)
198+
{
199+
g_fileIdx = (g_fileIdx == 0) ? (g_totalFilesFound - 1) : (g_fileIdx - 1);
200+
}
201+
else
202+
{
203+
g_is_first_loaded_file = false;
204+
}
188205
}
189206
while (LoadFileFromIdx(g_fileIdx) != fls_ok && g_fileIdx != startIdx);
190207
}

0 commit comments

Comments
 (0)