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.

120 lines
3.7KB

  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 modify
  7. it under the terms of version 2 of the GNU General Public License
  8. as published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License (version 2 or later) for more details.
  13. You should have received a copy of the GNU General Public License (version 2)
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #ifndef SYNTH_NOTE_H
  18. #define SYNTH_NOTE_H
  19. #include "../globals.h"
  20. class Allocator;
  21. class Controller;
  22. struct SynthParams
  23. {
  24. Allocator &memory; //Memory Allocator for the Note to use
  25. const Controller &ctl;
  26. const SYNTH_T &synth;
  27. const AbsTime &time;
  28. float frequency; //Note base frequency
  29. float velocity; //Velocity of the Note
  30. bool portamento;//True if portamento is used for this note
  31. int note; //Integer value of the note
  32. bool quiet; //Initial output condition for legato notes
  33. };
  34. struct LegatoParams
  35. {
  36. float frequency;
  37. float velocity;
  38. bool portamento;
  39. int midinote;
  40. bool externcall;
  41. };
  42. class SynthNote
  43. {
  44. public:
  45. SynthNote(SynthParams &pars);
  46. virtual ~SynthNote() {}
  47. /**Compute Output Samples
  48. * @return 0 if note is finished*/
  49. virtual int noteout(float *outl, float *outr) = 0;
  50. //TODO fix this spelling error [noisey commit]
  51. /**Release the key for the note and start release portion of envelopes.*/
  52. virtual void releasekey() = 0;
  53. /**Return if note is finished.
  54. * @return finished=1 unfinished=0*/
  55. virtual int finished() const = 0;
  56. virtual void legatonote(LegatoParams pars) = 0;
  57. virtual SynthNote *cloneLegato(void) = 0;
  58. /* For polyphonic aftertouch needed */
  59. void setVelocity(float velocity_);
  60. //Realtime Safe Memory Allocator For notes
  61. class Allocator &memory;
  62. protected:
  63. // Legato transitions
  64. class Legato
  65. {
  66. public:
  67. Legato(const SYNTH_T &synth_, float freq, float vel, int port,
  68. int note, bool quiet);
  69. void apply(SynthNote &note, float *outl, float *outr);
  70. int update(LegatoParams pars);
  71. private:
  72. bool silent;
  73. float lastfreq;
  74. LegatoMsg msg;
  75. int decounter;
  76. struct { // Fade In/Out vars
  77. int length;
  78. float m, step;
  79. } fade;
  80. public:
  81. struct { // Note parameters
  82. float freq, vel;
  83. bool portamento;
  84. int midinote;
  85. } param;
  86. const SYNTH_T &synth;
  87. public: /* Some get routines for legatonote calls (aftertouch feature)*/
  88. float getFreq() {return param.freq; }
  89. float getVelocity() {return param.vel; }
  90. bool getPortamento() {return param.portamento; }
  91. int getMidinote() {return param.midinote; }
  92. void setSilent(bool silent_) {silent = silent_; }
  93. void setDecounter(int decounter_) {decounter = decounter_; }
  94. } legato;
  95. const Controller &ctl;
  96. const SYNTH_T &synth;
  97. const AbsTime &time;
  98. };
  99. #endif