「midiの再生」
midiの再生
回答
ソース
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, midpipC1, midpipe1, StdCtrls,MMSystem;
type
TForm1 = class(TForm)
gMpdMidiOut1: TgMpdMidiOut;
Button1: TButton;
Button2: TButton;
gMpOutPortCombo1: TgMpOutPortCombo;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private 宣言 }
public
{ Public 宣言 }
end;
var
Form1: TForm1;
mciError: LongInt; //MCIの返り値
MusicName: String; //演奏ファイル名 openの前に名前を入れておきます。
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
MusicName:=''''+ExtractFilePath(Application.ExeName)+ 'flourish.mid'+'''';
//showmessage(MusicName);
MusicName:='c:\flourish.mid';
//演奏方法
//open命令でファイルを開いて、play命令で演奏を開始します。
//mciError := mciSendString(PChar('open ' + MusicName + ' type sequencer alias midifile'), nil, 0, 0);
mciError := mciSendString(PChar('open ' + MusicName + ' alias FILE'), '', 0, 0);
mciError := mciSendString(PChar('play FILE'), nil, 0, 0);
//命令に成功するとmciErrorに0が入ります。失敗するとエラーコードを返します。
showmessage(inttostr(mciError));
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//演奏を止める
//stop命令で演奏を止めて、close命令でファイルを閉じます。
mciSendString(PChar('stop FILE'), '', 0, 0);
mciSendString(PChar('close FILE'), '', 0, 0);
end;
end.