private async void WindowLoaded(object sender, RoutedEventArgs e) { var songInfo = PipeListener.StaticPipeListener?.LastPlayedSong; songCache = songInfo?.Clone() as SongInfo; if (songInfo == null) { await this.ShowMessageAsync("メッセージ", "現在何も再生されていません。\n(注:アプリケーションが起動する前に再生されていた曲は取得できません)"); this.Close(); return; } var isource = new Func <BitmapSource?>(() => { try { if (!songInfo.IsAlbumArtAvaliable()) { return(null); } return(GdiUtils.ToImageSource(songInfo.GetAlbumArt() !)); } catch { return(null); } })(); AlbumArtImage.Source = isource; TweetTextBox.Text = TweetConverter.SongInfoToString(ConfigStore.StaticConfig.TweetFormat, songInfo); TweetTextBox.Focus(); }
void OnUpdateInfo(SongInfo?newInfo) { bool hasInfo = newInfo.HasValue; songInfo = newInfo.GetValueOrDefault(); if (!songInfo.banner && songInfo.background) { songInfo.banner = songInfo.background; } background.SetTexture(songInfo.background); background.gameObject.SetActive(songInfo.background); banner.SetTexture(songInfo.banner); bannerParent.gameObject.SetActive(songInfo.banner); songDetails.text = hasInfo ? string.Format( LanguageLoader.GetText(1), songInfo.name, songInfo.level, songInfo.artist, songInfo.subArtist, songInfo.genre, songInfo.bpm, songInfo.notes, songInfo.LayoutName, songInfo.comments ) : string.Empty; ReloadRecord(); }
public PlayResource(string uri, AudioResource baseData, PlayInfo?playInfo = null, SongInfo?songInfo = null) { AudioResource = baseData; PlayUri = uri; PlayInfo = playInfo; SongInfo = songInfo; }
static IEnumerator LoadResource() { for (int i = 0; i < entries.Count; i++) { Entry entry = entries[i]; if (entry.isDirectory) { yield return(null); continue; } if ((entry.songInfo.background || string.IsNullOrEmpty(entry.songInfo.backgroundPath)) && (entry.songInfo.banner || string.IsNullOrEmpty(entry.songInfo.bannerPath))) { yield return(null); continue; } FileInfo fileInfo = new FileInfo(GetAbsolutePath(entry.songInfo.filePath)); var resourceLoader = new ResourceLoader(fileInfo.Directory.FullName); if (!entry.songInfo.background && !string.IsNullOrEmpty(entry.songInfo.backgroundPath)) { var backgroundObj = new ResourceObject(-1, ResourceType.bmp, entry.songInfo.backgroundPath); yield return(SmartCoroutineLoadBalancer.StartCoroutine(bmsManager, resourceLoader.LoadResource(backgroundObj))); entry.songInfo.background = backgroundObj.texture; } if (!entry.songInfo.banner && !string.IsNullOrEmpty(entry.songInfo.bannerPath)) { var bannerObj = new ResourceObject(-2, ResourceType.bmp, entry.songInfo.bannerPath); yield return(SmartCoroutineLoadBalancer.StartCoroutine(bmsManager, resourceLoader.LoadResource(bannerObj))); entry.songInfo.banner = bannerObj.texture; } entries[i] = entry; cachedEntries[fileInfo.FullName] = entry; if (selectedEntry.HasValue && string.Equals(entry.songInfo.filePath, selectedEntry.Value.filePath, StringComparison.Ordinal)) { selectedEntry = entry.songInfo; if (OnSelectionChanged != null) { OnSelectionChanged.Invoke(selectedEntry); } } InvokeListUpdated(); yield return(null); } loadResourceCoroutine = null; yield break; }
protected override void OnActiveSongChanged(object sender, ActiveSongChangedEventArgs e) { base.OnActiveSongChanged(sender, e); if (e.NewActiveSong != null) { lastActiveSong = e.NewActiveSong; } }
/// <summary> /// Updates the current state of the spotify process. /// </summary> /// <param name="newState">The new state of the spotify process.</param> /// <param name="newSong">The currently playing song, if applicable.</param> protected void UpdateState(SpotifyState newState, SongInfo? newSong = null) { var prevSong = ActiveSong; var prevState = State; ActiveSong = newSong; State = newState; if (prevState != newState) OnSpotifyStateChanged(prevState, newState); if (prevSong != newSong) OnActiveSongChanged(prevSong, newSong); }
void SelectionChanged(SongInfo?newInfo) { bool changed = false; if (currentInfo.HasValue != newInfo.HasValue) { changed = true; } else if (newInfo.HasValue && currentInfo.Value.filePath != newInfo.Value.filePath) { changed = true; } if (changed) { HideOptions(); } currentInfo = newInfo; }
void Awake() { if (!bmsManager) { bmsManager = GetComponent <BMSManager>(); } if (!bmsManager) { bmsManager = gameObject.AddComponent <BMSManager>(); } SongInfoLoader.SetBMSManager(bmsManager); gameMode.value = Loader.gameMode; gameMode.onValueChanged.AddListener(GameModeChange); colorMode.value = (int)Loader.colorMode; colorMode.onValueChanged.AddListener(ColorModeChange); autoModeToggle.isOn = Loader.autoMode; autoModeToggle.onValueChanged.AddListener(ToggleAuto); detuneToggle.isOn = Loader.enableDetune; detuneToggle.onValueChanged.AddListener(ToggleDetune); bgaToggle.isOn = Loader.enableBGA; bgaToggle.onValueChanged.AddListener(ToggleBGA); dynamicSpeedToggle.isOn = Loader.dynamicSpeed; dynamicSpeedToggle.onValueChanged.AddListener(ToggleDynamicSpeed); judgeModeDropDown.value = Loader.judgeMode; judgeModeDropDown.onValueChanged.AddListener(JudgeModeChange); speedSlider.value = Loader.speed; speedSlider.onValueChanged.AddListener(ChangeSpeed); notesLimitSlider.value = Loader.noteLimit; notesLimitSlider.onValueChanged.AddListener(ChangeNoteLimit); sortMode.value = savedSortMode; sortMode.onValueChanged.AddListener(ChangeSortMode); startGameButton.onClick.AddListener(StartGame); optionsButton.onClick.AddListener(ShowOptions); optionsBackButton.onClick.AddListener(HideOptions); currentInfo = SongInfoLoader.SelectedSong; SongInfoLoader.OnStartLoading += OnLoadingChanged; SongInfoLoader.OnListUpdated += OnLoadingChanged; SongInfoLoader.OnSelectionChanged += SelectionChanged; LanguageLoader.OnLanguageChange += LangChange; OnLoadingChanged(); }
private void OnMusicPlay(SongInfo songInfo) { Task.Run(async() => { if (!appConfig.EnableAutoTweet) { return; } if (appConfig.EnablePostDelay && !(tweetTask?.IsCompleted ?? true)) { //cancel tweet job Trace.WriteLine($"[AutoTweet PostDelay]Cancel tweet task start."); cancellationToken.Cancel(); resetEvent.Set(); if (tweetTask != null) { await tweetTask; } Trace.WriteLine($"[AutoTweet PostDelay]Cancel tweet task OK."); } //can't reuse this cancellationToken = new CancellationTokenSource(); //start task tweetTask = Task.Run(() => { try { //check for album art var enableAlbumArt = appConfig.EnableTweetWithAlbumArt; if (appConfig.EnableNoAlbumArtworkOnSameAlbum) { if (songInfo.Album == lastPlayedSong?.Album) { Trace.WriteLine($"[AutoTweet]Disabled album art tweet.(reason=same album)"); enableAlbumArt = false; } } //same album check if (appConfig.EnableNoTweetOnSameAlbum) { if (songInfo.Album == lastPlayedSong?.Album) { Trace.WriteLine($"[AutoTweet]Canceled tweet.(reason=EnableNoTweetOnSameAlbum)"); return; } } //post delay if (appConfig.EnablePostDelay) { Trace.WriteLine( $"[AutoTweet PostDelay]Waiting for {appConfig.PostDelaySecond * 1000}msec."); resetEvent.WaitOne(appConfig.PostDelaySecond * 1000); } //post delay(by last tweet time) if (appConfig.EnableTimePostDelay) { if (lastTweetTime != default(DateTime)) { if (!(DateTime.Now - lastTweetTime >= new TimeSpan(0, 0, appConfig.TimePostDelayMin, appConfig.TimePostDelaySec))) { Trace.WriteLine($"[AutoTweet]Canceled tweet.(reason=EnableTimePostDelay)"); return; } } } cancellationToken.Token.ThrowIfCancellationRequested(); lastPlayedSong = (SongInfo)songInfo.Clone(); lastTweetTime = DateTime.Now; //tweet it! try { //get account list(only enabled) appConfig.accountList.Where(itm => itm.Enabled).ToList().ForEach(async(accCont) => { //make tweet string var tweetText = Tsumugi.TweetConverter.SongInfoToString(appConfig.TweetFormat, songInfo, appConfig.EnableAutoDeleteText140, accCont); if (accCont.CountText(tweetText) > accCont.MaxTweetLength) { throw new Exception( $"[AutoTweet]Tweet text was over {accCont.MaxTweetLength} chars."); } //tweet if (enableAlbumArt && songInfo.IsAlbumArtAvaliable()) { if (accCont is MastodonAccount mastodonAccount) { await mastodonAccount.UpdateStatus(tweetText, songInfo.AlbumArtBase64, appConfig.MastodonTootVisibility); } else { await accCont.UpdateStatus(tweetText, songInfo.AlbumArtBase64); } } else { if (accCont is MastodonAccount mastodonAccount) { await mastodonAccount.UpdateStatus(tweetText, appConfig.MastodonTootVisibility); } else { await accCont.UpdateStatus(tweetText); } } Trace.WriteLine($"[AutoTweet]Sent tweet for account @{accCont.ID}."); }); } catch (Exception ex) { Trace.WriteLine($"[AutoTweet]Tweet error.\n{ex.Message}"); } } catch (OperationCanceledException) { Trace.WriteLine($"[AutoTweet] OperationCanceledException"); } catch (Exception ex) { Trace.WriteLine($"[AutoTweet] {ex.Message}"); } }); }); }
public void StartPipeListener() { //do not start more than 1 task. if (!new TaskStatus?[] { TaskStatus.RanToCompletion, TaskStatus.Faulted, TaskStatus.WaitingForChildrenToComplete, null }.Contains(listenerTask?.Status)) { return; } listenerTask = Task.Run(() => { while (true) { try { var resetStreamEvent = new AutoResetEvent(false); var stream = new NamedPipeServerStream("NowPlayingTunesV2PIPE", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); stream.BeginWaitForConnection(ar => { //WaitOne(0) returns true when state is set if (stopEvent.WaitOne(0)) { //Called when stopping task. streamStopWait.Set(); return; } //Must do this to connect to client. stream.EndWaitForConnection(ar); if (!stream.IsConnected) { return; } var memstream = new MemoryStream(); int readret = -1; while (readret != 0) { var buffer = new byte[1024]; readret = stream.Read(buffer, 0, buffer.Length); memstream.Write(buffer, 0, readret); } stream.Close(); resetStreamEvent.Set(); var bary = memstream.ToArray(); var rawjson = System.Text.Encoding.UTF8.GetString(bary); var sinfo = JsonConvert.DeserializeObject <SongInfo>(rawjson); LastPlayedSong = sinfo; OnMusicPlay(sinfo); }, null); //Wait for stop event //WaitAny will return index of WaitHandle array.(Can distingulish which ResetEvent was set.) if (WaitHandle.WaitAny(new WaitHandle[] { resetStreamEvent, stopEvent }) == 1) { //When stopEvent is called, close stream and escape listnertask. stream.Close(); return; } //do nothing when resetStreamEvent is set.(Just keep looping) } catch { } } }); }
public SongChangeEventArgs(SongInfo?oldSong, SongInfo?newSong) { this.OldSong = oldSong; this.NewSong = newSong; }
public ActiveSongChangedEventArgs(SongInfo? previousActiveSong, SongInfo? newActiveSong) { PreviousActiveSong = previousActiveSong; NewActiveSong = newActiveSong; }
private void OnActiveSongChanged(SongInfo? previous, SongInfo? current) => OnActiveSongChanged(new ActiveSongChangedEventArgs(previous, current));
public MpdStatus(SongInfo? songInfo, PlayerState state, int volume) { this._state = state; this._volume = volume; this._songInfo = songInfo; }