Version Beta 1.5.0.0 as marked by the aboutForm dialog.

This commit is contained in:
2021-01-21 13:54:52 -06:00
parent 12c9237d50
commit 406760bca2
8 changed files with 241 additions and 162 deletions
Binary file not shown.
Binary file not shown.
+13
View File
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoundBoard
{
class GenerateRandomPlayList
{
}
}
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.0.0")] [assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("0.9.0.0")] [assembly: AssemblyFileVersion("1.5.0.0")]
+1
View File
@@ -96,6 +96,7 @@
<Compile Include="aboutForm.Designer.cs"> <Compile Include="aboutForm.Designer.cs">
<DependentUpon>aboutForm.cs</DependentUpon> <DependentUpon>aboutForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="GenerateRandomPlayList.cs" />
<Compile Include="mainForm.cs"> <Compile Include="mainForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
+1 -1
View File
@@ -58,7 +58,7 @@
this.applicationVersionLabel.Name = "applicationVersionLabel"; this.applicationVersionLabel.Name = "applicationVersionLabel";
this.applicationVersionLabel.Size = new System.Drawing.Size(246, 80); this.applicationVersionLabel.Size = new System.Drawing.Size(246, 80);
this.applicationVersionLabel.TabIndex = 1; this.applicationVersionLabel.TabIndex = 1;
this.applicationVersionLabel.Text = "Dynamic Soundboard \r\n\r\nVersion Beta 0.9.0.0\r\nMP3 sound format supported!"; this.applicationVersionLabel.Text = "Dynamic Soundboard \r\n\r\nVersion Beta 1.5.0.0\r\nMP3 sound format supported!";
// //
// lordBalgruufPortrait // lordBalgruufPortrait
// //
+19 -3
View File
@@ -42,6 +42,7 @@
this.soundboardTabControl = new System.Windows.Forms.TabControl(); this.soundboardTabControl = new System.Windows.Forms.TabControl();
this.loopSelectedSoundCheckBox = new System.Windows.Forms.CheckBox(); this.loopSelectedSoundCheckBox = new System.Windows.Forms.CheckBox();
this.fileSystemWatcherMain = new System.IO.FileSystemWatcher(); this.fileSystemWatcherMain = new System.IO.FileSystemWatcher();
this.label1 = new System.Windows.Forms.Label();
this.mainMenu.SuspendLayout(); this.mainMenu.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.randomIterationNumericUpDown)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.randomIterationNumericUpDown)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcherMain)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcherMain)).BeginInit();
@@ -52,7 +53,8 @@
this.btnRandom.Location = new System.Drawing.Point(7, 545); this.btnRandom.Location = new System.Drawing.Point(7, 545);
this.btnRandom.Name = "btnRandom"; this.btnRandom.Name = "btnRandom";
this.btnRandom.Size = new System.Drawing.Size(81, 23); this.btnRandom.Size = new System.Drawing.Size(81, 23);
this.btnRandom.TabIndex = 1; this.btnRandom.TabIndex = 0;
this.btnRandom.TabStop = false;
this.btnRandom.Text = "Random"; this.btnRandom.Text = "Random";
this.btnRandom.UseVisualStyleBackColor = true; this.btnRandom.UseVisualStyleBackColor = true;
this.btnRandom.Click += new System.EventHandler(this.btnRandom_Click); this.btnRandom.Click += new System.EventHandler(this.btnRandom_Click);
@@ -132,7 +134,7 @@
0}); 0});
this.randomIterationNumericUpDown.Name = "randomIterationNumericUpDown"; this.randomIterationNumericUpDown.Name = "randomIterationNumericUpDown";
this.randomIterationNumericUpDown.Size = new System.Drawing.Size(58, 20); this.randomIterationNumericUpDown.Size = new System.Drawing.Size(58, 20);
this.randomIterationNumericUpDown.TabIndex = 4; this.randomIterationNumericUpDown.TabIndex = 1;
this.randomIterationNumericUpDown.TabStop = false; this.randomIterationNumericUpDown.TabStop = false;
this.randomIterationNumericUpDown.Value = new decimal(new int[] { this.randomIterationNumericUpDown.Value = new decimal(new int[] {
1, 1,
@@ -148,6 +150,7 @@
this.soundboardTabControl.SelectedIndex = 0; this.soundboardTabControl.SelectedIndex = 0;
this.soundboardTabControl.Size = new System.Drawing.Size(425, 506); this.soundboardTabControl.Size = new System.Drawing.Size(425, 506);
this.soundboardTabControl.TabIndex = 0; this.soundboardTabControl.TabIndex = 0;
this.soundboardTabControl.TabStop = false;
// //
// loopSelectedSoundCheckBox // loopSelectedSoundCheckBox
// //
@@ -155,7 +158,8 @@
this.loopSelectedSoundCheckBox.Location = new System.Drawing.Point(158, 549); this.loopSelectedSoundCheckBox.Location = new System.Drawing.Point(158, 549);
this.loopSelectedSoundCheckBox.Name = "loopSelectedSoundCheckBox"; this.loopSelectedSoundCheckBox.Name = "loopSelectedSoundCheckBox";
this.loopSelectedSoundCheckBox.Size = new System.Drawing.Size(129, 17); this.loopSelectedSoundCheckBox.Size = new System.Drawing.Size(129, 17);
this.loopSelectedSoundCheckBox.TabIndex = 3; this.loopSelectedSoundCheckBox.TabIndex = 2;
this.loopSelectedSoundCheckBox.TabStop = false;
this.loopSelectedSoundCheckBox.Text = "Loop Selected Sound"; this.loopSelectedSoundCheckBox.Text = "Loop Selected Sound";
this.loopSelectedSoundCheckBox.UseVisualStyleBackColor = true; this.loopSelectedSoundCheckBox.UseVisualStyleBackColor = true;
this.loopSelectedSoundCheckBox.CheckedChanged += new System.EventHandler(this.loopSelectedSoundCheckBox_CheckedChanged); this.loopSelectedSoundCheckBox.CheckedChanged += new System.EventHandler(this.loopSelectedSoundCheckBox_CheckedChanged);
@@ -165,17 +169,28 @@
this.fileSystemWatcherMain.EnableRaisingEvents = true; this.fileSystemWatcherMain.EnableRaisingEvents = true;
this.fileSystemWatcherMain.SynchronizingObject = this; this.fileSystemWatcherMain.SynchronizingObject = this;
// //
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(294, 548);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 4;
this.label1.Text = "label1";
//
// formMain // formMain
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(425, 578); this.ClientSize = new System.Drawing.Size(425, 578);
this.Controls.Add(this.label1);
this.Controls.Add(this.loopSelectedSoundCheckBox); this.Controls.Add(this.loopSelectedSoundCheckBox);
this.Controls.Add(this.randomIterationNumericUpDown); this.Controls.Add(this.randomIterationNumericUpDown);
this.Controls.Add(this.soundboardTabControl); this.Controls.Add(this.soundboardTabControl);
this.Controls.Add(this.btnRandom); this.Controls.Add(this.btnRandom);
this.Controls.Add(this.mainMenu); this.Controls.Add(this.mainMenu);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.KeyPreview = true;
this.MainMenuStrip = this.mainMenu; this.MainMenuStrip = this.mainMenu;
this.Name = "formMain"; this.Name = "formMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
@@ -205,6 +220,7 @@
private System.Windows.Forms.ToolStripMenuItem mainMenuHelpAbout; private System.Windows.Forms.ToolStripMenuItem mainMenuHelpAbout;
private System.Windows.Forms.CheckBox loopSelectedSoundCheckBox; private System.Windows.Forms.CheckBox loopSelectedSoundCheckBox;
private System.IO.FileSystemWatcher fileSystemWatcherMain; private System.IO.FileSystemWatcher fileSystemWatcherMain;
public System.Windows.Forms.Label label1;
} }
} }
+205 -156
View File
@@ -1,26 +1,25 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using System.IO; using System.IO;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection;
namespace SoundBoard namespace SoundBoard
{ {
public partial class formMain : Form public partial class formMain : Form, IMessageFilter
{ {
private const int WM_KEYDOWN = 0x100;
public WMPLib.WindowsMediaPlayer Player = new WMPLib.WindowsMediaPlayer(); public WMPLib.WindowsMediaPlayer Player = new WMPLib.WindowsMediaPlayer();
public Random randomNum = new Random(); public Random randomNum = new Random();
public ListBox listBoxEntity = new ListBox(); public ListView listViewEntity = new ListView();
ProcessStartInfo process = new ProcessStartInfo(); public string _workingDirectory = Path.GetDirectoryName(Application.ExecutablePath);
BackgroundWorker worker = new BackgroundWorker();
public string _workingDirectory;
public string[] _soundFiles; public string[] _soundFiles;
public string[] _soundDirectories; public string[] _soundDirectories;
@@ -31,29 +30,27 @@ namespace SoundBoard
private void formMain_Load(object sender, EventArgs e) private void formMain_Load(object sender, EventArgs e)
{ {
_workingDirectory = Path.GetDirectoryName(Application.ExecutablePath);
_soundFiles = Directory.GetFiles(_workingDirectory); _soundFiles = Directory.GetFiles(_workingDirectory);
//Build the UI, foreach directory create one TabPage and one ListView object
foreach (string sound in _soundFiles) foreach (string sound in _soundFiles)
{ {
CreateUITabs("Working Directory", _workingDirectory); CreateUITabs("Working Directory", _workingDirectory);
} }
_soundDirectories = Directory.GetDirectories(_workingDirectory, "*", SearchOption.TopDirectoryOnly);
_soundDirectories = Directory.GetDirectories(_workingDirectory);
foreach (string sounds in _soundDirectories) foreach (string sounds in _soundDirectories)
{ {
CreateUITabs(Path.GetFileName(sounds), sounds); CreateUITabs(Path.GetFileName(sounds), sounds);
} }
worker.WorkerSupportsCancellation = true; Application.AddMessageFilter(this);
worker.WorkerReportsProgress = true; fileSystemWatcherMain.Path = _workingDirectory; //watch in the application's working directory
fileSystemWatcherMain.Path = _workingDirectory; fileSystemWatcherMain.IncludeSubdirectories = true; //and watch in the subfolders for changes, but only one layer down from the app's directory
fileSystemWatcherMain.IncludeSubdirectories = true;
fileSystemWatcherMain.Created += new FileSystemEventHandler(fileSystemUpdateDetected); //file or folder created fileSystemWatcherMain.Created += new FileSystemEventHandler(fileSystemUpdateDetected); //file or folder created
fileSystemWatcherMain.Deleted += new FileSystemEventHandler(fileSystemUpdateDetected); //file or folder moved or deleted fileSystemWatcherMain.Deleted += new FileSystemEventHandler(fileSystemUpdateDetected); //file or folder moved or deleted
fileSystemWatcherMain.Renamed += new RenamedEventHandler(fileSystemUpdateDetected); //for any file changes like file extension changes 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 soundboardTabControl.SelectedIndexChanged += new EventHandler(CheckForDisabledListBox); //disables or enables the Show on Disk file menu object
Player.PlayStateChange += new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(WMP_PlayStateChange); Player.PlayStateChange += new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(WMP_PlayStateChange); //eventhandler for the playstate of the Player object
//check to see if the listBox is empty on form load //check to see if the listView is empty on form load
if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true) if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true)
{ {
mainMenuFileShowOnDisk.Enabled = true; mainMenuFileShowOnDisk.Enabled = true;
@@ -64,10 +61,41 @@ namespace SoundBoard
mainMenuFileShowOnDisk.Enabled = false; mainMenuFileShowOnDisk.Enabled = false;
btnRandom.Enabled = false; btnRandom.Enabled = false;
} }
soundboardTabControl.Select();
} }
private void WMP_PlayStateChange(int newState) private void WMP_PlayStateChange(int newState)
{ {
//check to see if the random play functions are running
if (btnRandom.Enabled == false)
{
if (Player.playState == WMPLib.WMPPlayState.wmppsTransitioning)
{
//Player is transitioning, so keep the controls disabled
btnRandom.Enabled = false;
loopSelectedSoundCheckBox.Enabled = false;
}
else if (Player.playState == WMPLib.WMPPlayState.wmppsPlaying)
{
//player is still playing the random playlist, keep the controls disbaled
btnRandom.Enabled = false;
loopSelectedSoundCheckBox.Enabled = false;
}
else if (Player.playState == WMPLib.WMPPlayState.wmppsReady)
{
//renable the controls, the Random functions are done
//first check to see if the loop checkBox is checked, if so set the player to "loop"
if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true)
{
btnRandom.Enabled = true;
}
if (loopSelectedSoundCheckBox.Checked == true)
{
Player.settings.setMode("loop", true);
}
loopSelectedSoundCheckBox.Enabled = true;
}
}
} }
private void fileSystemUpdateDetected(object sender, FileSystemEventArgs e) private void fileSystemUpdateDetected(object sender, FileSystemEventArgs e)
@@ -78,17 +106,16 @@ namespace SoundBoard
private void CheckForDisabledListBox(object sender, EventArgs e) private void CheckForDisabledListBox(object sender, EventArgs e)
{ {
ListBox listBoxEntity = new ListBox();
try try
{ {
listBoxEntity = (ListBox)soundboardTabControl.SelectedTab.Controls[0]; listViewEntity = (ListView)soundboardTabControl.SelectedTab.Controls[0];
} }
catch (Exception spam) catch (Exception spam)
{ {
return; return;
} }
if (listBoxEntity.Enabled == false) if (listViewEntity.Enabled == false)
{ {
mainMenuFileShowOnDisk.Enabled = false; mainMenuFileShowOnDisk.Enabled = false;
btnRandom.Enabled = false; btnRandom.Enabled = false;
@@ -107,9 +134,9 @@ namespace SoundBoard
foreach (TabPage tabPage in soundboardTabControl.TabPages) foreach (TabPage tabPage in soundboardTabControl.TabPages)
{ {
foreach (ListBox listBox in tabPage.Controls) foreach (ListView listView in tabPage.Controls)
{ {
listBox.Dispose(); listView.Dispose();
} }
tabPage.Dispose(); tabPage.Dispose();
} }
@@ -122,7 +149,7 @@ namespace SoundBoard
{ {
CreateUITabs(Path.GetFileName(files), files); CreateUITabs(Path.GetFileName(files), files);
} }
//check to see if the listBox is empty //check to see if the listView is empty
if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true) if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true)
{ {
mainMenuFileShowOnDisk.Enabled = true; mainMenuFileShowOnDisk.Enabled = true;
@@ -137,12 +164,14 @@ namespace SoundBoard
private void CreateUITabs(string tabName, string directoryPath) private void CreateUITabs(string tabName, string directoryPath)
{ {
//add tabs dynamically //Add tabs dynamically
int soundControlHeight = soundboardTabControl.Height; int soundControlHeight = soundboardTabControl.Height;
int soundControlWidth = soundboardTabControl.Width; int soundControlWidth = soundboardTabControl.Width;
string[] directoryFiles; //files in the target directory string[] directoryFiles; //Files in the target directory
TabPage tab = new TabPage(); TabPage tab = new TabPage();
ListBox localListBox = new ListBox(); ListView localListView = new ListView();
string[] columnNames = new string[2]; //Perhaps include a compatibility column to flag files that cause errors?
ListViewItem listItemObject;
if (soundboardTabControl.Controls.ContainsKey(tabName.Replace(" ", "") + "Tab")) if (soundboardTabControl.Controls.ContainsKey(tabName.Replace(" ", "") + "Tab"))
{ {
@@ -150,38 +179,60 @@ namespace SoundBoard
} }
else else
{ {
tab.Text = tabName; //display the folder's full name to the user //Construct the TabPage and its properties
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.Name = tabName.Replace(" ", "") + "Tab"; //create a legal name for the tab's (name) property
tab.Height = soundControlHeight; tab.Height = soundControlHeight;
tab.Height = soundControlWidth; tab.Height = soundControlWidth;
soundboardTabControl.Controls.Add(tab); soundboardTabControl.Controls.Add(tab);
localListBox.Height = soundControlHeight - 25; //Construct the ListView and its properties
localListBox.Width = soundControlWidth - 5; localListView.Height = soundControlHeight - 25;
localListBox.Name = tabName.Replace(" ", "") + "ListBox"; localListView.Width = soundControlWidth - 5;
tab.Controls.Add(localListBox); localListView.Name = tabName.Replace(" ", "") + "ListView";
localListBox.Click += new EventHandler((sender, e) => ListBoxOnLeftClick(sender, e, localListBox)); //create event handler for the lsit box and pass the object in localListView.FullRowSelect = true;
localListView.MultiSelect = false;
localListView.GridLines = true;
localListView.View = View.Details;
localListView.Activation = ItemActivation.OneClick;
localListView.TabStop = false;
tab.Controls.Add(localListView);
localListView.Columns.Add("File Name", 340, HorizontalAlignment.Left);
localListView.Columns.Add("File Ext", 50, HorizontalAlignment.Left);
localListView.ItemActivate += new EventHandler((sender, e) => ListViewOnLeftClick(sender, e, localListView));
} }
directoryFiles = Directory.GetFiles(Path.GetFullPath(directoryPath)); directoryFiles = Directory.GetFiles(Path.GetFullPath(directoryPath));
foreach (string files in directoryFiles) foreach (string file in directoryFiles)
{ {
switch (Path.GetExtension(files))//check to make sure the file is a sound file switch (Path.GetExtension(file).ToLower())
{ {
case ".wav": //Only include sound files in the ListView
case ".mp3": case ".mp3":
localListBox.Items.Add(Path.GetFileNameWithoutExtension(files)); case ".wav":
columnNames[0] = Path.GetFileNameWithoutExtension(file);
columnNames[1] = Path.GetExtension(file);
listItemObject = new ListViewItem(columnNames);
localListView.Items.Add(listItemObject);
break; break;
default: default:
break; break;
} }
} }
if (localListBox.Items.Count == 0) if (localListView.Items.Count == 0)
{ {
localListBox.Items.Add("No sound files found in the " + tabName + " directory."); if (tab.Name == "WorkingDirectoryTab")
localListBox.Enabled = false; {
localListView.Items.Add("No sound files detected in the application's working directory.");
}
else
{
localListView.Items.Add("No sound files detected in the " + tabName + " directory");
}
localListView.Enabled = false;
if (soundboardTabControl.SelectedIndex == 0) if (soundboardTabControl.SelectedIndex == 0)
{ {
mainMenuFileShowOnDisk.Enabled = false; mainMenuFileShowOnDisk.Enabled = false;
@@ -190,59 +241,59 @@ namespace SoundBoard
} }
} }
private void ListBoxOnLeftClick(object sender, EventArgs e, ListBox list) private void ListViewOnLeftClick(object sender, EventArgs e, ListView listView)
{ {
//check to make sure something is actually selected if (btnRandom.Enabled == false)
if (list.SelectedItem == null)
{ {
//If the btnRandom button is disabled that means a randomise function is running, so don't interupt it
return; return;
} }
//get the file's location on disk, double back if it's not a .wav file string fileName;
string fileExt;
string fileLocation; string fileLocation;
WMPLib.IWMPPlaylist _playList = Player.playlistCollection.newPlaylist("myPlayList"); //build the playlist object
fileName = listView.SelectedItems[0].SubItems[0].Text;
fileExt = listView.SelectedItems[0].SubItems[1].Text;
if (soundboardTabControl.SelectedIndex == 0) if (soundboardTabControl.SelectedIndex == 0)
{ {
fileLocation = _workingDirectory + "\\" + list.SelectedItem.ToString() + ".wav"; if (File.Exists(_workingDirectory + "\\" + fileName + fileExt))
if (!File.Exists(fileLocation))
{ {
fileLocation = _workingDirectory + "\\" + list.SelectedItem.ToString() + ".mp3"; fileLocation = _workingDirectory + "\\" + fileName + fileExt;
}
else
{
return;
} }
} }
else else
{ {
fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + list.SelectedItem.ToString() + ".wav"; if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + fileName + fileExt))
if (!File.Exists(fileLocation))
{ {
fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + list.SelectedItem.ToString() + ".mp3"; fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + fileName + fileExt;
}
else
{
return;
} }
} }
if (File.Exists(fileLocation))//check for the file's existance PlaySoundFile(fileLocation);
{
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", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void PlayRandomSounds()
{
} }
private void btnRandom_Click(object sender, EventArgs e) private void btnRandom_Click(object sender, EventArgs e)
{ {
int iterations = (int)randomIterationNumericUpDown.Value; int iterations = (int)randomIterationNumericUpDown.Value;
listBoxEntity = (ListBox)soundboardTabControl.SelectedTab.Controls[0]; listViewEntity = (ListView)soundboardTabControl.SelectedTab.Controls[0];
Player.currentPlaylist.clear();
if (listBoxEntity.Enabled == false) //DOuble check to see if the ListView has any items that can be played
if (listViewEntity.Enabled == false)
{ {
//the ListBox is disabled and therefore contains no sounds, so return //the ListView disabled and therefore contains no sounds, so return
return; return;
} }
//disable the Random Button and the NumericUpDown box //disable the Random Button and the loop checkbox
btnRandom.Enabled = false; btnRandom.Enabled = false;
randomIterationNumericUpDown.Enabled = false;
loopSelectedSoundCheckBox.Enabled = false; loopSelectedSoundCheckBox.Enabled = false;
if (mainMenuPlayAll.Checked == true) if (mainMenuPlayAll.Checked == true)
@@ -252,101 +303,82 @@ namespace SoundBoard
{ {
btnRandom.Enabled = true; btnRandom.Enabled = true;
} }
randomIterationNumericUpDown.Enabled = true;
loopSelectedSoundCheckBox.Enabled = true; loopSelectedSoundCheckBox.Enabled = true;
return; return;
} }
for (int i = 0; i < iterations; i++) for (int i = 0; i < iterations; i++)
{ {
string fileLocation; string fileLocation = "";
string fileExt;
string fileName;
//Check to see if the selected tab is the working directory's tab
if (soundboardTabControl.SelectedIndex == 0) if (soundboardTabControl.SelectedIndex == 0)
{ {
listBoxEntity.SelectedIndex = randomNum.Next(listBoxEntity.Items.Count); listViewEntity.Items[randomNum.Next(listViewEntity.Items.Count)].Selected = true;
if (File.Exists(_workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav")) fileName = listViewEntity.SelectedItems[0].SubItems[0].Text;
fileExt = listViewEntity.SelectedItems[0].SubItems[1].Text;
if (File.Exists(_workingDirectory + "\\" + fileName + fileExt))
{ {
fileLocation = _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav"; fileLocation = _workingDirectory + "\\" + fileName + fileExt;
}
else if (File.Exists(_workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3"))
{
fileLocation = _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3";
} }
else else
{ {
MessageBox.Show("The file '" + listBoxEntity.SelectedItem.ToString() + "' couldn't be found.", "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("The file couldn't be found.", "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true) if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true)
{ {
btnRandom.Enabled = true; btnRandom.Enabled = true;
} }
randomIterationNumericUpDown.Enabled = true;
loopSelectedSoundCheckBox.Enabled = true; loopSelectedSoundCheckBox.Enabled = true;
Player.currentPlaylist.clear();
return; return;
} }
} }
else else
{ {
listBoxEntity.SelectedIndex = randomNum.Next(listBoxEntity.Items.Count); listViewEntity.Items[randomNum.Next(listViewEntity.Items.Count)].Selected = true;
if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav")) fileName = listViewEntity.SelectedItems[0].SubItems[0].Text;
fileExt = listViewEntity.SelectedItems[0].SubItems[1].Text;
if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + fileName + fileExt))
{ {
fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav"; fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + fileName + fileExt;
}
else if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3"))
{
fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3";
} }
else else
{ {
MessageBox.Show("The file '" + listBoxEntity.SelectedItem.ToString() + "' couldn't be found.", "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + fileName + fileExt, "Not Found");
if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true) if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true)
{ {
btnRandom.Enabled = true; btnRandom.Enabled = true;
} }
randomIterationNumericUpDown.Enabled = true;
loopSelectedSoundCheckBox.Enabled = true; loopSelectedSoundCheckBox.Enabled = true;
return; Player.currentPlaylist.clear();
return;
} }
} }
//play the sound file //load the player with the randomly chosen sounds
PlaySoundFile(fileLocation, listBoxEntity.SelectedItem.ToString(), false); enumeratePlayerPlayList(fileLocation);
} }
//renable the controls //prepare the Player object and play the playlist
if (soundboardTabControl.SelectedTab.Controls[0].Enabled == true) btnRandom.Enabled = false;
{ Player.settings.setMode("loop", false);
btnRandom.Enabled = true; PlayPlayList();
}
randomIterationNumericUpDown.Enabled = true;
loopSelectedSoundCheckBox.Enabled = true;
} }
private void PlaySoundFile(string fileLocation, string fileName, bool willLoop = true) private void PlaySoundFile(string fileLocation)
{ {
//Set the file to be played's location
Player.URL = fileLocation; Player.URL = fileLocation;
//Attempt to play the file
try try
{ {
if (Player.settings.getMode("loop")) Player.controls.play();
{
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) catch (InvalidOperationException Ex)
{ {
MessageBox.Show("The file '" + fileName + "' couldn't be played.", "Invalid Sound File", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("The file couldn't be played.", "Invalid Sound File", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
} }
@@ -360,15 +392,16 @@ namespace SoundBoard
else else
{ {
Player.settings.setMode("loop", false); Player.settings.setMode("loop", false);
Player.close();
} }
} }
private void playRandomSoundBothColumns(int iterations) private void playRandomSoundBothColumns(int iterations)
{ {
int tempRandomNumber; int tempRandomNumber;
string fileLocation; string fileLocation = "";
listBoxEntity = (ListBox)soundboardTabControl.SelectedTab.Controls[0]; string fileName;
string fileExt;
listViewEntity = (ListView)soundboardTabControl.SelectedTab.Controls[0];
for (int i = 0; i <= iterations; i++) for (int i = 0; i <= iterations; i++)
{ {
@@ -379,13 +412,13 @@ namespace SoundBoard
soundboardTabControl.SelectedIndex = tempRandomNumber; soundboardTabControl.SelectedIndex = tempRandomNumber;
if (soundboardTabControl.SelectedIndex == 0) if (soundboardTabControl.SelectedIndex == 0)
{ {
if (File.Exists(_workingDirectory + "\\" + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav")) listViewEntity.Items[randomNum.Next(listViewEntity.Items.Count)].Selected = true;
fileName = listViewEntity.SelectedItems[0].SubItems[0].Text;
fileExt = listViewEntity.SelectedItems[0].SubItems[1].Text;
if (File.Exists(_workingDirectory + "\\" + fileName + fileExt))
{ {
fileLocation = _workingDirectory + "\\" + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav"; fileLocation = _workingDirectory + "\\" + fileName + fileExt;
}
else if (File.Exists(_workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3"))
{
fileLocation = _workingDirectory + "\\" + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3";
} }
else else
{ {
@@ -394,58 +427,50 @@ namespace SoundBoard
} }
else else
{ {
soundboardTabControl.SelectedIndex = tempRandomNumber; listViewEntity.Items[randomNum.Next(listViewEntity.Items.Count)].Selected = true;
listBoxEntity.SelectedIndex = randomNum.Next(listBoxEntity.Items.Count); fileName = listViewEntity.SelectedItems[0].SubItems[0].Text;
if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav")) fileExt = listViewEntity.SelectedItems[0].SubItems[1].Text;
if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + fileName + fileExt))
{ {
fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav"; fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + fileName + fileExt;
}
else if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3"))
{
fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3";
} }
else else
{ {
return; return;
} }
} }
PlaySoundFile(fileLocation, soundboardTabControl.SelectedTab.Text, false); enumeratePlayerPlayList(fileLocation);
} }
else else
{ {
playRandomSoundBothColumns(iterations); playRandomSoundBothColumns(iterations - i);
} }
} }
PlayPlayList();
} }
private void mainMenuFileShowOnDisk_Click(object sender, EventArgs e) private void mainMenuFileShowOnDisk_Click(object sender, EventArgs e)
{ {
listBoxEntity = (ListBox)soundboardTabControl.SelectedTab.Controls[0]; listViewEntity = (ListView)soundboardTabControl.SelectedTab.Controls[0];
if ((String)listBoxEntity.SelectedItem == null) string fileName;
{ string fileExt;
MessageBox.Show("No sound file selected...", soundboardTabControl.SelectedTab.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
return; fileName = listViewEntity.SelectedItems[0].SubItems[0].Text;
} fileExt = listViewEntity.SelectedItems[0].SubItems[1].Text;
if (soundboardTabControl.SelectedIndex == 0) if (soundboardTabControl.SelectedIndex == 0)
{ {
if (File.Exists(_workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav")) if (File.Exists(_workingDirectory + "\\" + fileName + fileExt))
{ {
Process.Start("explorer.exe", "/select, " + '"' + _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav" + '"'); Process.Start("explorer.exe", "/select, \"" + _workingDirectory + "\\" + fileName + fileExt + "\"");
}
else
{
Process.Start("explorer.exe", "/select, " + '"' + _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3" + '"');
} }
} }
else else
{ {
if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav")) if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + fileName + fileExt))
{ {
Process.Start("explorer.exe", "/select, " + '"' + _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav" + '"'); Process.Start("explorer.exe", "/select, \"" + _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + fileName + fileExt + "\"");
}
else
{
Process.Start("explorer.exe", "/select, " + '"' + _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3" + '"');
} }
} }
} }
@@ -461,5 +486,29 @@ namespace SoundBoard
{ {
Close(); Close();
} }
private void enumeratePlayerPlayList(string fileLocation)
{
WMPLib.IWMPMedia playList = Player.newMedia(fileLocation);
Player.currentPlaylist.appendItem(playList);
}
private void PlayPlayList()
{
Player.controls.play();
}
//Handles all messages being sent to controls
public bool PreFilterMessage(ref Message m)
{
Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
bool retVal = false;
if (m.Msg == WM_KEYDOWN)
{
// Handle the keypress
label1.Text = keyCode.ToString();
}
return retVal;
}
} }
} }