First commit for basic naive implementation
This commit is contained in:
29
MPDCtrl/Classes/AlbumImage.cs
Normal file
29
MPDCtrl/Classes/AlbumImage.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace MPDCtrl.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// AlbumCover class.
|
||||
/// </summary>
|
||||
public class AlbumImage
|
||||
{
|
||||
public bool IsDownloading { get; set; }
|
||||
|
||||
public bool IsSuccess { get; set; }
|
||||
|
||||
public string SongFilePath { get; set; }
|
||||
|
||||
public byte[] BinaryData { get; set; } = Array.Empty<byte>();
|
||||
|
||||
public int BinarySize { get; set; }
|
||||
|
||||
public ImageSource AlbumImageSource { get; set; }
|
||||
|
||||
}
|
||||
}
|
53
MPDCtrl/Classes/Playlist.cs
Normal file
53
MPDCtrl/Classes/Playlist.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MPDCtrl.Models
|
||||
{
|
||||
public class Playlist
|
||||
{
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
private string _lastModified;
|
||||
public string LastModified
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lastModified;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_lastModified == value)
|
||||
return;
|
||||
|
||||
_lastModified = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string LastModifiedFormated
|
||||
{
|
||||
get
|
||||
{
|
||||
DateTime _lastModifiedDateTime = default; //new DateTime(1998,04,30)
|
||||
|
||||
if (!string.IsNullOrEmpty(_lastModified))
|
||||
{
|
||||
try
|
||||
{
|
||||
_lastModifiedDateTime = DateTime.Parse(_lastModified, null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
}
|
||||
catch
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Wrong LastModified timestamp format. " + _lastModified);
|
||||
}
|
||||
}
|
||||
|
||||
var culture = System.Globalization.CultureInfo.CurrentCulture;
|
||||
return _lastModifiedDateTime.ToString(culture);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
52
MPDCtrl/Classes/Result.cs
Normal file
52
MPDCtrl/Classes/Result.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MPDCtrl.Models
|
||||
{
|
||||
public class Result
|
||||
{
|
||||
public bool IsSuccess;
|
||||
public string ErrorMessage;
|
||||
}
|
||||
|
||||
public class ConnectionResult: Result
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// generic
|
||||
public class CommandResult : Result
|
||||
{
|
||||
public string ResultText;
|
||||
}
|
||||
|
||||
public class CommandBinaryResult : Result
|
||||
{
|
||||
public int WholeSize;
|
||||
public int ChunkSize;
|
||||
public string Type;
|
||||
public byte[] BinaryData;
|
||||
}
|
||||
|
||||
// for commands that return playlist songs.
|
||||
public class CommandPlaylistResult : CommandResult
|
||||
{
|
||||
public ObservableCollection<SongInfo> PlaylistSongs;
|
||||
}
|
||||
|
||||
// for commands that return search result.
|
||||
public class CommandSearchResult : CommandResult
|
||||
{
|
||||
public ObservableCollection<SongInfo> SearchResult;
|
||||
}
|
||||
|
||||
// TODO: Not used?
|
||||
public class IdleResult : CommandResult
|
||||
{
|
||||
|
||||
}
|
||||
}
|
231
MPDCtrl/Classes/Song.cs
Normal file
231
MPDCtrl/Classes/Song.cs
Normal file
@ -0,0 +1,231 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
//using MPDCtrl.Common;
|
||||
|
||||
namespace MPDCtrl.Models
|
||||
{
|
||||
// SongFile > SongInfo > SongInfoEx
|
||||
|
||||
/// <summary>
|
||||
/// Generic song file class. (for listall)
|
||||
/// </summary>
|
||||
public class SongFile// : ViewModelBase
|
||||
{
|
||||
public string File { get; set; } = "";
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SongInfo class. (for playlist or search result)
|
||||
/// </summary>
|
||||
public class SongInfo : SongFile
|
||||
{
|
||||
public string Title { get; set; } = "";
|
||||
public string Track { get; set; } = "";
|
||||
public string Disc { get; set; } = "";
|
||||
public string Time { get; set; } = "";
|
||||
public string TimeFormated
|
||||
{
|
||||
get
|
||||
{
|
||||
string _timeFormatted = "";
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Time))
|
||||
{
|
||||
int sec, min, hour, s;
|
||||
|
||||
double dtime = double.Parse(Time);
|
||||
sec = Convert.ToInt32(dtime);
|
||||
|
||||
//sec = Int32.Parse(_time);
|
||||
min = sec / 60;
|
||||
s = sec % 60;
|
||||
hour = min / 60;
|
||||
min %= 60;
|
||||
|
||||
if ((hour == 0) && min == 0)
|
||||
{
|
||||
_timeFormatted = String.Format("{0}", s);
|
||||
}
|
||||
else if ((hour == 0) && (min != 0))
|
||||
{
|
||||
_timeFormatted = String.Format("{0}:{1:00}", min, s);
|
||||
}
|
||||
else if ((hour != 0) && (min != 0))
|
||||
{
|
||||
_timeFormatted = String.Format("{0}:{1:00}:{2:00}", hour, min, s);
|
||||
}
|
||||
else if (hour != 0)
|
||||
{
|
||||
_timeFormatted = String.Format("{0}:{1:00}:{2:00}", hour, min, s);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Oops@TimeFormated: " + Time + " : " + hour.ToString() + " " + min.ToString() + " " + s.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FormatException e)
|
||||
{
|
||||
// Ignore.
|
||||
// System.Diagnostics.Debug.WriteLine(e.Message);
|
||||
System.Diagnostics.Debug.WriteLine("Wrong Time format. " + Time + " " + e.Message);
|
||||
}
|
||||
|
||||
return _timeFormatted;
|
||||
}
|
||||
|
||||
}
|
||||
public double TimeSort
|
||||
{
|
||||
get
|
||||
{
|
||||
double dtime = double.NaN;
|
||||
try
|
||||
{
|
||||
dtime = double.Parse(Time);
|
||||
}
|
||||
catch { }
|
||||
return dtime;
|
||||
}
|
||||
}
|
||||
public string Duration { get; set; } = "";
|
||||
public string Artist { get; set; } = "";
|
||||
public string Album { get; set; } = "";
|
||||
public string AlbumArtist { get; set; } = "";
|
||||
public string Composer { get; set; } = "";
|
||||
public string Date { get; set; } = "";
|
||||
public string Genre { get; set; } = "";
|
||||
|
||||
private string _lastModified;
|
||||
public string LastModified
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lastModified;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_lastModified == value)
|
||||
return;
|
||||
|
||||
_lastModified = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string LastModifiedFormated
|
||||
{
|
||||
get
|
||||
{
|
||||
DateTime _lastModifiedDateTime = default; //new DateTime(1998,04,30)
|
||||
|
||||
if (!string.IsNullOrEmpty(_lastModified))
|
||||
{
|
||||
try
|
||||
{
|
||||
_lastModifiedDateTime = DateTime.Parse(_lastModified, null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
}
|
||||
catch
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Wrong LastModified timestamp format. " + _lastModified);
|
||||
}
|
||||
}
|
||||
|
||||
var culture = System.Globalization.CultureInfo.CurrentCulture;
|
||||
return _lastModifiedDateTime.ToString(culture);
|
||||
}
|
||||
}
|
||||
|
||||
// for sorting and (playlist pos)
|
||||
private int _index;
|
||||
public int Index
|
||||
{
|
||||
get
|
||||
{
|
||||
return _index;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_index == value)
|
||||
return;
|
||||
|
||||
_index = value;
|
||||
//this.NotifyPropertyChanged(nameof(Index));
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isSelected;
|
||||
public bool IsSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_isSelected == value)
|
||||
return;
|
||||
|
||||
_isSelected = value;
|
||||
|
||||
//NotifyPropertyChanged("IsSelected");
|
||||
}
|
||||
}
|
||||
|
||||
public int IndexPlusOne
|
||||
{
|
||||
get
|
||||
{
|
||||
return _index+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// song class with some extra info. (for queue)
|
||||
/// </summary>
|
||||
public class SongInfoEx : SongInfo
|
||||
{
|
||||
// Queue specific
|
||||
|
||||
public string Id { get; set; }
|
||||
|
||||
private string _pos;
|
||||
public string Pos
|
||||
{
|
||||
get
|
||||
{
|
||||
return _pos;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_pos == value)
|
||||
return;
|
||||
|
||||
_pos = value;
|
||||
//this.NotifyPropertyChanged(nameof(Pos));
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isPlaying;
|
||||
public bool IsPlaying
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isPlaying;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_isPlaying == value)
|
||||
return;
|
||||
|
||||
_isPlaying = value;
|
||||
//this.NotifyPropertyChanged(nameof(IsPlaying));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
149
MPDCtrl/Classes/Status.cs
Normal file
149
MPDCtrl/Classes/Status.cs
Normal file
@ -0,0 +1,149 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MPDCtrl.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// MPD "status" class. (for "status" command result)
|
||||
/// </summary>
|
||||
public class Status
|
||||
{
|
||||
public enum MpdPlayState
|
||||
{
|
||||
Play, Pause, Stop
|
||||
};
|
||||
|
||||
private MpdPlayState _ps;
|
||||
private string _bitrate;
|
||||
private int _volume = 50;
|
||||
private bool _volumeIsSet;
|
||||
private bool _repeat;
|
||||
private bool _random;
|
||||
private bool _consume;
|
||||
private bool _single;
|
||||
private string _songID = "";
|
||||
private double _songTime = 0;
|
||||
private double _songElapsed = 0;
|
||||
private string _error = "";
|
||||
|
||||
public MpdPlayState MpdState
|
||||
{
|
||||
get { return _ps; }
|
||||
set { _ps = value; }
|
||||
}
|
||||
|
||||
public string MpdBitrate
|
||||
{
|
||||
get { return _bitrate; }
|
||||
set
|
||||
{
|
||||
_bitrate = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int MpdVolume
|
||||
{
|
||||
get { return _volume; }
|
||||
set
|
||||
{
|
||||
_volume = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool MpdVolumeIsSet
|
||||
{
|
||||
get { return _volumeIsSet; }
|
||||
set
|
||||
{
|
||||
_volumeIsSet = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool MpdRepeat
|
||||
{
|
||||
get { return _repeat; }
|
||||
set
|
||||
{
|
||||
_repeat = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool MpdRandom
|
||||
{
|
||||
get { return _random; }
|
||||
set
|
||||
{
|
||||
_random = value;
|
||||
}
|
||||
}
|
||||
public bool MpdConsume
|
||||
{
|
||||
get { return _consume; }
|
||||
set
|
||||
{
|
||||
_consume = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool MpdSingle
|
||||
{
|
||||
get { return _single; }
|
||||
set
|
||||
{
|
||||
_single = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string MpdSongID
|
||||
{
|
||||
get { return _songID; }
|
||||
set
|
||||
{
|
||||
_songID = value;
|
||||
}
|
||||
}
|
||||
|
||||
public double MpdSongTime
|
||||
{
|
||||
get { return _songTime; }
|
||||
set
|
||||
{
|
||||
_songTime = value;
|
||||
}
|
||||
}
|
||||
|
||||
public double MpdSongElapsed
|
||||
{
|
||||
get { return _songElapsed; }
|
||||
set
|
||||
{
|
||||
_songElapsed = value;
|
||||
}
|
||||
}
|
||||
public string MpdError
|
||||
{
|
||||
get { return _error; }
|
||||
set
|
||||
{
|
||||
_error = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_volume = 50;
|
||||
_volumeIsSet = false;
|
||||
_repeat = false;
|
||||
_random = false;
|
||||
_consume = false;
|
||||
_songID = "";
|
||||
_songTime = 0;
|
||||
_songElapsed = 0;
|
||||
_error = "";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user