From 2967a01cb8dc9d00c21be4b0f84a99a51713ce74 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Mon, 29 Apr 2013 16:14:24 +0200 Subject: [PATCH] Changed name of CInput to CController Added message for missing mic in partymode Removed pointless input entry for record devices --- .../CPartyScreenChallengeMain.cs | 2 + .../CPartyScreenChallengeMedleyMain.cs | 2 + Vocaluxe/Base/CConfig.cs | 99 +++++--------- Vocaluxe/Base/{CInput.cs => CController.cs} | 26 ++-- Vocaluxe/Base/CDataBase.cs | 16 +-- Vocaluxe/Base/CGraphics.cs | 10 +- Vocaluxe/Base/CLanguage.cs | 8 +- Vocaluxe/Base/CMain.cs | 8 +- Vocaluxe/Base/CSongCategorizer.cs | 30 ++-- Vocaluxe/Base/CSound.cs | 25 ++-- Vocaluxe/Base/Font/CGlyph.cs | 1 - Vocaluxe/GameModes/CGameModes.cs | 3 - .../Lib/Input/{IInput.cs => IController.cs} | 2 +- Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs | 2 +- Vocaluxe/Lib/Sound/CDirectSoundRecord.cs | 61 ++++----- Vocaluxe/Lib/Sound/CPortAudioRecord.cs | 60 ++++---- Vocaluxe/Lib/Sound/IRecord.cs | 16 +-- Vocaluxe/Program.cs | 6 +- Vocaluxe/Screens/CScreenOptionsRecord.cs | 129 ++++++------------ Vocaluxe/Screens/CScreenOptionsTheme.cs | 1 - Vocaluxe/Screens/CScreenParty.cs | 14 +- Vocaluxe/Screens/CScreenSing.cs | 2 + Vocaluxe/Screens/CScreenSong.cs | 2 + Vocaluxe/Vocaluxe.csproj | 4 +- VocaluxeLib/Menu/CBasic.cs | 6 +- VocaluxeLib/Menu/CParticle.cs | 2 + VocaluxeLib/Menu/CText.cs | 12 ++ VocaluxeLib/Menu/IMenu.cs | 2 +- VocaluxeLib/Menu/SingNotes/CNotes.cs | 16 +-- .../Menu/SongMenu/CSongMenuTileBoard.cs | 11 +- 30 files changed, 232 insertions(+), 346 deletions(-) rename Vocaluxe/Base/{CInput.cs => CController.cs} (73%) rename Vocaluxe/Lib/Input/{IInput.cs => IController.cs} (99%) diff --git a/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs b/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs index 85730d80..21a40bc0 100644 --- a/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs +++ b/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs @@ -504,7 +504,9 @@ namespace VocaluxeLib.PartyModes.Challenge _RoundsTable[i].Number.Text = (i + 1 + _RoundsTableOffset) + ")"; int pID = _GameState.ProfileIDs[_GameState.Combs[i + _RoundsTableOffset].Player[p]]; _RoundsTable[i].TextPlayer[p].Text = profile[pID].PlayerName; + // ReSharper disable ConvertIfStatementToConditionalTernaryExpression if ((_GameState.CurrentRoundNr - 1) > i + _RoundsTableOffset) + // ReSharper restore ConvertIfStatementToConditionalTernaryExpression _RoundsTable[i].TextScores[p].Text = _GameState.Results[i + _RoundsTableOffset, p].ToString(); else _RoundsTable[i].TextScores[p].Text = ""; diff --git a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs index 02343aa0..99046d1e 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs @@ -504,7 +504,9 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _RoundsTable[i].Number.Text = (i + 1 + _RoundsTableOffset) + ")"; int pID = _GameState.ProfileIDs[_GameState.Combs[i + _RoundsTableOffset].Player[p]]; _RoundsTable[i].TextPlayer[p].Text = profile[pID].PlayerName; + // ReSharper disable ConvertIfStatementToConditionalTernaryExpression if ((_GameState.CurrentRoundNr - 1) > i + _RoundsTableOffset) + // ReSharper restore ConvertIfStatementToConditionalTernaryExpression _RoundsTable[i].TextScores[p].Text = _GameState.Results[i + _RoundsTableOffset, p].ToString(); else _RoundsTable[i].TextScores[p].Text = ""; diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index f15bb95d..01fcfac2 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Text; @@ -266,7 +267,6 @@ namespace Vocaluxe.Base MicConfig[p - 1] = new SMicConfig(0); xmlReader.GetValue("//root/Record/MicConfig" + p + "/DeviceName", out MicConfig[p - 1].DeviceName, String.Empty); xmlReader.GetValue("//root/Record/MicConfig" + p + "/DeviceDriver", out MicConfig[p - 1].DeviceDriver, String.Empty); - xmlReader.GetValue("//root/Record/MicConfig" + p + "/InputName", out MicConfig[p - 1].InputName, String.Empty); xmlReader.TryGetIntValue("//root/Record/MicConfig" + p + "/Channel", ref MicConfig[p - 1].Channel); } @@ -514,13 +514,12 @@ namespace Vocaluxe.Base for (int p = 1; p <= CSettings.MaxNumPlayer; p++) { - if (MicConfig[p - 1].DeviceName != "" && MicConfig[p - 1].InputName != "" && MicConfig[p - 1].Channel > 0) + if (MicConfig[p - 1].DeviceName != "" && MicConfig[p - 1].Channel > 0) { writer.WriteStartElement("MicConfig" + p); writer.WriteElementString("DeviceName", MicConfig[p - 1].DeviceName); writer.WriteElementString("DeviceDriver", MicConfig[p - 1].DeviceDriver); - writer.WriteElementString("InputName", MicConfig[p - 1].InputName); writer.WriteElementString("Channel", MicConfig[p - 1].Channel.ToString()); writer.WriteEndElement(); @@ -563,19 +562,11 @@ namespace Vocaluxe.Base /// public static bool IsMicConfig() { - SRecordDevice[] devices = CSound.RecordGetDevices(); + ReadOnlyCollection devices = CSound.RecordGetDevices(); if (devices == null) return false; - for (int dev = 0; dev < devices.Length; dev++) - { - for (int inp = 0; inp < devices[dev].Inputs.Count; inp++) - { - if (devices[dev].Inputs[inp].PlayerChannel1 != 0 || devices[dev].Inputs[inp].PlayerChannel2 != 0) - return true; - } - } - return false; + return devices.Any(t => t.PlayerChannel1 != 0 || t.PlayerChannel2 != 0); } /// @@ -585,19 +576,11 @@ namespace Vocaluxe.Base /// public static bool IsMicConfig(int player) { - SRecordDevice[] devices = CSound.RecordGetDevices(); + ReadOnlyCollection devices = CSound.RecordGetDevices(); if (devices == null) return false; - for (int dev = 0; dev < devices.Length; dev++) - { - for (int inp = 0; inp < devices[dev].Inputs.Count; inp++) - { - if (devices[dev].Inputs[inp].PlayerChannel1 == player || devices[dev].Inputs[inp].PlayerChannel2 == player) - return true; - } - } - return false; + return devices.Any(t => t.PlayerChannel1 == player || t.PlayerChannel2 == player); } public static int GetMaxNumMics() @@ -620,65 +603,53 @@ namespace Vocaluxe.Base { //Look for (usb-)mic //SRecordDevice[] Devices = new SRecordDevice[CSound.RecordGetDevices().Length]; - SRecordDevice[] devices = CSound.RecordGetDevices(); + ReadOnlyCollection devices = CSound.RecordGetDevices(); if (devices == null) return false; - for (int dev = 0; dev < devices.Length; dev++) + foreach (CRecordDevice device in devices) { //Has Device some signal-names in name -> This could be a (usb-)mic - if (Regex.IsMatch(devices[dev].Name, "Usb|Wireless", RegexOptions.IgnoreCase)) + if (Regex.IsMatch(device.Name, "Usb|Wireless", RegexOptions.IgnoreCase)) { - //Check if there are inputs. - if (devices[dev].Inputs.Count >= 1) + //Check if there is one or more channels + if (device.Channels >= 2) { - //Check if there is one or more channels - if (devices[dev].Inputs[0].Channels >= 2) - { - //Set this device to player 1 - MicConfig[0].DeviceName = devices[dev].Name; - MicConfig[0].DeviceDriver = devices[dev].Driver; - MicConfig[0].InputName = devices[dev].Inputs[0].Name; - MicConfig[0].Channel = 1; - //Set this device to player 2 - MicConfig[1].DeviceName = devices[dev].Name; - MicConfig[1].DeviceDriver = devices[dev].Driver; - MicConfig[1].InputName = devices[dev].Inputs[0].Name; - MicConfig[1].Channel = 2; + //Set this device to player 1 + MicConfig[0].DeviceName = device.Name; + MicConfig[0].DeviceDriver = device.Driver; + MicConfig[0].Channel = 1; + //Set this device to player 2 + MicConfig[1].DeviceName = device.Name; + MicConfig[1].DeviceDriver = device.Driver; + MicConfig[1].Channel = 2; - return true; - } + return true; } } } //If no usb-mics found -> Look for Devices with "mic" or "mik" - for (int dev = 0; dev < devices.Length; dev++) + foreach (CRecordDevice device in devices) { //Has Device some signal-names in name -> This could be a mic - if (Regex.IsMatch(devices[dev].Name, "Mic|Mik", RegexOptions.IgnoreCase)) + if (Regex.IsMatch(device.Name, "Mic|Mik", RegexOptions.IgnoreCase)) { - //Check if there are inputs. - if (devices[dev].Inputs.Count >= 1) + //Check if there is one or more channels + if (device.Channels >= 1) { - //Check if there is one or more channels - if (devices[dev].Inputs[0].Channels >= 1) + //Set this device to player 1 + MicConfig[0].DeviceName = device.Name; + MicConfig[0].DeviceDriver = device.Driver; + MicConfig[0].Channel = 1; + + if (device.Channels >= 2) { - //Set this device to player 1 - MicConfig[0].DeviceName = devices[dev].Name; - MicConfig[0].DeviceDriver = devices[dev].Driver; - MicConfig[0].InputName = devices[dev].Inputs[0].Name; - MicConfig[0].Channel = 1; + //Set this device to player 2 + MicConfig[1].DeviceName = device.Name; + MicConfig[1].DeviceDriver = device.Driver; + MicConfig[1].Channel = 2; - if (devices[dev].Inputs[0].Channels >= 2) - { - //Set this device to player 2 - MicConfig[1].DeviceName = devices[dev].Name; - MicConfig[1].DeviceDriver = devices[dev].Driver; - MicConfig[1].InputName = devices[dev].Inputs[0].Name; - MicConfig[1].Channel = 2; - - return true; - } + return true; } } } diff --git a/Vocaluxe/Base/CInput.cs b/Vocaluxe/Base/CController.cs similarity index 73% rename from Vocaluxe/Base/CInput.cs rename to Vocaluxe/Base/CController.cs index 84632970..5014eef8 100644 --- a/Vocaluxe/Base/CInput.cs +++ b/Vocaluxe/Base/CController.cs @@ -23,56 +23,56 @@ using VocaluxeLib.Menu; namespace Vocaluxe.Base { - static class CInput + static class CController { - private static IInput _Input; + private static IController _Controller; public static void Init() { - _Input = new CWiiMote(); + _Controller = new CWiiMote(); - _Input.Init(); + _Controller.Init(); } public static void Close() { - _Input.Close(); - _Input = null; + _Controller.Close(); + _Controller = null; } public static void Connect() { - _Input.Connect(); + _Controller.Connect(); } public static void Disconnect() { - _Input.Disconnect(); + _Controller.Disconnect(); } public static bool IsConnected() { - return _Input.IsConnected(); + return _Controller.IsConnected(); } public static void Update() { - _Input.Update(); + _Controller.Update(); } public static bool PollKeyEvent(ref SKeyEvent keyEvent) { - return _Input.PollKeyEvent(ref keyEvent); + return _Controller.PollKeyEvent(ref keyEvent); } public static bool PollMouseEvent(ref SMouseEvent mouseEvent) { - return _Input.PollMouseEvent(ref mouseEvent); + return _Controller.PollMouseEvent(ref mouseEvent); } public static void SetRumble(float duration) { - _Input.SetRumble(duration); + _Controller.SetRumble(duration); } } } \ No newline at end of file diff --git a/Vocaluxe/Base/CDataBase.cs b/Vocaluxe/Base/CDataBase.cs index 7d9ecdda..79ae5999 100644 --- a/Vocaluxe/Base/CDataBase.cs +++ b/Vocaluxe/Base/CDataBase.cs @@ -708,17 +708,9 @@ namespace Vocaluxe.Base } //This is a USDX 1.01 DB - if (!dateExists) - { - command.CommandText = - "INSERT INTO Scores (SongID, PlayerName, Score, LineNr, Date, Medley, Duet, Difficulty) SELECT SongID, Player, Score, '0', '0', '0', '0', Difficulty from US_Scores"; - } - else - { - // This is a CMD 1.01 DB - command.CommandText = - "INSERT INTO Scores (SongID, PlayerName, Score, LineNr, Date, Medley, Duet, Difficulty) SELECT SongID, Player, Score, '0', Date, '0', '0', Difficulty from US_Scores"; - } + command.CommandText = !dateExists + ? "INSERT INTO Scores (SongID, PlayerName, Score, LineNr, Date, Medley, Duet, Difficulty) SELECT SongID, Player, Score, '0', '0', '0', '0', Difficulty from US_Scores" + : "INSERT INTO Scores (SongID, PlayerName, Score, LineNr, Date, Medley, Duet, Difficulty) SELECT SongID, Player, Score, '0', Date, '0', '0', Difficulty from US_Scores"; command.ExecuteNonQuery(); command.CommandText = "INSERT INTO Songs SELECT ID, Artist, Title, TimesPlayed from US_Songs"; @@ -763,7 +755,9 @@ namespace Vocaluxe.Base stmt = new Sqlite3.Vdbe(); + // ReSharper disable ConvertIfStatementToConditionalTernaryExpression if (!dateExists) + // ReSharper restore ConvertIfStatementToConditionalTernaryExpression res = Sqlite3.sqlite3_prepare_v2(oldDB, "SELECT id, PlayerName FROM Scores", -1, ref stmt, 0); else res = Sqlite3.sqlite3_prepare_v2(oldDB, "SELECT id, PlayerName, Date FROM Scores", -1, ref stmt, 0); diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index 23e0c7ec..a7f03f65 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -320,7 +320,7 @@ namespace Vocaluxe.Base CVideo.Update(); CSound.Update(); CBackgroundMusic.Update(); - CInput.Update(); + CController.Update(); if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && _CurrentScreen != EScreens.ScreenSing) CSongs.LoadCover(); @@ -512,7 +512,7 @@ namespace Vocaluxe.Base bool resume = true; bool eventsAvailable; - bool inputEventsAvailable = CInput.PollKeyEvent(ref inputKeyEvent); + bool inputEventsAvailable = CController.PollKeyEvent(ref inputKeyEvent); while ((eventsAvailable = keys.PollEvent(ref keyEvent)) || inputEventsAvailable) { @@ -617,10 +617,10 @@ namespace Vocaluxe.Base } if (!eventsAvailable) - inputEventsAvailable = CInput.PollKeyEvent(ref inputKeyEvent); + inputEventsAvailable = CController.PollKeyEvent(ref inputKeyEvent); } - inputEventsAvailable = CInput.PollMouseEvent(ref inputMouseEvent); + inputEventsAvailable = CController.PollMouseEvent(ref inputMouseEvent); while ((eventsAvailable = mouse.PollEvent(ref mouseEvent)) || inputEventsAvailable) { @@ -678,7 +678,7 @@ namespace Vocaluxe.Base resume &= _Screens[(int)_CurrentScreen].HandleMouse(mouseEvent); if (!eventsAvailable) - inputEventsAvailable = CInput.PollMouseEvent(ref inputMouseEvent); + inputEventsAvailable = CController.PollMouseEvent(ref inputMouseEvent); } return resume; } diff --git a/Vocaluxe/Base/CLanguage.cs b/Vocaluxe/Base/CLanguage.cs index c9024d67..fa48225c 100644 --- a/Vocaluxe/Base/CLanguage.cs +++ b/Vocaluxe/Base/CLanguage.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using System.Xml; using VocaluxeLib.Menu; @@ -168,12 +169,7 @@ namespace Vocaluxe.Base List files = new List(); files.AddRange(CHelper.ListFiles(path, "*.xml", true, true)); - foreach (string file in files) - { - if (!_LoadPartyLanguageFile(partyModeID, file)) - return false; - } - return true; + return files.All(file => _LoadPartyLanguageFile(partyModeID, file)); } private static bool _LoadLanguageEntries(CXMLReader xmlReader, out Dictionary texts) diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index e894da18..4f959225 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -46,13 +46,13 @@ namespace Vocaluxe.Base private static readonly ISound _Sound = new CBsound(); private static readonly ICover _Cover = new CBcover(); private static readonly IDataBase _DataBase = new CBdataBase(); - private static readonly IInputs _Input = new CBinputs(); + private static readonly IControllers _Controller = new CBcontrollers(); private static readonly IPlaylist _Playlist = new CBplaylist(); public static void Init() { CBase.Assign(_Config, _Settings, _Theme, _Log, _BackgroundMusic, _Draw, _Graphics, _Fonts, _Language, - _Game, _Profiles, _Record, _Songs, _Video, _Sound, _Cover, _DataBase, _Input, _Playlist); + _Game, _Profiles, _Record, _Songs, _Video, _Sound, _Cover, _DataBase, _Controller, _Playlist); } } @@ -770,11 +770,11 @@ namespace Vocaluxe.Base } } - class CBinputs : IInputs + class CBcontrollers : IControllers { public void SetRumble(float duration) { - CInput.SetRumble(duration); + CController.SetRumble(duration); } } diff --git a/Vocaluxe/Base/CSongCategorizer.cs b/Vocaluxe/Base/CSongCategorizer.cs index d442bd20..db61fe26 100644 --- a/Vocaluxe/Base/CSongCategorizer.cs +++ b/Vocaluxe/Base/CSongCategorizer.cs @@ -67,17 +67,17 @@ namespace Vocaluxe.Base { CCategory lastCategory = null; CCategory notLetterCat = null; - for (int i = 0; i < CSongs.Sorter.SortedSongs.Length; i++) + foreach (CSongPointer songPointer in CSongs.Sorter.SortedSongs) { - Char firstLetter = Char.ToUpper(CSongs.Sorter.SortedSongs[i].SortString.Normalize(NormalizationForm.FormD)[0]); + Char firstLetter = Char.ToUpper(songPointer.SortString.Normalize(NormalizationForm.FormD)[0]); if (Char.IsLetter(firstLetter)) { - if (lastCategory == null || CSongs.Sorter.SortedSongs[i].SortString != lastCategory.Name) + if (lastCategory == null || songPointer.SortString != lastCategory.Name) { - lastCategory = new CCategory(CSongs.Sorter.SortedSongs[i].SortString); + lastCategory = new CCategory(songPointer.SortString); _Categories.Add(lastCategory); } - lastCategory.Songs.Add(CSongs.Sorter.SortedSongs[i]); + lastCategory.Songs.Add(songPointer); } else { @@ -86,7 +86,7 @@ namespace Vocaluxe.Base notLetterCat = new CCategory("#"); _Categories.Add(notLetterCat); } - notLetterCat.Songs.Add(CSongs.Sorter.SortedSongs[i]); + notLetterCat.Songs.Add(songPointer); } } } @@ -95,16 +95,16 @@ namespace Vocaluxe.Base { CCategory lastCategory = null; CCategory noCategory = null; - for (int i = 0; i < CSongs.Sorter.SortedSongs.Length; i++) + foreach (CSongPointer songPointer in CSongs.Sorter.SortedSongs) { - if (CSongs.Sorter.SortedSongs[i].SortString != "") + if (songPointer.SortString != "") { - if (lastCategory == null || CSongs.Sorter.SortedSongs[i].SortString != lastCategory.Name) + if (lastCategory == null || songPointer.SortString != lastCategory.Name) { - lastCategory = new CCategory(CSongs.Sorter.SortedSongs[i].SortString); + lastCategory = new CCategory(songPointer.SortString); _Categories.Add(lastCategory); } - lastCategory.Songs.Add(CSongs.Sorter.SortedSongs[i]); + lastCategory.Songs.Add(songPointer); } else { @@ -113,7 +113,7 @@ namespace Vocaluxe.Base noCategory = new CCategory(noCategoryName); _Categories.Add(noCategory); } - noCategory.Songs.Add(CSongs.Sorter.SortedSongs[i]); + noCategory.Songs.Add(songPointer); } } } @@ -149,13 +149,13 @@ namespace Vocaluxe.Base { if (sorting == ESongSorting.TR_CONFIG_DECADE) { - for (int i = 0; i < CSongs.Sorter.SortedSongs.Length; i++) + foreach (CSongPointer songPointer in CSongs.Sorter.SortedSongs) { - string year = CSongs.Sorter.SortedSongs[i].SortString; + string year = songPointer.SortString; if (year != "") { year = year.Substring(0, 3); - CSongs.Sorter.SortedSongs[i].SortString = year + "0 - " + year + "9"; + songPointer.SortString = year + "0 - " + year + "9"; } } } diff --git a/Vocaluxe/Base/CSound.cs b/Vocaluxe/Base/CSound.cs index 70b0e598..1ac824a7 100644 --- a/Vocaluxe/Base/CSound.cs +++ b/Vocaluxe/Base/CSound.cs @@ -18,6 +18,7 @@ #endregion using System; +using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using Vocaluxe.Lib.Sound; @@ -226,9 +227,7 @@ namespace Vocaluxe.Base public static bool RecordStart() { - SRecordDevice[] devices = RecordGetDevices(); - - return _Record.Start(devices); + return _Record.Start(); } public static bool RecordStop() @@ -276,23 +275,16 @@ namespace Vocaluxe.Base return _Record.ToneWeigth(player); } - public static SRecordDevice[] RecordGetDevices() + public static ReadOnlyCollection RecordGetDevices() { - SRecordDevice[] devices = _Record.RecordDevices(); + ReadOnlyCollection devices = _Record.RecordDevices(); if (devices != null) { - for (int dev = 0; dev < devices.Length; dev++) + foreach (CRecordDevice device in devices) { - for (int inp = 0; inp < devices[dev].Inputs.Count; inp++) - { - SInput input = devices[dev].Inputs[inp]; - - input.PlayerChannel1 = _GetPlayerFromMicConfig(devices[dev].Name, devices[dev].Driver, input.Name, 1); - input.PlayerChannel2 = _GetPlayerFromMicConfig(devices[dev].Name, devices[dev].Driver, input.Name, 2); - - devices[dev].Inputs[inp] = input; - } + device.PlayerChannel1 = _GetPlayerFromMicConfig(device.Name, device.Driver, 1); + device.PlayerChannel2 = _GetPlayerFromMicConfig(device.Name, device.Driver, 2); } return devices; } @@ -300,14 +292,13 @@ namespace Vocaluxe.Base return null; } - private static int _GetPlayerFromMicConfig(string device, string devicedriver, string input, int channel) + private static int _GetPlayerFromMicConfig(string device, string devicedriver, int channel) { for (int p = 0; p < CSettings.MaxNumPlayer; p++) { if (CConfig.MicConfig[p].Channel != 0 && CConfig.MicConfig[p].DeviceName == device && CConfig.MicConfig[p].DeviceDriver == devicedriver && - CConfig.MicConfig[p].InputName == input && CConfig.MicConfig[p].Channel == channel) return p + 1; } diff --git a/Vocaluxe/Base/Font/CGlyph.cs b/Vocaluxe/Base/Font/CGlyph.cs index c9cfe58b..a8b5bdc8 100644 --- a/Vocaluxe/Base/Font/CGlyph.cs +++ b/Vocaluxe/Base/Font/CGlyph.cs @@ -20,7 +20,6 @@ using System; using System.Drawing; using System.Drawing.Drawing2D; -using System.Drawing.Imaging; using System.Drawing.Text; using System.Windows.Forms; using VocaluxeLib.Menu; diff --git a/Vocaluxe/GameModes/CGameModes.cs b/Vocaluxe/GameModes/CGameModes.cs index a29847a0..822d599e 100644 --- a/Vocaluxe/GameModes/CGameModes.cs +++ b/Vocaluxe/GameModes/CGameModes.cs @@ -17,10 +17,7 @@ // */ #endregion -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using Vocaluxe.Base; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; diff --git a/Vocaluxe/Lib/Input/IInput.cs b/Vocaluxe/Lib/Input/IController.cs similarity index 99% rename from Vocaluxe/Lib/Input/IInput.cs rename to Vocaluxe/Lib/Input/IController.cs index a78a5018..f54c25bf 100644 --- a/Vocaluxe/Lib/Input/IInput.cs +++ b/Vocaluxe/Lib/Input/IController.cs @@ -32,7 +32,7 @@ namespace Vocaluxe.Lib.Input ScrollUp } - interface IInput + interface IController { void Init(); void Close(); diff --git a/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs b/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs index 867458d6..2ff404d1 100644 --- a/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs +++ b/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs @@ -27,7 +27,7 @@ using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Input.WiiMote { - class CWiiMote : IInput, IDisposable + class CWiiMote : IController, IDisposable { private CWiiMoteLib _WiiMote; diff --git a/Vocaluxe/Lib/Sound/CDirectSoundRecord.cs b/Vocaluxe/Lib/Sound/CDirectSoundRecord.cs index 746e4bca..fad206a4 100644 --- a/Vocaluxe/Lib/Sound/CDirectSoundRecord.cs +++ b/Vocaluxe/Lib/Sound/CDirectSoundRecord.cs @@ -17,6 +17,7 @@ // */ #endregion +using System.Collections.ObjectModel; using SlimDX.DirectSound; using SlimDX.Multimedia; using System; @@ -29,8 +30,7 @@ namespace Vocaluxe.Lib.Sound class CDirectSoundRecord : IRecord { private bool _Initialized; - private List _Devices; - private SRecordDevice[] _DeviceConfig; + private List _Devices; private List _Sources; private readonly CBuffer[] _Buffer; @@ -47,7 +47,7 @@ namespace Vocaluxe.Lib.Sound public bool Init() { DeviceCollection devices = DirectSoundCapture.GetDevices(); - _Devices = new List(); + _Devices = new List(); _Sources = new List(); int id = 0; @@ -55,21 +55,17 @@ namespace Vocaluxe.Lib.Sound { using (DirectSoundCapture ds = new DirectSoundCapture(dev.DriverGuid)) { - SRecordDevice device = new SRecordDevice {Driver = dev.DriverGuid.ToString(), ID = id, Name = dev.Description, Inputs = new List()}; + CRecordDevice device = new CRecordDevice {Driver = dev.DriverGuid.ToString(), ID = id, Name = dev.Description, Channels = ds.Capabilities.Channels}; - SInput inp = new SInput {Name = "Default", Channels = ds.Capabilities.Channels}; + if (device.Channels > 2) + device.Channels = 2; //more are not supported in vocaluxe - if (inp.Channels > 2) - inp.Channels = 2; //more are not supported in vocaluxe - - device.Inputs.Add(inp); _Devices.Add(device); id++; } } - _DeviceConfig = _Devices.ToArray(); _Initialized = true; return true; @@ -85,7 +81,7 @@ namespace Vocaluxe.Lib.Sound //System.IO.File.WriteAllBytes("test0.raw", _Buffer[0].Buffer); } - public bool Start(SRecordDevice[] deviceConfig) + public bool Start() { if (!_Initialized) return false; @@ -93,21 +89,16 @@ namespace Vocaluxe.Lib.Sound foreach (CBuffer buffer in _Buffer) buffer.Reset(); - _DeviceConfig = deviceConfig; - bool[] active = new bool[deviceConfig.Length]; - Guid[] guid = new Guid[deviceConfig.Length]; - short[] channels = new short[deviceConfig.Length]; - for (int dev = 0; dev < deviceConfig.Length; dev++) + bool[] active = new bool[_Devices.Count]; + Guid[] guid = new Guid[_Devices.Count]; + short[] channels = new short[_Devices.Count]; + for (int dev = 0; dev < _Devices.Count; dev++) { active[dev] = false; - for (int inp = 0; inp < deviceConfig[dev].Inputs.Count; inp++) - { - if (deviceConfig[dev].Inputs[inp].PlayerChannel1 > 0 || - deviceConfig[dev].Inputs[inp].PlayerChannel2 > 0) - active[dev] = true; - guid[dev] = new Guid(deviceConfig[dev].Driver); - channels[dev] = (short)deviceConfig[dev].Inputs[0].Channels; - } + if (_Devices[dev].PlayerChannel1 > 0 || _Devices[dev].PlayerChannel2 > 0) + active[dev] = true; + guid[dev] = new Guid(_Devices[dev].Driver); + channels[dev] = (short)_Devices[dev].Channels; } for (int i = 0; i < _Devices.Count; i++) @@ -121,8 +112,6 @@ namespace Vocaluxe.Lib.Sound _Sources.Add(source); } } - - _DeviceConfig = deviceConfig; return true; } @@ -189,7 +178,7 @@ namespace Vocaluxe.Lib.Sound return _Buffer[player].ToneValid; } - public SRecordDevice[] RecordDevices() + public ReadOnlyCollection RecordDevices() { if (!_Initialized) return null; @@ -197,7 +186,7 @@ namespace Vocaluxe.Lib.Sound if (_Devices.Count == 0) return null; - return _Devices.ToArray(); + return _Devices.AsReadOnly(); } public int NumHalfTones(int player) @@ -232,21 +221,21 @@ namespace Vocaluxe.Lib.Sound rightBuffer[i] = e.Data[i * 2 - (i % 2) + 2]; } - for (int i = 0; i < _DeviceConfig.Length; i++) + foreach (CRecordDevice device in _Devices) { - if (_DeviceConfig[i].Driver == e.Guid.ToString()) + if (device.Driver == e.Guid.ToString()) { - if (_DeviceConfig[i].Inputs[0].PlayerChannel1 > 0) - _Buffer[_DeviceConfig[i].Inputs[0].PlayerChannel1 - 1].ProcessNewBuffer(leftBuffer); + if (device.PlayerChannel1 > 0) + _Buffer[device.PlayerChannel1 - 1].ProcessNewBuffer(leftBuffer); - if (_DeviceConfig[i].Inputs[0].PlayerChannel2 > 0) - _Buffer[_DeviceConfig[i].Inputs[0].PlayerChannel2 - 1].ProcessNewBuffer(rightBuffer); + if (device.PlayerChannel2 > 0) + _Buffer[device.PlayerChannel2 - 1].ProcessNewBuffer(rightBuffer); } } } } - public class CSampleDataEventArgs : EventArgs + private class CSampleDataEventArgs : EventArgs { public CSampleDataEventArgs(byte[] data, Guid guid) { @@ -258,7 +247,7 @@ namespace Vocaluxe.Lib.Sound public Guid Guid { get; private set; } } - public class CSoundCardSource : IDisposable + private class CSoundCardSource : IDisposable { private volatile bool _Running; private readonly int _BufferSize; diff --git a/Vocaluxe/Lib/Sound/CPortAudioRecord.cs b/Vocaluxe/Lib/Sound/CPortAudioRecord.cs index 5508dfce..0f51fa31 100644 --- a/Vocaluxe/Lib/Sound/CPortAudioRecord.cs +++ b/Vocaluxe/Lib/Sound/CPortAudioRecord.cs @@ -17,6 +17,7 @@ // */ #endregion +using System.Collections.ObjectModel; using System.Threading; using System; using System.Collections.Generic; @@ -29,8 +30,7 @@ namespace Vocaluxe.Lib.Sound class CPortAudioRecord : IRecord { private bool _Initialized; - private List _Devices; - private SRecordDevice[] _DeviceConfig; + private List _Devices; private CPortAudio.PaStreamCallbackDelegate _MyRecProc; private IntPtr[] _RecHandle; @@ -39,7 +39,7 @@ namespace Vocaluxe.Lib.Sound public CPortAudioRecord() { - _DeviceConfig = null; + _Devices = null; _Buffer = new CBuffer[CSettings.MaxNumPlayer]; for (int i = 0; i < _Buffer.Length; i++) @@ -54,7 +54,7 @@ namespace Vocaluxe.Lib.Sound /// true if success public bool Init() { - _Devices = new List(); + _Devices = new List(); try { @@ -73,22 +73,17 @@ namespace Vocaluxe.Lib.Sound CPortAudio.SPaDeviceInfo info = CPortAudio.PaGetDeviceInfo(i); if (info.HostApi == hostAPI && info.MaxInputChannels > 0) { - SRecordDevice dev = new SRecordDevice {ID = i, Name = info.Name, Driver = info.Name + i, Inputs = new List()}; + CRecordDevice dev = new CRecordDevice {ID = i, Name = info.Name, Driver = info.Name + i, Channels = info.MaxInputChannels}; - SInput inp = new SInput {Name = "Default", Channels = info.MaxInputChannels}; + if (dev.Channels > 2) + dev.Channels = 2; //more are not supported in vocaluxe - if (inp.Channels > 2) - inp.Channels = 2; //more are not supported in vocaluxe - - dev.Inputs.Add(inp); _Devices.Add(dev); } } _RecHandle = new IntPtr[_Devices.Count]; - _MyRecProc = MyPaStreamCallback; - - _DeviceConfig = _Devices.ToArray(); + _MyRecProc = _MyPaStreamCallback; } catch (Exception e) { @@ -103,16 +98,12 @@ namespace Vocaluxe.Lib.Sound /// /// Start Voice Capturing /// - /// /// - public bool Start(SRecordDevice[] deviceConfig) + public bool Start() { if (!_Initialized) return false; - if (deviceConfig == null) - return false; - if (_RecHandle == null || _RecHandle.Length == 0) return false; @@ -132,17 +123,12 @@ namespace Vocaluxe.Lib.Sound for (int i = 0; i < _RecHandle.Length; i++) _RecHandle[i] = IntPtr.Zero; - _DeviceConfig = deviceConfig; - bool[] active = new bool[deviceConfig.Length]; - for (int dev = 0; dev < deviceConfig.Length; dev++) + bool[] active = new bool[_Devices.Count]; + for (int dev = 0; dev < _Devices.Count; dev++) { active[dev] = false; - for (int inp = 0; inp < deviceConfig[dev].Inputs.Count; inp++) - { - if (deviceConfig[dev].Inputs[inp].PlayerChannel1 > 0 || - deviceConfig[dev].Inputs[inp].PlayerChannel2 > 0) - active[dev] = true; - } + if (_Devices[dev].PlayerChannel1 > 0 || _Devices[dev].PlayerChannel2 > 0) + active[dev] = true; } for (int i = 0; i < _RecHandle.Length; i++) @@ -151,10 +137,10 @@ namespace Vocaluxe.Lib.Sound { CPortAudio.SPaStreamParameters inputParams = new CPortAudio.SPaStreamParameters { - ChannelCount = _DeviceConfig[i].Inputs[0].Channels, - Device = _DeviceConfig[i].ID, + ChannelCount = _Devices[i].Channels, + Device = _Devices[i].ID, SampleFormat = CPortAudio.EPaSampleFormat.PaInt16, - SuggestedLatency = CPortAudio.PaGetDeviceInfo(_DeviceConfig[i].ID).DefaultLowInputLatency + SuggestedLatency = CPortAudio.PaGetDeviceInfo(_Devices[i].ID).DefaultLowInputLatency }; if (_ErrorCheck("OpenStream (rec)", CPortAudio.Pa_OpenStream( @@ -273,7 +259,7 @@ namespace Vocaluxe.Lib.Sound return _Buffer[player].ToneWeigth; } - public SRecordDevice[] RecordDevices() + public ReadOnlyCollection RecordDevices() { if (!_Initialized) return null; @@ -281,10 +267,10 @@ namespace Vocaluxe.Lib.Sound if (_Devices.Count == 0) return null; - return _Devices.ToArray(); + return _Devices.AsReadOnly(); } - public CPortAudio.EPaStreamCallbackResult MyPaStreamCallback( + private CPortAudio.EPaStreamCallbackResult _MyPaStreamCallback( IntPtr input, IntPtr output, uint frameCount, @@ -315,11 +301,11 @@ namespace Vocaluxe.Lib.Sound { if (new IntPtr(i) == userData) { - if (_DeviceConfig[i].Inputs[0].PlayerChannel1 > 0) - _Buffer[_DeviceConfig[i].Inputs[0].PlayerChannel1 - 1].ProcessNewBuffer(leftBuffer); + if (_Devices[i].PlayerChannel1 > 0) + _Buffer[_Devices[i].PlayerChannel1 - 1].ProcessNewBuffer(leftBuffer); - if (_DeviceConfig[i].Inputs[0].PlayerChannel2 > 0) - _Buffer[_DeviceConfig[i].Inputs[0].PlayerChannel2 - 1].ProcessNewBuffer(rightBuffer); + if (_Devices[i].PlayerChannel2 > 0) + _Buffer[_Devices[i].PlayerChannel2 - 1].ProcessNewBuffer(rightBuffer); break; } diff --git a/Vocaluxe/Lib/Sound/IRecord.cs b/Vocaluxe/Lib/Sound/IRecord.cs index 2246f3e3..e7de0ce8 100644 --- a/Vocaluxe/Lib/Sound/IRecord.cs +++ b/Vocaluxe/Lib/Sound/IRecord.cs @@ -18,23 +18,17 @@ #endregion using System; -using System.Collections.Generic; +using System.Collections.ObjectModel; namespace Vocaluxe.Lib.Sound { - struct SRecordDevice + class CRecordDevice { public int ID; public string Name; public string Driver; - public List Inputs; - } - struct SInput - { - public string Name; public int Channels; - public int PlayerChannel1; public int PlayerChannel2; } @@ -43,7 +37,6 @@ namespace Vocaluxe.Lib.Sound { public string DeviceName; public string DeviceDriver; - public string InputName; public int Channel; // ReSharper disable UnusedParameter.Local @@ -52,7 +45,6 @@ namespace Vocaluxe.Lib.Sound { DeviceName = String.Empty; DeviceDriver = String.Empty; - InputName = String.Empty; Channel = 0; } } @@ -62,7 +54,7 @@ namespace Vocaluxe.Lib.Sound bool Init(); void CloseAll(); - bool Start(SRecordDevice[] deviceConfig); + bool Start(); bool Stop(); void AnalyzeBuffer(int player); @@ -74,6 +66,6 @@ namespace Vocaluxe.Lib.Sound int NumHalfTones(int player); float[] ToneWeigth(int player); - SRecordDevice[] RecordDevices(); + ReadOnlyCollection RecordDevices(); } } \ No newline at end of file diff --git a/Vocaluxe/Program.cs b/Vocaluxe/Program.cs index 75845cb1..5f204724 100644 --- a/Vocaluxe/Program.cs +++ b/Vocaluxe/Program.cs @@ -185,8 +185,8 @@ namespace Vocaluxe // Init Input CLog.StartBenchmark(0, "Init Input"); - CInput.Init(); - CInput.Connect(); + CController.Init(); + CController.Connect(); CLog.StopBenchmark(0, "Init Input"); // Init Game; @@ -220,7 +220,7 @@ namespace Vocaluxe try { CLog.CloseAll(); - CInput.Close(); + CController.Close(); CSound.RecordCloseAll(); CSound.CloseAllStreams(); CVideo.VdCloseAll(); diff --git a/Vocaluxe/Screens/CScreenOptionsRecord.cs b/Vocaluxe/Screens/CScreenOptionsRecord.cs index a1ced44f..ae4d785c 100644 --- a/Vocaluxe/Screens/CScreenOptionsRecord.cs +++ b/Vocaluxe/Screens/CScreenOptionsRecord.cs @@ -18,6 +18,7 @@ #endregion using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Diagnostics; using System.Windows.Forms; using Vocaluxe.Base; @@ -42,7 +43,6 @@ namespace Vocaluxe.Screens private const float _MaxDelayTime = 1f; private const string _SelectSlideRecordDevices = "SelectSlideRecordDevices"; - private const string _SelectSlideRecordInputs = "SelectSlideRecordInputs"; private const string _SelectSlideRecordChannel1 = "SelectSlideRecordChannel1"; private const string _SelectSlideRecordChannel2 = "SelectSlideRecordChannel2"; @@ -63,9 +63,8 @@ namespace Vocaluxe.Screens private readonly string[] _StaticEnergyChannel = new string[] {"StaticEnergyChannel1", "StaticEnergyChannel2"}; private float[] _ChannelEnergy; - private SRecordDevice[] _Devices; + private ReadOnlyCollection _Devices; private int _DeviceNr; - private int _InputNr; private SDelayTest[] _DelayTest; private bool _DelayTestRunning; @@ -81,7 +80,7 @@ namespace Vocaluxe.Screens _ThemeTexts = new string[] {_TextWarning, _TextDelayChannel1, _TextDelayChannel2}; _ThemeButtons = new string[] {_ButtonExit, _ButtonDelayTest}; - _ThemeSelectSlides = new string[] {_SelectSlideRecordDevices, _SelectSlideRecordInputs, _SelectSlideRecordChannel1, _SelectSlideRecordChannel2, _SelectSlideDelay}; + _ThemeSelectSlides = new string[] {_SelectSlideRecordDevices, _SelectSlideRecordChannel1, _SelectSlideRecordChannel2, _SelectSlideDelay}; _ThemeEqualizers = new string[] {_EqualizerChannel1, _EqualizerChannel2}; } @@ -160,9 +159,6 @@ namespace Vocaluxe.Screens if (_SelectSlides[_SelectSlideRecordDevices].Selected) _OnDeviceEvent(); - if (_SelectSlides[_SelectSlideRecordInputs].Selected) - _OnInputEvent(); - if (_SelectSlides[_SelectSlideRecordChannel1].Selected || _SelectSlides[_SelectSlideRecordChannel2].Selected) _SetMicConfig(); @@ -175,9 +171,6 @@ namespace Vocaluxe.Screens if (_SelectSlides[_SelectSlideRecordDevices].Selected) _OnDeviceEvent(); - if (_SelectSlides[_SelectSlideRecordInputs].Selected) - _OnInputEvent(); - if (_SelectSlides[_SelectSlideRecordChannel1].Selected || _SelectSlides[_SelectSlideRecordChannel2].Selected) _SetMicConfig(); @@ -205,9 +198,6 @@ namespace Vocaluxe.Screens if (_SelectSlides[_SelectSlideRecordDevices].Selected) _OnDeviceEvent(); - if (_SelectSlides[_SelectSlideRecordInputs].Selected) - _OnInputEvent(); - if (_SelectSlides[_SelectSlideRecordChannel1].Selected || _SelectSlides[_SelectSlideRecordChannel2].Selected) _SetMicConfig(); @@ -311,28 +301,22 @@ namespace Vocaluxe.Screens base.OnShow(); _SelectSlides[_SelectSlideRecordDevices].Clear(); - _SelectSlides[_SelectSlideRecordInputs].Clear(); for (int i = 0; i < _ChannelEnergy.Length; i++) _ChannelEnergy[i] = 0f; _DeviceNr = -1; - _InputNr = -1; _Devices = CSound.RecordGetDevices(); if (_Devices != null) { _DeviceNr = 0; - _InputNr = 0; - _GetFirstConfiguredRecordDevice(ref _DeviceNr, ref _InputNr); + _GetFirstConfiguredRecordDevice(ref _DeviceNr); - for (int dev = 0; dev < _Devices.Length; dev++) - _SelectSlides[_SelectSlideRecordDevices].AddValue(_Devices[dev].Name); + foreach (CRecordDevice device in _Devices) + _SelectSlides[_SelectSlideRecordDevices].AddValue(device.Name); _SelectSlides[_SelectSlideRecordDevices].Selection = _DeviceNr; - for (int inp = 0; inp < _Devices[0].Inputs.Count; inp++) - _SelectSlides[_SelectSlideRecordInputs].AddValue(_Devices[0].Inputs[inp].Name); - _SelectSlides[_SelectSlideRecordInputs].Selection = _InputNr; _UpdateChannels(); } @@ -416,24 +400,7 @@ namespace Vocaluxe.Screens { if (_SelectSlides[_SelectSlideRecordDevices].Selection != _DeviceNr) { - _SelectSlides[_SelectSlideRecordInputs].Clear(); _DeviceNr = _SelectSlides[_SelectSlideRecordDevices].Selection; - _InputNr = 0; - - for (int inp = 0; inp < _Devices[_DeviceNr].Inputs.Count; inp++) - _SelectSlides[_SelectSlideRecordInputs].AddValue(_Devices[_DeviceNr].Inputs[inp].Name); - _InputNr = 0; - _SelectSlides[_SelectSlideRecordInputs].Selection = 0; - _UpdateChannels(); - } - } - - private void _OnInputEvent() - { - if (_SelectSlides[_SelectSlideRecordInputs].Selection != _InputNr) - { - _InputNr = _SelectSlides[_SelectSlideRecordInputs].Selection; - _UpdateChannels(); } } @@ -457,25 +424,20 @@ namespace Vocaluxe.Screens for (int p = 0; p < CSettings.MaxNumPlayer; p++) CConfig.MicConfig[p].Channel = 0; - for (int dev = 0; dev < _Devices.Length; dev++) + foreach (CRecordDevice device in _Devices) { - for (int inp = 0; inp < _Devices[dev].Inputs.Count; inp++) + if (device.PlayerChannel1 > 0) { - if (_Devices[dev].Inputs[inp].PlayerChannel1 > 0) - { - CConfig.MicConfig[_Devices[dev].Inputs[inp].PlayerChannel1 - 1].Channel = 1; - CConfig.MicConfig[_Devices[dev].Inputs[inp].PlayerChannel1 - 1].DeviceName = _Devices[dev].Name; - CConfig.MicConfig[_Devices[dev].Inputs[inp].PlayerChannel1 - 1].DeviceDriver = _Devices[dev].Driver; - CConfig.MicConfig[_Devices[dev].Inputs[inp].PlayerChannel1 - 1].InputName = _Devices[dev].Inputs[inp].Name; - } + CConfig.MicConfig[device.PlayerChannel1 - 1].Channel = 1; + CConfig.MicConfig[device.PlayerChannel1 - 1].DeviceName = device.Name; + CConfig.MicConfig[device.PlayerChannel1 - 1].DeviceDriver = device.Driver; + } - if (_Devices[dev].Inputs[inp].PlayerChannel2 > 0) - { - CConfig.MicConfig[_Devices[dev].Inputs[inp].PlayerChannel2 - 1].Channel = 2; - CConfig.MicConfig[_Devices[dev].Inputs[inp].PlayerChannel2 - 1].DeviceName = _Devices[dev].Name; - CConfig.MicConfig[_Devices[dev].Inputs[inp].PlayerChannel2 - 1].DeviceDriver = _Devices[dev].Driver; - CConfig.MicConfig[_Devices[dev].Inputs[inp].PlayerChannel2 - 1].InputName = _Devices[dev].Inputs[inp].Name; - } + if (device.PlayerChannel2 > 0) + { + CConfig.MicConfig[device.PlayerChannel2 - 1].Channel = 2; + CConfig.MicConfig[device.PlayerChannel2 - 1].DeviceName = device.Name; + CConfig.MicConfig[device.PlayerChannel2 - 1].DeviceDriver = device.Driver; } } CConfig.SaveConfig(); @@ -487,16 +449,15 @@ namespace Vocaluxe.Screens { if (_DeviceNr < 0) return; - SInput input = _Devices[_DeviceNr].Inputs[_InputNr]; - input.PlayerChannel1 = _SelectSlides[_SelectSlideRecordChannel1].Selection; - input.PlayerChannel2 = _SelectSlides[_SelectSlideRecordChannel2].Selection; - _Devices[_DeviceNr].Inputs[_InputNr] = input; + CRecordDevice device = _Devices[_DeviceNr]; + device.PlayerChannel1 = _SelectSlides[_SelectSlideRecordChannel1].Selection; + device.PlayerChannel2 = _SelectSlides[_SelectSlideRecordChannel2].Selection; } private void _UpdateChannels() { - _SelectSlides[_SelectSlideRecordChannel1].Selection = _Devices[_DeviceNr].Inputs[_InputNr].PlayerChannel1; - _SelectSlides[_SelectSlideRecordChannel2].Selection = _Devices[_DeviceNr].Inputs[_InputNr].PlayerChannel2; + _SelectSlides[_SelectSlideRecordChannel1].Selection = _Devices[_DeviceNr].PlayerChannel1; + _SelectSlides[_SelectSlideRecordChannel2].Selection = _Devices[_DeviceNr].PlayerChannel2; _SaveMicConfig(); } @@ -510,25 +471,22 @@ namespace Vocaluxe.Screens if (_Devices == null) return true; - for (int dev = 0; dev < _Devices.Length; dev++) + foreach (CRecordDevice device in _Devices) { - for (int inp = 0; inp < _Devices[dev].Inputs.Count; inp++) + if (device.PlayerChannel1 > 0) { - if (_Devices[dev].Inputs[inp].PlayerChannel1 > 0) - { - if (isSet[_Devices[dev].Inputs[inp].PlayerChannel1 - 1]) - return false; + if (isSet[device.PlayerChannel1 - 1]) + return false; - isSet[_Devices[dev].Inputs[inp].PlayerChannel1 - 1] = true; - } + isSet[device.PlayerChannel1 - 1] = true; + } - if (_Devices[dev].Inputs[inp].PlayerChannel2 > 0) - { - if (isSet[_Devices[dev].Inputs[inp].PlayerChannel2 - 1]) - return false; + if (device.PlayerChannel2 > 0) + { + if (isSet[device.PlayerChannel2 - 1]) + return false; - isSet[_Devices[dev].Inputs[inp].PlayerChannel2 - 1] = true; - } + isSet[device.PlayerChannel2 - 1] = true; } } return true; @@ -545,7 +503,7 @@ namespace Vocaluxe.Screens _DelayTestRunning = true; } - private void _GetFirstConfiguredRecordDevice(ref int device, ref int input) + private void _GetFirstConfiguredRecordDevice(ref int device) { if (_Devices == null) return; @@ -553,22 +511,15 @@ namespace Vocaluxe.Screens if (CConfig.MicConfig == null) return; - for (int i = 0; i < _Devices.Length; i++) + if (CConfig.MicConfig[0].Channel <= 0) + return; + + for (int i = 0; i < _Devices.Count; i++) { if (_Devices[i].Name == CConfig.MicConfig[0].DeviceName && _Devices[i].Driver == CConfig.MicConfig[0].DeviceDriver) { - for (int j = 0; j < _Devices[i].Inputs.Count; j++) - { - if (_Devices[i].Inputs[j].Name == CConfig.MicConfig[0].InputName) - { - if (CConfig.MicConfig[0].Channel > 0) - { - device = i; - input = j; - return; - } - } - } + device = i; + return; } } } diff --git a/Vocaluxe/Screens/CScreenOptionsTheme.cs b/Vocaluxe/Screens/CScreenOptionsTheme.cs index 5ad72a24..a0570294 100644 --- a/Vocaluxe/Screens/CScreenOptionsTheme.cs +++ b/Vocaluxe/Screens/CScreenOptionsTheme.cs @@ -17,7 +17,6 @@ // */ #endregion -using System; using System.Windows.Forms; using Vocaluxe.Base; using Vocaluxe.Base.Font; diff --git a/Vocaluxe/Screens/CScreenParty.cs b/Vocaluxe/Screens/CScreenParty.cs index f6e37116..79d12cad 100644 --- a/Vocaluxe/Screens/CScreenParty.cs +++ b/Vocaluxe/Screens/CScreenParty.cs @@ -177,6 +177,7 @@ namespace Vocaluxe.Screens if (!_PartyModeInfos[index].Playable) { _Buttons[_ButtonStart].Visible = false; + _Texts[_TextError].Text = "TR_SCREENPARTY_ERROR"; _Texts[_TextError].Visible = true; } else @@ -193,10 +194,19 @@ namespace Vocaluxe.Screens int index = _SelectSlides[_SelectSlideModes].Selection; if (index >= _PartyModeInfos.Count) - return; + { + _Buttons[_ButtonStart].Visible = false; + _Texts[_TextError].Text = "TR_SCREENPARTY_ERROR"; + _Texts[_TextError].Visible = true; + } if (CConfig.GetMaxNumMics() == 0) - return; //TODO: Add message! + { + _Buttons[_ButtonStart].Visible = false; + _Texts[_TextError].Text = CLanguage.Translate("TR_SCREENNAMES_WARNING_MICS_PL").Replace("%v", ""); + _Texts[_TextError].Visible = true; + return; + } CParty.SetPartyMode(_PartyModeInfos[index].PartyModeID); CGraphics.FadeTo(EScreens.ScreenPartyDummy); diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 21aff197..43772d45 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -384,7 +384,9 @@ namespace Vocaluxe.Screens for (int p = 0; p < CGame.NumPlayer; p++) { + // ReSharper disable ConvertIfStatementToConditionalTernaryExpression if (CGame.Players[p].Points < 10000) + // ReSharper restore ConvertIfStatementToConditionalTernaryExpression _Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = CGame.Players[p].Points.ToString("0000"); else _Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = CGame.Players[p].Points.ToString("00000"); diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 49e62367..a9de0f7d 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -1157,7 +1157,9 @@ namespace Vocaluxe.Screens if (_SelectSlides[_SelectSlideOptionsPlaylistOpen].NumValues > 0) _SelectSlides[_SelectSlideOptionsPlaylistOpen].Visible = true; + // ReSharper disable ConvertIfStatementToConditionalTernaryExpression if (_Buttons[_ButtonOptionsRandom].Visible) + // ReSharper restore ConvertIfStatementToConditionalTernaryExpression _SetInteractionToButton(_Buttons[_ButtonOptionsRandom]); else _SetInteractionToButton(_Buttons[_ButtonOptionsRandomCategory]); diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index 1d1164c9..46d4c11c 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -178,7 +178,7 @@ - + @@ -217,7 +217,7 @@ - + diff --git a/VocaluxeLib/Menu/CBasic.cs b/VocaluxeLib/Menu/CBasic.cs index db31f26b..99fe0818 100644 --- a/VocaluxeLib/Menu/CBasic.cs +++ b/VocaluxeLib/Menu/CBasic.cs @@ -38,12 +38,12 @@ namespace VocaluxeLib.Menu public static ISound Sound; public static ICover Cover; public static IDataBase DataBase; - public static IInputs Input; + public static IControllers Controller; public static IPlaylist Playlist; public static void Assign(IConfig config, ISettings settings, ITheme theme, ILog log, IBackgroundMusic backgroundMusic, IDrawing draw, IGraphics graphics, IFonts fonts, ILanguage language, IGame game, IProfiles profiles, IRecording record, - ISongs songs, IVideo video, ISound sound, ICover cover, IDataBase dataBase, IInputs input, IPlaylist playlist) + ISongs songs, IVideo video, ISound sound, ICover cover, IDataBase dataBase, IControllers controller, IPlaylist playlist) { Config = config; Settings = settings; @@ -62,7 +62,7 @@ namespace VocaluxeLib.Menu Sound = sound; Cover = cover; DataBase = dataBase; - Input = input; + Controller = controller; Playlist = playlist; } } diff --git a/VocaluxeLib/Menu/CParticle.cs b/VocaluxeLib/Menu/CParticle.cs index d33001f0..e9a832cc 100644 --- a/VocaluxeLib/Menu/CParticle.cs +++ b/VocaluxeLib/Menu/CParticle.cs @@ -297,7 +297,9 @@ namespace VocaluxeLib.Menu public void Draw() { + // ReSharper disable ConvertIfStatementToConditionalTernaryExpression if (_TextureName != "") + // ReSharper restore ConvertIfStatementToConditionalTernaryExpression CBase.Drawing.DrawTexture(CBase.Theme.GetSkinTexture(_TextureName, _PartyModeID), _Rect, new SColorF(_Color.R, _Color.G, _Color.B, _Color.A * Alpha2 * _Alpha)); else CBase.Drawing.DrawTexture(_Texture, _Rect, new SColorF(_Color.R, _Color.G, _Color.B, _Color.A * Alpha2 * _Alpha)); diff --git a/VocaluxeLib/Menu/CText.cs b/VocaluxeLib/Menu/CText.cs index c164bfba..6284e88b 100644 --- a/VocaluxeLib/Menu/CText.cs +++ b/VocaluxeLib/Menu/CText.cs @@ -127,7 +127,9 @@ namespace VocaluxeLib.Menu if (Math.Abs(_MaxWidth - value) > 0.01) { _MaxWidth = value; + // ReSharper disable ConvertIfStatementToConditionalTernaryExpression if (_MaxWidth > 0) + // ReSharper restore ConvertIfStatementToConditionalTernaryExpression Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), _MaxWidth, 3f * CBase.Settings.GetRenderH(), 0f); else Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), 3f * CBase.Settings.GetRenderW(), 3f * CBase.Settings.GetRenderH(), 0f); @@ -332,7 +334,9 @@ namespace VocaluxeLib.Menu Selected = false; + // ReSharper disable ConvertIfStatementToConditionalTernaryExpression if (MaxWidth > 0) + // ReSharper restore ConvertIfStatementToConditionalTernaryExpression Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), MaxWidth, 3f * CBase.Settings.GetRenderH(), 0f); else Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), 3f * CBase.Settings.GetRenderW(), 3f * CBase.Settings.GetRenderH(), 0f); @@ -367,7 +371,9 @@ namespace VocaluxeLib.Menu Selected = false; + // ReSharper disable ConvertIfStatementToConditionalTernaryExpression if (MaxWidth > 0) + // ReSharper restore ConvertIfStatementToConditionalTernaryExpression Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), MaxWidth, 3f * CBase.Settings.GetRenderH(), 0f); else Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), 3f * CBase.Settings.GetRenderW(), 3f * CBase.Settings.GetRenderH(), 0f); @@ -400,7 +406,9 @@ namespace VocaluxeLib.Menu Selected = false; + // ReSharper disable ConvertIfStatementToConditionalTernaryExpression if (MaxWidth > 0) + // ReSharper restore ConvertIfStatementToConditionalTernaryExpression Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), MaxWidth, 3f * CBase.Settings.GetRenderH(), 0f); else Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), 3f * CBase.Settings.GetRenderW(), 3f * CBase.Settings.GetRenderH(), 0f); @@ -435,7 +443,9 @@ namespace VocaluxeLib.Menu Selected = false; + // ReSharper disable ConvertIfStatementToConditionalTernaryExpression if (MaxWidth > 0) + // ReSharper restore ConvertIfStatementToConditionalTernaryExpression Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), MaxWidth, 3f * CBase.Settings.GetRenderH(), 0f); else Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), 3f * CBase.Settings.GetRenderW(), 3f * CBase.Settings.GetRenderH(), 0f); @@ -509,7 +519,9 @@ namespace VocaluxeLib.Menu { LoadTextures(); + // ReSharper disable ConvertIfStatementToConditionalTernaryExpression if (MaxWidth > 0) + // ReSharper restore ConvertIfStatementToConditionalTernaryExpression Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), MaxWidth, 3f * CBase.Settings.GetRenderH(), 0f); else Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), 3f * CBase.Settings.GetRenderW(), 3f * CBase.Settings.GetRenderH(), 0f); diff --git a/VocaluxeLib/Menu/IMenu.cs b/VocaluxeLib/Menu/IMenu.cs index 6c82b349..b698adaa 100644 --- a/VocaluxeLib/Menu/IMenu.cs +++ b/VocaluxeLib/Menu/IMenu.cs @@ -302,7 +302,7 @@ namespace VocaluxeLib.Menu bool GetCover(string fileName, ref STexture texture, int coverSize); } - public interface IInputs + public interface IControllers { void SetRumble(float duration); } diff --git a/VocaluxeLib/Menu/SingNotes/CNotes.cs b/VocaluxeLib/Menu/SingNotes/CNotes.cs index 0de66cf3..de2da998 100644 --- a/VocaluxeLib/Menu/SingNotes/CNotes.cs +++ b/VocaluxeLib/Menu/SingNotes/CNotes.cs @@ -348,13 +348,7 @@ namespace VocaluxeLib.Menu.SingNotes public string Lyrics { - get - { - string lyrics = String.Empty; - foreach (CNote note in _Notes) - lyrics += note.Text; - return lyrics; - } + get { return _Notes.Aggregate(String.Empty, (current, note) => current + note.Text); } } public int NoteCount @@ -364,13 +358,7 @@ namespace VocaluxeLib.Menu.SingNotes public int Points { - get - { - int points = 0; - foreach (CNote note in _Notes) - points += note.Points; - return points; - } + get { return _Notes.Sum(note => note.Points); } } public CNote[] Notes diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index ccdc15bd..542e4d67 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -347,7 +347,7 @@ namespace VocaluxeLib.Menu.SongMenu sel = true; if (mouseEvent.Sender == ESender.WiiMote && _ActualSelection != lastselection && _ActualSelection != -1) - CBase.Input.SetRumble(0.050f); + CBase.Controller.SetRumble(0.050f); if (!sel) _ActualSelection = -1; @@ -392,7 +392,9 @@ namespace VocaluxeLib.Menu.SongMenu tile.Draw(1.2f, tile.Rect.Z - 0.1f, EAspect.Crop); else { + // ReSharper disable ConvertIfStatementToConditionalTernaryExpression if (tile.Texture.Index != _CoverTexture.Index) + // ReSharper restore ConvertIfStatementToConditionalTernaryExpression tile.Draw(1f, tile.Rect.Z, EAspect.Crop); else tile.Draw(1f, tile.Rect.Z, EAspect.Stretch); @@ -433,7 +435,9 @@ namespace VocaluxeLib.Menu.SongMenu _Artist.Text = CBase.Songs.GetCategory(actcat).Name; int num = CBase.Songs.NumSongsInCategory(actcat); + // ReSharper disable ConvertIfStatementToConditionalTernaryExpression if (num != 1) + // ReSharper restore ConvertIfStatementToConditionalTernaryExpression _Title.Text = CBase.Language.Translate("TR_SCREENSONG_NUMSONGS").Replace("%v", num.ToString()); else _Title.Text = CBase.Language.Translate("TR_SCREENSONG_NUMSONG").Replace("%v", num.ToString()); @@ -623,10 +627,7 @@ namespace VocaluxeLib.Menu.SongMenu { if (itemCount > i + offset) { - if (isInCategory) - _Tiles[i].Texture = CBase.Songs.GetVisibleSong(i + offset).CoverTextureSmall; - else - _Tiles[i].Texture = CBase.Songs.GetCategory(i + offset).CoverTextureSmall; + _Tiles[i].Texture = isInCategory ? CBase.Songs.GetVisibleSong(i + offset).CoverTextureSmall : CBase.Songs.GetCategory(i + offset).CoverTextureSmall; _Tiles[i].Color = new SColorF(1f, 1f, 1f, 1f); } else