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.

87 lines
2.2KB

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