Added first basic playlist-format.

This commit is contained in:
Florian Kuepper committed 2012-06-18 17:28:21 +02:00
1 parent 8ef112f6b6
commit 6202c67156
7 files changed
+299 -5

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<Info>
<PlaylistName>Test</PlaylistName>
</Info>
<Songs>
<Song1>
<Artist>2raumwohnung</Artist>
<Title>36 grad</Title>
<GameMode>TR_GAMEMODE_NORMAL</GameMode>
</Song1>
<Song2>
<Artist>Aura Dione</Artist>
<Title>Geronimo</Title>
<GameMode>TR_GAMEMODE_SHORTSONG</GameMode>
</Song2>
<Song3>
<Artist>Die Toten Hosen</Artist>
<Title>Tage wie diese</Title>
<GameMode>TR_GAMEMODE_MEDLEY</GameMode>
</Song3>
</Songs>
</root>
+2
View File
@@ -27,6 +27,7 @@ namespace Vocaluxe.Base
public int SongID; public int SongID;
public bool Medley; public bool Medley;
public bool Duet; public bool Duet;
public bool ShortSong;
public long DateTicks; public long DateTicks;
public bool SongFinished; public bool SongFinished;
} }
@@ -214,6 +215,7 @@ namespace Vocaluxe.Base
_Player[i].SongID = -1; _Player[i].SongID = -1;
_Player[i].Medley = false; _Player[i].Medley = false;
_Player[i].Duet = false; _Player[i].Duet = false;
_Player[i].ShortSong = false;
_Player[i].DateTicks = DateTime.Now.Ticks; _Player[i].DateTicks = DateTime.Now.Ticks;
_Player[i].SongFinished = false; _Player[i].SongFinished = false;
} }
+261
View File
@@ -0,0 +1,261 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using Vocaluxe.Lib.Song;
namespace Vocaluxe.Base
{
class CPlaylistSong
{
public int SongID;
public GameModes.EGameMode gm;
public CPlaylistSong(int SongID, GameModes.EGameMode gm)
{
this.SongID = SongID;
this.gm = gm;
}
public CPlaylistSong()
{
gm = GameModes.EGameMode.TR_GAMEMODE_NORMAL;
}
}
struct SPlaylist
{
public string PlaylistName;
public string PlaylistFile;
public List<CPlaylistSong> Songs;
}
static class CPlaylists
{
private static XmlWriterSettings _settings = new XmlWriterSettings();
private static CHelper Helper = new CHelper();
private static List<SPlaylist> _Playlists;
public static SPlaylist[] Playlists
{
get { return _Playlists.ToArray(); }
}
public static int NumPlaylists
{
get { return _Playlists.Count; }
}
public static void Init()
{
_settings.Indent = true;
_settings.Encoding = System.Text.Encoding.UTF8;
_settings.ConformanceLevel = ConformanceLevel.Document;
LoadPlaylists();
}
public static void LoadPlaylists()
{
_Playlists = new List<SPlaylist>();
List<string> files = new List<string>();
files.AddRange(Helper.ListFiles(CSettings.sFolderPlaylists, "*.xml", true, true));
foreach (string file in files)
{
LoadPlaylist(file);
}
SortPlaylistsByName();
}
public static void DeletePlaylist(int PlaylistID)
{
if (PlaylistID < 0 || PlaylistID >= _Playlists.Count)
return;
if (_Playlists[PlaylistID].PlaylistFile != String.Empty)
{
try
{
File.Delete(_Playlists[PlaylistID].PlaylistFile);
_Playlists.RemoveAt(PlaylistID);
}
catch (Exception)
{
CLog.LogError("Can't delete Profile File " + _Playlists[PlaylistID].PlaylistFile + ".xml");
}
}
}
#region private methods
private static void SortPlaylistsByName()
{
_Playlists.Sort(CompareByPlaylistName);
}
private static int CompareByPlaylistName(SPlaylist a, SPlaylist b)
{
return String.Compare(a.PlaylistName, b.PlaylistName);
}
private static void SavePlaylist(int PlaylistID)
{
if (PlaylistID < 0 || PlaylistID >= _Playlists.Count)
return;
string filename = string.Empty;
foreach (char chr in _Playlists[PlaylistID].PlaylistName)
{
if (char.IsLetter(chr))
filename += chr.ToString();
}
if (filename == String.Empty)
filename = "1";
int i = 0;
while (File.Exists(Path.Combine(CSettings.sFolderPlaylists, filename + ".xml")))
{
i++;
if (!File.Exists(Path.Combine(CSettings.sFolderPlaylists, filename + i + ".xml")))
{
filename += i;
}
}
SPlaylist playlist = _Playlists[PlaylistID];
playlist.PlaylistFile = Path.Combine(CSettings.sFolderPlaylists, filename + ".xml");
_Playlists[PlaylistID] = playlist;
XmlWriter writer;
try
{
writer = XmlWriter.Create(_Playlists[PlaylistID].PlaylistFile, _settings);
}
catch (Exception e)
{
CLog.LogError("Error creating/opening Playlist File " + _Playlists[PlaylistID].PlaylistFile + ": " + e.Message);
return;
}
if (writer == null)
{
CLog.LogError("Error creating/opening Playlist File " + _Playlists[PlaylistID].PlaylistFile);
return;
}
writer.WriteStartDocument();
writer.WriteStartElement("root");
writer.WriteStartElement("Info");
writer.WriteElementString("PlaylistName", _Playlists[PlaylistID].PlaylistName);
writer.WriteEndElement();
writer.WriteStartElement("Songs");
for (i = 0; i < playlist.Songs.Count; i++)
{
CSong[] songs = CSongs.AllSongs;
CSong song = new CSong();
for (int s = 0; i <= songs.Length; s++)
{
if (songs[s].ID == playlist.Songs[i].SongID)
{
song = songs[s];
break;
}
}
writer.WriteStartElement("Song" + (i+1).ToString());
writer.WriteElementString("Artist", song.Artist);
writer.WriteElementString("Title", song.Title);
writer.WriteElementString("GameMode", Enum.GetName(typeof(GameModes.EGameMode), playlist.Songs[i].gm));
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndElement(); //end of root
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
private static void LoadPlaylist(string FileName)
{
bool loaded = false;
XPathDocument xPathDoc = null;
XPathNavigator navigator = null;
SPlaylist playlist = new SPlaylist();
playlist.PlaylistFile = Path.Combine(CSettings.sFolderPlaylists, FileName);
try
{
xPathDoc = new XPathDocument(playlist.PlaylistFile);
navigator = xPathDoc.CreateNavigator();
loaded = true;
}
catch (Exception e)
{
loaded = false;
if (navigator != null)
navigator = null;
if (xPathDoc != null)
xPathDoc = null;
CLog.LogError("Error opening Playlist File " + FileName + ": " + e.Message);
}
if (loaded)
{
string value = String.Empty;
if (CHelper.GetValueFromXML("//root/Info/PlaylistName", navigator, ref value, value))
{
playlist.PlaylistName = value;
playlist.Songs = new List<CPlaylistSong>();
List<string> songs = CHelper.GetValuesFromXML("Songs", navigator);
string artist = String.Empty;
string title = String.Empty;
GameModes.EGameMode gm = GameModes.EGameMode.TR_GAMEMODE_NORMAL;
for (int i = 0; i < songs.Count; i++)
{
CHelper.GetValueFromXML("//root/Songs/" + songs[i] + "/Artist", navigator, ref artist, String.Empty);
CHelper.GetValueFromXML("//root/Songs/" + songs[i] + "/Title", navigator, ref title, String.Empty);
CHelper.TryGetEnumValueFromXML<GameModes.EGameMode>("//root/Songs/" + songs[i] + "/GameMode", navigator, ref gm);
CPlaylistSong song = new CPlaylistSong();
CSong[] AllSongs = CSongs.AllSongs;
for (int s = 0; s < AllSongs.Length; s++)
{
if (AllSongs[s].Artist == artist && AllSongs[s].Title == title)
{
song.SongID = AllSongs[s].ID;
break;
}
}
song.gm = gm;
playlist.Songs.Add(song);
}
_Playlists.Add(playlist);
}
else
{
CLog.LogError("Can't find PlaylistName in Playlist File: " + FileName);
}
}
}
#endregion
}
}
+1
View File
@@ -94,6 +94,7 @@ namespace Vocaluxe.Base
public const string sFolderLanguages = "Languages"; public const string sFolderLanguages = "Languages";
public const string sFolderScreenshots = "Screenshots"; public const string sFolderScreenshots = "Screenshots";
public const string sFolderBackgroundMusic = "BackgroundMusic"; public const string sFolderBackgroundMusic = "BackgroundMusic";
public const string sFolderPlaylists = "Playlists";
//public const String[] ToneStrings = new String[]{ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" }; //public const String[] ToneStrings = new String[]{ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
public const int ToneMin = -36; public const int ToneMin = -36;
+6 -2
View File
@@ -39,12 +39,13 @@ namespace Vocaluxe.GameModes
_Rounds[round, player].PointsLineBonus = 0f; _Rounds[round, player].PointsLineBonus = 0f;
_Rounds[round, player].Medley = false; _Rounds[round, player].Medley = false;
_Rounds[round, player].Duet = false; _Rounds[round, player].Duet = false;
_Rounds[round, player].ShortSong = false;
_Rounds[round, player].SongFinished = false; _Rounds[round, player].SongFinished = false;
} }
} }
} }
public void SetPoints(int Round, int SongID, SPlayer[] Player, bool Medley, bool Duet) public void SetPoints(int Round, int SongID, SPlayer[] Player, bool Medley, bool Duet, bool ShortSong)
{ {
long DateTicks = DateTime.Now.Ticks; long DateTicks = DateTime.Now.Ticks;
for (int player = 0; player < Player.Length; player++) for (int player = 0; player < Player.Length; player++)
@@ -56,6 +57,7 @@ namespace Vocaluxe.GameModes
_Rounds[Round, player].PointsLineBonus = Player[player].PointsLineBonus; _Rounds[Round, player].PointsLineBonus = Player[player].PointsLineBonus;
_Rounds[Round, player].Medley = Medley; _Rounds[Round, player].Medley = Medley;
_Rounds[Round, player].Duet = Duet; _Rounds[Round, player].Duet = Duet;
_Rounds[Round, player].ShortSong = ShortSong;
_Rounds[Round, player].DateTicks = DateTicks; _Rounds[Round, player].DateTicks = DateTicks;
_Rounds[Round, player].SongFinished = Player[player].SongFinished; _Rounds[Round, player].SongFinished = Player[player].SongFinished;
} }
@@ -91,6 +93,7 @@ namespace Vocaluxe.GameModes
player[p].Difficulty = _Rounds[Round, p].Difficulty; player[p].Difficulty = _Rounds[Round, p].Difficulty;
player[p].Medley = _Rounds[Round, p].Medley; player[p].Medley = _Rounds[Round, p].Medley;
player[p].Duet = _Rounds[Round, p].Duet; player[p].Duet = _Rounds[Round, p].Duet;
player[p].ShortSong = _Rounds[Round, p].ShortSong;
player[p].DateTicks = _Rounds[Round, p].DateTicks; player[p].DateTicks = _Rounds[Round, p].DateTicks;
player[p].SongFinished = _Rounds[Round, p].SongFinished; player[p].SongFinished = _Rounds[Round, p].SongFinished;
player[p].ProfileID = _Rounds[Round, p].ProfileID; player[p].ProfileID = _Rounds[Round, p].ProfileID;
@@ -223,7 +226,8 @@ namespace Vocaluxe.GameModes
_SongQueque[_CurrentSong].SongID, _SongQueque[_CurrentSong].SongID,
Player, Player,
_SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_MEDLEY, _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_MEDLEY,
_SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_DUET); _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_DUET,
_SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_SHORTSONG);
} }
_CurrentSong++; _CurrentSong++;
} }
+5
View File
@@ -223,6 +223,11 @@ namespace Vocaluxe.Screens
CBackgroundMusic.CanSing = true; CBackgroundMusic.CanSing = true;
CLog.StopBenchmark(3, "Load Cover"); CLog.StopBenchmark(3, "Load Cover");
//Init Playlists
CLog.StartBenchmark(0, "Init Playlists");
CPlaylists.Init();
CLog.StopBenchmark(0, "Init Playlists");
} }
private void CheckStartIntroVideos() private void CheckStartIntroVideos()
+1 -3
View File
@@ -125,6 +125,7 @@
<Compile Include="Base\CGame.cs" /> <Compile Include="Base\CGame.cs" />
<Compile Include="Base\CLanguage.cs" /> <Compile Include="Base\CLanguage.cs" />
<Compile Include="Base\CLog.cs" /> <Compile Include="Base\CLog.cs" />
<Compile Include="Base\CPlaylists.cs" />
<Compile Include="Base\CProfiles.cs" /> <Compile Include="Base\CProfiles.cs" />
<Compile Include="Base\CUtility.cs" /> <Compile Include="Base\CUtility.cs" />
<Compile Include="Base\CSettings.cs" /> <Compile Include="Base\CSettings.cs" />
@@ -132,12 +133,9 @@
<Compile Include="Base\CTheme.cs" /> <Compile Include="Base\CTheme.cs" />
<Compile Include="Base\CVideo.cs" /> <Compile Include="Base\CVideo.cs" />
<Compile Include="GameModes\CGameMode.cs" /> <Compile Include="GameModes\CGameMode.cs" />
<Compile Include="GameModes\CGameModeDuet.cs" />
<Compile Include="GameModes\CGameModeMedley.cs" />
<Compile Include="GameModes\CGameModeNormal.cs"> <Compile Include="GameModes\CGameModeNormal.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="GameModes\CGameModeShortSong.cs" />
<Compile Include="GameModes\IGameMode.cs" /> <Compile Include="GameModes\IGameMode.cs" />
<Compile Include="Lib\Draw\CDirect3D.cs"> <Compile Include="Lib\Draw\CDirect3D.cs">
<SubType>Form</SubType> <SubType>Form</SubType>