Link to home
Start Free TrialLog in
Avatar of afanti
afanti

asked on

MidiStreams - how to use?

OK, here's the question:

How can I get a MidiStream running?  More specifically, what's wrong with my call to midiStreamOut in the following program, and how can I fix it?

I'll gladly give 100 points for a solution.

Thanks,

Alex Fanti
University of Massachusetts


Source code follows:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses
  MMsystem;

var
  MidiStream_handle: HMIDISTRM;
  errorstr : array[1..254] of char;

procedure TForm1.Button1Click(Sender: TObject);
var
  MMResult : longint;
  pMidiStream_handle: PHMIDISTRM;
  DeviceID : UINT;
  pDeviceID : PUINT;
begin
  DeviceID := -1;  // midimapper
  pDeviceID := @DeviceID;
  pMidiStream_handle := @MidiStream_handle;
  MMResult := midiStreamOpen(pMidiStream_handle, pDeviceID, 1, 0, 0, 0);
  MMResult := midiOutGetErrorText(MMResult, @errorstr, Length(errorstr));
  label1.caption := errorstr; //inttostr(DeviceID);
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  MMResult : longint;
begin
  MMResult := midiStreamStop(MidiStream_handle);
  MMResult := midiOutGetErrorText(MMResult, @errorstr, Length(errorstr));
  label1.caption := errorstr; //inttostr(DeviceID);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  MMResult : longint;
begin
  MMResult := midiStreamClose(MidiStream_handle);
  MMResult := midiOutGetErrorText(MMResult, @errorstr, Length(errorstr));
  label1.caption := errorstr; //inttostr(DeviceID);
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  MMResult : longint;
  AnEvent : TMidiEvent;
  pAnEvent : PMidiEvent;
  MidiHeader : TMidiHdr;
  pMidiHeader : PMidiHdr;
begin

  AnEvent.dwDeltaTime := 30; // start at 30 milliseconds
  AnEvent.dwStreamID := 0;  // must be 0
  AnEvent.dwEvent := $3C90;  // play middle C on channel 1 of the midi device
  AnEvent.dwParms[0] := 0;
  pAnEvent := @AnEvent;

  MidiHeader.lpData:= @AnEvent;               { pointer to locked data block }
  MidiHeader.dwBufferLength:= SizeOf(AnEvent);       { length of data in data block }
  MidiHeader.dwFlags:= 0;                 { assorted flags (see defines) }

  pMidiHeader := @MidiHeader;
  MMResult := midiOutPrepareHeader(MidiStream_handle, pMidiHeader, SizeOf(MidiHeader));

//  Finally, here's the problem...
// The next call fails.  There's something wrong with the
//  MidiHdr, MidiEvent the  pointers, or something.
//    What do you think?

  MMResult := midiStreamOut(MidiStream_handle, pMidiHeader, SizeOf(MidiHeader));

  MMResult := midiOutGetErrorText(MMResult, @errorstr, Length(errorstr));
  label1.caption := errorstr; //inttostr(DeviceID);
end;

end.
ASKER CERTIFIED SOLUTION
Avatar of sperling
sperling

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ben_iti
Ben_iti

Hello there

So does that mean in order to send a stream of data through the midistreamout , you must first declare the values in MEVT_EVENTTYPE
then MEVT_EVENTPARM then continue with declaring the other values needed to create the MIDIEVENT structure
then from there I can use
the MidiStreamOut

MMResult := midiStreamOut(MidiStream_handle, pMidiHeader, SizeOf(MidiHeader));


then i should be able to stream midi data then if I want to have a continous buffer, I would then have to make my own circular buffer??

Am I right?
Please let me know

Ben