arduino-audio-tools
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
AudioSourceVector< FileType > Class Template Reference

Flexible Audio Data Source using a Vector of (file) names with minimal RAM usage. Files are stored with separated path index and name to minimize memory consumption. Identical paths are stored only once in a shared path registry. This class is a template to support multiple SD libraries and other Streams. More...

#include <AudioSource.h>

Inheritance diagram for AudioSourceVector< FileType >:
AudioSource PathNamesRegistry

Public Types

typedef FileType *(* FileToStreamCallback) (const char *path, FileType &oldFile)
 

Public Member Functions

 AudioSourceVector ()=default
 
 AudioSourceVector (FileToStreamCallback callback)
 Constructor with callback for file to stream conversion.
 
void addName (const char *nameWithPath) override
 Add a file with full path (path and name will be separated automatically)
 
template<typename T , size_t N>
void addNames (T(&nameArray)[N])
 Add multiple files at once.
 
bool begin () override
 Reset actual stream and move to root.
 
void clear ()
 Clear all files and path registry.
 
bool deleteIndex (size_t idx)
 Remove a file by index.
 
bool deleteName (const char *nameWithPath)
 Remove a file by full path.
 
FileTypegetCurrentFile ()
 Get the current file reference for use in callback.
 
virtual int index () override
 Returns the actual index of the stream.
 
int indexOf (const char *path)
 Find index of file by path.
 
virtual bool isAutoNext ()
 Returns default setting go to the next.
 
bool isEmpty ()
 Check if empty.
 
const charname (int index)
 provides the name at the given index
 
virtual FileTypenextStream (int offset) override
 Returns next audio stream.
 
Streamoperator[] (int idx)
 access with array syntax
 
virtual StreampreviousStream (int offset)
 Returns previous audio stream.
 
virtual FileTypeselectStream (const char *path) override
 Returns audio stream by path.
 
virtual FileTypeselectStream (int index) override
 Returns audio stream at the indicated index.
 
virtual void setAutoNext (bool flag)
 
virtual StreamsetIndex (int index)
 same as selectStream - I just prefer this name
 
virtual bool setMetadataCallback (void(*fn)(MetaDataType info, const char *str, int len), ID3TypeSelection sel=SELECT_ICY)
 
void setNameToStreamCallback (FileToStreamCallback callback)
 Set the callback for converting file path to stream.
 
virtual void setTimeout (int millisec)
 Sets the timeout of Stream in milliseconds.
 
virtual void setTimeoutAutoNext (int millisec)
 
int size ()
 Get the number of files.
 
virtual int timeoutAutoNext ()
 Provides the timeout which is triggering to move to the next stream.
 
virtual const chartoStr () override
 provides the actual stream (e.g. file) name or url
 

Protected Member Functions

int findOrAddPath (const char *path)
 Find existing path in registry or add new one, returns index.
 
FileEntrygetFileEntry (int index) const
 Get file entry at index.
 
Str getFullPath (int index)
 Get full path of file at index.
 
const chargetPath (int pathIndex)
 Get path from registry at index.
 

Protected Attributes

int current_index = 0
 
Str current_path
 
FileTypecurrent_stream = nullptr
 
Vector< FileEntryfiles
 
bool is_auto_next = true
 
FileToStreamCallback nameToStreamCallback = nullptr
 
Vector< Strpath_registry
 
int timeout_auto_next_value = 500
 

Detailed Description

template<typename FileType>
class audio_tools::AudioSourceVector< FileType >

Flexible Audio Data Source using a Vector of (file) names with minimal RAM usage. Files are stored with separated path index and name to minimize memory consumption. Identical paths are stored only once in a shared path registry. This class is a template to support multiple SD libraries and other Streams.

Note
A mandatory callback function must be provided to convert a file path (and optionally an old file instance) into a stream or file object. This callback is set via the constructor or setNameToStreamCallback().

Example callback signature: FileType* callback(const char* path, FileType& oldFile);

Without this callback, the class cannot open or access files for playback. Also don't forget to close the old file to prevent any memory leaks.

Author
Phil Schatzmann

Member Typedef Documentation

◆ FileToStreamCallback

template<typename FileType >
typedef FileType *(* FileToStreamCallback) (const char *path, FileType &oldFile)

Constructor & Destructor Documentation

◆ AudioSourceVector() [1/2]

template<typename FileType >
AudioSourceVector ( )
default

◆ AudioSourceVector() [2/2]

template<typename FileType >
AudioSourceVector ( FileToStreamCallback  callback)
inline

Constructor with callback for file to stream conversion.

Member Function Documentation

◆ addName()

template<typename FileType >
void addName ( const char nameWithPath)
inlineoverridevirtual

Add a file with full path (path and name will be separated automatically)

Implements PathNamesRegistry.

◆ addNames()

template<typename FileType >
template<typename T , size_t N>
void addNames ( T(&)  nameArray[N])
inline

Add multiple files at once.

