// ----
// ---- file   : StSampleBank.h
// ---- author : Bastian Spiegel <bs@tkscript.de>
// ---- legal  : (c) 2009-2019 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: 23Sep2009
// ----          
// ---- changed: 26Dec2009, 27Dec2009, 29Dec2009, 02Jan2010, 05Jan2010, 07Jan2010, 15Jan2010
// ----          19Jan2010, 21Jan2010, 29Apr2010, 24Mar2013, 23Dec2018, 27Dec2018, 31Dec2018
// ----          17Jan2019, 23Apr2019
// ----
// ----
// ----

#ifndef __ST_SAMPLEBANK_H__
#define __ST_SAMPLEBANK_H__

YG("tksampler")


YC class StSampleBank : public YAC_Object {
  public:
   StSample *first_sample;  // deletable list of samples

   StSampleMutexGroup *first_mutex_group; // deletable list of mutex groups

   YAC_String *name;

   sUI max_voices; // maximum number of times this samplebank can be played in one generator

   sF32 transpose;
   sF32 freq_rand_amount;
   sF32 volume;
   sF32 volume_rand_amount;
   sF32 pan;
   sF32 pan_rand_amount;
   sF32 sampleoffset_rand_amount;

   sBool b_unique_notes; // 0=allow multiple voices to play the same note, 1=soft-stop prev. voice when note is retriggered


  protected:
   sUI num_samples; // optimization

  public:
   StSampleBank(void);
   ~StSampleBank();

   YAC(StSampleBank);

   YM void _freeSamples (void);
   YM void _freeMutexGroups (void);

   YM YAC_Object *_getFirstSample (void);
   YM YAC_Object *_getSampleByIdx (sUI _idx);
   YM sSI         _getSampleIdx (YAC_Object *_sample);
   YM void        _addSample      (YAC_Object *_sample);
   YM void        _removeSample   (YAC_Object *_sample);
   YM sUI         _getNumSamples  (void);
   YM void        _setEnableSkipRange (sBool _bEnable);
   YM void        _swapSamples    (sUI _idxLeft);

   YM YAC_Object *_getFirstMutexGroup         (void);
   YM YAC_Object *_getMutexGroupByIdx         (sUI _idx);
   YM void        _addMutexGroup              (YAC_Object *_mtxgrp);
   YM void        _removeMutexGroup           (YAC_Object *_mtxgrp);
   YM sSI         _getMutexGroupIndexByObject (YAC_Object *_mtxgrp);
   YM sUI         _getNumMutexGroups          (void);

   YM YAC_Object *_getName (void);
   YM void        _setName (YAC_Object *_str);

   YM void        _setMaxVoices (sUI _maxVoices);
   YM sUI         _getMaxVoices (void);

   YM void        _setTranspose (sF32 _transpose);
   YM sF32        _getTranspose (void);

   YM void        _setFreqRandAmount (sF32 _amt);
   YM sF32        _getFreqRandAmount (void);

   YM void        _setVolume (sF32 _vol);
   YM sF32        _getVolume (void);

   YM void        _setVolumeRandAmount (sF32 _amt);
   YM sF32        _getVolumeRandAmount (void);

   YM void        _setPan (sF32 _pan);
   YM sF32        _getPan (void);

   YM void        _setPanRandAmount (sF32 _amt);
   YM sF32        _getPanRandAmount (void);

   YM void        _setSampleOffsetRandAmount (sF32 _amt);
   YM sF32        _getSampleOffsetRandAmount (void);

   YM void        _setEnableUniqueNotes (sBool _bEnable);
   YM sSI         _getEnableUniqueNotes (void);

   // Called internally when a sample is added, deleted, or moved up/down.
   // Must be called externally when a range is changed.
   YM void updateAltGroups (void);

   // For UI/Debugging, count the number of alt groups
   YM sSI _getNumAltGroups (void);
};


#endif // __ST_SAMPLEBANK_H__
