diff --git a/SoundBoard.v11.suo b/SoundBoard.v11.suo index aec83de..69c10cb 100644 Binary files a/SoundBoard.v11.suo and b/SoundBoard.v11.suo differ diff --git a/SoundBoard/Properties/AssemblyInfo.cs b/SoundBoard/Properties/AssemblyInfo.cs index 5a9a118..a468d8c 100644 --- a/SoundBoard/Properties/AssemblyInfo.cs +++ b/SoundBoard/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.5.0.0")] -[assembly: AssemblyFileVersion("0.5.0.0")] +[assembly: AssemblyVersion("0.7.0.0")] +[assembly: AssemblyFileVersion("0.7.0.0")] diff --git a/SoundBoard/aboutForm.Designer.cs b/SoundBoard/aboutForm.Designer.cs index 96729ae..be6708c 100644 --- a/SoundBoard/aboutForm.Designer.cs +++ b/SoundBoard/aboutForm.Designer.cs @@ -58,7 +58,7 @@ this.applicationVersionLabel.Name = "applicationVersionLabel"; this.applicationVersionLabel.Size = new System.Drawing.Size(194, 60); this.applicationVersionLabel.TabIndex = 1; - this.applicationVersionLabel.Text = "YouTube Soundboard \r\n\r\nVersion 0.5.0.0\r\n"; + this.applicationVersionLabel.Text = "YouTube Soundboard \r\n\r\nVersion 0.7.0.0\r\n"; // // asdfLabel // diff --git a/SoundBoard/mainForm.Designer.cs b/SoundBoard/mainForm.Designer.cs index 8988dbe..56562fc 100644 --- a/SoundBoard/mainForm.Designer.cs +++ b/SoundBoard/mainForm.Designer.cs @@ -39,17 +39,12 @@ this.mainMenuHelp = new System.Windows.Forms.ToolStripMenuItem(); this.mainMenuHelpAbout = new System.Windows.Forms.ToolStripMenuItem(); this.randomIterationNumericUpDown = new System.Windows.Forms.NumericUpDown(); - this.asdfMovieTabPage = new System.Windows.Forms.TabPage(); - this.asdfMovieListBox = new System.Windows.Forms.ListBox(); - this.gamerPoopTabPage = new System.Windows.Forms.TabPage(); - this.gamerPoopListBox = new System.Windows.Forms.ListBox(); this.soundboardTabControl = new System.Windows.Forms.TabControl(); this.loopSelectedSoundCheckBox = new System.Windows.Forms.CheckBox(); + this.fileSystemWatcherMain = new System.IO.FileSystemWatcher(); this.mainMenu.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.randomIterationNumericUpDown)).BeginInit(); - this.asdfMovieTabPage.SuspendLayout(); - this.gamerPoopTabPage.SuspendLayout(); - this.soundboardTabControl.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcherMain)).BeginInit(); this.SuspendLayout(); // // btnRandom @@ -109,8 +104,9 @@ // this.mainMenuPlayAll.CheckOnClick = true; this.mainMenuPlayAll.Name = "mainMenuPlayAll"; - this.mainMenuPlayAll.Size = new System.Drawing.Size(113, 22); + this.mainMenuPlayAll.Size = new System.Drawing.Size(152, 22); this.mainMenuPlayAll.Text = "Play &All"; + this.mainMenuPlayAll.Click += new System.EventHandler(this.mainMenuPlayAll_Click); // // mainMenuHelp // @@ -138,61 +134,20 @@ this.randomIterationNumericUpDown.Name = "randomIterationNumericUpDown"; this.randomIterationNumericUpDown.Size = new System.Drawing.Size(58, 20); this.randomIterationNumericUpDown.TabIndex = 4; + this.randomIterationNumericUpDown.TabStop = false; this.randomIterationNumericUpDown.Value = new decimal(new int[] { 1, 0, 0, 0}); // - // asdfMovieTabPage - // - this.asdfMovieTabPage.Controls.Add(this.asdfMovieListBox); - this.asdfMovieTabPage.Location = new System.Drawing.Point(4, 22); - this.asdfMovieTabPage.Name = "asdfMovieTabPage"; - this.asdfMovieTabPage.Padding = new System.Windows.Forms.Padding(3); - this.asdfMovieTabPage.Size = new System.Drawing.Size(410, 480); - this.asdfMovieTabPage.TabIndex = 1; - this.asdfMovieTabPage.Text = "ASDF Movie"; - this.asdfMovieTabPage.UseVisualStyleBackColor = true; - // - // asdfMovieListBox - // - this.asdfMovieListBox.FormattingEnabled = true; - this.asdfMovieListBox.Location = new System.Drawing.Point(-4, -2); - this.asdfMovieListBox.Margin = new System.Windows.Forms.Padding(0); - this.asdfMovieListBox.Name = "asdfMovieListBox"; - this.asdfMovieListBox.Size = new System.Drawing.Size(418, 485); - this.asdfMovieListBox.TabIndex = 0; - // - // gamerPoopTabPage - // - this.gamerPoopTabPage.Controls.Add(this.gamerPoopListBox); - this.gamerPoopTabPage.Location = new System.Drawing.Point(4, 22); - this.gamerPoopTabPage.Name = "gamerPoopTabPage"; - this.gamerPoopTabPage.Padding = new System.Windows.Forms.Padding(3); - this.gamerPoopTabPage.Size = new System.Drawing.Size(410, 480); - this.gamerPoopTabPage.TabIndex = 0; - this.gamerPoopTabPage.Text = "Gamer Poop"; - this.gamerPoopTabPage.UseVisualStyleBackColor = true; - // - // gamerPoopListBox - // - this.gamerPoopListBox.FormattingEnabled = true; - this.gamerPoopListBox.Location = new System.Drawing.Point(-4, -2); - this.gamerPoopListBox.Margin = new System.Windows.Forms.Padding(0); - this.gamerPoopListBox.Name = "gamerPoopListBox"; - this.gamerPoopListBox.Size = new System.Drawing.Size(418, 485); - this.gamerPoopListBox.TabIndex = 0; - // // soundboardTabControl // - this.soundboardTabControl.Controls.Add(this.gamerPoopTabPage); - this.soundboardTabControl.Controls.Add(this.asdfMovieTabPage); this.soundboardTabControl.Location = new System.Drawing.Point(7, 27); this.soundboardTabControl.Name = "soundboardTabControl"; this.soundboardTabControl.SelectedIndex = 0; this.soundboardTabControl.Size = new System.Drawing.Size(418, 506); - this.soundboardTabControl.TabIndex = 2; + this.soundboardTabControl.TabIndex = 0; // // loopSelectedSoundCheckBox // @@ -200,11 +155,16 @@ this.loopSelectedSoundCheckBox.Location = new System.Drawing.Point(158, 549); this.loopSelectedSoundCheckBox.Name = "loopSelectedSoundCheckBox"; this.loopSelectedSoundCheckBox.Size = new System.Drawing.Size(129, 17); - this.loopSelectedSoundCheckBox.TabIndex = 5; + this.loopSelectedSoundCheckBox.TabIndex = 3; this.loopSelectedSoundCheckBox.Text = "Loop Selected Sound"; this.loopSelectedSoundCheckBox.UseVisualStyleBackColor = true; this.loopSelectedSoundCheckBox.CheckedChanged += new System.EventHandler(this.loopSelectedSoundCheckBox_CheckedChanged); // + // fileSystemWatcherMain + // + this.fileSystemWatcherMain.EnableRaisingEvents = true; + this.fileSystemWatcherMain.SynchronizingObject = this; + // // formMain // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -224,9 +184,7 @@ this.mainMenu.ResumeLayout(false); this.mainMenu.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.randomIterationNumericUpDown)).EndInit(); - this.asdfMovieTabPage.ResumeLayout(false); - this.gamerPoopTabPage.ResumeLayout(false); - this.soundboardTabControl.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcherMain)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -242,14 +200,11 @@ private System.Windows.Forms.ToolStripMenuItem randSettingsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem mainMenuPlayAll; private System.Windows.Forms.ToolStripMenuItem mainMenuFileShowOnDisk; - private System.Windows.Forms.TabPage asdfMovieTabPage; - private System.Windows.Forms.ListBox asdfMovieListBox; - private System.Windows.Forms.TabPage gamerPoopTabPage; - private System.Windows.Forms.ListBox gamerPoopListBox; private System.Windows.Forms.TabControl soundboardTabControl; private System.Windows.Forms.ToolStripMenuItem mainMenuHelp; private System.Windows.Forms.ToolStripMenuItem mainMenuHelpAbout; private System.Windows.Forms.CheckBox loopSelectedSoundCheckBox; + private System.IO.FileSystemWatcher fileSystemWatcherMain; } } diff --git a/SoundBoard/mainForm.cs b/SoundBoard/mainForm.cs index a7b7c2f..c45a72a 100644 --- a/SoundBoard/mainForm.cs +++ b/SoundBoard/mainForm.cs @@ -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; + } } } diff --git a/SoundBoard/mainForm.resx b/SoundBoard/mainForm.resx index 1877780..e3e9191 100644 --- a/SoundBoard/mainForm.resx +++ b/SoundBoard/mainForm.resx @@ -120,6 +120,9 @@ 17, 17 + + 127, 17 + 43