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.

SynthNote.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. class Allocator;
  15. class Controller;
  16. struct SynthParams
  17. {
  18. Allocator &memory; //Memory Allocator for the Note to use
  19. const Controller &ctl;
  20. const SYNTH_T &synth;
  21. const AbsTime &time;
  22. float frequency; //Note base frequency
  23. float velocity; //Velocity of the Note
  24. bool portamento;//True if portamento is used for this note
  25. int note; //Integer value of the note
  26. bool quiet; //Initial output condition for legato notes
  27. };
  28. struct LegatoParams
  29. {
  30. float frequency;
  31. float velocity;
  32. bool portamento;
  33. int midinote;
  34. bool externcall;
  35. };
  36. class SynthNote
  37. {
  38. public:
  39. SynthNote(SynthParams &pars);
  40. virtual ~SynthNote() {}
  41. /**Compute Output Samples
  42. * @return 0 if note is finished*/
  43. virtual int noteout(float *outl, float *outr) = 0;
  44. //TODO fix this spelling error [noisey commit]
  45. /**Release the key for the note and start release portion of envelopes.*/
  46. virtual void releasekey() = 0;
  47. /**Return if note is finished.
  48. * @return finished=1 unfinished=0*/
  49. virtual bool finished() const = 0;
  50. /**Make a note die off next buffer compute*/
  51. virtual void entomb(void) = 0;
  52. virtual void legatonote(LegatoParams pars) = 0;
  53. virtual SynthNote *cloneLegato(void) = 0;
  54. /* For polyphonic aftertouch needed */
  55. void setVelocity(float velocity_);
  56. //Realtime Safe Memory Allocator For notes
  57. class Allocator &memory;
  58. protected:
  59. // Legato transitions
  60. class Legato
  61. {
  62. public:
  63. Legato(const SYNTH_T &synth_, float freq, float vel, int port,
  64. int note, bool quiet);
  65. void apply(SynthNote &note, float *outl, float *outr);
  66. int update(LegatoParams pars);
  67. private:
  68. bool silent;
  69. float lastfreq;
  70. LegatoMsg msg;
  71. int decounter;
  72. struct { // Fade In/Out vars
  73. int length;
  74. float m, step;
  75. } fade;
  76. public:
  77. struct { // Note parameters
  78. float freq, vel;
  79. bool portamento;
  80. int midinote;
  81. } param;
  82. const SYNTH_T &synth;
  83. public: /* Some get routines for legatonote calls (aftertouch feature)*/
  84. float getFreq() {return param.freq; }
  85. float getVelocity() {return param.vel; }
  86. bool getPortamento() {return param.portamento; }
  87. int getMidinote() {return param.midinote; }
  88. void setSilent(bool silent_) {silent = silent_; }
  89. void setDecounter(int decounter_) {decounter = decounter_; }
  90. } legato;
  91. const Controller &ctl;
  92. const SYNTH_T &synth;
  93. const AbsTime &time;
  94. WatchManager *wm;
  95. };
  96. #endif