jackaudio.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. This file is part of QTau
  3. Copyright (C) 2013-2018 Tobias "Tomoko" Platen <tplaten@posteo.de>
  4. Copyright (C) 2013 digited <https://github.com/digited>
  5. Copyright (C) 2010-2013 HAL@ShurabaP <https://github.com/haruneko>
  6. QTau is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. SPDX-License-Identifier: GPL-3.0+
  17. */
  18. #ifndef JACKCONNECTOR_H
  19. #define JACKCONNECTOR_H
  20. #include <jack/jack.h>
  21. #include <jack/ringbuffer.h>
  22. #include "Utils.h"
  23. typedef jack_default_audio_sample_t sample_t;
  24. #define TRANSPORT_NONE 0
  25. #define TRANSPORT_START 1
  26. #define TRANSPORT_STOP 2
  27. #define TRANSPORT_ZERO 3
  28. #define TRANSPORT_STARTPOS 4
  29. class JackAudio
  30. {
  31. jack_client_t* _client=nullptr;
  32. jack_port_t* _write_port=nullptr;
  33. jack_ringbuffer_t* _write_rb=nullptr;
  34. jack_ringbuffer_t* _control_rb=nullptr;
  35. jack_port_t* _midi_port=nullptr;
  36. jack_ringbuffer_t* _midi_rb=nullptr;
  37. bool _playback=false;
  38. jack_transport_state_t _transport_state;
  39. jack_transport_state_t _previous_transport_state;
  40. volatile int _transport_command=0;
  41. int _buffer_size=0;
  42. bool _use_transport=0;
  43. bool _state_changed=0;
  44. int _position=0;
  45. int _eventfd=0;
  46. float _startpos=0;
  47. static int process (jack_nframes_t nframes, void *arg);
  48. static int sync(jack_transport_state_t state, jack_position_t *pos, void *arg);
  49. public:
  50. explicit JackAudio(bool autoconnect);
  51. void shutdown();
  52. int sampleRate();
  53. int writeData(void* famebuf,int bytes_per_frame);
  54. void changeTranportState(int command){_transport_command = command;}
  55. bool isRolling() {return _transport_state==JackTransportRolling;}
  56. void setUseTransport(bool use_transport){_use_transport=use_transport;}
  57. int getBufferSize() {return _buffer_size;}
  58. float* allocateBuffer();
  59. bool stateChanged(){bool retval= _state_changed;_state_changed=false;return retval;}
  60. int positionChange(){int retval= _position; _position=-1;return retval;}
  61. jack_transport_state_t transportState(){return _transport_state;}
  62. int createEFD();
  63. int getSamplerate(){return jack_get_sample_rate(_client);}
  64. int readMidiData(char* buffer,int maxlength);
  65. void transportStartPos(float startpos){_startpos=startpos;_transport_command=TRANSPORT_STARTPOS;}
  66. };
  67. #endif // JACKCONNECTOR_H