Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
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.

239 lines
5.7KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #pragma once
  19. #include "common.h"
  20. /* raw MIDI event + timestamp */
  21. class midievent
  22. {
  23. public:
  24. class sysex {
  25. size_t _size, _alloc;
  26. byte_t *_data;
  27. public:
  28. sysex ( void );
  29. ~sysex ( void );
  30. void append ( byte_t *data, size_t size );
  31. const byte_t * data ( void ) const;
  32. long size ( void ) const;
  33. };
  34. private:
  35. sysex *_sysex;
  36. tick_t _timestamp; /* in ticks */
  37. struct {
  38. byte_t status, /* full status byte */
  39. lsb, /* data 1 */
  40. msb; /* data 2 */
  41. } _data;
  42. public:
  43. static inline int
  44. event_size ( byte_t op )
  45. {
  46. switch ( op )
  47. {
  48. case NOTE_ON: case NOTE_OFF: case AFTERTOUCH:
  49. case CONTROL_CHANGE: case PITCH_WHEEL:
  50. return 3;
  51. case PROGRAM_CHANGE: case CHANNEL_PRESSURE:
  52. return 2;
  53. default:
  54. return 1;
  55. }
  56. };
  57. /* define MIDI status bytes */
  58. enum {
  59. STATUS_BIT = 0x80,
  60. NOTE_OFF = 0x80,
  61. NOTE_ON = 0x90,
  62. AFTERTOUCH = 0xA0,
  63. CONTROL_CHANGE = 0xB0,
  64. PROGRAM_CHANGE = 0xC0,
  65. CHANNEL_PRESSURE = 0xD0,
  66. PITCH_WHEEL = 0xE0,
  67. CLEAR_CHAN_MASK = 0xF0,
  68. MIDI_CLOCK = 0xF8,
  69. SYSEX = 0xF0,
  70. SYSEX_END = 0xF7,
  71. META = 0xFF
  72. };
  73. midievent ( void );
  74. ~midievent ( void );
  75. tick_t timestamp ( void ) const;
  76. void timestamp ( tick_t time );
  77. void status ( byte_t status );
  78. byte_t status ( void ) const;
  79. void channel ( byte_t channel );
  80. byte_t channel ( void ) const;
  81. byte_t opcode ( void ) const;
  82. void opcode ( byte_t o );
  83. void lsb ( byte_t n );
  84. void msb ( byte_t n );
  85. int lsb ( void ) const;
  86. int msb ( void ) const;
  87. int pitch ( void ) const;
  88. void pitch ( int n );
  89. void data ( byte_t D1, byte_t D2 );
  90. void data ( byte_t *D1, byte_t *D2 ) const;
  91. void raw ( byte_t *p, int l) const;
  92. int size ( void ) const;
  93. void note_velocity ( int vel );
  94. bool is_note_on ( void ) const;
  95. bool is_note_off ( void ) const;
  96. virtual unsigned char note ( void ) const;
  97. virtual void note ( char note );
  98. unsigned char note_velocity ( void ) const;
  99. bool is_same_note ( midievent * e ) const;
  100. const char * name ( void ) const;
  101. int name ( const char *name ) const;
  102. void print ( void ) const;
  103. void pretty_print ( void ) const;
  104. bool operator< ( const midievent &rhs ) const;
  105. bool operator>= ( const midievent &rhs ) const;
  106. bool operator== ( const midievent &rhs ) const;
  107. };
  108. /**********************/
  109. /* Inlined accessors */
  110. /**********************/
  111. inline tick_t
  112. midievent::timestamp ( void ) const
  113. {
  114. return _timestamp;
  115. }
  116. inline void
  117. midievent::timestamp ( tick_t time )
  118. {
  119. _timestamp = time;
  120. }
  121. inline void
  122. midievent::status ( byte_t status )
  123. {
  124. _data.status = status;
  125. }
  126. inline byte_t
  127. midievent::status ( void ) const
  128. {
  129. return _data.status;
  130. }
  131. inline void
  132. midievent::channel ( byte_t channel )
  133. {
  134. _data.status = (_data.status & 0xF0) | (channel & 0x0F);
  135. }
  136. inline byte_t
  137. midievent::channel ( void ) const
  138. {
  139. return _data.status & 0x0F;
  140. }
  141. inline byte_t
  142. midievent::opcode ( void ) const
  143. {
  144. return _data.status & 0xF0;
  145. }
  146. inline void
  147. midievent::opcode ( byte_t opcode )
  148. {
  149. _data.status = (_data.status & 0x0F) | (opcode & 0xF0);
  150. }
  151. inline void
  152. midievent::lsb ( byte_t n )
  153. {
  154. _data.lsb = n & 0x7F;
  155. }
  156. inline void
  157. midievent::msb ( byte_t n )
  158. {
  159. _data.msb = n & 0x7F;
  160. }
  161. inline int
  162. midievent::lsb ( void ) const
  163. {
  164. return _data.lsb;
  165. }
  166. inline int
  167. midievent::msb ( void ) const
  168. {
  169. return _data.msb;
  170. }
  171. inline bool
  172. midievent::is_note_on ( void ) const
  173. {
  174. return (opcode() == NOTE_ON);
  175. }
  176. inline bool
  177. midievent::is_note_off ( void ) const
  178. {
  179. return (opcode() == NOTE_OFF);
  180. }
  181. inline unsigned char
  182. midievent::note ( void ) const
  183. {
  184. return _data.lsb;
  185. }
  186. inline bool
  187. midievent::operator< ( const midievent &rhs ) const
  188. {
  189. return _timestamp < rhs._timestamp;
  190. }
  191. inline bool
  192. midievent::operator>= ( const midievent &rhs ) const
  193. {
  194. return _timestamp >= rhs._timestamp;
  195. }