// ----
// ---- file   : CustomSynth.h
// ---- author : Bastian Spiegel <bs@tkscript.de>
// ---- legal  : (c) 2011 by Bastian Spiegel. 
// ----          Distributed under terms of the GNU LESSER GENERAL PUBLIC LICENSE (LGPL). See 
// ----          http://www.gnu.org/licenses/licenses.html#LGPL or COPYING for further information.
// ----
// ---- info   : This is part of the "syntracker" midi sequencer.
// ----
// ---- created: 06Apr2011
// ----          
// ---- changed: 
// ----          
// ----
// ----

#ifndef __CUSTOMSYNTH_H__
#define __CUSTOMSYNTH_H__


YG("customsynth")


YC class CustomSynth  : public YAC_Object {

  public:
      sF32 *freq_table;

      sF32 mix_rate;

      sF32 volume;

      SynthVoice  * voices;
      sUI           num_voices;

  protected:
      void freeVoices(void);

  public:
		YAC(CustomSynth);

      CustomSynth(void);
      ~CustomSynth();

  public:

      // Set mixing rate
      YM void _setMixRate(sF32 _rate);
      
      // Set frequency table (128 MIDI notes)
      YM void _setFreqTable(YAC_Object *_fa);

      // Allocate internal voices
      YM void _allocVoices(sUI _polyphony);

      // Immediately stop/reset all voices
      YM void _resetVoices(void);

      // Immediately stop/reset voice
      YM void _stopVoice(sSI _voiceNr);

      // Set global synth volume
      YM void _setVolume(sF32 _volume);

      // Get global synth volume
      YM sF32 _getVolume(void);

      // Called after voice allocation. Set base note.
      YM void _setVoiceBaseNote(sSI _voiceNr, sF32 _baseNote);

      // Called when a CTL_VOL event occurs
      //  (note) _volume is in 0..1 range
      YM void _setVoiceVolume(sSI _voiceNr, sF32 _volume);

      // Called when a CTL_PAN event occurs
      //  (note) _pan is in -1..1 range
      YM void _setVoicePan(sSI _voiceNr, sF32 _pan);

      // Called when a CTL_FREQ event occurs
      //  (note) _pitchbend is in number-of-notes
      YM void _setVoicePitchbend(sSI _voiceNr, sF32 _pitchbend);

      // Called when a CTL_TOUCH event occurs
      //  (note) _pressure is in 0..1 range
      YM void _setVoicePressure(sSI _voiceNr, sF32 _pressure);

      // Called when the voice is retriggered (CTL_RETRIG)
      YM void _restartVoice(sSI _voiceNr);

      // Called at the end of a "tick" when all controllers/params have been set
      //  and the voice shall start to play using that configuration
      YM void _initStartedVoice(sSI _voiceNr);

      // Called when voice shall begin its release phase
      YM void _noteOff(sSI _voiceNr, sF32 _vel);

      // Render interleaved left/right sample pairs
      YM void _render(YAC_Object *_fa);

      // custom params:
      YM void _setVoiceAltVolume(sSI _voiceNr, sF32 _altVolume);

      YM void _setVoicePulseWidth(sSI _voiceNr, sF32 _pulseWidth);

      YM void _setVoiceBrilliance(sSI _voiceNr, sF32 _brilliance);

};


#endif // __CUSTOMSYNTH_H__
