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.

95 lines
2.6KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. JackEngine.h - Jack Driver
  4. Copyright 2009, Alan Calvert
  5. 2014, 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 JACK_ENGINE_H
  18. #define JACK_ENGINE_H
  19. #include <string>
  20. #include <pthread.h>
  21. #include <semaphore.h>
  22. #include <jack/jack.h>
  23. #include <pthread.h>
  24. #include "MidiIn.h"
  25. #include "AudioOut.h"
  26. typedef jack_default_audio_sample_t jsample_t;
  27. class JackEngine:public AudioOut, MidiIn
  28. {
  29. public:
  30. JackEngine(const SYNTH_T &synth);
  31. ~JackEngine() { }
  32. bool Start();
  33. void Stop();
  34. void setMidiEn(bool nval);
  35. bool getMidiEn() const;
  36. void setAudioEn(bool nval);
  37. bool getAudioEn() const;
  38. int getBuffersize() { return audio.jackNframes; }
  39. std::string clientName();
  40. int clientId();
  41. protected:
  42. int processCallback(jack_nframes_t nframes);
  43. static int _processCallback(jack_nframes_t nframes, void *arg);
  44. int bufferSizeCallback(jack_nframes_t nframes);
  45. static int _bufferSizeCallback(jack_nframes_t nframes, void *arg);
  46. static void _errorCallback(const char *msg);
  47. static void _infoCallback(const char *msg);
  48. static int _xrunCallback(void *arg);
  49. private:
  50. bool connectServer(std::string server);
  51. bool connectJack();
  52. void disconnectJack();
  53. bool openAudio();
  54. void stopAudio();
  55. bool processAudio(jack_nframes_t nframes);
  56. bool openMidi();
  57. void stopMidi();
  58. jack_client_t *jackClient;
  59. struct audio {
  60. unsigned int jackSamplerate;
  61. unsigned int jackNframes;
  62. jack_port_t *ports[2];
  63. jsample_t *portBuffs[2];
  64. } audio;
  65. struct osc {
  66. jack_port_t *oscport;
  67. } osc;
  68. struct midi {
  69. jack_port_t *inport;
  70. bool jack_sync;
  71. } midi;
  72. void handleMidi(unsigned long frames);
  73. };
  74. #endif