@@ -229,7 +229,7 @@ class NamePrinter : public Print {
229
229
};
230
230
231
231
/* *
232
- * @brief Audio Data Source managing a Vector of (file) names with minimal RAM
232
+ * @brief Flexible Audio Data Source using a Vector of (file) names with minimal RAM
233
233
* usage. Files are stored with separated path index and name to minimize memory
234
234
* consumption. Identical paths are stored only once in a shared path registry.
235
235
* This class is a template to support multiple SD libraries and other Streams.
@@ -365,6 +365,43 @@ class AudioSourceVector : public AudioSource, public PathNamesRegistry {
365
365
366
366
}
367
367
368
+ // / Remove a file by full path
369
+ bool deleteName (const char * nameWithPath) {
370
+ TRACED ();
371
+ if (nameWithPath == nullptr ) return false ;
372
+
373
+ int idx = indexOf (nameWithPath);
374
+ if (idx >= 0 ) {
375
+ LOGI (" deleteName: '%s' at index %d" , nameWithPath, idx);
376
+ return deleteIndex (idx);
377
+ }
378
+
379
+ LOGW (" deleteName: File not found: '%s'" , nameWithPath);
380
+ return false ;
381
+ }
382
+
383
+ // / Remove a file by index
384
+ bool deleteIndex (size_t idx) {
385
+ TRACED ();
386
+ if (idx >= files.size ()) {
387
+ LOGW (" deleteIndex: Invalid index: %d (size: %d)" , (int )idx, files.size ());
388
+ return false ;
389
+ }
390
+
391
+ LOGI (" deleteIndex: Removing file at index %d" , (int )idx);
392
+ files.erase (files.begin () + idx);
393
+
394
+ // Adjust current_index if necessary
395
+ if (current_index >= (int )idx) {
396
+ current_index--;
397
+ if (current_index < 0 && !files.empty ()) {
398
+ current_index = 0 ;
399
+ }
400
+ }
401
+
402
+ return true ;
403
+ }
404
+
368
405
// / Add multiple files at once
369
406
template <typename T, size_t N>
370
407
void addNames (T (&nameArray)[N]) {
0 commit comments