jack2 codebase
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.

119 lines
3.6KB

  1. /*
  2. Copyright (C) 2009 Devin Anderson
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #ifndef __JackPhysicalMidiOutput__
  16. #define __JackPhysicalMidiOutput__
  17. #include "JackMidiPort.h"
  18. #include "ringbuffer.h"
  19. namespace Jack {
  20. class JackPhysicalMidiOutput {
  21. private:
  22. jack_midi_data_t
  23. ApplyRunningStatus(jack_midi_data_t **, size_t *);
  24. jack_ringbuffer_t *output_ring;
  25. JackMidiBuffer *port_buffer;
  26. jack_ringbuffer_t *rt_output_ring;
  27. jack_midi_data_t running_status;
  28. protected:
  29. /**
  30. * Override to specify the next frame at which a midi byte can be sent.
  31. * The returned frame must be greater than or equal to the frame
  32. * argument. The default returns the frame passed to it.
  33. */
  34. virtual jack_nframes_t
  35. Advance(jack_nframes_t);
  36. /**
  37. * Override to customize how to react when a MIDI event can't be
  38. * buffered and can't be sent immediately. The default calls
  39. * 'jack_error' and specifies the number of bytes lost.
  40. */
  41. virtual void
  42. HandleEventLoss(JackMidiEvent *);
  43. /**
  44. * This method *must* be overridden to specify what happens when a MIDI
  45. * byte is sent at the specfied frame. The frame argument specifies
  46. * the frame at which the MIDI byte should be sent, and the second
  47. * argument specifies the byte itself. The return value is the next
  48. * frame at which a MIDI byte can be sent, and must be greater than or
  49. * equal to the frame argument.
  50. */
  51. virtual jack_nframes_t
  52. Send(jack_nframes_t, jack_midi_data_t) = 0;
  53. /**
  54. * Override to optimize behavior when sending MIDI data that's in the
  55. * ringbuffer. The first frame argument is the current frame, and the
  56. * second frame argument is the boundary frame. The function returns
  57. * the next frame at which MIDI data can be sent, regardless of whether
  58. * or not the boundary is reached. The default implementation calls
  59. * 'Send' with each byte in the ringbuffer until either the ringbuffer
  60. * is empty, or a frame beyond the boundary frame is returned by
  61. * 'Send'.
  62. */
  63. virtual jack_nframes_t
  64. SendBufferedData(jack_ringbuffer_t *, jack_nframes_t, jack_nframes_t);
  65. public:
  66. /**
  67. * The non-realtime buffer size and the realtime buffer size are both
  68. * optional arguments.
  69. */
  70. JackPhysicalMidiOutput(size_t non_rt_buffer_size=1024,
  71. size_t rt_buffer_size=64);
  72. virtual ~JackPhysicalMidiOutput();
  73. /**
  74. * Called to process MIDI data during a period.
  75. */
  76. void
  77. Process(jack_nframes_t);
  78. /**
  79. * Set the MIDI buffer that will contain the outgoing MIDI messages.
  80. */
  81. inline void
  82. SetPortBuffer(JackMidiBuffer *port_buffer)
  83. {
  84. this->port_buffer = port_buffer;
  85. }
  86. };
  87. }
  88. #endif