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.

69 lines
2.3KB

  1. /* Copyright 2013-2019 Matt Tytel
  2. *
  3. * vital is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * vital is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with vital. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include "JuceHeader.h"
  18. #include "json/json.h"
  19. #include "synth_constants.h"
  20. using json = nlohmann::json;
  21. class WavetableComponent;
  22. namespace vital {
  23. class WaveFrame;
  24. } // namespace vital
  25. class WavetableKeyframe {
  26. public:
  27. static float linearTween(float point_from, float point_to, float t);
  28. static float cubicTween(float point_prev, float point_from, float point_to, float point_next,
  29. float range_prev, float range, float range_next, float t);
  30. WavetableKeyframe() : position_(0), owner_(nullptr) { }
  31. virtual ~WavetableKeyframe() { }
  32. int index();
  33. int position() const { return position_; }
  34. void setPosition(int position) {
  35. VITAL_ASSERT(position >= 0 && position < vital::kNumOscillatorWaveFrames);
  36. position_ = position;
  37. }
  38. virtual void copy(const WavetableKeyframe* keyframe) = 0;
  39. virtual void interpolate(const WavetableKeyframe* from_keyframe,
  40. const WavetableKeyframe* to_keyframe, float t) = 0;
  41. virtual void smoothInterpolate(const WavetableKeyframe* prev_keyframe,
  42. const WavetableKeyframe* from_keyframe,
  43. const WavetableKeyframe* to_keyframe,
  44. const WavetableKeyframe* next_keyframe, float t) { }
  45. virtual void render(vital::WaveFrame* wave_frame) = 0;
  46. virtual json stateToJson();
  47. virtual void jsonToState(json data);
  48. WavetableComponent* owner() { return owner_; }
  49. void setOwner(WavetableComponent* owner) { owner_ = owner; }
  50. protected:
  51. int position_;
  52. WavetableComponent* owner_;
  53. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WavetableKeyframe)
  54. };