using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Soundmusic
{
staticclassEqualz
{
staticint Vol = 5;
staticint Bas = 5;
staticint treb = 5;
publicstaticint Volume
{
get
{
return Vol;
}
set
{
if (value>= 0 || value<= 10)
Vol = value;
}
}
publicstaticint Bass
{
get
{
return Bas;
}
set
{
if (value>= 0 || value<= 10)
Bas = value;
}
}
publicstaticint Treble
{
get
{
return treb;
}
set
{
treb = value;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Soundmusic
{
classCD
{
string artist;
string[] song = newstring[3];
int[] durn = newint[3];
publicstring Artist
{
get
{
return artist;
}
privateset
{
artist = value;
}
}
publicstring getSong(int i)
{
if (i >= 0 && i < song.Length)
return song[i];
else
return"";
}
publicint getDuration(int i)
{
if (i >= 0 && i < durn.Length)
return durn[i];
else
return 0;
}
publicint totalSong()
{
return song.Length;
}
public CD(string artist, string song1, int dur1, string song2, int dur2, string song3, int dur3)
{
Artist = artist;
song[0] = song1;
song[1] = song2;
song[2] = song3;
durn[0] = dur1;
durn[1] = dur2;
durn[2] = dur3;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Soundmusic
{
structChannel
{
string name, chan;
public Channel(string name, string chan)
{
this.name = name;
this.chan = chan;
}
publicstring Name
{
get
{
return name;
}
set
{
name = value;
}
}
publicstring Channl
{
get
{
return chan;
}
set
{
chan = value;
}
}
}
publicpartialclassRadio : Form
{
double lowLimit = 88.0;
double hiLimit = 108.9;
double freq;
List<Channel> channelList = newList<Channel>();
Channel DJFM = newChannel("DJ FM", "94.8");
Channel Istara = newChannel("Istara", "101.1");
Channel Prambors = newChannel("Prambors", "89.3");
Channel EBS = newChannel("EBS", "105.9");
Channel Trijaya = newChannel("Trijaya", "104.7");
Channel MRadio = newChannel("M-Radio", "98.8");
privatevoid AddChan()
{
channelList.Add(DJFM);
channelList.Add(Istara);
channelList.Add(Prambors);
channelList.Add(EBS);
channelList.Add(Trijaya);
channelList.Add(MRadio);
}
privatevoid CheckChannel()
{
channelName.Text = "";
foreach (Channel ch in channelList)
{
if (freqBox.Text == ch.Channl)
{
channelName.Text = ch.Name;
break;
}
}
}
public Radio()
{
InitializeComponent();
freq = lowLimit;
freqBox.Text = freq.ToString("##.##");
AddChan();
}
privatevoid radioNext_Click(object sender, EventArgs e)
{
if (freq < hiLimit)
freq += 0.1;
else
freq = lowLimit;
freqBox.Text = freq.ToString("##.##");
}
privatevoid freqBox_Leave(object sender, EventArgs e)
{
if (double.Parse(freqBox.Text) > hiLimit || double.Parse(freqBox.Text) < lowLimit)
{
MessageBox.Show("Frequency exceeds the limit","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
freqBox.Text = freq.ToString("##.##");
}
freq = double.Parse(freqBox.Text);
}
privatevoid radioPrev_Click(object sender, EventArgs e)
{
if (freq > lowLimit)
freq -= 0.1;
else
freq = hiLimit;
freqBox.Text = freq.ToString("##.##");
}
privatevoid Radio_Load(object sender, EventArgs e)
{
volBar.Value = Equalz.Volume;
}
privatevoid volBar_Scroll(object sender, EventArgs e)
{
Equalz.Volume = volBar.Value;
}
privatevoid freqBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
if (double.Parse(freqBox.Text) > hiLimit || double.Parse(freqBox.Text) < lowLimit)
{
MessageBox.Show("Frequency exceeds the limit", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
freqBox.Text = freq.ToString("##.##");
}
freq = double.Parse(freqBox.Text);
}
}
privatevoid freqBox_TextChanged(object sender, EventArgs e)
{
CheckChannel();
}
privatevoid autoNext_Click(object sender, EventArgs e)
{
channelName.Text = "";
while (channelName.Text == ""&& freq < hiLimit)
{
freq += 0.1;
freqBox.Text = freq.ToString("##.##");
}
}
privatevoid autoPrev_Click(object sender, EventArgs e)
{
channelName.Text = "";
while (channelName.Text == ""&& freq > lowLimit)
{
freq -= 0.1;
freqBox.Text = freq.ToString("##.##");
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Soundmusic
{
publicpartialclassMusicPlayer : Form
{
CD myCD = newCD("Peterpan", "Satu Bintang", 180000, "Topeng", 210000, "Tak Ada yang Abadi", 240000);
int counter = 0;
bool isPlay = false;
bool isRecord = false;
int dur = 0;
int MaxTimeRec = 300000;
public MusicPlayer()
{
InitializeComponent();
}
private void MusicPlayer_Load(object sender, EventArgs e)
{
volBar.Value = Equalz.Volume;
bassBar.Value = Equalz.Bass;
trebleBar.Value = Equalz.Treble;
setSong(counter);
myTimer.Stop();
isPlay = false;
isRecord = false;
PlayPauseButton.Text = "Play";
recordButton.Text = "Rec";
}
private string ConvertToTime(int i)
{
int min = i / 60000;
int sec = (i - (min * 60000)) / 1000;
string time = min.ToString() + ":" + sec.ToString();
if (sec == 0)
time += "0";
if (sec<10)
{
time = min.ToString() + ":0" + sec.ToString();
}
return time;
}
private void setSong(int i)
{
ArtNamelabel.Text = myCD.Artist;
songLabel.Text = myCD.getSong(i);
durationPlayBar.Maximum = myCD.getDuration(i) / myTimer.Interval;
endTimeLabel.Text = ConvertToTime(myCD.getDuration(i));
durationPlayBar.Value = 0;
dur = 0;
startTimeLabel.Text = "0:00";
}
private void volBar_Scroll(object sender, EventArgs e)
{
Equalz.Volume = volBar.Value;
}
private void bassBar_Scroll(object sender, EventArgs e)
{
Equalz.Bass = bassBar.Value;
}
private void trebleBar_Scroll(object sender, EventArgs e)
{
Equalz.Treble = trebleBar.Value;
}
private void nextSongButton_Click(object sender, EventArgs e)
{
myTimer.Stop();
if (counter < myCD.totalSong() - 1)
{
setSong(++counter);
}
myTimer.Start();
}
privatevoid prevSongButton_Click(object sender, EventArgs e)
{
myTimer.Stop();
if (counter > 0)
{
setSong(--counter);
}
myTimer.Start();
}
private void myTimer_Tick(object sender, EventArgs e)
{
if (durationPlayBar.Value < durationPlayBar.Maximum)
durationPlayBar.Value += 1;
else
{
myTimer.Stop();
return;
}
dur += 1000;
startTimeLabel.Text = ConvertToTime(dur);
}
private void PlayPauseButton_Click(object sender, EventArgs e)
{
if (!isPlay)
{
PlayPauseButton.Text = "Pause";
myTimer.Start();
isPlay = true;
recordButton.Enabled = false;
}
else
{
PlayPauseButton.Text = "Play";
myTimer.Stop();
isPlay = false;
recordButton.Enabled = true;
}
}
private void stopButton_Click(object sender, EventArgs e)
{
myTimer.Stop();
setSong(counter);
PlayPauseButton.Text = "Play";
isPlay = false;
recordButton.Enabled = true;
}
private void MusicPlayer_Leave(object sender, EventArgs e)
{
myTimer.Stop();
}
private void durationPlayBar_Scroll(object sender, EventArgs e)
{
startTimeLabel.Text = ConvertToTime(durationPlayBar.Value * 1000);
dur = durationPlayBar.Value * 1000;
}
public void recording()
{
nextSongButton.Enabled = !nextSongButton.Enabled;
prevSongButton.Enabled = !prevSongButton.Enabled;
stopButton.Enabled = !stopButton.Enabled;
PlayPauseButton.Enabled = !PlayPauseButton.Enabled;
artPoint.Visible = !artPoint.Visible;
songPoint.Visible = !songPoint.Visible;
ArtNamelabel.Visible = !ArtNamelabel.Visible;
}
private void recordButton_Click(object sender, EventArgs e)
{
if (!isRecord)
{
songLabel.Text = "Recording.........";
recordButton.Text = "End";
recording();
myTimer.Start();
isRecord = true;
durationPlayBar.Maximum = MaxTimeRec / myTimer.Interval;
endTimeLabel.Text = ConvertToTime(MaxTimeRec);
durationPlayBar.Value = 0;
dur = 0;
startTimeLabel.Text = "0:00";
}
else
{
recordButton.Text = "Rec";
recording();
myTimer.Stop();
isRecord = false;
myTimer.Stop();
setSong(counter);
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Soundmusic
{
publicpartialclassHome : Form
{
public Home()
{
InitializeComponent();
}
Radio myRad = newRadio();
privatevoid goToRadio_Click(object sender, EventArgs e)
{
myRad.ShowDialog();
}
MusicPlayer myMP = newMusicPlayer();
privatevoid goToMusicPlayer_Click(object sender, EventArgs e)
{
myMP.ShowDialog();
}