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.

238 lines
6.4KB

  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. /* this class represents a single raw MIDI event plus a timestamp */
  19. #pragma once
  20. #include "types.h"
  21. #include <stdlib.h>
  22. namespace MIDI
  23. {
  24. class midievent
  25. {
  26. public:
  27. class sysex {
  28. size_t _size, _alloc;
  29. byte_t *_data;
  30. public:
  31. sysex ( void );
  32. ~sysex ( void );
  33. void append ( byte_t *data, size_t size );
  34. const byte_t * data ( void ) const;
  35. long size ( void ) const;
  36. };
  37. private:
  38. sysex *_sysex;
  39. tick_t _timestamp; /* in ticks */
  40. struct {
  41. byte_t status, /* full status byte */
  42. lsb, /* data 1 */
  43. msb; /* data 2 */
  44. } _data;
  45. public:
  46. static inline int
  47. event_size ( byte_t op )
  48. {
  49. switch ( op )
  50. {
  51. case NOTE_ON: case NOTE_OFF: case AFTERTOUCH:
  52. case CONTROL_CHANGE: case PITCH_WHEEL:
  53. return 3;
  54. case PROGRAM_CHANGE: case CHANNEL_PRESSURE:
  55. return 2;
  56. default:
  57. return 1;
  58. }
  59. };
  60. /* define MIDI status bytes */
  61. enum {
  62. STATUS_BIT = 0x80,
  63. NOTE_OFF = 0x80,
  64. NOTE_ON = 0x90,
  65. AFTERTOUCH = 0xA0,
  66. CONTROL_CHANGE = 0xB0,
  67. PROGRAM_CHANGE = 0xC0,
  68. CHANNEL_PRESSURE = 0xD0,
  69. PITCH_WHEEL = 0xE0,
  70. CLEAR_CHAN_MASK = 0xF0,
  71. MIDI_CLOCK = 0xF8,
  72. SYSEX = 0xF0,
  73. SYSEX_END = 0xF7,
  74. META = 0xFF
  75. };
  76. midievent ( void );
  77. virtual ~midievent ( void );
  78. tick_t timestamp ( void ) const;
  79. void timestamp ( tick_t time );
  80. void status ( byte_t status );
  81. byte_t status ( void ) const;
  82. void channel ( byte_t channel );
  83. byte_t channel ( void ) const;
  84. byte_t opcode ( void ) const;
  85. void opcode ( byte_t o );
  86. void lsb ( byte_t n );
  87. void msb ( byte_t n );
  88. int lsb ( void ) const;
  89. int msb ( void ) const;
  90. int pitch ( void ) const;
  91. void pitch ( int n );
  92. void data ( byte_t D1, byte_t D2 );
  93. void data ( byte_t *D1, byte_t *D2 ) const;
  94. void raw ( byte_t *p, int l) const;
  95. int size ( void ) const;
  96. void note_velocity ( int vel );
  97. bool is_note_on ( void ) const;
  98. bool is_note_off ( void ) const;
  99. virtual unsigned char note ( void ) const;
  100. virtual void note ( char note );
  101. unsigned char note_velocity ( void ) const;
  102. bool is_same_note ( midievent * e ) const;
  103. const char * name ( void ) const;
  104. int name ( const char *name ) const;
  105. void print ( void ) const;
  106. void pretty_print ( void ) const;
  107. bool operator< ( const midievent &rhs ) const;
  108. bool operator>= ( const midievent &rhs ) const;
  109. bool operator== ( const midievent &rhs ) const;
  110. };
  111. /**********************/
  112. /* Inlined accessors */
  113. /**********************/
  114. inline tick_t
  115. midievent::timestamp ( void ) const
  116. {
  117. return _timestamp;
  118. }
  119. inline void
  120. midievent::timestamp ( tick_t time )
  121. {
  122. _timestamp = time;
  123. }
  124. inline void
  125. midievent::status ( byte_t status )
  126. {
  127. _data.status = status;
  128. }
  129. inline byte_t
  130. midievent::status ( void ) const
  131. {
  132. return _data.status;
  133. }
  134. inline void
  135. midievent::channel ( byte_t channel )
  136. {
  137. _data.status = (_data.status & 0xF0) | (channel & 0x0F);
  138. }
  139. inline byte_t
  140. midievent::channel ( void ) const
  141. {
  142. return _data.status & 0x0F;
  143. }
  144. inline byte_t
  145. midievent::opcode ( void ) const
  146. {
  147. return _data.status & 0xF0;
  148. }
  149. inline void
  150. midievent::opcode ( byte_t opcode )
  151. {
  152. _data.status = (_data.status & 0x0F) | (opcode & 0xF0);
  153. }
  154. inline void
  155. midievent::lsb ( byte_t n )
  156. {
  157. _data.lsb = n & 0x7F;
  158. }
  159. inline void
  160. midievent::msb ( byte_t n )
  161. {
  162. _data.msb = n & 0x7F;
  163. }
  164. inline int
  165. midievent::lsb ( void ) const
  166. {
  167. return _data.lsb;
  168. }
  169. inline int
  170. midievent::msb ( void ) const
  171. {
  172. return _data.msb;
  173. }
  174. inline bool
  175. midievent::is_note_on ( void ) const
  176. {
  177. return (opcode() == NOTE_ON);
  178. }
  179. inline bool
  180. midievent::is_note_off ( void ) const
  181. {
  182. return (opcode() == NOTE_OFF);
  183. }
  184. inline bool
  185. midievent::operator< ( const midievent &rhs ) const
  186. {
  187. return _timestamp < rhs._timestamp;
  188. }
  189. inline bool
  190. midievent::operator>= ( const midievent &rhs ) const
  191. {
  192. return _timestamp >= rhs._timestamp;
  193. }
  194. }