Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

MidiStreams - how to use?

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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