protected string MusicInfo(MPD.MusicInfo music, ref int curindex) { bool found = false; // Used for required arguments System.Text.StringBuilder ret = new System.Text.StringBuilder(); // The return string string temp; // A temporary string while (curindex < MusicInfoFormat.Length) { // Our current character char curchar = MusicInfoFormat[curindex]; if (curchar == '|') { curindex++; // If we didn't find one argument if (!found) // Let's try this now ret.Remove(0, ret.Length); else // Else just skip it MusicInfoSkipFormatting(ref curindex); continue; } if (curchar == '&') { curindex++; // If we didn't find one argument if (!found) // Skip the following format instructions MusicInfoSkipFormatting(ref curindex); else // Else set "found" as false found = false; continue; } if (curchar == '[') { curindex++; // Try to parse whats inside the square brackets temp = this.MusicInfo(music, ref curindex); if (temp != null) { // and then add it to the current result ret.Append(temp); found = true; } continue; } if (curchar == ']') { // Our time has come, return the current result if (!found && ret.Length > 0) // but only if found everything needed ret = null; break; } if (curchar != '#' && curchar != '%') { // Adds to the buffer any character other character curindex++; ret.Append(curchar); continue; } if (curchar == '#' && curindex+1 < MusicInfoFormat.Length) { // Writes only the character after "#" curindex += 2; ret.Append(MusicInfoFormat[curindex+1]); continue; } // If we're here, it's because there's a %something% sequence // curindex is the first "%", try to find the other temp = null; int finalindex = MusicInfoFormat.IndexOf('%', curindex+1); // If we found it if (finalindex >= 0) { // Then see what it is (the "+1" and the "-1" correspond to the "%" chars) string option = MusicInfoFormat.Substring(curindex+1, finalindex-curindex-1); // See if have length constrains int i = option.IndexOf(':'); int limit = -1; if (i > 0) { limit = Convert.ToInt32(option.Substring(i+1)); option = option.Substring(0, i); } switch (option) { case "file": temp = music.Filename; break; case "artist": if (music.Artist != "") temp = music.Artist; break; case "title": if (music.Title != "") temp = music.Title; break; case "album": if (music.Album != "") temp = music.Album; break; case "track": if (music.Track != "") temp = music.Track; break; case "name": if (music.Name != "") temp = music.Name; break; case "time": if (music.Time != -1) temp = Format.TimeInSeconds(music.Time); break; } // Could we format correctly? if (temp != null) { // Check size limits if (limit > -1 && temp.Length > limit) temp = temp.Substring(0, limit) + "..."; // Add to the result and set "found" to true ret.Append(temp); found = true; } else { // Or else just add what we've got ret.AppendFormat("%{0}%", option); } // Move to the index of the last char plus one curindex = finalindex+1; } else { // But if we didn't find the corresponding "%", just print it ret.Append("%"); curindex++; } } // Increment the curindex as maybe we're getting called by ourselves curindex++; if (ret != null) return ret.ToString(); else return null; }
public override IEnumerable <Item> ChildrenOfItem(Item parent) { List <Item> children; children = new List <Item> (); if (parent is IApplicationItem && parent.Name == "MPD") { children.Add(new BrowseAlbumsMusicItem()); children.Add(new BrowseArtistsMusicItem()); children.AddRange(MPDRunnableItem.DefaultItems); } else if (parent is ArtistMusicItem) { //Show all the albums then an 'all music by this artist' button foreach (AlbumMusicItem album in AllAlbumsBy(parent as ArtistMusicItem)) { children.Add(album); } children.Add(new BrowseAllMusicItem(parent as ArtistMusicItem)); } else if (parent is AlbumMusicItem) { foreach (SongMusicItem song in MPD.LoadSongsFor(parent as AlbumMusicItem)) { children.Add(song); } } else if (parent is BrowseAlbumsMusicItem) { foreach (AlbumMusicItem album in albums) { children.Add(album); } } else if (parent is BrowseArtistsMusicItem) { foreach (ArtistMusicItem artist in artists) { children.Add(artist); } } else if (parent is BrowseAllMusicItem) { foreach (SongMusicItem song in MPD.LoadSongsFor((parent as BrowseAllMusicItem).Artist)) { children.Add(song); } } return(children); }
public override IEnumerable <Item> Perform(IEnumerable <Item> items, IEnumerable <Item> modifierItems) { new Thread((ThreadStart) delegate { foreach (Item item in items) { List <SongMusicItem> songs = MPD.LoadSongsFor(item as MusicItem); foreach (SongMusicItem song in songs) { MPD.Client("play " + song.Number); break; } break; } }).Start(); return(null); }
public override void UpdateItems() { items.Clear(); // Add play, pause, etc. controls. items.AddRange(MPDRunnableItem.DefaultItems); // Add browse features. items.Add(new BrowseAlbumsMusicItem()); items.Add(new BrowseArtistsMusicItem()); // Add albums and artists. MPD.LoadAlbumsAndArtists(out albums, out artists); foreach (Item album in albums) { items.Add(album); } foreach (Item artist in artists) { items.Add(artist); } }
public string MusicInfo(MPD.MusicInfo music) { // Just a little wrapper int curindex = 0; return this.MusicInfo(music, ref curindex); }
public void Run() { new Thread((ThreadStart) delegate { MPD.Client(command); }).Start(); }