Check results of Init() calls

Also Part 2 of commits regarding nested benchmarks
This commit is contained in:
Flamefire committed 2014-03-16 18:06:56 +01:00
1 parent 723a76b6be
commit e321b3d657
18 files changed
+245 -137

No files matched your search

+15 -8
View File
@@ -36,19 +36,26 @@ namespace Vocaluxe.Base
_KeysPool = new List<SKeyEvent>(); _KeysPool = new List<SKeyEvent>();
_MousePool = new List<SMouseEvent>(); _MousePool = new List<SMouseEvent>();
_Controller.Add(new CWiiMote()); _AddController(new CWiiMote());
_Controller.Add(CVocaluxeServer.Controller); _AddController(CVocaluxeServer.Controller);
}
foreach (IController controller in _Controller) private static void _AddController(IController controller)
controller.Init(); {
if (controller.Init())
_Controller.Add(controller);
} }
public static void Close() public static void Close()
{ {
foreach (IController controller in _Controller) if (_Controller != null)
controller.Close(); {
foreach (IController controller in _Controller)
_Controller = new List<IController>(); controller.Close();
_Controller = null;
_KeysPool = null;
_MousePool = null;
}
} }
public static void Connect() public static void Connect()
+14 -10
View File
@@ -56,7 +56,7 @@ namespace Vocaluxe.Base
private static SQLiteConnection _ConnectionCover; private static SQLiteConnection _ConnectionCover;
private static SQLiteTransaction _TransactionCover; private static SQLiteTransaction _TransactionCover;
public static void Init() public static bool Init()
{ {
_HighscoreFilePath = Path.Combine(Environment.CurrentDirectory, CSettings.FileHighscoreDB); _HighscoreFilePath = Path.Combine(Environment.CurrentDirectory, CSettings.FileHighscoreDB);
_CoverFilePath = Path.Combine(Environment.CurrentDirectory, CSettings.FileCoverDB); _CoverFilePath = Path.Combine(Environment.CurrentDirectory, CSettings.FileCoverDB);
@@ -66,14 +66,15 @@ namespace Vocaluxe.Base
if (!_InitCoverDB()) if (!_InitCoverDB())
{ {
CLog.LogError("Error initializing Cover-DB", true, true); CLog.LogError("Error initializing Cover-DB", true, true);
return; return false;
} }
if (!_InitCreditsRessourcesDB()) if (!_InitCreditsRessourcesDB())
{ {
CLog.LogError("Error initializing Cover-DB", true, true); CLog.LogError("Error initializing Cover-DB", true, true);
return; return false;
} }
GC.Collect(); GC.Collect();
return true;
} }
#region Highscores #region Highscores
@@ -431,7 +432,7 @@ namespace Vocaluxe.Base
return false; return false;
} }
private static void _InitHighscoreDB() private static bool _InitHighscoreDB()
{ {
string oldDBFilePath = Path.Combine(Environment.CurrentDirectory, CSettings.FileOldHighscoreDB); string oldDBFilePath = Path.Combine(Environment.CurrentDirectory, CSettings.FileOldHighscoreDB);
if (File.Exists(oldDBFilePath)) if (File.Exists(oldDBFilePath))
@@ -441,17 +442,17 @@ namespace Vocaluxe.Base
if (!_CreateOrConvert(oldDBFilePath)) if (!_CreateOrConvert(oldDBFilePath))
{ {
CLog.LogError("Cannot init Highscore DB: Error opening database: " + oldDBFilePath, true, true); CLog.LogError("Cannot init Highscore DB: Error opening database: " + oldDBFilePath, true, true);
return; return false;
} }
if (!_CreateOrConvert(_HighscoreFilePath)) if (!_CreateOrConvert(_HighscoreFilePath))
{ {
CLog.LogError("Cannot init Highscore DB: Error opening database: " + _HighscoreFilePath, true, true); CLog.LogError("Cannot init Highscore DB: Error opening database: " + _HighscoreFilePath, true, true);
return; return false;
} }
if (!_ImportData(oldDBFilePath)) if (!_ImportData(oldDBFilePath))
{ {
CLog.LogError("Cannot init Highscore DB: Error importing data", true, true); CLog.LogError("Cannot init Highscore DB: Error importing data", true, true);
return; return false;
} }
} }
else else
@@ -460,13 +461,17 @@ namespace Vocaluxe.Base
if (!_CreateOrConvert(_HighscoreFilePath)) if (!_CreateOrConvert(_HighscoreFilePath))
{ {
CLog.LogError("Cannot init Highscore DB: Error opening database: " + _HighscoreFilePath, true, true); CLog.LogError("Cannot init Highscore DB: Error opening database: " + _HighscoreFilePath, true, true);
return; return false;
} }
} }
File.Delete(oldDBFilePath); File.Delete(oldDBFilePath);
} }
else if (!_CreateOrConvert(_HighscoreFilePath)) else if (!_CreateOrConvert(_HighscoreFilePath))
{
CLog.LogError("Cannot init Highscore DB: Error opening database: " + _HighscoreFilePath, true, true); CLog.LogError("Cannot init Highscore DB: Error opening database: " + _HighscoreFilePath, true, true);
return false;
}
return true;
} }
private static void _CreateHighscoreDB(string filePath) private static void _CreateHighscoreDB(string filePath)
@@ -1169,13 +1174,12 @@ namespace Vocaluxe.Base
} }
} }
public static void CloseConnections() public static void Close()
{ {
CommitCovers(); CommitCovers();
if (_ConnectionCover != null) if (_ConnectionCover != null)
{ {
_ConnectionCover.Close();
_ConnectionCover.Dispose(); _ConnectionCover.Dispose();
_ConnectionCover = null; _ConnectionCover = null;
} }
+11 -5
View File
@@ -28,8 +28,10 @@ namespace Vocaluxe.Base
{ {
private static IDraw _Draw; private static IDraw _Draw;
public static void InitDraw() public static bool InitDraw()
{ {
if (_Draw != null)
return false;
switch (CConfig.Renderer) switch (CConfig.Renderer)
{ {
case ERenderer.TR_CONFIG_SOFTWARE: case ERenderer.TR_CONFIG_SOFTWARE:
@@ -45,6 +47,7 @@ namespace Vocaluxe.Base
{ {
CLog.LogError(e.Message + " - Error in initializing of OpenGL. Please check whether" + CLog.LogError(e.Message + " - Error in initializing of OpenGL. Please check whether" +
" your graphic card drivers are up to date.", true, true); " your graphic card drivers are up to date.", true, true);
return false;
} }
break; break;
@@ -59,6 +62,7 @@ namespace Vocaluxe.Base
CLog.LogError(e.Message + " - Error in initializing of Direct3D. Please check if " + CLog.LogError(e.Message + " - Error in initializing of Direct3D. Please check if " +
"your DirectX redistributables and graphic card drivers are up to date. You can " + "your DirectX redistributables and graphic card drivers are up to date. You can " +
"download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109", true, true); "download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109", true, true);
return false;
} }
break; break;
#endif #endif
@@ -67,8 +71,7 @@ namespace Vocaluxe.Base
_Draw = new CDrawWinForm(); _Draw = new CDrawWinForm();
break; break;
} }
if (!_Draw.Init()) return _Draw.Init();
CLog.LogError("Could not init drawing interface!", true, true);
} }
public static void MainLoop() public static void MainLoop()
@@ -79,8 +82,11 @@ namespace Vocaluxe.Base
public static void Unload() public static void Unload()
{ {
_Draw.Unload(); if (_Draw != null)
_Draw = null; {
_Draw.Unload();
_Draw = null;
}
} }
public static int GetScreenWidth() public static int GetScreenWidth()
+7 -7
View File
@@ -61,10 +61,10 @@ namespace Vocaluxe.Base
} }
#region public methods #region public methods
public static void InitGraphics() public static void Init()
{ {
// Add Screens, must be the same order as in EScreens! // Add Screens, must be the same order as in EScreens!
CLog.StartBenchmark(1, "Build Screen List"); CLog.StartBenchmark("Build Screen List");
_Screens.Add(new CScreenTest()); _Screens.Add(new CScreenTest());
_Screens.Add(new CScreenLoad()); _Screens.Add(new CScreenLoad());
@@ -91,7 +91,7 @@ namespace Vocaluxe.Base
_PopupScreens.Add(new CPopupScreenVolumeControl()); _PopupScreens.Add(new CPopupScreenVolumeControl());
_PopupScreens.Add(new CPopupScreenServerQR()); _PopupScreens.Add(new CPopupScreenServerQR());
CLog.StopBenchmark(1, "Build Screen List"); CLog.StopBenchmark("Build Screen List");
_CurrentScreen = EScreens.ScreenLoad; _CurrentScreen = EScreens.ScreenLoad;
_NextScreen = EScreens.ScreenNull; _NextScreen = EScreens.ScreenNull;
@@ -101,9 +101,9 @@ namespace Vocaluxe.Base
_GlobalAlpha = 1f; _GlobalAlpha = 1f;
_ZOffset = 0f; _ZOffset = 0f;
CLog.StartBenchmark(0, "Load Theme"); CLog.StartBenchmark("Load Theme");
LoadTheme(); LoadTheme();
CLog.StopBenchmark(0, "Load Theme"); CLog.StopBenchmark("Load Theme");
} }
public static void LoadTheme() public static void LoadTheme()
@@ -112,10 +112,10 @@ namespace Vocaluxe.Base
for (int i = 0; i < _Screens.Count; i++) for (int i = 0; i < _Screens.Count; i++)
{ {
CLog.StartBenchmark(1, "Load Theme " + Enum.GetNames(typeof(EScreens))[i]); CLog.StartBenchmark("Load Theme " + Enum.GetNames(typeof(EScreens))[i]);
_Screens[i].Init(); _Screens[i].Init();
_Screens[i].LoadTheme(CTheme.GetThemeScreensPath(-1)); _Screens[i].LoadTheme(CTheme.GetThemeScreensPath(-1));
CLog.StopBenchmark(1, "Load Theme " + Enum.GetNames(typeof(EScreens))[i]); CLog.StopBenchmark("Load Theme " + Enum.GetNames(typeof(EScreens))[i]);
} }
foreach (IMenu popup in _PopupScreens) foreach (IMenu popup in _PopupScreens)
+1
View File
@@ -223,6 +223,7 @@ namespace Vocaluxe.Base
foreach (string file in files) foreach (string file in files)
{ {
SPartyMode pm = _LoadPartyMode(file); SPartyMode pm = _LoadPartyMode(file);
if(pm.NoErrors)
_PartyModes.Add(pm.PartyModeID, pm); _PartyModes.Add(pm.PartyModeID, pm);
} }
} }
+9 -2
View File
@@ -10,8 +10,10 @@ namespace Vocaluxe.Base
{ {
private static IRecord _Record; private static IRecord _Record;
public static void Init() public static bool Init()
{ {
if (_Record != null)
return false;
switch (CConfig.RecordLib) switch (CConfig.RecordLib)
{ {
#if WIN #if WIN
@@ -25,11 +27,16 @@ namespace Vocaluxe.Base
_Record = new CPortAudioRecord(); _Record = new CPortAudioRecord();
break; break;
} }
return _Record.Init();
} }
public static void Close() public static void Close()
{ {
_Record.Close(); if (_Record != null)
{
_Record.Close();
_Record = null;
}
} }
public static bool Start() public static bool Start()
+10 -10
View File
@@ -332,11 +332,11 @@ namespace Vocaluxe.Base
public static void LoadSongs() public static void LoadSongs()
{ {
CLog.StartBenchmark(1, "Load Songs"); CLog.StartBenchmark("Load Songs");
SongsLoaded = false; SongsLoaded = false;
_Songs.Clear(); _Songs.Clear();
CLog.StartBenchmark(2, "List Songs"); CLog.StartBenchmark("List Songs");
var files = new List<string>(); var files = new List<string>();
foreach (string p in CConfig.SongFolder) foreach (string p in CConfig.SongFolder)
{ {
@@ -344,9 +344,9 @@ namespace Vocaluxe.Base
files.AddRange(CHelper.ListFiles(path, "*.txt", true, true)); files.AddRange(CHelper.ListFiles(path, "*.txt", true, true));
files.AddRange(CHelper.ListFiles(path, "*.txd", true, true)); files.AddRange(CHelper.ListFiles(path, "*.txd", true, true));
} }
CLog.StopBenchmark(2, "List Songs"); CLog.StopBenchmark("List Songs");
CLog.StartBenchmark(2, "Read TXTs"); CLog.StartBenchmark("Read TXTs");
foreach (string file in files) foreach (string file in files)
{ {
CSong song = CSong.LoadSong(file); CSong song = CSong.LoadSong(file);
@@ -356,24 +356,24 @@ namespace Vocaluxe.Base
if (song.LoadNotes()) if (song.LoadNotes())
_Songs.Add(song); _Songs.Add(song);
} }
CLog.StopBenchmark(2, "Read TXTs"); CLog.StopBenchmark("Read TXTs");
CLog.StartBenchmark(2, "Sort Songs"); CLog.StartBenchmark("Sort Songs");
Sorter.SongSorting = CConfig.SongSorting; Sorter.SongSorting = CConfig.SongSorting;
Sorter.IgnoreArticles = CConfig.IgnoreArticles; Sorter.IgnoreArticles = CConfig.IgnoreArticles;
Categorizer.Tabs = CConfig.Tabs; Categorizer.Tabs = CConfig.Tabs;
Categorizer.ObjectChanged += _HandleCategoriesChanged; Categorizer.ObjectChanged += _HandleCategoriesChanged;
CLog.StopBenchmark(2, "Sort Songs"); CLog.StopBenchmark("Sort Songs");
Category = -1; Category = -1;
SongsLoaded = true; SongsLoaded = true;
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART) if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART)
{ {
CLog.StartBenchmark(2, "Load Covers/Notes"); CLog.StartBenchmark("Load Covers/Notes");
_LoadCover(); _LoadCover();
CLog.StopBenchmark(2, "Load Covers/Notes"); CLog.StopBenchmark("Load Covers/Notes");
} }
CLog.StopBenchmark(1, "Load Songs "); CLog.StopBenchmark("Load Songs ");
GC.Collect(); GC.Collect();
} }
+10 -1
View File
@@ -38,6 +38,8 @@ namespace Vocaluxe.Base
public static bool Init() public static bool Init()
{ {
if (_Playback != null)
return false;
switch (CConfig.PlayBackLib) switch (CConfig.PlayBackLib)
{ {
case EPlaybackLib.PortAudio: case EPlaybackLib.PortAudio:
@@ -75,7 +77,14 @@ namespace Vocaluxe.Base
public static void CloseAllStreams() public static void CloseAllStreams()
{ {
_Playback.CloseAll(); if (_Playback != null)
_Playback.CloseAll();
}
public static void Close()
{
CloseAllStreams();
_Playback = null;
} }
#region Stream Handling #region Stream Handling
+16 -7
View File
@@ -142,22 +142,30 @@ namespace Vocaluxe.Base
#endregion Vars #endregion Vars
#region Theme and Skin loading and writing #region Theme and Skin loading and writing
public static void InitTheme() public static bool Init()
{ {
_ListThemes(); _ListThemes();
ListSkins(); ListSkins();
LoadSkins(); return LoadSkins() && LoadTheme();
LoadTheme();
} }
public static void LoadSkins() public static bool LoadSkins()
{ {
//Fail if loading of any skin failed or no skin was loaded
//TODO: implement handlers that failing skins are logged and ignored
bool result = false;
for (int index = 0; index < _Skins.Count; index++) for (int index = 0; index < _Skins.Count; index++)
{ {
if (_Skins[index].PartyModeID == -1) if (_Skins[index].PartyModeID == -1)
LoadSkin(index); {
if (LoadSkin(index))
result = true;
else
return false;
}
} }
return result;
} }
public static bool LoadSkin(int skinIndex) public static bool LoadSkin(int skinIndex)
@@ -225,13 +233,14 @@ namespace Vocaluxe.Base
} }
} }
public static void LoadTheme() public static bool LoadTheme()
{ {
for (int i = 0; i < _Themes.Count; i++) for (int i = 0; i < _Themes.Count; i++)
{ {
if (_Themes[i].Name == CConfig.Theme && _Themes[i].PartyModeID == -1) if (_Themes[i].Name == CConfig.Theme && _Themes[i].PartyModeID == -1)
LoadTheme(i); return LoadTheme(i);
} }
return false;
} }
public static bool LoadTheme(int themeIndex) public static bool LoadTheme(int themeIndex)
+10 -4
View File
@@ -29,8 +29,10 @@ namespace Vocaluxe.Base
private static IVideoDecoder _VideoDecoder; private static IVideoDecoder _VideoDecoder;
#region Init #region Init
public static void Init() public static bool Init()
{ {
if (_VideoDecoder != null)
return false;
switch (CConfig.VideoDecoder) switch (CConfig.VideoDecoder)
{ {
case EVideoDecoder.FFmpeg: case EVideoDecoder.FFmpeg:
@@ -44,14 +46,18 @@ namespace Vocaluxe.Base
break; break;
} }
_VideoDecoder.Init(); return _VideoDecoder.Init();
} }
#endregion Init #endregion Init
#region Interface #region Interface
public static void CloseAll() public static void Close()
{ {
_VideoDecoder.CloseAll(); if (_VideoDecoder != null)
{
_VideoDecoder.CloseAll();
_VideoDecoder = null;
}
} }
public static int GetNumStreams() public static int GetNumStreams()
+11 -3
View File
@@ -26,8 +26,10 @@ namespace Vocaluxe.Base
{ {
private static IWebcam _Webcam; private static IWebcam _Webcam;
public static void Init() public static bool Init()
{ {
if (_Webcam != null)
return false;
switch (CConfig.WebcamLib) switch (CConfig.WebcamLib)
{ {
case EWebcamLib.AForgeNet: case EWebcamLib.AForgeNet:
@@ -38,11 +40,13 @@ namespace Vocaluxe.Base
_Webcam = new CAForgeNet(); _Webcam = new CAForgeNet();
break; break;
} }
_Webcam.Init(); if (!_Webcam.Init())
return false;
_Webcam.Select(CConfig.WebcamConfig); _Webcam.Select(CConfig.WebcamConfig);
CConfig.WebcamConfig = _Webcam.GetConfig(); CConfig.WebcamConfig = _Webcam.GetConfig();
CConfig.SaveConfig(); CConfig.SaveConfig();
return true;
} }
public static bool GetFrame(ref CTexture tex) public static bool GetFrame(ref CTexture tex)
@@ -57,7 +61,11 @@ namespace Vocaluxe.Base
public static void Close() public static void Close()
{ {
_Webcam.Close(); if (_Webcam != null)
{
_Webcam.Close();
_Webcam = null;
}
} }
public static void Pause() public static void Pause()
+4 -4
View File
@@ -361,9 +361,9 @@ namespace Vocaluxe.Base.Fonts
public static void LoadThemeFonts(string themeName, string fontFolder, CXMLReader xmlReader) public static void LoadThemeFonts(string themeName, string fontFolder, CXMLReader xmlReader)
{ {
_LoadFontFiles(xmlReader, fontFolder, themeName); _LoadFontFiles(xmlReader, fontFolder, themeName);
CLog.StartBenchmark(1, "BuildGlyphs"); CLog.StartBenchmark("BuildGlyphs");
_BuildGlyphs(); _BuildGlyphs();
CLog.StopBenchmark(1, "BuildGlyphs"); CLog.StopBenchmark("BuildGlyphs");
} }
/// <summary> /// <summary>
@@ -372,9 +372,9 @@ namespace Vocaluxe.Base.Fonts
public static void LoadPartyModeFonts(int partyModeID, string fontFolder, CXMLReader xmlReader) public static void LoadPartyModeFonts(int partyModeID, string fontFolder, CXMLReader xmlReader)
{ {
_LoadFontFiles(xmlReader, fontFolder, "", partyModeID); _LoadFontFiles(xmlReader, fontFolder, "", partyModeID);
CLog.StartBenchmark(1, "BuildGlyphs"); CLog.StartBenchmark("BuildGlyphs");
_BuildGlyphs(); _BuildGlyphs();
CLog.StopBenchmark(1, "BuildGlyphs"); CLog.StopBenchmark("BuildGlyphs");
} }
public static void SaveThemeFonts(string themeName, XmlWriter writer) public static void SaveThemeFonts(string themeName, XmlWriter writer)
+17 -6
View File
@@ -18,8 +18,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.IO; using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using ServerLib; using ServerLib;
@@ -29,16 +30,23 @@ using VocaluxeLib;
using VocaluxeLib.Menu; using VocaluxeLib.Menu;
using VocaluxeLib.Profile; using VocaluxeLib.Profile;
using VocaluxeLib.Songs; using VocaluxeLib.Songs;
using System.Security.Cryptography;
namespace Vocaluxe.Base.Server namespace Vocaluxe.Base.Server
{ {
static class CVocaluxeServer static class CVocaluxeServer
{ {
private class CServerController : CControllerFramework
{
public override string GetName()
{
return "App controller";
}
}
private static CServer _Server; private static CServer _Server;
//private static CDiscover _Discover; //private static CDiscover _Discover;
public static readonly CControllerFramework Controller = new CControllerFramework(); public static readonly CControllerFramework Controller = new CServerController();
public static void Init() public static void Init()
{ {
@@ -69,7 +77,6 @@ namespace Vocaluxe.Base.Server
CServer.AddPlaylist = _AddPlaylist; CServer.AddPlaylist = _AddPlaylist;
//_Discover = new CDiscover(CConfig.ServerPort, CCommands.BroadcastKeyword); //_Discover = new CDiscover(CConfig.ServerPort, CCommands.BroadcastKeyword);
Controller.Init();
} }
public static void Start() public static void Start()
@@ -83,8 +90,12 @@ namespace Vocaluxe.Base.Server
public static void Close() public static void Close()
{ {
_Server.Stop(); if (_Server != null)
//_Discover.Stop(); {
_Server.Stop();
_Server = null;
//_Discover.Stop();
}
} }
public static string GetServerAddress() public static string GetServerAddress()
+2 -1
View File
@@ -32,7 +32,8 @@ namespace Vocaluxe.Lib.Input
interface IController interface IController
{ {
void Init(); string GetName();
bool Init();
void Close(); void Close();
void Connect(); void Connect();
void Disconnect(); void Disconnect();
+31 -5
View File
@@ -42,19 +42,28 @@ namespace Vocaluxe.Lib.Input.WiiMote
private bool _Connected; private bool _Connected;
private Thread _HandlerThread; private Thread _HandlerThread;
private AutoResetEvent _EvTerminate;
private Object _Sync; private Object _Sync;
private bool _Active; private bool _Active;
private CRumbleTimer _RumbleTimer; private CRumbleTimer _RumbleTimer;
private CGesture _Gesture; private CGesture _Gesture;
public void Init() public string GetName()
{ {
return "WiiMote";
}
public bool Init()
{
if (_HandlerThread != null)
return false;
_Sync = new Object(); _Sync = new Object();
_RumbleTimer = new CRumbleTimer(); _RumbleTimer = new CRumbleTimer();
_Gesture = new CGesture(); _Gesture = new CGesture();
_HandlerThread = new Thread(_MainLoop) {Name = "WiiMote", Priority = ThreadPriority.BelowNormal}; _HandlerThread = new Thread(_MainLoop) {Name = "WiiMote", Priority = ThreadPriority.BelowNormal};
_EvTerminate = new AutoResetEvent(false);
_KeysPool = new List<SKeyEvent>(); _KeysPool = new List<SKeyEvent>();
_CurrentKeysPool = new List<SKeyEvent>(); _CurrentKeysPool = new List<SKeyEvent>();
@@ -64,17 +73,31 @@ namespace Vocaluxe.Lib.Input.WiiMote
_ButtonStates = new bool[11]; _ButtonStates = new bool[11];
_OldPosition = new Point(); _OldPosition = new Point();
return true;
} }
public void Close() public void Close()
{ {
_Active = false; _Active = false;
_WiiMote.Disconnect(); if (_HandlerThread != null)
{
//Join before freeing stuff
//This also ensures, that no other thread is created till the current one is terminated
_EvTerminate.Set();
_HandlerThread.Join();
_HandlerThread = null;
_EvTerminate.Dispose();
_EvTerminate = null;
_KeysPool = null;
_CurrentKeysPool = null;
_MousePool = null;
_CurrentMousePool = null;
}
} }
public void Connect() public void Connect()
{ {
if (_Active) if (_Active || _HandlerThread == null)
return; return;
_Active = true; _Active = true;
_HandlerThread.Start(); _HandlerThread.Start();
@@ -82,7 +105,8 @@ namespace Vocaluxe.Lib.Input.WiiMote
public void Disconnect() public void Disconnect()
{ {
_Active = false; //TODO: Allow reconnect
Close();
} }
public bool IsConnected() public bool IsConnected()
@@ -92,6 +116,8 @@ namespace Vocaluxe.Lib.Input.WiiMote
public void Update() public void Update()
{ {
if (_HandlerThread == null)
return;
_CopyEvents(); _CopyEvents();
} }
@@ -137,7 +163,7 @@ namespace Vocaluxe.Lib.Input.WiiMote
if (!_WiiMote.Connected) if (!_WiiMote.Connected)
{ {
if (!_DoConnect()) if (!_DoConnect())
Thread.Sleep(1000); _EvTerminate.WaitOne(1000);
} }
else else
{ {
@@ -15,11 +15,11 @@
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>. // along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion #endregion
using System.Collections.ObjectModel;
using System.Threading;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading;
using Vocaluxe.Base; using Vocaluxe.Base;
namespace Vocaluxe.Lib.Sound.Record.PortAudio namespace Vocaluxe.Lib.Sound.Record.PortAudio
@@ -27,7 +27,7 @@ namespace Vocaluxe.Lib.Sound.Record.PortAudio
class CPortAudioRecord : IRecord class CPortAudioRecord : IRecord
{ {
private bool _Initialized; private bool _Initialized;
private List<CRecordDevice> _Devices; private readonly List<CRecordDevice> _Devices = new List<CRecordDevice>();
private PortAudioSharp.PortAudio.PaStreamCallbackDelegate _MyRecProc; private PortAudioSharp.PortAudio.PaStreamCallbackDelegate _MyRecProc;
private IntPtr[] _RecHandle; private IntPtr[] _RecHandle;
@@ -36,13 +36,9 @@ namespace Vocaluxe.Lib.Sound.Record.PortAudio
public CPortAudioRecord() public CPortAudioRecord()
{ {
_Devices = null;
_Buffer = new CBuffer[CSettings.MaxNumPlayer]; _Buffer = new CBuffer[CSettings.MaxNumPlayer];
for (int i = 0; i < _Buffer.Length; i++) for (int i = 0; i < _Buffer.Length; i++)
_Buffer[i] = new CBuffer(); _Buffer[i] = new CBuffer();
Init();
} }
/// <summary> /// <summary>
@@ -51,8 +47,6 @@ namespace Vocaluxe.Lib.Sound.Record.PortAudio
/// <returns>true if success</returns> /// <returns>true if success</returns>
public bool Init() public bool Init()
{ {
_Devices = new List<CRecordDevice>();
try try
{ {
if (_Initialized) if (_Initialized)
@@ -61,9 +55,8 @@ namespace Vocaluxe.Lib.Sound.Record.PortAudio
if (_ErrorCheck("Initialize", PortAudioSharp.PortAudio.Pa_Initialize())) if (_ErrorCheck("Initialize", PortAudioSharp.PortAudio.Pa_Initialize()))
return false; return false;
_Initialized = true; _Devices.Clear();
int hostAPI = _ApiSelect(); int hostAPI = _ApiSelect();
int numDevices = PortAudioSharp.PortAudio.Pa_GetDeviceCount(); int numDevices = PortAudioSharp.PortAudio.Pa_GetDeviceCount();
for (int i = 0; i < numDevices; i++) for (int i = 0; i < numDevices; i++)
{ {
@@ -76,8 +69,12 @@ namespace Vocaluxe.Lib.Sound.Record.PortAudio
} }
} }
foreach (CBuffer buffer in _Buffer)
buffer.Reset();
_RecHandle = new IntPtr[_Devices.Count]; _RecHandle = new IntPtr[_Devices.Count];
_MyRecProc = _MyPaStreamCallback; _MyRecProc = _MyPaStreamCallback;
_Initialized = true;
} }
catch (Exception e) catch (Exception e)
{ {
@@ -101,6 +98,8 @@ namespace Vocaluxe.Lib.Sound.Record.PortAudio
if (_RecHandle == null || _RecHandle.Length == 0) if (_RecHandle == null || _RecHandle.Length == 0)
return false; return false;
Stop();
foreach (CBuffer buffer in _Buffer) foreach (CBuffer buffer in _Buffer)
buffer.Reset(); buffer.Reset();
+63 -49
View File
@@ -20,15 +20,21 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using Vocaluxe.Base; using Vocaluxe.Base;
using System.Runtime.ExceptionServices;
using Vocaluxe.Base.Fonts; using Vocaluxe.Base.Fonts;
using Vocaluxe.Base.Server; using Vocaluxe.Base.Server;
namespace Vocaluxe namespace Vocaluxe
{ {
class CLoadingException : Exception
{
public CLoadingException(string component)
: base("Failed to load " + component) {}
}
static class CMainProgram static class CMainProgram
{ {
private static CSplashScreen _SplashScreen; private static CSplashScreen _SplashScreen;
@@ -85,146 +91,154 @@ namespace Vocaluxe
Application.DoEvents(); Application.DoEvents();
// Init Language // Init Language
CLog.StartBenchmark(0, "Init Language"); CLog.StartBenchmark("Init Language");
CLanguage.Init(); CLanguage.Init();
CLog.StopBenchmark(0, "Init Language"); CLog.StopBenchmark("Init Language");
Application.DoEvents(); Application.DoEvents();
// load config // load config
CLog.StartBenchmark(0, "Init Config"); CLog.StartBenchmark("Init Config");
CConfig.LoadCommandLineParams(args); CConfig.LoadCommandLineParams(args);
CConfig.UseCommandLineParamsBefore(); CConfig.UseCommandLineParamsBefore();
CConfig.Init(); CConfig.Init();
CConfig.UseCommandLineParamsAfter(); CConfig.UseCommandLineParamsAfter();
CLog.StopBenchmark(0, "Init Config"); CLog.StopBenchmark("Init Config");
Application.DoEvents(); Application.DoEvents();
_SplashScreen = new CSplashScreen(); _SplashScreen = new CSplashScreen();
Application.DoEvents(); Application.DoEvents();
// Init Draw // Init Draw
CLog.StartBenchmark(0, "Init Draw"); CLog.StartBenchmark("Init Draw");
CDraw.InitDraw(); if (!CDraw.InitDraw())
CLog.StopBenchmark(0, "Init Draw"); throw new CLoadingException("drawing");
CLog.StopBenchmark("Init Draw");
Application.DoEvents(); Application.DoEvents();
// Init Database // Init Database
CLog.StartBenchmark(0, "Init Database"); CLog.StartBenchmark("Init Database");
CDataBase.Init(); if (!CDataBase.Init())
CLog.StopBenchmark(0, "Init Database"); throw new CLoadingException("database");
CLog.StopBenchmark("Init Database");
Application.DoEvents(); Application.DoEvents();
// Init Playback // Init Playback
CLog.StartBenchmark(0, "Init Playback"); CLog.StartBenchmark("Init Playback");
CSound.Init(); if (!CSound.Init())
CLog.StopBenchmark(0, "Init Playback"); throw new CLoadingException("playback");
CLog.StopBenchmark("Init Playback");
Application.DoEvents(); Application.DoEvents();
// Init Record // Init Record
CLog.StartBenchmark(0, "Init Record"); CLog.StartBenchmark("Init Record");
CRecord.Init(); if (!CRecord.Init())
CLog.StopBenchmark(0, "Init Record"); throw new CLoadingException("record");
CLog.StopBenchmark("Init Record");
Application.DoEvents(); Application.DoEvents();
//Init Webcam //Init Webcam
CLog.StartBenchmark(0, "Init Webcam"); CLog.StartBenchmark("Init Webcam");
CWebcam.Init(); if (!CWebcam.Init())
CLog.StopBenchmark(0, "Init Webcam"); throw new CLoadingException("webcam");
CLog.StopBenchmark("Init Webcam");
Application.DoEvents(); Application.DoEvents();
// Init Background Music // Init Background Music
CLog.StartBenchmark(0, "Init Background Music"); CLog.StartBenchmark("Init Background Music");
CBackgroundMusic.Init(); CBackgroundMusic.Init();
CLog.StopBenchmark(0, "Init Background Music"); CLog.StopBenchmark("Init Background Music");
Application.DoEvents(); Application.DoEvents();
// Init Profiles // Init Profiles
CLog.StartBenchmark(0, "Init Profiles"); CLog.StartBenchmark("Init Profiles");
CProfiles.Init(); CProfiles.Init();
CLog.StopBenchmark(0, "Init Profiles"); CLog.StopBenchmark("Init Profiles");
Application.DoEvents(); Application.DoEvents();
// Init Font // Init Font
CLog.StartBenchmark(0, "Init Font"); CLog.StartBenchmark("Init Font");
CFonts.Init(); CFonts.Init();
CLog.StopBenchmark(0, "Init Font"); CLog.StopBenchmark("Init Font");
Application.DoEvents(); Application.DoEvents();
// Init VideoDecoder // Init VideoDecoder
CLog.StartBenchmark(0, "Init Videodecoder"); CLog.StartBenchmark("Init Videodecoder");
CVideo.Init(); if (!CVideo.Init())
CLog.StopBenchmark(0, "Init Videodecoder"); throw new CLoadingException("video");
CLog.StopBenchmark("Init Videodecoder");
Application.DoEvents(); Application.DoEvents();
// Load Cover // Load Cover
CLog.StartBenchmark(0, "Init Cover"); CLog.StartBenchmark("Init Cover");
CCover.Init(); CCover.Init();
CLog.StopBenchmark(0, "Init Cover"); CLog.StopBenchmark("Init Cover");
Application.DoEvents(); Application.DoEvents();
// Theme System // Theme System
CLog.StartBenchmark(0, "Init Theme"); CLog.StartBenchmark("Init Theme");
CTheme.InitTheme(); if (!CTheme.Init())
CLog.StopBenchmark(0, "Init Theme"); throw new CLoadingException("theme");
CLog.StopBenchmark("Init Theme");
Application.DoEvents(); Application.DoEvents();
// Init Screens // Init Screens
CLog.StartBenchmark(0, "Init Screens"); CLog.StartBenchmark("Init Screens");
CGraphics.InitGraphics(); CGraphics.Init();
CLog.StopBenchmark(0, "Init Screens"); CLog.StopBenchmark("Init Screens");
Application.DoEvents(); Application.DoEvents();
// Init Server // Init Server
CLog.StartBenchmark(0, "Init Server"); CLog.StartBenchmark("Init Server");
CVocaluxeServer.Init(); CVocaluxeServer.Init();
CLog.StopBenchmark(0, "Init Server"); CLog.StopBenchmark("Init Server");
Application.DoEvents(); Application.DoEvents();
// Init Input // Init Input
CLog.StartBenchmark(0, "Init Input"); CLog.StartBenchmark("Init Input");
CController.Init(); CController.Init();
CController.Connect(); CController.Connect();
CLog.StopBenchmark(0, "Init Input"); CLog.StopBenchmark("Init Input");
Application.DoEvents(); Application.DoEvents();
// Init Game; // Init Game;
CLog.StartBenchmark(0, "Init Game"); CLog.StartBenchmark("Init Game");
CGame.Init(); CGame.Init();
CProfiles.Update(); CProfiles.Update();
CConfig.UsePlayers(); CConfig.UsePlayers();
CLog.StopBenchmark(0, "Init Game"); CLog.StopBenchmark("Init Game");
Application.DoEvents(); Application.DoEvents();
// Init Party Modes; // Init Party Modes;
CLog.StartBenchmark(0, "Init Party Modes"); CLog.StartBenchmark("Init Party Modes");
CParty.Init(); CParty.Init();
CLog.StopBenchmark(0, "Init Party Modes"); CLog.StopBenchmark("Init Party Modes");
Application.DoEvents(); Application.DoEvents();
} }
catch (Exception e) catch (Exception e)
{ {
MessageBox.Show("Error on start up: " + e.Message + e.StackTrace); MessageBox.Show("Error on start up: " + e.Message);
CLog.LogError("Error on start up: " + e); CLog.LogError("Error on start up: " + e);
if (_SplashScreen != null) if (_SplashScreen != null)
_SplashScreen.Close(); _SplashScreen.Close();
_CloseProgram(); _CloseProgram();
return;
} }
Application.DoEvents(); Application.DoEvents();
@@ -244,10 +258,10 @@ namespace Vocaluxe
CVocaluxeServer.Close(); CVocaluxeServer.Close();
CController.Close(); CController.Close();
CRecord.Close(); CRecord.Close();
CSound.CloseAllStreams(); CSound.Close();
CVideo.CloseAll(); CVideo.Close();
CDraw.Unload(); CDraw.Unload();
CDataBase.CloseConnections(); CDataBase.Close();
CWebcam.Close(); CWebcam.Close();
CLog.CloseAll(); CLog.CloseAll();
} }
+4 -4
View File
@@ -129,7 +129,7 @@ namespace Vocaluxe.Screens
videoPlayer.PreLoad(); videoPlayer.PreLoad();
} }
CLog.StartBenchmark(0, "Load Songs Full"); CLog.StartBenchmark("Load Songs Full");
_SongLoaderThread.IsBackground = true; _SongLoaderThread.IsBackground = true;
_SongLoaderThread.Start(); _SongLoaderThread.Start();
@@ -198,12 +198,12 @@ namespace Vocaluxe.Screens
CBackgroundMusic.CanSing = true; CBackgroundMusic.CanSing = true;
CLog.StopBenchmark(0, "Load Songs Full"); CLog.StopBenchmark("Load Songs Full");
//Init Playlists //Init Playlists
CLog.StartBenchmark(0, "Init Playlists"); CLog.StartBenchmark("Init Playlists");
CPlaylists.Init(); CPlaylists.Init();
CLog.StopBenchmark(0, "Init Playlists"); CLog.StopBenchmark("Init Playlists");
} }
private void _CheckStartIntroVideos() private void _CheckStartIntroVideos()