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.

122 lines
3.0KB

  1. /*
  2. Copyright (C) 2010 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. #include "JackEngineControl.h"
  16. #include "JackFrameTimer.h"
  17. #include "JackGlobals.h"
  18. #include "JackMidiUtil.h"
  19. #include "JackTime.h"
  20. jack_midi_data_t
  21. Jack::ApplyRunningStatus(size_t *size, jack_midi_data_t **buffer,
  22. jack_midi_data_t running_status)
  23. {
  24. // Stolen and modified from alsa/midi_pack.h
  25. jack_midi_data_t status = **buffer;
  26. if ((status >= 0x80) && (status < 0xf0)) {
  27. if (status == running_status) {
  28. (*buffer)++;
  29. (*size)--;
  30. } else {
  31. running_status = status;
  32. }
  33. } else if (status < 0xf8) {
  34. running_status = 0;
  35. }
  36. return running_status;
  37. }
  38. jack_midi_data_t
  39. Jack::ApplyRunningStatus(jack_midi_event_t *event,
  40. jack_midi_data_t running_status)
  41. {
  42. return ApplyRunningStatus(&(event->size), &(event->buffer),
  43. running_status);
  44. }
  45. jack_nframes_t
  46. Jack::GetCurrentFrame()
  47. {
  48. jack_time_t time = GetMicroSeconds();
  49. JackEngineControl *control = GetEngineControl();
  50. JackTimer timer;
  51. control->ReadFrameTime(&timer);
  52. return timer.Time2Frames(time, control->fBufferSize);
  53. }
  54. jack_nframes_t
  55. Jack::GetFramesFromTime(jack_time_t time)
  56. {
  57. JackEngineControl* control = GetEngineControl();
  58. JackTimer timer;
  59. control->ReadFrameTime(&timer);
  60. return timer.Time2Frames(time, control->fBufferSize);
  61. }
  62. jack_nframes_t
  63. Jack::GetLastFrame()
  64. {
  65. return GetEngineControl()->fFrameTimer.ReadCurrentState()->CurFrame();
  66. }
  67. int
  68. Jack::GetMessageLength(jack_midi_data_t status_byte)
  69. {
  70. switch (status_byte & 0xf0) {
  71. case 0x80:
  72. case 0x90:
  73. case 0xa0:
  74. case 0xb0:
  75. case 0xe0:
  76. return 3;
  77. case 0xc0:
  78. case 0xd0:
  79. return 2;
  80. case 0xf0:
  81. switch (status_byte) {
  82. case 0xf0:
  83. return 0;
  84. case 0xf1:
  85. case 0xf3:
  86. return 2;
  87. case 0xf2:
  88. return 3;
  89. case 0xf4:
  90. case 0xf5:
  91. case 0xf7:
  92. case 0xfd:
  93. break;
  94. default:
  95. return 1;
  96. }
  97. }
  98. return -1;
  99. }
  100. jack_time_t
  101. Jack::GetTimeFromFrames(jack_nframes_t frames)
  102. {
  103. JackEngineControl* control = GetEngineControl();
  104. JackTimer timer;
  105. control->ReadFrameTime(&timer);
  106. return timer.Frames2Time(frames, control->fBufferSize);
  107. }