arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
AudioPlayerProtocol.h
1#pragma once
2#include "AudioTools/CoreAudio/AudioPlayer.h"
3
4namespace audio_tools {
5
6/***
7 * @brief Abstract class for protocol to control the audio player.
8 * @ingroup player
9 * @author Phil Schatzmann
10 */
12 public:
15 virtual bool processCommand(const char* input, Print& result) = 0;
16
18 virtual bool processCommand(Stream& input, Print& result) {
19 char buffer[max_input_buffer_size];
20 int len = readLine(input, buffer, max_input_buffer_size);
21 if (len == 0) return false;
22 return processCommand(buffer, result);
23 }
25 virtual void setPlayer(AudioPlayer& player) { p_player = &player; }
26
28 void setMaxInputBufferSize(int size) { max_input_buffer_size = size; }
29
30 protected:
31 AudioPlayer* p_player = nullptr;
32 int max_input_buffer_size = 256;
33
35 int readLine(Stream& in, char* str, int max) {
36 int index = 0;
37 if (in.available() > 0) {
38 index = in.readBytesUntil('\n', str, max);
39 str[index] = '\0'; // null termination character
40 }
41 return index;
42 }
43};
44
45} // namespace audio_tools
Implements a simple audio player which supports the following commands:
Definition AudioPlayer.h:38
Definition AudioPlayerProtocol.h:11
void setMaxInputBufferSize(int size)
Defines the input buffer size used by the readLine function (default 256)
Definition AudioPlayerProtocol.h:28
int readLine(Stream &in, char *str, int max)
Reads a line delimited by ' ' from the stream.
Definition AudioPlayerProtocol.h:35
virtual bool processCommand(const char *input, Print &result)=0
virtual void setPlayer(AudioPlayer &player)
Defines the player.
Definition AudioPlayerProtocol.h:25
virtual bool processCommand(Stream &input, Print &result)
Proceess commands passed by Stream (e.g. Serial)
Definition AudioPlayerProtocol.h:18
Definition NoArduino.h:62
Definition NoArduino.h:142
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10