Solved

MidiStreams - how to use?

Posted on 1997-03-12
2
910 Views
Last Modified: 2012-05-04
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.
0
Comment
Question by:afanti
2 Comments
 
LVL 3

Accepted Solution

by:
sperling earned 50 total points
ID: 1334754
Can you use midiStreamOut when you're trying to send a shortmsg?

I'd suggest you created a real midi stream, and attempted to play it. This error might occur because midiStreamOut expects a stream of data, not just a single event.

To play 3C90, use midiOutShortMsg

Erik.
0
 

Expert Comment

by:Ben_iti
ID: 3173952
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
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now