Programmable real-time audio signal processing application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gvHashFunc.cpp 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //| Copyright: (C) 2019-2020 Kevin Larke <contact AT larke DOT org>
  2. //| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file.
  3. #include "cmPrefix.h"
  4. #include "cmGlobal.h"
  5. #include "cmFloatTypes.h"
  6. #include "cmRpt.h"
  7. #include "cmErr.h"
  8. #include "cmCtx.h"
  9. #include "cmTime.h"
  10. #include "cmMidi.h"
  11. #include "cmGr.h"
  12. #include "gvHashFunc.h"
  13. void gvRoundHashValueFunc( void* arg, cmChar_t* label, unsigned labelCharCnt, cmGrV_t value )
  14. {
  15. snprintf(label,labelCharCnt,"%i",(int)round(value));
  16. }
  17. void gvMidiSciPitchValueFunc( void* arg, cmChar_t* label, unsigned labelCharCnt, cmGrV_t value )
  18. {
  19. assert( label != NULL && labelCharCnt > 0 );
  20. if( labelCharCnt > 0 )
  21. label[0] = 0;
  22. if( 0 <= value && value <= 127 )
  23. cmMidiToSciPitch((cmMidiByte_t)floor(value), label, labelCharCnt );
  24. else
  25. {
  26. if( labelCharCnt > 3 )
  27. strcpy(label,"?");
  28. }
  29. }
  30. void gvMinSecMsHashValueFunc( void* arg, cmChar_t* label, unsigned labelCharCnt, cmGrV_t value )
  31. {
  32. gvHashFuncArg* p = (gvHashFuncArg*)arg;
  33. int min=0,sec=0,ms=0;
  34. double smpPerMin = p->sampleRate() * 60.0;
  35. double smpPerMs = p->sampleRate() / 1000.0;
  36. if( value > smpPerMin )
  37. {
  38. min = (int)floor( value / smpPerMin );
  39. value -= min * smpPerMin;
  40. }
  41. if( value > p->sampleRate() )
  42. {
  43. sec = (int)floor( value / p->sampleRate() );
  44. value -= sec * p->sampleRate();
  45. }
  46. if( value > smpPerMs )
  47. {
  48. ms = (int)floor( value / smpPerMs );
  49. value -= ms * smpPerMs;
  50. }
  51. snprintf(label,labelCharCnt,"%i:%2i:%2i",min,sec,ms);
  52. }