Skip to content

Commit 12b40dd

Browse files
committed
Change AudioSource: begin from void to bool
1 parent 3b071f2 commit 12b40dd

14 files changed

+36
-22
lines changed

src/AudioTools/Disk/AudioSource.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace audio_tools {
1616
class AudioSource {
1717
public:
1818
/// Reset actual stream and move to root
19-
virtual void begin() = 0;
19+
virtual bool begin() = 0;
2020

2121
/// Returns next audio stream
2222
virtual Stream* nextStream(int offset) = 0;
@@ -90,9 +90,10 @@ class AudioSourceCallback : public AudioSource {
9090
}
9191

9292
/// Reset actual stream and move to root
93-
virtual void begin() override {
93+
virtual bool begin() override {
9494
TRACED();
9595
if (onStartCallback != nullptr) onStartCallback();
96+
return true;
9697
};
9798

9899
/// Returns next (with positive index) or previous stream (with negative
@@ -259,10 +260,11 @@ class AudioSourceVector : public AudioSource, public PathNamesRegistry {
259260
: nameToStreamCallback(callback) {}
260261

261262
/// Reset actual stream and move to root
262-
virtual void begin() override {
263+
bool begin() override {
263264
TRACED();
264265
current_index = 0;
265266
current_stream = nullptr;
267+
return true;
266268
}
267269

268270
/// Returns next audio stream
@@ -548,10 +550,11 @@ class AudioSourceArray : public AudioSource {
548550
nameToStreamCallback(callback) {}
549551

550552
/// Reset actual stream and move to root
551-
virtual void begin() override {
553+
virtual bool begin() override {
552554
TRACED();
553555
current_index = 0;
554556
current_stream = nullptr;
557+
return true;
555558
}
556559

557560
/// Returns next audio stream

src/AudioTools/Disk/AudioSourceFTP.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ class AudioSourceFTP : public AudioSource {
3030
}
3131

3232
/// Resets the actual data
33-
void begin()override {
33+
bool begin()override {
3434
TRACED();
3535
idx = 0;
3636
files.clear();
37-
addDirectory(p_path);
37+
return addDirectory(p_path);
3838
}
3939

4040
/// Resets the actual data

src/AudioTools/Disk/AudioSourceIdxSD.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class AudioSourceIdxSD : public AudioSource {
5151
}
5252
#endif
5353

54-
virtual void begin() override {
54+
virtual bool begin() override {
5555
TRACED();
5656
if (!is_sd_setup) {
5757
while (!start_sd()) {
@@ -62,6 +62,7 @@ class AudioSourceIdxSD : public AudioSource {
6262
}
6363
idx.begin(start_path, extension, file_name_pattern, setup_index);
6464
idx_pos = 0;
65+
return is_sd_setup;
6566
}
6667

6768
void end() {

src/AudioTools/Disk/AudioSourceIdxSDFAT.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,18 @@ class AudioSourceIdxSDFAT : public AudioSource {
6969

7070
virtual ~AudioSourceIdxSDFAT() { end(); }
7171

72-
virtual void begin() override {
72+
virtual bool begin() override {
7373
TRACED();
7474
if (!is_sd_setup) {
7575
if (!sd.begin(*p_cfg)) {
7676
LOGE("sd.begin failed");
77-
return;
77+
return false;
7878
}
7979
is_sd_setup = true;
8080
}
8181
idx.begin(start_path, exension, file_name_pattern, setup_index);
8282
idx_pos = 0;
83+
return is_sd_setup;
8384
}
8485

8586
void end() {

src/AudioTools/Disk/AudioSourceIdxSDMMC.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,18 @@ class AudioSourceIdxSDMMC : public AudioSource {
3939
setup_index = setupIndex;
4040
}
4141

42-
virtual void begin() override {
42+
virtual __GCC_ATOMIC_BOOL_LOCK_FREE begin() override {
4343
TRACED();
4444
if (!is_sd_setup) {
4545
if (!SD_MMC.begin("/sdcard", true)) {
4646
LOGE("SD_MMC.begin failed");
47-
return;
47+
return false;
4848
}
4949
is_sd_setup = true;
5050
}
5151
idx.begin(start_path, exension, file_name_pattern, setup_index);
5252
idx_pos = 0;
53+
return is_sd_setup;
5354
}
5455

5556
void end() {

src/AudioTools/Disk/AudioSourceLittleFS.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class AudioSourceLittleFS : public AudioSource {
2121
exension = ext;
2222
}
2323

24-
virtual void begin() override {
24+
virtual bool begin() override {
2525
TRACED();
2626
if (!is_sd_setup) {
2727
while (!LittleFS.begin()) {
@@ -32,6 +32,7 @@ class AudioSourceLittleFS : public AudioSource {
3232
}
3333
idx.begin(start_path, exension, file_name_pattern);
3434
idx_pos = 0;
35+
return is_sd_setup;
3536
}
3637

3738
void end() {

src/AudioTools/Disk/AudioSourceSD.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class AudioSourceSD : public AudioSource {
5353

5454
#endif
5555

56-
virtual void begin() override {
56+
virtual bool begin() override {
5757
TRACED();
5858
if (!is_sd_setup) {
5959
while (!start_sd()) {
@@ -64,6 +64,7 @@ class AudioSourceSD : public AudioSource {
6464
}
6565
idx.begin(start_path, extension, file_name_pattern);
6666
idx_pos = 0;
67+
return is_sd_setup;
6768
}
6869

6970
void end() {

src/AudioTools/Disk/AudioSourceSDFAT.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,18 @@ class AudioSourceSDFAT : public AudioSource {
7272
if (owns_cfg) delete (p_cfg);
7373
}
7474

75-
virtual void begin() override {
75+
virtual bool begin() override {
7676
TRACED();
7777
if (!is_sd_setup) {
7878
if (!sd.begin(*p_cfg)) {
7979
LOGE("sd.begin failed");
80-
return;
80+
return false;
8181
}
8282
is_sd_setup = true;
8383
}
8484
idx.begin(start_path, exension, file_name_pattern);
8585
idx_pos = 0;
86+
return is_sd_setup;
8687
}
8788

8889
void end() {

src/AudioTools/Disk/AudioSourceSDMMC.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class AudioSourceSDMMC : public AudioSource {
3838
setup_index = setupIndex;
3939
}
4040

41-
virtual void begin() override {
41+
virtual bool begin() override {
4242
TRACED();
4343
if (!is_sd_setup) {
4444
if (!SD_MMC.begin("/sdcard", true)) {
@@ -49,6 +49,7 @@ class AudioSourceSDMMC : public AudioSource {
4949
}
5050
idx.begin(start_path, exension, file_name_pattern);
5151
idx_pos = 0;
52+
return is_sd_setup;
5253
}
5354

5455
void end() {

src/AudioTools/Disk/AudioSourceSPIFFS.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class AudioSourceSPIFFS : public AudioSource {
2121
exension = ext;
2222
}
2323

24-
virtual void begin() override {
24+
virtual bool begin() override {
2525
TRACED();
2626
if (!is_sd_setup) {
2727
while (!SPIFFS.begin()) {
@@ -32,6 +32,7 @@ class AudioSourceSPIFFS : public AudioSource {
3232
}
3333
idx.begin(start_path, exension, file_name_pattern);
3434
idx_pos = 0;
35+
return is_sd_setup;
3536
}
3637

3738
void end() {

0 commit comments

Comments
 (0)