Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#3

AW: MIDI öffnen und zu Frequenz (hz) und Länge(ms) konvertieren

  Alt 13. Feb 2012, 17:56
Zitat:
Ich weiß irgendwie nicht, was du jetzt möchtest. Willst du
Er will ein fertiges programm um Midi abspielen zu können

Hier mal ne kleine Unit von mir auf mmsystem aufgebaut.

Delphi-Quellcode:
unit MidiPlayer;

interface

uses Windows, Messages, mmsystem, StrUtils, SysUtils, Dialogs;

type
  TKaraGLPlayer = class
  private
    { private-Deklarationen }
    MIDI_Device: Uint;
    command: PWideChar;
    return: array [0..50]of char;
    resultSize: Integer;
  protected
    { protected-Deklarationen }
  public
    { public-Deklarationen }
    duration: Integer;
    paused: Bool;
    function getPosition: Integer;
    procedure play;
    procedure pausePlay;
    procedure stop;
    constructor Create(fileName: string; autoplay: Bool);
    destructor Destroy;
  end;

implementation

{ TKaraGLPlayer }

constructor TKaraGLPlayer.Create(fileName: string; autoplay: Bool);
var
  lResult: cardinal;
begin

  //init variables
  paused := FALSE;
  MIDI_Device := 0;
  resultSize := 50;

   // We want to play a MIDI.
   command := PWideChar('open "' + fileName + '" type sequencer alias karagl wait');
  lResult := mciSendString(command, return, resultSize, 0);

   if lResult <> 0 then
  begin
    mciGetErrorString(lResult, return, 50);
    ShowMessage('MCI error:'  + return);
      duration := 0;
   end;

   // Calculate duration
   command := ('set karagl time format milliseconds wait');
   mciSendString(command, return, resultSize, 0);

   command := ('status karagl length wait');
   mciSendString(command, return, resultSize, 0);
   if (StrLen(return) > 0) then
      duration := StrToInt(return)
   else
  duration := 0;

   if autoplay then
      play;

end;

destructor TKaraGLPlayer.Destroy;
begin
   command := ('close karagl wait');
  mciSendString(command, return, resultSize, 0);

  MIDI_Device := 0;
end;

function TKaraGLPlayer.getPosition: Integer;
begin
   command := ('status karagl position wait');
   mciSendString(command, return, resultSize, 0);
  if (StrLen(return) > 0) then
       result := StrToInt(return)
    else
    result := 0;

end;

procedure TKaraGLPlayer.pausePlay;
begin
    paused := not paused;

    if paused then
    begin
       command := ('pause karagl notify');
      mciSendString(command, return, resultSize, 0);
    end else
    begin
       command := ('resume karagl notify');
      mciSendString(command, return, resultSize, 0);
    end;
end;

procedure TKaraGLPlayer.play;
begin
   command := ('play karagl notify');
   mciSendString(command, return, resultSize, 0);

end;

procedure TKaraGLPlayer.stop;
begin
   command := ('stop karagl notify');
  mciSendString(command, return, resultSize, 0);

end;

end.
Wenn's hilft..
Den Rest bitte selber machen.

PS:
Delphi-Quellcode:
var
fileName: string;
MusicPlayer: TKaraGLPlayer;
...
  OpenDialog1.Filter := 'Lyrics Dateien (*.kar;*.mid)|*.kar;*.mid';
  if OpenDialog1.Execute then
    fileName := OpenDialog1.FileName;

  MusicPlayer := TKaraGLPlayer.Create(fileName, true);
gruss

Geändert von EWeiss (13. Feb 2012 um 18:43 Uhr)
  Mit Zitat antworten Zitat