Audio plugin host https://kx.studio/carla
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.

119 lines
3.5KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Note.h - Abstract Base Class for synthesizers
  4. Copyright (C) 2010-2010 Mark McCurry
  5. Author: Mark McCurry
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. */
  11. #ifndef SYNTH_NOTE_H
  12. #define SYNTH_NOTE_H
  13. #include "../globals.h"
  14. namespace zyncarla {
  15. class Allocator;
  16. class Controller;
  17. struct SynthParams
  18. {
  19. Allocator &memory; //Memory Allocator for the Note to use
  20. const Controller &ctl;
  21. const SYNTH_T &synth;
  22. const AbsTime &time;
  23. float frequency; //Note base frequency
  24. float velocity; //Velocity of the Note
  25. bool portamento;//True if portamento is used for this note
  26. int note; //Integer value of the note
  27. bool quiet; //Initial output condition for legato notes
  28. };
  29. struct LegatoParams
  30. {
  31. float frequency;
  32. float velocity;
  33. bool portamento;
  34. int midinote;
  35. bool externcall;
  36. };
  37. class SynthNote
  38. {
  39. public:
  40. SynthNote(SynthParams &pars);
  41. virtual ~SynthNote() {}
  42. /**Compute Output Samples
  43. * @return 0 if note is finished*/
  44. virtual int noteout(float *outl, float *outr) = 0;
  45. //TODO fix this spelling error [noisey commit]
  46. /**Release the key for the note and start release portion of envelopes.*/
  47. virtual void releasekey() = 0;
  48. /**Return if note is finished.
  49. * @return finished=1 unfinished=0*/
  50. virtual bool finished() const = 0;
  51. /**Make a note die off next buffer compute*/
  52. virtual void entomb(void) = 0;
  53. virtual void legatonote(LegatoParams pars) = 0;
  54. virtual SynthNote *cloneLegato(void) = 0;
  55. /* For polyphonic aftertouch needed */
  56. void setVelocity(float velocity_);
  57. //Realtime Safe Memory Allocator For notes
  58. class Allocator &memory;
  59. protected:
  60. // Legato transitions
  61. class Legato
  62. {
  63. public:
  64. Legato(const SYNTH_T &synth_, float freq, float vel, int port,
  65. int note, bool quiet);
  66. void apply(SynthNote &note, float *outl, float *outr);
  67. int update(LegatoParams pars);
  68. private:
  69. bool silent;
  70. float lastfreq;
  71. LegatoMsg msg;
  72. int decounter;
  73. struct { // Fade In/Out vars
  74. int length;
  75. float m, step;
  76. } fade;
  77. public:
  78. struct { // Note parameters
  79. float freq, vel;
  80. bool portamento;
  81. int midinote;
  82. } param;
  83. const SYNTH_T &synth;
  84. public: /* Some get routines for legatonote calls (aftertouch feature)*/
  85. float getFreq() {return param.freq; }
  86. float getVelocity() {return param.vel; }
  87. bool getPortamento() {return param.portamento; }
  88. int getMidinote() {return param.midinote; }
  89. void setSilent(bool silent_) {silent = silent_; }
  90. void setDecounter(int decounter_) {decounter = decounter_; }
  91. } legato;
  92. const Controller &ctl;
  93. const SYNTH_T &synth;
  94. const AbsTime &time;
  95. WatchManager *wm;
  96. };
  97. }
  98. #endif