PERCOBAAN 8
MEMBUAT SIMULASI PIANO
(Mengunakan Delphi XE8)
1. Tujuan. Agar Bintara Mahasiswa mampu membuat program simulasi piano.
2. Alat dan Bahan.
a. Laptop;
b. Aplikasi Delphi;
c. Sndplaysound;
d. Tool Button;
e. Tool Label;
f. Tool Shape.
3. Dasar Teori
a. Sndplaysound.
sndPlaySound pada Delphi adalah sebuah fungsi yang digunakan untuk memainkan file audio WAV. Fungsi ini diaktifkan dengan menggunakan unit mmsystem.
b. Tool Button.
Tool button pada Delphi adalah Palet Alat yang berisi daftar kategori item yang tersedia. Palet Alat dapat digunakan untuk: Membantu proyek baru, Menambahkan komponen ke formulir, Menambahkan cuplikan kode ke Editor Kode.
c. Tool Label.
Tool button pada Delphi adalah Palet Alat yang berisi daftar kategori item yang tersedia. Palet Alat dapat digunakan untuk: Membantu proyek baru, Menambahkan komponen ke formulir, Menambahkan cuplikan kode ke Editor Kode.
d. Tool Shape.
Tool Shape dalam Delphi adalah komponen grafis yang digunakan untuk menggambar bentuk-bentuk geometris pada aplikasi yang sedang dikembangkan. Komponen ini memungkinkan pengguna untuk menampilkan berbagai bentuk seperti persegi, lingkaran, dan segitiga, serta mengatur warna dan ukuran sesuai kebutuhan desain aplikasi.
4. Langkah Percobaan.
a. Flowchart;
b. Buat Coding untuk menjalankan simulasi piano. Berikut adalah contoh program sederhana:
3;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, MMsystem,
Vcl.Imaging.pngimage;
type
TForm3 = class(TForm)
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button13: TButton;
Button14: TButton;
Label1: TLabel;
Label2: TLabel;
Shape1: TShape;
Shape2: TShape;
Shape3: TShape;
Shape4: TShape;
Shape5: TShape;
Shape6: TShape;
Shape7: TShape;
Shape8: TShape;
Shape9: TShape;
Shape10: TShape;
Shape11: TShape;
Shape12: TShape;
Shape13: TShape;
Shape14: TShape;
Shape16: TShape;
Button1: TButton;
Edit1: TEdit;
Image1: TImage;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button14Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.Button10Click(Sender: TObject);
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\10.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=true;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
end;
procedure TForm3.Button11Click(Sender: TObject);
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\11.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=true;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
end;
procedure TForm3.Button12Click(Sender: TObject);
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\12.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=true;
shape13.Visible:=false;
shape14.Visible:=false;
end;
procedure TForm3.Button13Click(Sender: TObject);
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\13.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=true;
shape14.Visible:=false;
end;
procedure TForm3.Button14Click(Sender: TObject);
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\14.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=true;
end;
procedure TForm3.Button1Click(Sender: TObject);
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\1.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=true;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
end;
procedure TForm3.Button2Click(Sender: TObject);
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\2.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=true;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
end;
procedure TForm3.Button3Click(Sender: TObject);
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\3.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=true;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
end;
procedure TForm3.Button4Click(Sender: TObject);
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\4.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=true;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
end;
procedure TForm3.Button5Click(Sender: TObject);
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\5.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=true;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
end;
procedure TForm3.Button6Click(Sender: TObject);
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\6.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=true;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
end;
procedure TForm3.Button7Click(Sender: TObject);
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\7.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=true;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
end;
procedure TForm3.Button8Click(Sender: TObject);
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\8.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=true;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
end;
procedure TForm3.Button9Click(Sender: TObject);
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\9.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=true;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
end;
procedure TForm3.Edit1Change(Sender: TObject);
begin
if Edit1.Text='1' then
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\1.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=true;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
Edit1.Text:=''
end;
if Edit1.Text='2' then
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\2.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=true;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
Edit1.Text:=''
end;
if Edit1.Text='3' then
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\3.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=true;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
Edit1.Text:=''
end;
if Edit1.Text='4' then
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\4.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=true;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
Edit1.Text:=''
end;
if Edit1.Text='5' then
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\5.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=true;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
Edit1.Text:=''
end;
if Edit1.Text='6' then
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\6.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=true;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
Edit1.Text:=''
end;
if Edit1.Text='7' then
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\7.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=true;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
Edit1.Text:=''
end;
if Edit1.Text='8' then
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\8.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=true;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
Edit1.Text:=''
end;
if Edit1.Text='9' then
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\9.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=true;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
Edit1.Text:=''
end;
if Edit1.Text='0' then
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\10.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=true;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
Edit1.Text:=''
end;
if Edit1.Text='q' then
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\11.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=true;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=false;
Edit1.Text:=''
end;
if Edit1.Text='w' then
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\12.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=true;
shape13.Visible:=false;
shape14.Visible:=false;
Edit1.Text:=''
end;
if Edit1.Text='e' then
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\13.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=true;
shape14.Visible:=false;
Edit1.Text:=''
end;
if Edit1.Text='r' then
begin
sndPlaysound('E:\AA EGI\PERCOBAAN 8\NADA 2\14.wav',SND_NODEFAULT OR SND_ASYNC);
shape1.Visible:=false;
shape2.Visible:=false;
shape3.Visible:=false;
shape4.Visible:=false;
shape5.Visible:=false;
shape6.Visible:=false;
shape7.Visible:=false;
shape8.Visible:=false;
shape9.Visible:=false;
shape10.Visible:=false;
shape11.Visible:=false;
shape12.Visible:=false;
shape13.Visible:=false;
shape14.Visible:=true;
Edit1.Text:=''
end;
end;
end.
5. Hasil dan Pembahasan
a. Hasil Video.
1) Tampilan Awal.
2) Tampilan Video.
b. Pembahasan.
Pada percobaan Delphi kali ini, kita memanfaatkan untuk membuat simulasi piano. Tool yang digunakan dalam percobaan kali ini adalah Button, Label, Shape dan sndplaysound. Percobaan kali ini menggabungkan sistem kerja antara berbagai tool sehingga menghasilkan aplikasi simulator yang dapat digunakan untuk mengeluarkan suara notasi piano.
Sistem kerja aplikasi ini, pada saat form dirun maka akan muncul tampilan piano. Apabila kita menekan button 1 atau Do atau tombol lain secara bergantian, maka akan keluar suara dari piano tersebut. Kemudian pada percobaan ini juga terdapat tool baru itu sndplaySound. Fitur ini digunakan untuk penginputan sound yang berjenis file .wav.
6. Kesimpulan.
Membuat aplikasi piano menggunakan Delphi XE8 merupakan proyek yang menarik dan bermanfaat bagi pengembangan keterampilan pemrograman serta pemahaman tentang audio digital. Dalam proyek ini, kita telah melalui beberapa langkah penting, mulai dari merancang antarmuka pengguna yang intuitif hingga mengimplementasikan fungsi suara yang realistis.
Melalui penggunaan komponen visual dan audio di Delphi XE8, kita dapat menciptakan pengalaman bermain piano yang responsif dan menyenangkan. Proses ini tidak hanya meningkatkan pemahaman teknis mengenai pemrograman berbasis objek, tetapi juga membuka wawasan tentang pengolahan sinyal audio.
Dengan berhasil menyelesaikan proyek ini, pengguna dapat belajar mengenai:
- Desain Antarmuka: Mendesain layout yang menarik dan mudah digunakan.
- Pemrograman Audio: Menggunakan library audio untuk memainkan suara dengan kualitas tinggi.
- Interaktivitas: Mengimplementasikan responsifitas terhadap input pengguna untuk pengalaman yang lebih interaktif.
Proyek ini juga memberikan dasar yang kuat untuk pengembangan aplikasi musik lainnya di masa depan. Dengan pemahaman yang didapat dari pembuatan piano ini, pengembang dapat bereksperimen lebih lanjut dengan fitur-fitur lanjutan, seperti perekaman suara, efek audio, atau integrasi dengan perangkat musik lainnya.
Secara keseluruhan, menciptakan piano dengan Delphi XE8 bukan hanya sekadar tugas teknis, tetapi juga perjalanan kreatif yang dapat menginspirasi pengembang untuk terus berinovasi dalam dunia musik dan teknologi.
7. Daftar Pustaka.


