diff --git a/ClientServerLib/ClientServerLib/CServer.cs b/ClientServerLib/ClientServerLib/CServer.cs index b661b3ed..282498c2 100644 --- a/ClientServerLib/ClientServerLib/CServer.cs +++ b/ClientServerLib/ClientServerLib/CServer.cs @@ -43,7 +43,6 @@ namespace ClientServerLib set { CServer.getProfileList = value; } } - #endregion #region photo @@ -69,13 +68,28 @@ namespace ClientServerLib #region songs - private static GetCurrentSongDelegate getCurrentSong; - public static GetCurrentSongDelegate GetCurrentSong + private static GetSongDelegate getSong; + public static GetSongDelegate GetSong { - internal get { return CServer.getCurrentSong; } - set { CServer.getCurrentSong = value; } + internal get { return CServer.getSong; } + set { CServer.getSong = value; } } + private static GetAllSongsDelegate getAllSongs; + public static GetAllSongsDelegate GetAllSongs + { + get { return CServer.getAllSongs; } + set { CServer.getAllSongs = value; } + } + + private static GetCurrentSongIdDelegate getCurrentSongId; + public static GetCurrentSongIdDelegate GetCurrentSongId + { + get { return CServer.getCurrentSongId; } + set { CServer.getCurrentSongId = value; } + } + + #endregion public CServer(int port) diff --git a/ClientServerLib/ClientServerLib/CWebservice.cs b/ClientServerLib/ClientServerLib/CWebservice.cs index bb6e7584..332426f2 100644 --- a/ClientServerLib/ClientServerLib/CWebservice.cs +++ b/ClientServerLib/ClientServerLib/CWebservice.cs @@ -90,8 +90,20 @@ namespace ClientServerLib [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, - UriTemplate = "/getCurrentSong")] - SongInfo getCurrentSong(); + UriTemplate = "/getSong?songId={songId}")] + SongInfo getSong(int songId); + + [OperationContract] + [WebInvoke(Method = "GET", + ResponseFormat = WebMessageFormat.Json, + UriTemplate = "/getCurrentSongId")] + int getCurrentSongId(); + + [OperationContract] + [WebInvoke(Method = "GET", + ResponseFormat = WebMessageFormat.Json, + UriTemplate = "/getAllSongs")] + SongInfo[] getAllSongs(); #endregion } @@ -249,11 +261,22 @@ namespace ClientServerLib #region songs - public SongInfo getCurrentSong() + public SongInfo getSong(int songId) { - return CServer.GetCurrentSong(); + return CServer.GetSong(songId); + } + + public int getCurrentSongId() + { + return CServer.GetCurrentSongId(); + } + + public SongInfo[] getAllSongs() + { + return CServer.GetAllSongs(); } #endregion + } } diff --git a/ClientServerLib/ClientServerLib/DataStructs.cs b/ClientServerLib/ClientServerLib/DataStructs.cs index 49d441fb..c93a89e3 100644 --- a/ClientServerLib/ClientServerLib/DataStructs.cs +++ b/ClientServerLib/ClientServerLib/DataStructs.cs @@ -11,7 +11,7 @@ using System.Text.RegularExpressions; namespace ClientServerLib { public delegate bool SendKeyEventDelegate(string key); - + #region profile @@ -93,7 +93,11 @@ namespace ClientServerLib #region songs - public delegate SongInfo GetCurrentSongDelegate(); + public delegate SongInfo GetSongDelegate(int songId); + + public delegate SongInfo[] GetAllSongsDelegate(); + + public delegate int GetCurrentSongIdDelegate(); [DataContract] public struct SongInfo @@ -112,6 +116,8 @@ namespace ClientServerLib public string Year { get; set; } [DataMember] public bool IsDuet { get; set; } + [DataMember] + public int SongId { get; set; } } #endregion diff --git a/Vocaluxe/Base/Server/CVocaluxeServer.cs b/Vocaluxe/Base/Server/CVocaluxeServer.cs index 02ff9332..94d9a32e 100644 --- a/Vocaluxe/Base/Server/CVocaluxeServer.cs +++ b/Vocaluxe/Base/Server/CVocaluxeServer.cs @@ -60,7 +60,9 @@ namespace Vocaluxe.Base.Server CServer.GetProfileList = getProfileList; CServer.SendPhoto = sendPhoto; CServer.GetSiteFile = getSiteFile; - CServer.GetCurrentSong = getCurrentSong; + CServer.GetSong = getSong; + CServer.GetAllSongs = getAllSongs; + CServer.GetCurrentSongId = getCurrentSongId; _Discover = new CDiscover(CConfig.ServerPort, CCommands.BroadcastKeyword); Controller.Init(); @@ -328,10 +330,32 @@ namespace Vocaluxe.Base.Server #region songs - private static SongInfo getCurrentSong() + private static SongInfo getSong(int songId) + { + CSong song = CSongs.GetSong(songId); + return getSongInfo(song, true); + } + + private static SongInfo[] getAllSongs() + { + var songs = CSongs.Songs; + return (from s in songs + select getSongInfo(s, false)).ToArray(); + } + + private static int getCurrentSongId() + { + CSong song = CGame.GetSong(); + if (song == null) + { + return -1; + } + return song.ID; + } + + private static SongInfo getSongInfo(CSong song, bool includeCover) { SongInfo result = new SongInfo(); - CSong song = CGame.GetSong(); if (song != null) { result.Title = song.Title; @@ -340,8 +364,12 @@ namespace Vocaluxe.Base.Server result.Language = song.Language.FirstOrDefault(); result.Year = song.Year; result.IsDuet = song.IsDuet; - Image cover = Image.FromFile(song.Folder + "\\" + song.CoverFileName); - result.Cover = new Base64Image(cover, cover.RawFormat); + result.SongId = song.ID; + if (includeCover) + { + Image cover = Image.FromFile(song.Folder + "\\" + song.CoverFileName); + result.Cover = new Base64Image(cover, cover.RawFormat); + } } return result; } diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index f37c5aa4..a966bc45 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -175,10 +175,6 @@ ..\Output\AForge.Video.DirectShow.dll False - - ..\ClientServerLib\ClientServerLib\bin\ClientServerLib.dll - True - ..\Output\Community.CsharpSqlite.dll @@ -350,6 +346,9 @@ Always + + Always + Always diff --git a/Vocaluxe/Website/img/playlist.png b/Vocaluxe/Website/img/playlist.png new file mode 100644 index 00000000..370a115e Binary files /dev/null and b/Vocaluxe/Website/img/playlist.png differ diff --git a/Vocaluxe/Website/index.html b/Vocaluxe/Website/index.html index 4c8ffafe..e3efa819 100644 --- a/Vocaluxe/Website/index.html +++ b/Vocaluxe/Website/index.html @@ -42,12 +42,19 @@
  • - +

    Current Song

    Display informations about the current song

  • +
  • + + +

    All songs

    +

    List all available songs

    +
    +
  • @@ -154,6 +161,18 @@ +
    +
    +

    All songs

    +
    + + +
    +
      +
      + +
      +
      diff --git a/Vocaluxe/Website/js/main.js b/Vocaluxe/Website/js/main.js index bd9ee378..96e70ae7 100644 --- a/Vocaluxe/Website/js/main.js +++ b/Vocaluxe/Website/js/main.js @@ -1,5 +1,7 @@ -var ownProfileId = 1; -var profileIdRequest = 1; +var ownProfileId = -1; +var profileIdRequest = -1; +var songIdRequest = -1 +var allSongsCache = null; $(document).ready(function () { replaceTransitionHandler(); @@ -135,7 +137,7 @@ function initPageLoadHandler() { //pageLoadHandler for displaySong $(document).on('pagebeforeshow', '#displaySong', function () { var promise = $.ajax({ - url: "getCurrentSong" + url: "getSong?songId=" + songIdRequest }).done(function (result) { if (result.Title != null) { $('#displaySongTitle').text(result.Title); @@ -178,13 +180,48 @@ function initPageLoadHandler() { else { $('#displaySongLanguage').text("-"); } - - $('#displaySongIsDuet').text(result.IsDuet?"Yes":"No"); + + $('#displaySongIsDuet').text(result.IsDuet ? "Yes" : "No"); }); // Save promise on page so the transition handler can find it. $(this).data('promise', promise); }); + + //pageLoadHandler for selectSong + $(document).on('pagebeforeshow', '#selectSong', function () { + function handleGetAllSongs() { + $('#selectSongList').children().remove(); + + function handleSelectSongLineClick(e) { + songIdRequest = parseInt(e.currentTarget.id.replace("selectSongLine_", "")); + $.mobile.changePage("#displaySong", { transition: "slidefade" }); + } + + for (var id in allSongsCache) { + $('
    • '/*+' '*/ + '

      ' + allSongsCache[id].Artist + '

      ' + allSongsCache[id].Title + '

    • ') + .appendTo('#selectSongList') + .click(handleSelectSongLineClick); + } + + $('#selectSongList').listview('refresh'); + } + + if (allSongsCache == null) { + var promise = $.ajax({ + url: "getAllSongs" + }).done(function (data) { + allSongsCache = data; + handleGetAllSongs() + }); + + // Save promise on page so the transition handler can find it. + $(this).data('promise', promise); + } + else { + handleGetAllSongs() + } + }); } function initLoginPageHandler() { @@ -202,6 +239,26 @@ function initMainPageHandler() { $.mobile.changePage("#displayProfile", { transition: "slidefade" }); }); + $('#currentSongLink').click(function () { + $('#content').wrap('
      '); + $.mobile.loading('show', { + text: 'Getting current song...', + textVisible: true + }); + + $.ajax({ + url: "getCurrentSongId" + }).done(function (result) { + songIdRequest = parseInt(result); + $.mobile.loading('hide'); + $('#content').unwrap(); + $.mobile.changePage("#displaySong", { transition: "slidefade" }); + }).fail(function (result) { + $.mobile.loading('hide'); + $('#content').unwrap(); + }); + }); + $('#mainPageTakePhotoLink').click(function () { if ($('#captureContainer').length > 0) { $('#captureContainer').remove();