Verions Beta 0.9 as marked by the folder name.
This commit is contained in:
+187
-66
@@ -8,21 +8,21 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using System.Media;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
|
||||
namespace SoundBoard
|
||||
{
|
||||
public partial class formMain : Form
|
||||
{
|
||||
|
||||
public SoundPlayer player = new SoundPlayer();
|
||||
public WMPLib.WindowsMediaPlayer Player = new WMPLib.WindowsMediaPlayer();
|
||||
public Random randomNum = new Random();
|
||||
public ListBox listBoxEntity = new ListBox();
|
||||
ProcessStartInfo process = new ProcessStartInfo();
|
||||
BackgroundWorker worker = new BackgroundWorker();
|
||||
public string _workingDirectory;
|
||||
public string[] _soundFiles;
|
||||
public string[] _soundDirectories;
|
||||
public bool willLoopSound = false;
|
||||
|
||||
public formMain()
|
||||
{
|
||||
@@ -43,17 +43,31 @@ namespace SoundBoard
|
||||
{
|
||||
CreateUITabs(Path.GetFileName(sounds), sounds);
|
||||
}
|
||||
|
||||
worker.WorkerSupportsCancellation = true;
|
||||
worker.WorkerReportsProgress = true;
|
||||
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)
|
||||
Player.PlayStateChange += new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(WMP_PlayStateChange);
|
||||
//check to see if the listBox is empty on form load
|
||||
if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true)
|
||||
{
|
||||
listBoxEntity.SelectedIndex = 0;
|
||||
mainMenuFileShowOnDisk.Enabled = true;
|
||||
btnRandom.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mainMenuFileShowOnDisk.Enabled = false;
|
||||
btnRandom.Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void WMP_PlayStateChange(int newState)
|
||||
{
|
||||
}
|
||||
|
||||
private void fileSystemUpdateDetected(object sender, FileSystemEventArgs e)
|
||||
@@ -77,11 +91,12 @@ namespace SoundBoard
|
||||
if (listBoxEntity.Enabled == false)
|
||||
{
|
||||
mainMenuFileShowOnDisk.Enabled = false;
|
||||
btnRandom.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
listBoxEntity.SelectedIndex = 0;
|
||||
mainMenuFileShowOnDisk.Enabled = true;
|
||||
btnRandom.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,8 +104,15 @@ namespace SoundBoard
|
||||
{
|
||||
_workingDirectory = Path.GetDirectoryName(Application.ExecutablePath);
|
||||
_soundDirectories = Directory.GetDirectories(_workingDirectory);
|
||||
|
||||
soundboardTabControl.Controls.Clear();
|
||||
|
||||
foreach (TabPage tabPage in soundboardTabControl.TabPages)
|
||||
{
|
||||
foreach (ListBox listBox in tabPage.Controls)
|
||||
{
|
||||
listBox.Dispose();
|
||||
}
|
||||
tabPage.Dispose();
|
||||
}
|
||||
|
||||
foreach (string sounds in _soundFiles)
|
||||
{
|
||||
@@ -100,6 +122,17 @@ namespace SoundBoard
|
||||
{
|
||||
CreateUITabs(Path.GetFileName(files), files);
|
||||
}
|
||||
//check to see if the listBox is empty
|
||||
if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true)
|
||||
{
|
||||
mainMenuFileShowOnDisk.Enabled = true;
|
||||
btnRandom.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mainMenuFileShowOnDisk.Enabled = false;
|
||||
btnRandom.Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateUITabs(string tabName, string directoryPath)
|
||||
@@ -119,15 +152,15 @@ namespace SoundBoard
|
||||
{
|
||||
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 = soundControlHeight;
|
||||
tab.Height = soundControlWidth;
|
||||
soundboardTabControl.Controls.Add(tab);
|
||||
|
||||
localListBox.Height = soundControlHeight - 20;
|
||||
localListBox.Width = soundControlWidth - 7;
|
||||
localListBox.Height = soundControlHeight - 25;
|
||||
localListBox.Width = soundControlWidth - 5;
|
||||
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
|
||||
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));
|
||||
@@ -144,6 +177,7 @@ namespace SoundBoard
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (localListBox.Items.Count == 0)
|
||||
{
|
||||
localListBox.Items.Add("No sound files found in the " + tabName + " directory.");
|
||||
@@ -151,6 +185,7 @@ namespace SoundBoard
|
||||
if (soundboardTabControl.SelectedIndex == 0)
|
||||
{
|
||||
mainMenuFileShowOnDisk.Enabled = false;
|
||||
btnRandom.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,6 +199,7 @@ namespace SoundBoard
|
||||
}
|
||||
//get the file's location on disk, double back if it's not a .wav file
|
||||
string fileLocation;
|
||||
WMPLib.IWMPPlaylist _playList = Player.playlistCollection.newPlaylist("myPlayList"); //build the playlist object
|
||||
if (soundboardTabControl.SelectedIndex == 0)
|
||||
{
|
||||
fileLocation = _workingDirectory + "\\" + list.SelectedItem.ToString() + ".wav";
|
||||
@@ -182,31 +218,18 @@ namespace SoundBoard
|
||||
}
|
||||
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");
|
||||
}
|
||||
PlaySoundFile(fileLocation, list.SelectedItem.ToString()); //if the file exists then play it
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("The file '" + list.SelectedItem.ToString() + "' couldn't be found.", "File Not Found");
|
||||
MessageBox.Show("The file '" + list.SelectedItem.ToString() + "' couldn't be found.", "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayRandomSounds()
|
||||
{
|
||||
}
|
||||
|
||||
private void btnRandom_Click(object sender, EventArgs e)
|
||||
{
|
||||
int iterations = (int)randomIterationNumericUpDown.Value;
|
||||
@@ -225,7 +248,10 @@ namespace SoundBoard
|
||||
if (mainMenuPlayAll.Checked == true)
|
||||
{
|
||||
playRandomSoundBothColumns(iterations);
|
||||
btnRandom.Enabled = true;
|
||||
if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true)
|
||||
{
|
||||
btnRandom.Enabled = true;
|
||||
}
|
||||
randomIterationNumericUpDown.Enabled = true;
|
||||
loopSelectedSoundCheckBox.Enabled = true;
|
||||
return;
|
||||
@@ -233,92 +259,193 @@ namespace SoundBoard
|
||||
|
||||
for (int i = 0; i < iterations; i++)
|
||||
{
|
||||
string fileLocation;
|
||||
if (soundboardTabControl.SelectedIndex == 0)
|
||||
{
|
||||
listBoxEntity.SelectedIndex = randomNum.Next(listBoxEntity.Items.Count);
|
||||
if (File.Exists(_workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav"))
|
||||
{
|
||||
player.SoundLocation = _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav";
|
||||
fileLocation = _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav";
|
||||
}
|
||||
else if (File.Exists(_workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3"))
|
||||
{
|
||||
player.SoundLocation = _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3";
|
||||
fileLocation = _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3";
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("The file '" + listBoxEntity.SelectedItem.ToString() + "' couldn't be found.", "File Not Found");
|
||||
MessageBox.Show("The file '" + listBoxEntity.SelectedItem.ToString() + "' couldn't be found.", "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true)
|
||||
{
|
||||
btnRandom.Enabled = true;
|
||||
}
|
||||
|
||||
randomIterationNumericUpDown.Enabled = true;
|
||||
loopSelectedSoundCheckBox.Enabled = true;
|
||||
return;
|
||||
}
|
||||
player.Load();
|
||||
player.PlaySync();
|
||||
}
|
||||
else
|
||||
{
|
||||
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";
|
||||
fileLocation = _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";
|
||||
fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3";
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("The file '" + listBoxEntity.SelectedItem.ToString() + "' couldn't be found.", "File Not Found");
|
||||
MessageBox.Show("The file '" + listBoxEntity.SelectedItem.ToString() + "' couldn't be found.", "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true)
|
||||
{
|
||||
btnRandom.Enabled = true;
|
||||
}
|
||||
|
||||
randomIterationNumericUpDown.Enabled = true;
|
||||
loopSelectedSoundCheckBox.Enabled = true;
|
||||
return;
|
||||
}
|
||||
player.Load();
|
||||
player.PlaySync();
|
||||
}
|
||||
//play the sound file
|
||||
PlaySoundFile(fileLocation, listBoxEntity.SelectedItem.ToString(), false);
|
||||
}
|
||||
//renable the controls
|
||||
btnRandom.Enabled = true;
|
||||
if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true)
|
||||
{
|
||||
btnRandom.Enabled = true;
|
||||
}
|
||||
randomIterationNumericUpDown.Enabled = true;
|
||||
loopSelectedSoundCheckBox.Enabled = true;
|
||||
}
|
||||
|
||||
private void PlaySoundFile(string fileLocation, string fileName, bool willLoop = true)
|
||||
{
|
||||
Player.URL = fileLocation;
|
||||
|
||||
try
|
||||
{
|
||||
if (Player.settings.getMode("loop"))
|
||||
{
|
||||
if (!willLoop)
|
||||
{
|
||||
Player.settings.setMode("loop", false);
|
||||
Player.controls.play();
|
||||
}
|
||||
else
|
||||
{
|
||||
Player.controls.play();
|
||||
}
|
||||
Player.settings.setMode("loop", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Player.controls.play();
|
||||
}
|
||||
}
|
||||
catch (InvalidOperationException Ex)
|
||||
{
|
||||
MessageBox.Show("The file '" + fileName + "' couldn't be played.", "Invalid Sound File", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void loopSelectedSoundCheckBox_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (loopSelectedSoundCheckBox.Checked == true)
|
||||
{
|
||||
willLoopSound = true;
|
||||
Player.settings.setMode("loop", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
willLoopSound = false;
|
||||
player.Stop();
|
||||
Player.settings.setMode("loop", false);
|
||||
Player.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void playRandomSoundBothColumns(int iterations)
|
||||
{
|
||||
int tempRandomNumber;
|
||||
string fileLocation;
|
||||
listBoxEntity = (ListBox)soundboardTabControl.SelectedTab.Controls[0];
|
||||
|
||||
for (int i = 0; i <= iterations; i++)
|
||||
{
|
||||
tempRandomNumber = randomNum.Next(0, soundboardTabControl.TabCount);
|
||||
|
||||
if (soundboardTabControl.TabPages[tempRandomNumber].Controls[0].Enabled == true)
|
||||
{
|
||||
soundboardTabControl.SelectedIndex = tempRandomNumber;
|
||||
if (soundboardTabControl.SelectedIndex == 0)
|
||||
{
|
||||
if (File.Exists(_workingDirectory + "\\" + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav"))
|
||||
{
|
||||
fileLocation = _workingDirectory + "\\" + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav";
|
||||
}
|
||||
else if (File.Exists(_workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3"))
|
||||
{
|
||||
fileLocation = _workingDirectory + "\\" + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3";
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
soundboardTabControl.SelectedIndex = tempRandomNumber;
|
||||
listBoxEntity.SelectedIndex = randomNum.Next(listBoxEntity.Items.Count);
|
||||
if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav"))
|
||||
{
|
||||
fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav";
|
||||
}
|
||||
else if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3"))
|
||||
{
|
||||
fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3";
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
PlaySoundFile(fileLocation, soundboardTabControl.SelectedTab.Text, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
playRandomSoundBothColumns(iterations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void mainMenuFileShowOnDisk_Click(object sender, EventArgs e)
|
||||
{
|
||||
string filePath;
|
||||
string arg;
|
||||
listBoxEntity = (ListBox)soundboardTabControl.SelectedTab.Controls[0];
|
||||
|
||||
if ((String)listBoxEntity.SelectedItem == null)
|
||||
{
|
||||
MessageBox.Show("No sound file selected...", soundboardTabControl.SelectedTab.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (soundboardTabControl.SelectedIndex == 0)
|
||||
{
|
||||
filePath = _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav";
|
||||
arg = "/select, " + '"' + filePath + '"';
|
||||
Process.Start("explorer.exe", arg);
|
||||
if (File.Exists(_workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav"))
|
||||
{
|
||||
Process.Start("explorer.exe", "/select, " + '"' + _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav" + '"');
|
||||
}
|
||||
else
|
||||
{
|
||||
Process.Start("explorer.exe", "/select, " + '"' + _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3" + '"');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
filePath = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav";
|
||||
if (File.Exists(filePath))
|
||||
if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav"))
|
||||
{
|
||||
Process.Start("explorer.exe", "/select, " + '"' + filePath + '"');
|
||||
Process.Start("explorer.exe", "/select, " + '"' + _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav" + '"');
|
||||
}
|
||||
else if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3"))
|
||||
else
|
||||
{
|
||||
filePath = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3";
|
||||
Process.Start("explorer.exe", "/select, " + '"' + filePath + '"');
|
||||
Process.Start("explorer.exe", "/select, " + '"' + _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3" + '"');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,11 +461,5 @@ namespace SoundBoard
|
||||
{
|
||||
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