/controls/midi/KOLMIDITYPE.PAS

http://github.com/rofl0r/KOL · Pascal · 102 lines · 58 code · 18 blank · 26 comment · 2 complexity · b2b3814d371629be92a893b57cfeac86 MD5 · raw file

  1. {
  2. Unit: KOLMidiType
  3. purpose: Midi Type definitions
  4. Author: KOL translation and > 64 sysex buffering: Thaddy de Koning
  5. Original Author: David Churcher
  6. Copyright: released to the public domain
  7. Remarks: Well known Great components.
  8. Do not confuse this with my project JEDI midi translation for KOL
  9. }
  10. { $Header: /MidiComp/MIDITYPE.PAS 2 10/06/97 7:33 Davec $ }
  11. { Written by David Churcher <dchurcher@cix.compulink.co.uk>,
  12. released to the public domain. }
  13. unit KOLMIDITYPE;
  14. interface
  15. uses Kol, windows,Messages, MMSystem, KolMidiDefs, KOlCircbuf;
  16. type
  17. {-------------------------------------------------------------------}
  18. { A MIDI input/output event }
  19. pMyMidiEvent =^TMyMidiEvent;
  20. TMyMidiEvent = object(Tobj)
  21. public
  22. MidiMessage: Byte; { MIDI message status byte }
  23. Data1: Byte; { MIDI message data 1 byte }
  24. Data2: Byte; { MIDI message data 2 byte }
  25. Time: DWORD; { Time in ms since midiInOpen }
  26. SysexLength: Word; { Length of sysex data (0 if none) }
  27. Sysex: PChar; { Pointer to sysex data buffer }
  28. destructor Destroy; virtual;//override; { Frees sysex data buffer if nec. }
  29. end;
  30. //PMyMidiEvent = ^TMyMidiEvent;
  31. {-------------------------------------------------------------------}
  32. { Encapsulates the MIDIHDR with its memory handle and sysex buffer }
  33. PMyMidiHdr = ^TMyMidiHdr;
  34. TMyMidiHdr = object(TObj)
  35. public
  36. hdrHandle: THandle;
  37. hdrPointer: PMIDIHDR;
  38. sysexHandle: THandle;
  39. sysexPointer: Pointer;
  40. //constructor Create(BufferSize: Word);
  41. destructor Destroy; virtual;
  42. end;
  43. function NewMidiHeader(BufferSize:Word):pMyMidiHdr;
  44. function NewMidiEvent:PMyMidiEvent;
  45. implementation
  46. {-------------------------------------------------------------------}
  47. { Free any sysex buffer associated with the event }
  48. destructor TMyMidiEvent.Destroy;
  49. begin
  50. if (Sysex <> Nil) then
  51. Freemem(Sysex, SysexLength);
  52. inherited Destroy;
  53. end;
  54. function NewMidiEvent:PMyMidiEvent;
  55. begin
  56. New(Result,Create);
  57. end;
  58. {-------------------------------------------------------------------}
  59. { Allocate memory for the sysex header and buffer }
  60. //constructor TMyMidiHdr.Create(BufferSize:Word);
  61. function NewMidiHeader(BufferSize:Word):pMyMidiHdr;
  62. begin
  63. //inherited Create;
  64. New(Result,Create);
  65. with Result^do
  66. begin
  67. if BufferSize > 0 then
  68. begin
  69. hdrPointer := GlobalSharedLockedAlloc(sizeof(TMIDIHDR), hdrHandle);
  70. sysexPointer := GlobalSharedLockedAlloc(BufferSize, sysexHandle);
  71. hdrPointer^.lpData := sysexPointer;
  72. hdrPointer^.dwBufferLength := BufferSize;
  73. end;
  74. end;
  75. end;
  76. {-------------------------------------------------------------------}
  77. destructor TMyMidiHdr.Destroy;
  78. begin
  79. GlobalSharedLockedFree( hdrHandle, hdrPointer );
  80. GlobalSharedLockedFree( sysexHandle, sysexPointer );
  81. inherited Destroy;
  82. end;
  83. end.