Version 0.7 as marked by the folder name.
This commit is contained in:
+232
-99
@@ -18,67 +18,205 @@ namespace SoundBoard
|
||||
|
||||
public SoundPlayer player = new SoundPlayer();
|
||||
public Random randomNum = new Random();
|
||||
bool willLoopSound = false;
|
||||
public ListBox listBoxEntity = new ListBox();
|
||||
public string _workingDirectory;
|
||||
public string[] _soundFiles;
|
||||
public string[] _soundDirectories;
|
||||
public bool willLoopSound = false;
|
||||
|
||||
public formMain()
|
||||
{
|
||||
InitializeComponent();
|
||||
//create event handlers for onClick events in the ListBoxes
|
||||
gamerPoopListBox.MouseClick += new MouseEventHandler(soundListBox_OnLeftClick);
|
||||
asdfMovieListBox.MouseClick += new MouseEventHandler(soundListBox_OnLeftClick);
|
||||
}
|
||||
|
||||
private void soundListBox_OnLeftClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (soundboardTabControl.SelectedIndex == 0)
|
||||
{
|
||||
string fullPath = Path.GetFullPath("gamer_poop/") + gamerPoopListBox.SelectedItem + ".wav";
|
||||
player.SoundLocation = fullPath;
|
||||
player.Load();
|
||||
if (willLoopSound)
|
||||
{
|
||||
player.PlayLooping();
|
||||
}
|
||||
else
|
||||
{
|
||||
player.Play();
|
||||
}
|
||||
}
|
||||
else if (soundboardTabControl.SelectedIndex == 1)
|
||||
{
|
||||
string fullPath = Path.GetFullPath("asdfmovie/") + asdfMovieListBox.SelectedItem + ".wav";
|
||||
player.SoundLocation = fullPath;
|
||||
player.Load();
|
||||
if (willLoopSound)
|
||||
{
|
||||
player.PlayLooping();
|
||||
}
|
||||
else
|
||||
{
|
||||
player.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void formMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
string[] soundFiles;
|
||||
soundFiles = Directory.GetFiles(Path.GetFullPath("gamer_poop/"));
|
||||
foreach (string str in soundFiles)
|
||||
_workingDirectory = Path.GetDirectoryName(Application.ExecutablePath);
|
||||
_soundFiles = Directory.GetFiles(_workingDirectory);
|
||||
foreach (string sound in _soundFiles)
|
||||
{
|
||||
this.gamerPoopListBox.Items.Add(Path.GetFileNameWithoutExtension(str));
|
||||
CreateUITabs("Working Directory", _workingDirectory);
|
||||
}
|
||||
soundFiles = Directory.GetFiles(Path.GetFullPath("asdfmovie/"));
|
||||
foreach (string str in soundFiles)
|
||||
|
||||
_soundDirectories = Directory.GetDirectories(_workingDirectory);
|
||||
foreach (string sounds in _soundDirectories)
|
||||
{
|
||||
asdfMovieListBox.Items.Add(Path.GetFileNameWithoutExtension(str));
|
||||
CreateUITabs(Path.GetFileName(sounds), sounds);
|
||||
}
|
||||
fileSystemWatcherMain.Path = _workingDirectory;
|
||||
fileSystemWatcherMain.IncludeSubdirectories = true;
|
||||
fileSystemWatcherMain.Created += new FileSystemEventHandler(fileSystemUpdateDetected); //file or folder created
|
||||
fileSystemWatcherMain.Deleted += new FileSystemEventHandler(fileSystemUpdateDetected); //file or folder moved or deleted
|
||||
fileSystemWatcherMain.Renamed += new RenamedEventHandler(fileSystemUpdateDetected); //for any file changes like file extension changes
|
||||
soundboardTabControl.SelectedIndexChanged += new EventHandler(CheckForDisabledListBox); //disables ore enables the Show on Disk file menu object
|
||||
listBoxEntity = (ListBox)soundboardTabControl.SelectedTab.Controls[0];
|
||||
if (listBoxEntity.Enabled == true)
|
||||
{
|
||||
listBoxEntity.SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void fileSystemUpdateDetected(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
//perform the UI refresh operation
|
||||
RefreshUIControls();
|
||||
}
|
||||
|
||||
private void CheckForDisabledListBox(object sender, EventArgs e)
|
||||
{
|
||||
ListBox listBoxEntity = new ListBox();
|
||||
try
|
||||
{
|
||||
listBoxEntity = (ListBox)soundboardTabControl.SelectedTab.Controls[0];
|
||||
}
|
||||
catch (Exception spam)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (listBoxEntity.Enabled == false)
|
||||
{
|
||||
mainMenuFileShowOnDisk.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
listBoxEntity.SelectedIndex = 0;
|
||||
mainMenuFileShowOnDisk.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshUIControls()
|
||||
{
|
||||
_workingDirectory = Path.GetDirectoryName(Application.ExecutablePath);
|
||||
_soundDirectories = Directory.GetDirectories(_workingDirectory);
|
||||
|
||||
soundboardTabControl.Controls.Clear();
|
||||
|
||||
foreach (string sounds in _soundFiles)
|
||||
{
|
||||
CreateUITabs("Working Directory", _workingDirectory);
|
||||
}
|
||||
foreach (string files in _soundDirectories)
|
||||
{
|
||||
CreateUITabs(Path.GetFileName(files), files);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateUITabs(string tabName, string directoryPath)
|
||||
{
|
||||
//add tabs dynamically
|
||||
int soundControlHeight = soundboardTabControl.Height;
|
||||
int soundControlWidth = soundboardTabControl.Width;
|
||||
string[] directoryFiles; //files in the target directory
|
||||
TabPage tab = new TabPage();
|
||||
ListBox localListBox = new ListBox();
|
||||
|
||||
if (soundboardTabControl.Controls.ContainsKey(tabName.Replace(" ", "") + "Tab"))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
tab.Text = tabName; //display the folder's full name to the user
|
||||
tab.Name = tabName.Replace(" ", "") + "Tab"; //create a legal name for the tab's (name) property
|
||||
tab.Height = soundControlHeight - 20;
|
||||
tab.Height = soundControlWidth;
|
||||
soundboardTabControl.Controls.Add(tab);
|
||||
|
||||
localListBox.Height = soundControlHeight - 20;
|
||||
localListBox.Width = soundControlWidth - 7;
|
||||
localListBox.Name = tabName.Replace(" ", "") + "ListBox";
|
||||
tab.Controls.Add(localListBox);
|
||||
localListBox.Click += new EventHandler((sender, e) => ListBoxOnLeftClick(sender, e, localListBox)); //create event handler for the lsit box and pass the object in
|
||||
}
|
||||
|
||||
directoryFiles = Directory.GetFiles(Path.GetFullPath(directoryPath));
|
||||
|
||||
foreach (string files in directoryFiles)
|
||||
{
|
||||
switch (Path.GetExtension(files))//check to make sure the file is a sound file
|
||||
{
|
||||
case ".wav":
|
||||
case ".mp3":
|
||||
localListBox.Items.Add(Path.GetFileNameWithoutExtension(files));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (localListBox.Items.Count == 0)
|
||||
{
|
||||
localListBox.Items.Add("No sound files found in the " + tabName + " directory.");
|
||||
localListBox.Enabled = false;
|
||||
if (soundboardTabControl.SelectedIndex == 0)
|
||||
{
|
||||
mainMenuFileShowOnDisk.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ListBoxOnLeftClick(object sender, EventArgs e, ListBox list)
|
||||
{
|
||||
//check to make sure something is actually selected
|
||||
if (list.SelectedItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//get the file's location on disk, double back if it's not a .wav file
|
||||
string fileLocation;
|
||||
if (soundboardTabControl.SelectedIndex == 0)
|
||||
{
|
||||
fileLocation = _workingDirectory + "\\" + list.SelectedItem.ToString() + ".wav";
|
||||
if (!File.Exists(fileLocation))
|
||||
{
|
||||
fileLocation = _workingDirectory + "\\" + list.SelectedItem.ToString() + ".mp3";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + list.SelectedItem.ToString() + ".wav";
|
||||
if (!File.Exists(fileLocation))
|
||||
{
|
||||
fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + list.SelectedItem.ToString() + ".mp3";
|
||||
}
|
||||
}
|
||||
if (File.Exists(fileLocation))//check for the file's existance
|
||||
{
|
||||
player.SoundLocation = fileLocation;
|
||||
player.Load();
|
||||
//try playing the sound file
|
||||
try
|
||||
{
|
||||
if (willLoopSound)
|
||||
{
|
||||
player.PlayLooping();
|
||||
}
|
||||
else
|
||||
{
|
||||
player.Play();
|
||||
}
|
||||
}
|
||||
catch (InvalidOperationException Ex)
|
||||
{
|
||||
MessageBox.Show("The file '" + list.SelectedItem.ToString() + "' couldn't be played.", "Invalid Sound File");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("The file '" + list.SelectedItem.ToString() + "' couldn't be found.", "File Not Found");
|
||||
}
|
||||
}
|
||||
|
||||
private void btnRandom_Click(object sender, EventArgs e)
|
||||
{
|
||||
int iterations = (int)randomIterationNumericUpDown.Value;
|
||||
string fullPath;
|
||||
listBoxEntity = (ListBox)soundboardTabControl.SelectedTab.Controls[0];
|
||||
|
||||
if (listBoxEntity.Enabled == false)
|
||||
{
|
||||
//the ListBox is disabled and therefore contains no sounds, so return
|
||||
return;
|
||||
}
|
||||
//disable the Random Button and the NumericUpDown box
|
||||
btnRandom.Enabled = false;
|
||||
randomIterationNumericUpDown.Enabled = false;
|
||||
@@ -95,30 +233,43 @@ namespace SoundBoard
|
||||
|
||||
for (int i = 0; i < iterations; i++)
|
||||
{
|
||||
int tempRandomNumber;
|
||||
|
||||
if (soundboardTabControl.SelectedIndex == 0)
|
||||
{
|
||||
tempRandomNumber = randomNum.Next(gamerPoopListBox.Items.Count - 1);
|
||||
gamerPoopListBox.SelectedIndex = tempRandomNumber;
|
||||
fullPath = Path.GetFullPath("gamer_poop/") + gamerPoopListBox.SelectedItem + ".wav";
|
||||
player.SoundLocation = fullPath;
|
||||
player.Load();
|
||||
player.PlaySync();
|
||||
}
|
||||
else if (soundboardTabControl.SelectedIndex == 1)
|
||||
{
|
||||
tempRandomNumber = randomNum.Next(asdfMovieListBox.Items.Count - 1);
|
||||
asdfMovieListBox.SelectedIndex = tempRandomNumber;
|
||||
fullPath = Path.GetFullPath("asdfmovie/") + asdfMovieListBox.SelectedItem + ".wav";
|
||||
player.SoundLocation = fullPath;
|
||||
listBoxEntity.SelectedIndex = randomNum.Next(listBoxEntity.Items.Count);
|
||||
if (File.Exists(_workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav"))
|
||||
{
|
||||
player.SoundLocation = _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav";
|
||||
}
|
||||
else if (File.Exists(_workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3"))
|
||||
{
|
||||
player.SoundLocation = _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3";
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("The file '" + listBoxEntity.SelectedItem.ToString() + "' couldn't be found.", "File Not Found");
|
||||
return;
|
||||
}
|
||||
player.Load();
|
||||
player.PlaySync();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("The " + soundboardTabControl.SelectedTab.Text + " tab has no sounds to play.", "No Waves Here");
|
||||
return;
|
||||
listBoxEntity.SelectedIndex = randomNum.Next(listBoxEntity.Items.Count);
|
||||
if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav"))
|
||||
{
|
||||
player.SoundLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav";
|
||||
}
|
||||
else if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3"))
|
||||
{
|
||||
player.SoundLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3";
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("The file '" + listBoxEntity.SelectedItem.ToString() + "' couldn't be found.", "File Not Found");
|
||||
return;
|
||||
}
|
||||
player.Load();
|
||||
player.PlaySync();
|
||||
}
|
||||
}
|
||||
//renable the controls
|
||||
@@ -142,58 +293,33 @@ namespace SoundBoard
|
||||
|
||||
private void playRandomSoundBothColumns(int iterations)
|
||||
{
|
||||
int tempRandomNumber = 0;
|
||||
int incrementor = 0;
|
||||
string soundPath;
|
||||
|
||||
while (incrementor < iterations)
|
||||
{
|
||||
Random rand = new Random();
|
||||
tempRandomNumber = rand.Next(0, 200);
|
||||
if (tempRandomNumber <= 100)
|
||||
{
|
||||
soundboardTabControl.SelectedIndex = 0;
|
||||
tempRandomNumber = randomNum.Next(gamerPoopListBox.Items.Count - 1);
|
||||
gamerPoopListBox.SelectedIndex = tempRandomNumber;
|
||||
soundPath = Path.GetFullPath("gamer_poop/") + gamerPoopListBox.SelectedItem + ".wav";
|
||||
player.SoundLocation = soundPath;
|
||||
player.Load();
|
||||
player.PlaySync();
|
||||
}
|
||||
else
|
||||
{
|
||||
soundboardTabControl.SelectedIndex = 1;
|
||||
tempRandomNumber = randomNum.Next(asdfMovieListBox.Items.Count - 1);
|
||||
asdfMovieListBox.SelectedIndex = tempRandomNumber;
|
||||
soundPath = Path.GetFullPath("asdfmovie/") + asdfMovieListBox.SelectedItem + ".wav";
|
||||
player.SoundLocation = soundPath;
|
||||
player.Load();
|
||||
player.PlaySync();
|
||||
}
|
||||
incrementor++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void mainMenuFileShowOnDisk_Click(object sender, EventArgs e)
|
||||
{
|
||||
string filePath;
|
||||
string arg;
|
||||
listBoxEntity = (ListBox)soundboardTabControl.SelectedTab.Controls[0];
|
||||
|
||||
if (soundboardTabControl.SelectedIndex == 0)
|
||||
{
|
||||
filePath = Path.GetFullPath("gamer_poop/") + gamerPoopListBox.SelectedItem + ".wav";
|
||||
arg = "/select, " + '"' + filePath + '"';
|
||||
Process.Start("explorer.exe", arg);
|
||||
}
|
||||
else if (soundboardTabControl.SelectedIndex == 1)
|
||||
{
|
||||
filePath = Path.GetFullPath("asdfmovie/") + asdfMovieListBox.SelectedItem + ".wav";
|
||||
filePath = _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav";
|
||||
arg = "/select, " + '"' + filePath + '"';
|
||||
Process.Start("explorer.exe", arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Unable to open files in this tab.", "Error");
|
||||
filePath = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav";
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
Process.Start("explorer.exe", "/select, " + '"' + filePath + '"');
|
||||
}
|
||||
else if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3"))
|
||||
{
|
||||
filePath = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3";
|
||||
Process.Start("explorer.exe", "/select, " + '"' + filePath + '"');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,11 +327,18 @@ namespace SoundBoard
|
||||
{
|
||||
aboutForm aboutDialogForm = new aboutForm();
|
||||
aboutDialogForm.ShowDialog();
|
||||
aboutDialogForm.Dispose();
|
||||
}
|
||||
|
||||
private void mainMenuFileExit_Click(object sender, EventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void mainMenuPlayAll_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show("Under construction", "To Be Added", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
|
||||
mainMenuPlayAll.Checked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user