Recent

Author Topic: Plz help me with installing a component converted from Delphi  (Read 5502 times)

Garfunkel

  • New Member
  • *
  • Posts: 16
Plz help me with installing a component converted from Delphi
« on: September 26, 2015, 08:45:11 pm »
Please help me to install and properly use this package - MIDIGen. I converted it from Delphi package (see the attachment) and it installs ok (though i had to check 'Register' in the File Properties of MidiGen) but whenever I put the component on my project form lazarus exits with error... Please help!

derek.john.evans

  • Guest
Re: Plz help me with installing a component converted from Delphi
« Reply #1 on: September 27, 2015, 03:03:54 am »
AllocateHWnd() is not implemented in Lazarus.
Code: Pascal  [Select][+][-]
  1. function AllocateHWnd(Method: TWndMethod): HWND;
  2.   begin
  3.     { dummy }
  4.     runerror(217);
  5.     Result:=0;
  6.   end;  
  7.  

There is some code here on how to get windows messages in Lazarus. (ie: Hooking into the Windows messages)
http://wiki.lazarus.freepascal.org/Win32/64_Interface#Processing_non-user_messages_in_your_window
http://forum.lazarus.freepascal.org/index.php?topic=6062.0

That may solve your problems. But, there are more advanced MIDI components in the WinMIDI package.

Download this:
http://www.pilotlogic.com/codetyphon/current/src/typhon_src.7z

1) Copy out the folder "typhon_src.7z\typhon\components\pl_Win_MIDI\" to your components directory.
2) Open the package and compile/install.

Note: Im unsure were this library originated from, but the version is "03-05-2015 Ver 5.4.1"

Attached is a screen shot of the WinMIDI component tab.
« Last Edit: October 02, 2015, 02:59:59 am by Geepster »

Garfunkel

  • New Member
  • *
  • Posts: 16
Re: Plz help me with installing a component converted from Delphi
« Reply #2 on: September 27, 2015, 09:32:31 am »
AllocateHWnd() is not implemented in Lazarus.
Thanks a lot! I've never heard of WinMIDI component, I'll give it a go.

Garfunkel

  • New Member
  • *
  • Posts: 16
Re: Plz help me with installing a component converted from Delphi
« Reply #3 on: September 27, 2015, 11:34:51 am »
Unfortunately, WinMIDI does not have the functionality I need :( Particularily, PlayString (s:string) ; kind of procedure, where you can use it like this : PlayString('C4') and get the note C of 4th octave. So basically I need only one MIDI note output with controlled Velocity and Duration.

derek.john.evans

  • Guest
Re: Plz help me with installing a component converted from Delphi
« Reply #4 on: September 27, 2015, 01:37:27 pm »
Yep, you are right. I cant see a string to note function. But, it would look something like:
Code: Pascal  [Select][+][-]
  1. function StringToNote(AString: String): Integer;
  2. begin
  3.   AString := Trim(AString);
  4.   if Length(AString) = 0 then begin
  5.     AString := 'C';
  6.   end;
  7.   if Length(AString) = 1 then begin
  8.     AString += '4';
  9.   end;
  10.   case UpperCase(AString[1]) of
  11.     'C': begin
  12.       Result := 0;
  13.     end;
  14.     'D': begin
  15.       Result := 2;
  16.     end;
  17.     'E': begin
  18.       Result := 4;
  19.     end;
  20.     'F': begin
  21.       Result := 5;
  22.     end;
  23.     'G': begin
  24.       Result := 7;
  25.     end;
  26.     'A': begin
  27.       Result := 9;
  28.     end;
  29.     'B': begin
  30.       Result := 11;
  31.     end else begin
  32.       Result := 0;
  33.     end;
  34.   end;
  35.   if Pos('#', AString) > 0 then begin
  36.     Result += 1;
  37.   end;
  38.   Result := Result + (StrToInt(AString[Length(AString)]) + 1) * 12;
  39. end;  
  40.  

And then a simple play string function would be:
Code: Pascal  [Select][+][-]
  1. procedure MidiPlayString(const AMidi: TMidiOutputPort; const AString: String);
  2. var
  3.   LIndex, LNote: Integer;
  4. begin
  5.   with TStringList.Create do begin
  6.     try
  7.       CommaText := AString;
  8.       for LIndex := 0 to Count - 1 do begin
  9.         LNote := StringToNote(Strings[LIndex]);
  10.         AMidi.NoteOn(0, LNote, 127);
  11.         Sleep(200);
  12.         AMidi.NoteOff(0, LNote, 0);
  13.       end;
  14.     finally
  15.       Free;
  16.     end;
  17.   end;
  18. end;
  19.  

Testing code:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   MidiOutputPort1.PortId := -1;
  4.   MidiOutputPort1.Active := True;
  5. end;
  6.  
  7. procedure TForm1.Button1Click(Sender: TObject);
  8. begin
  9.   MidiPlayString(MidiOutputPort1, 'C4,D4,E4,F4,G4,A4,B4,C5,C#5');
  10. end;  
  11.  

« Last Edit: October 02, 2015, 02:59:25 am by Geepster »

Garfunkel

  • New Member
  • *
  • Posts: 16
Re: Plz help me with installing a component converted from Delphi
« Reply #5 on: September 27, 2015, 02:24:54 pm »
Yep, you are right. I cant see a string to note function. But, it would look something like:
It works! thanks  :)

Garfunkel

  • New Member
  • *
  • Posts: 16
Re: Plz help me with installing a component converted from Delphi
« Reply #6 on: June 09, 2017, 02:11:00 pm »
Hi all! Is there a way to use midi sounds in Linux? For example, I need to generate midi sounds (of certain pitch, velocity etc) and play it, not an external file but a dinamically created midi message. As i know mmsystem doesn't work with Linux so any workaround?

 

TinyPortal © 2005-2018