Imperfector.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #include "Imperfector.h"
  2. #include "StdInclude.h"
  3. #include <cmath>
  4. namespace {
  5. #if DEBUG
  6. // This must hold true at the start/end of each batch (i.e. if we handle all of the diffs in one render batch this should be valid but if we only handle some of the diffs it might not be )
  7. bool CheckSampleParamsInvariant(const TGUISampleParameters& iSampleParams) {
  8. JBOX_ASSERT(iSampleParams.fRootNote < 128);
  9. JBOX_ASSERT(iSampleParams.fTuneCents >= -50)
  10. JBOX_ASSERT(iSampleParams.fTuneCents <= 50);
  11. JBOX_ASSERT(iSampleParams.fPlayRangeStart >= 0.0f);
  12. JBOX_ASSERT(iSampleParams.fPlayRangeEnd <= 1.0f);
  13. JBOX_ASSERT(iSampleParams.fPlayRangeStart <= iSampleParams.fPlayRangeEnd);
  14. JBOX_ASSERT(iSampleParams.fLoopRangeStart >= 0.0f);
  15. JBOX_ASSERT(iSampleParams.fLoopRangeEnd <= 1.0f);
  16. JBOX_ASSERT(iSampleParams.fLoopRangeStart >= iSampleParams.fPlayRangeStart);
  17. JBOX_ASSERT(iSampleParams.fLoopRangeEnd <= iSampleParams.fPlayRangeEnd);
  18. JBOX_ASSERT(iSampleParams.fLoopRangeStart <= iSampleParams.fLoopRangeEnd);
  19. JBOX_ASSERT(iSampleParams.fLoopMode <= kLoopMode_FwdBwdLoopMode);
  20. JBOX_ASSERT(iSampleParams.fVolumeLevel <= 127);
  21. return true;
  22. }
  23. #endif //DEBUG
  24. void UpdateZoneParametersFromDiff(const TJBox_PropertyDiff& iDiff, TGUISampleParameters& ioZP) {
  25. const TJBox_Float64 numberDouble = JBox_GetNumber(iDiff.fCurrentValue);
  26. const TJBox_Int8 numberInt8 = static_cast<TJBox_Int8>(numberDouble);
  27. const TJBox_UInt8 numberUInt8 = static_cast<TJBox_UInt8>(numberDouble);
  28. switch (iDiff.fPropertyTag) {
  29. case kJBox_UserSampleRootKey:
  30. ioZP.fRootNote = numberUInt8;
  31. break;
  32. case kJBox_UserSampleTuneCents:
  33. ioZP.fTuneCents = numberInt8 - 50;
  34. break;
  35. case kJBox_UserSamplePlayRangeStart:
  36. ioZP.fPlayRangeStart = numberDouble;
  37. break;
  38. case kJBox_UserSamplePlayRangeEnd:
  39. ioZP.fPlayRangeEnd = numberDouble;
  40. break;
  41. case kJBox_UserSampleLoopMode:
  42. ioZP.fLoopMode = numberUInt8;
  43. break;
  44. case kJBox_UserSampleLoopRangeStart:
  45. ioZP.fLoopRangeStart = numberDouble;
  46. break;
  47. case kJBox_UserSampleLoopRangeEnd:
  48. ioZP.fLoopRangeEnd = numberDouble;
  49. break;
  50. case kJBox_UserSamplePreviewVolumeLevel:
  51. ioZP.fVolumeLevel = numberUInt8;
  52. break;
  53. default:
  54. JBOX_ASSERT(false);
  55. }
  56. }
  57. } // namespace
  58. TJBox_Int64 CImperfector::TagToInt(const TJBox_Tag iTag) const
  59. {
  60. const TJBox_Value& jboxValue = JBox_LoadMOMPropertyByTag(fMotherBoardCustomPropertiesRef, iTag);
  61. const TJBox_Float64& valueFloat = JBox_GetNumber(jboxValue);
  62. const TJBox_Int64& value = static_cast<TJBox_Int64>(valueFloat);
  63. return value;
  64. }
  65. TJBox_Float64 CImperfector::TagToFloat(const TJBox_Tag iTag) const
  66. {
  67. const TJBox_Value& jboxValue = JBox_LoadMOMPropertyByTag(fMotherBoardCustomPropertiesRef, iTag);
  68. return JBox_GetNumber(jboxValue);
  69. }
  70. TJBox_Bool CImperfector::TagToBool(const TJBox_Tag iTag) const
  71. {
  72. const TJBox_Value& jboxValue = JBox_LoadMOMPropertyByTag(fMotherBoardCustomPropertiesRef, iTag);
  73. return JBox_GetBoolean(jboxValue);
  74. return TJBox_Bool();
  75. }
  76. CImperfector::CImperfector(TJBox_Float64 iSampleRate)
  77. :
  78. fIsPlaying(false),
  79. fSampleRate(iSampleRate),
  80. fLastNumeratorNote(kInvalidNoteNumber),
  81. fLastDenominatorNote(kInvalidNoteNumber),
  82. fLastPosition(0)
  83. {
  84. CustomPropertiesRef = JBox_GetMotherboardObjectRef("/custom_properties");
  85. fTransportRef = JBox_GetMotherboardObjectRef("/transport");
  86. fNoteStates = JBox_GetMotherboardObjectRef("/note_states");
  87. fEnvironmenRef = JBox_GetMotherboardObjectRef("/environment");
  88. // CV inputs
  89. TJBox_ObjectRef numeratorNoteCVRef = JBox_GetMotherboardObjectRef("/cv_inputs/numerator_note_cv");
  90. fNumeratorNoteCVInputRef = JBox_MakePropertyRef(numeratorNoteCVRef, "value");
  91. fNumeratorNoteCVConnectedRef = JBox_MakePropertyRef(numeratorNoteCVRef, "connected");
  92. TJBox_ObjectRef denominatorNoteCVRef = JBox_GetMotherboardObjectRef("/cv_inputs/denominator_note_cv");
  93. fDenominatorNoteCVInputRef = JBox_MakePropertyRef(denominatorNoteCVRef, "value");
  94. fDenominatorNoteCVConnectedRef = JBox_MakePropertyRef(denominatorNoteCVRef, "connected");
  95. }
  96. void CImperfector::RenderBatch(const TJBox_PropertyDiff iPropertyDiffs[], TJBox_UInt32 iDiffCount) {
  97. }
  98. void CImperfector::HandleDiffs(const TJBox_PropertyDiff iPropertyDiffs[], TJBox_UInt32 iDiffCount)
  99. {
  100. for (TJBox_UInt32 i = 0; i < iDiffCount; ++i) {
  101. const TJBox_PropertyDiff& diff = iPropertyDiffs[i];
  102. if (diff.fPropertyRef.fObject == fTransportRef && diff.fPropertyTag == kJBox_TransportPlaying)
  103. {
  104. fIsPlaying = JBox_GetBoolean(diff.fCurrentValue);
  105. }
  106. else if (diff.fPropertyRef.fObject == fTransportRef && diff.fPropertyTag == kJBox_TransportLoopEnabled)
  107. {
  108. fIsLooping = JBox_GetBoolean(diff.fCurrentValue);
  109. }
  110. else if (diff.fPropertyRef.fObject == fTransportRef && diff.fPropertyTag == kJBox_TransportTempo)
  111. {
  112. fTempo = JBox_GetNumber(diff.fCurrentValue);
  113. }
  114. else if (diff.fPropertyRef.fObject == fEnvironmenRef && diff.fPropertyTag == kJBox_EnvironmentPlayerBypassed)
  115. {
  116. fIsBypassedByHost = JBox_GetBoolean(diff.fCurrentValue);
  117. }
  118. else if (diff.fPropertyRef.fObject == fCustomPropertiesRef && diff.fPropertyTag == kOnOffTag)
  119. {
  120. fIsEnabled = JBox_GetBoolean(diff.fCurrentValue);
  121. }
  122. }
  123. }
  124. void CImperfector::FlashNoteOnLamp()
  125. {
  126. }
  127. void CImperfector::HandleNoteOnLampTurnOff()
  128. {
  129. }
  130. void CImperfector::ResetIfRequested()
  131. {
  132. }