◆ begin()

template<typename FileType >
bool begin ( )
inlineoverridevirtual

Reset actual stream and move to root.

Implements AudioSource.

◆ clear()

template<typename FileType >
void clear ( )
inline

Clear all files and path registry.

◆ deleteIndex()

template<typename FileType >
bool deleteIndex ( size_t  idx)
inline

Remove a file by index.

◆ deleteName()

template<typename FileType >
bool deleteName ( const char nameWithPath)
inline

Remove a file by full path.

◆ findOrAddPath()

template<typename FileType >
int findOrAddPath ( const char path)
inlineprotected

Find existing path in registry or add new one, returns index.

◆ getCurrentFile()

template<typename FileType >
FileType & getCurrentFile ( )
inline

Get the current file reference for use in callback.

◆ getFileEntry()

template<typename FileType >
FileEntry & getFileEntry ( int  index) const
inlineprotected

Get file entry at index.

◆ getFullPath()

template<typename FileType >
Str getFullPath ( int  index)
inlineprotected

Get full path of file at index.

◆ getPath()

template<typename FileType >
const char * getPath ( int  pathIndex)
inlineprotected

Get path from registry at index.

◆ index()

template<typename FileType >
virtual int index ( )
inlineoverridevirtual

Returns the actual index of the stream.

Reimplemented from AudioSource.

◆ indexOf()

template<typename FileType >
int indexOf ( const char path)
inline

Find index of file by path.

◆ isAutoNext()

virtual bool isAutoNext ( )
inlinevirtualinherited

◆ isEmpty()

template<typename FileType >
bool isEmpty ( )
inline

Check if empty.

◆ name()

template<typename FileType >
const char * name ( int  index)
inline

provides the name at the given index

◆ nextStream()

template<typename FileType >
virtual FileType * nextStream ( int  offset)
inlineoverridevirtual

Returns next audio stream.

Implements AudioSource.

◆ operator[]()

Stream * operator[] ( int  idx)
inlineinherited

access with array syntax

◆ previousStream()

virtual Stream * previousStream ( int  offset)
inlinevirtualinherited

Returns previous audio stream.

Reimplemented in AudioSourceFTP< ClientType >, and AudioSourceURL.

◆ selectStream() [1/2]

template<typename FileType >
virtual FileType * selectStream ( const char path)
inlineoverridevirtual

Returns audio stream by path.

Implements AudioSource.

◆ selectStream() [2/2]

template<typename FileType >
virtual FileType * selectStream ( int  index)
inlineoverridevirtual

Returns audio stream at the indicated index.

Reimplemented from AudioSource.

◆ setAutoNext()

virtual void setAutoNext ( bool  flag)
inlinevirtualinherited

Reimplemented in AudioSourceCallback.

◆ setIndex()

virtual Stream * setIndex ( int  index)
inlinevirtualinherited

same as selectStream - I just prefer this name

◆ setMetadataCallback()

virtual bool setMetadataCallback ( void(*)(MetaDataType info, const char *str, int len)  fn,
ID3TypeSelection  sel = SELECT_ICY 
)
inlinevirtualinherited

Reimplemented in AudioSourceURL.

◆ setNameToStreamCallback()

template<typename FileType >
void setNameToStreamCallback ( FileToStreamCallback  callback)
inline

Set the callback for converting file path to stream.

◆ setTimeout()

virtual void setTimeout ( int  millisec)
inlinevirtualinherited

Sets the timeout of Stream in milliseconds.

Reimplemented in AudioSourceURL, and AudioSourceSDFAT< AudioFs, AudioFile >.

◆ setTimeoutAutoNext()

virtual void setTimeoutAutoNext ( int  millisec)
inlinevirtualinherited

Sets the timeout which is triggering to move to the next stream. - the default value is 500 ms

◆ size()

template<typename FileType >
int size ( )
inline

Get the number of files.

◆ timeoutAutoNext()

virtual int timeoutAutoNext ( )
inlinevirtualinherited

Provides the timeout which is triggering to move to the next stream.

◆ toStr()

template<typename FileType >
virtual const char * toStr ( )
inlineoverridevirtual

provides the actual stream (e.g. file) name or url

Reimplemented from AudioSource.

Member Data Documentation

◆ current_index

template<typename FileType >
int current_index = 0
protected

◆ current_path

template<typename FileType >
Str current_path
protected

◆ current_stream

template<typename FileType >
FileType* current_stream = nullptr
protected

◆ files

template<typename FileType >
Vector<FileEntry> files
protected

◆ is_auto_next

bool is_auto_next = true
protectedinherited

◆ nameToStreamCallback

template<typename FileType >
FileToStreamCallback nameToStreamCallback = nullptr
protected

◆ path_registry

template<typename FileType >
Vector<Str> path_registry
protected

◆ timeout_auto_next_value

int timeout_auto_next_value = 500
protectedinherited

The documentation for this class was generated from the following file: