External plugins for 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.

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