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.

JackEngine.h 2.4KB

10 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. JackEngine.h
  3. Copyright 2009, Alan Calvert
  4. This file is part of yoshimi, which is free software: you can
  5. redistribute it and/or modify it under the terms of the GNU General
  6. Public License as published by the Free Software Foundation, either
  7. version 3 of the License, or (at your option) any later version.
  8. yoshimi is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with yoshimi. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef JACK_ENGINE_H
  16. #define JACK_ENGINE_H
  17. #include <string>
  18. #include <pthread.h>
  19. #include <semaphore.h>
  20. #include <jack/jack.h>
  21. #include <pthread.h>
  22. #include "MidiIn.h"
  23. #include "AudioOut.h"
  24. typedef jack_default_audio_sample_t jsample_t;
  25. class JackEngine:public AudioOut, MidiIn
  26. {
  27. public:
  28. JackEngine();
  29. ~JackEngine() { }
  30. bool Start();
  31. void Stop();
  32. void setMidiEn(bool nval);
  33. bool getMidiEn() const;
  34. void setAudioEn(bool nval);
  35. bool getAudioEn() const;
  36. int getBuffersize() { return audio.jackNframes; }
  37. std::string clientName();
  38. int clientId();
  39. protected:
  40. int processCallback(jack_nframes_t nframes);
  41. static int _processCallback(jack_nframes_t nframes, void *arg);
  42. int bufferSizeCallback(jack_nframes_t nframes);
  43. static int _bufferSizeCallback(jack_nframes_t nframes, void *arg);
  44. static void _errorCallback(const char *msg);
  45. static void _infoCallback(const char *msg);
  46. static int _xrunCallback(void *arg);
  47. private:
  48. bool connectServer(std::string server);
  49. bool connectJack();
  50. void disconnectJack();
  51. bool openAudio();
  52. void stopAudio();
  53. bool processAudio(jack_nframes_t nframes);
  54. bool openMidi();
  55. void stopMidi();
  56. jack_client_t *jackClient;
  57. struct audio {
  58. unsigned int jackSamplerate;
  59. unsigned int jackNframes;
  60. jack_port_t *ports[2];
  61. jsample_t *portBuffs[2];
  62. } audio;
  63. struct midi {
  64. jack_port_t *inport;
  65. bool jack_sync;
  66. } midi;
  67. void handleMidi(unsigned long frames);
  68. };
  69. #endif