#ifndef DACPLAYER_H
#define DACPLAYER_H
#include "oneway.h"
#include "gpio.h"
#include "tone.h"
#include "audio.h"
#include "pcmdma.h"
#include "pwmconfig.h"

/// Třída, která hraje čistě na pozadí.
class MidiPlayer : public OneWay {
  // Veřejné metody
  public:
    /// Konstruktor
    explicit MidiPlayer () noexcept;
    unsigned Send (uint16_t * const ptr, const unsigned len) override;
    void     stop ();
    void     pass ();
  protected:
  // Chráněné metody
    /// Obsluha tónu
    void ToneChange    (void);
    /// Obsluha vzorku
    short nextSample (void);
    /// Generuj vzorek pro všechny tóny  @return Vzorek
    short genSample (void) {
      int res = 0;
      for (unsigned int i=0; i<maxGens; i++) res += gens[i].step();
      // Pro jistotu omezíme - předejdeme chrastění
      if (res > maxValue) res = maxValue;
      if (res < minValue) res = minValue;
      return (res);
    }
  private:
    Tone                  gens[maxGens]; /// Generátory tónů
    GpioClass             led, but;
    unsigned              passcnt;
    volatile bool         running;
    unsigned char const * melody;
    unsigned              index;
    volatile int          pause;

};
extern "C" const unsigned char * const scores[];

#endif // DACPLAYER_H