Solved

MidiStreams - how to use?

Posted on 1997-03-12
2
922 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 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

13 Experts available now in Live!

Get 1:1 Help Now