I use the following code in my project to play midi note on key press (this is midi-related part of source):
uses
MMSystem;
var
hMidi, midimsg, notenum, instrumNum :integer;
procedure TForm1.FormCreate(Sender: TObject);
begin
midiOutOpen(@hmidi, 0, 0, 0, 0);
midimsg := $C0+$100*29; // set midi instrument to overdriven guitar (29th in GM midi instrument list)
midiOutShortMsg (hmidi, midimsg);
end;
procedure playNote(var note:integer);
begin
midimsg := $90 + (note * $100) + (127 * $10000) + 0;
midiOutShortMsg (hmidi, midimsg);
end;
procedure stopNote(var note:integer);
begin
midimsg := $80 + (note * $100) + 0 ;
midiOutShortMsg (hmidi, midimsg);
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
playNote(60);
end;
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
stopNote(60);
end;
procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
midiOutClose(hmidi);
end;
I know that there are midi messages to change the pitch and volume. But I could not find any examples of their usage in delphi.
Please, help me to modify the playNote procedure to make sound similar to guitar bend effect (smooth pitch shift of played note on semitone or whole tone up) and similarly to change the volume of note (fade-in and fade-out effect).
Thank you in advance!
I found a solution.
Drop a
TProgressBaron the form, and set itsMinandMaxto0and16383, respectively.Then you can ‘bend’ the pitch by scrolling your mouse wheel. (Notice that the factor 4 I use when handling the mouse wheel might be unsuitable for your mouse and your current mouse settings.)
Sample: pitchbend.exe [I removed the EXE file from my website because Google Chrome considered it to be a malware. Although this was almost certainly a false positive, I was afraid that it would have a negative effect on my Google rankings.]