using System;
using System.Text;
using Ion.Storage;
using System.Data;
using Holo.Source;
namespace Holo.Managers
{
///
/// Provides management for virtual sound machines and virtual songs.
///
public static class soundMachineManager
{
///
/// Returns the string with all the soundsets in the Hand of a certain user.
///
/// The database ID of the user to get the soundsets of.
public static string getHandSoundsets(int userID)
{
using (DatabaseClient dbClient = (Eucalypt.dbManager.GetClient()))
{
DataTable table = dbClient.ReadDataTable("SELECT soundmachine_soundset FROM furniture WHERE ownerid = '" + userID + "' AND roomid = '0' AND soundmachine_soundset > 0 ORDER BY id ASC");
StringBuilder Soundsets = new StringBuilder(Encoding.encodeVL64(table.Rows.Count));
foreach (DataRow row in table.Rows)
Soundsets.Append(Encoding.encodeVL64(Convert.ToInt32(row[0])));
return Soundsets.ToString();
}
}
///
/// Returns the length of a song in seconds as an integer. The length is calculated by counting the notes on the four tracks, if an error occurs here, then -1 is returned as length.
///
/// The songdata. (all 4 tracks)
public static int calculateSongLength(string Data)
{
int songLength = 0;
try
{
string[] Track = Data.Split(':');
for (int i = 1; i < 8; i += 3)
{
int trackLength = 0;
string[] Samples = Track[i].Split(';');
for (int j = 0; j < Samples.Length; j++)
trackLength += int.Parse(Samples[j].Substring(Samples[j].IndexOf(",") + 1));
if (trackLength > songLength)
songLength = trackLength;
}
return songLength;
}
catch { return -1; }
}
public static string getMachineSongList(int machineID)
{
using (DatabaseClient dbClient = (Eucalypt.dbManager.GetClient()))
{
FuseBuilder List = new FuseBuilder();
DataTable table = dbClient.ReadDataTable("SELECT id,length,title,burnt FROM soundmachine_songs WHERE machineid = '" + machineID + "' ORDER BY id ASC");
List.AppendWired(table.Rows.Count);
foreach (DataRow row in table.Rows)
{
List.AppendWired(row[0]);
List.AppendWired(row[1]);
List.AppendString(row[2]);
List.AppendWired(row[3]);
}
return List.ToString();
}
}
public static string getMachinePlaylist(int machineID)
{
using (DatabaseClient dbClient = (Eucalypt.dbManager.GetClient()))
{
FuseBuilder List = new FuseBuilder();
DataColumn column = dbClient.ReadDataColumn("SELECT songid FROM soundmachine_playlists WHERE machineid = '" + machineID + "' ORDER BY pos ASC");
List.AppendWired(0);
List.AppendWired(column.Table.Rows.Count);
int i = 1;
foreach (DataRow row in column.Table.Rows)
{
List.AppendWired(row[0]);
List.AppendWired(i);
DataRow songrow = dbClient.ReadDataRow("SELECT userid,title FROM soundmachine_songs WHERE id = '" + row[0] + "'");
List.AppendString(songrow[1]);
List.AppendString(dbClient.ReadString("SELECT name FROM users WHERE id = '" + songrow[0] + "'"));
i++;
}
return List.ToString();
}
}
public static string getSong(int songID)
{
using (DatabaseClient dbClient = (Eucalypt.dbManager.GetClient()))
{
DataRow row = dbClient.ReadDataRow("SELECT title,data FROM soundmachine_songs WHERE id = '" + songID + "'");
if (row != null)
{
FuseBuilder Song = new FuseBuilder();
Song.AppendWired(songID);
Song.AppendString(row[0]);
Song.AppendString(row[1]);
return Song.ToString();
}
else
return "holo.cast.soundmachine.song.unknown";
}
}
}
}