Solved

MidiStreams - how to use?

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 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