home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / buzzmachines_massive.exe / Dev / Geoffroy Notefilter SourceCode / BuzzParameterDuration.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-05-08  |  2.0 KB  |  95 lines

  1. // BuzzParameterDuration.cpp: implementation of the BuzzParameterDuration class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4.  
  5. #include "BuzzParameterDuration.h"
  6.  
  7. //////////////////////////////////////////////////////////////////////
  8. // Construction/Destruction
  9. //////////////////////////////////////////////////////////////////////
  10.  
  11. word BuzzParameterDuration::MIN_SLIDER_VALUE = 0;
  12. word BuzzParameterDuration::MAX_SLIDER_VALUE = 0xFFFE;
  13. word BuzzParameterDuration::UNCHANGED_SLIDER_VALUE = 0xFFFF;
  14. word BuzzParameterDuration::INIT_SLIDER_VALUE = 0;
  15.  
  16. BuzzParameterDuration::BuzzParameterDuration() : BuzzParameter<word,dword>()
  17. {
  18.     unit = BuzzParameterUnit_SAMPLES;
  19.     samplesPerTick = 44100;
  20.     sampleRate = 44100;
  21.     setSliderValue(INIT_SLIDER_VALUE);
  22. }
  23.  
  24. BuzzParameterDuration::~BuzzParameterDuration()
  25. {
  26. }
  27.  
  28. void BuzzParameterDuration::compute()
  29. {
  30.     // convert in samples
  31.  
  32.     switch (unit) {
  33.     case BuzzParameterUnit_SAMPLES:
  34.         currentRealValue = currentSliderValue * 1000;
  35.         break;
  36.  
  37.     case BuzzParameterUnit_MS:
  38.         currentRealValue = currentSliderValue * sampleRate / 10000;
  39.         break;
  40.  
  41.     case BuzzParameterUnit_TICKS:
  42.         currentRealValue = currentSliderValue * samplesPerTick;
  43.         break;
  44.  
  45.     default:
  46.         currentRealValue = 0; // error
  47.         break;
  48.     }
  49. }
  50.  
  51. char const * BuzzParameterDuration::toString(word const value)
  52. {
  53.     static char txt[50];
  54.     txt[0]=0;
  55.  
  56.     switch (unit) {
  57.     case BuzzParameterUnit_SAMPLES:
  58.         sprintf(txt,"%d samples",value * 1000);
  59.         break;
  60.  
  61.     case BuzzParameterUnit_MS:
  62.         sprintf(txt,"%d.%d ms",value/10,value%10);
  63.         break;
  64.  
  65.     case BuzzParameterUnit_TICKS:
  66.         sprintf(txt,"%d ticks",value);
  67.         break;
  68.  
  69.     default:
  70.         sprintf(txt,"error, no unity set");
  71.         break;
  72.     }
  73.  
  74.     return txt;
  75.  
  76. }
  77.  
  78. void BuzzParameterDuration::setUnit(byte unit)
  79. {
  80.     this->unit = unit;
  81.     compute();
  82. }
  83.  
  84. void BuzzParameterDuration::setSamplesPerTick(int n)
  85. {
  86.     this->samplesPerTick = n;
  87.     compute();
  88. }
  89.  
  90. void BuzzParameterDuration::setSampleRate(int sampleRate) 
  91. {
  92.     this->sampleRate = sampleRate;
  93.     compute();
  94. }
  95.