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.

80 lines
2.6KB

  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 "wavetable_component.h"
  19. class PhaseModifier : public WavetableComponent {
  20. public:
  21. enum PhaseStyle {
  22. kNormal,
  23. kEvenOdd,
  24. kHarmonic,
  25. kHarmonicEvenOdd,
  26. kClear,
  27. kNumPhaseStyles
  28. };
  29. class PhaseModifierKeyframe : public WavetableKeyframe {
  30. public:
  31. PhaseModifierKeyframe();
  32. virtual ~PhaseModifierKeyframe() { }
  33. void copy(const WavetableKeyframe* keyframe) override;
  34. void interpolate(const WavetableKeyframe* from_keyframe,
  35. const WavetableKeyframe* to_keyframe, float t) override;
  36. void render(vital::WaveFrame* wave_frame) override;
  37. json stateToJson() override;
  38. void jsonToState(json data) override;
  39. float getPhase() { return phase_; }
  40. float getMix() { return mix_; }
  41. void setPhase(float phase) { phase_ = phase; }
  42. void setMix(float mix) { mix_ = mix; }
  43. void setPhaseStyle(PhaseStyle style) { phase_style_ = style; }
  44. protected:
  45. float phase_;
  46. float mix_;
  47. PhaseStyle phase_style_;
  48. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PhaseModifierKeyframe)
  49. };
  50. PhaseModifier() : phase_style_(kNormal) { }
  51. virtual ~PhaseModifier() = default;
  52. virtual WavetableKeyframe* createKeyframe(int position) override;
  53. virtual void render(vital::WaveFrame* wave_frame, float position) override;
  54. virtual WavetableComponentFactory::ComponentType getType() override;
  55. virtual json stateToJson() override;
  56. virtual void jsonToState(json data) override;
  57. PhaseModifierKeyframe* getKeyframe(int index);
  58. void setPhaseStyle(PhaseStyle style) { phase_style_ = style; }
  59. PhaseStyle getPhaseStyle() const { return phase_style_; }
  60. protected:
  61. PhaseModifierKeyframe compute_frame_;
  62. PhaseStyle phase_style_;
  63. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PhaseModifier)
  64. };