//============= PLAY ============= #region Play /**<summary>Starts or continues the song.</summary>*/ private void Play() { if (Config.HasMidi) { firstNote = true; TerrariaWindowLocator.Update(true); if (!TerrariaWindowLocator.HasFocus) { TerrariaWindowLocator.Focus(); Thread.Sleep(400); } if (TerrariaWindowLocator.IsOpen) { clientArea = TerrariaWindowLocator.ClientArea; noteWatch.Restart(); // When the sequencer finishes it leaves its position at 1 if (sequencer.Position <= 1) { sequencer.Start(); } else { sequencer.Continue(); } checkCount = 0; Dispatcher.Invoke(() => { toggleButtonStop.IsChecked = false; toggleButtonPlay.IsChecked = true; toggleButtonPause.IsChecked = false; playbackUITimer.Start(); }); } else { Dispatcher.Invoke(() => { toggleButtonPlay.IsChecked = false; TriggerMessageBox.Show(this, MessageIcon.Warning, "You cannot play a midi when Terraria isn't running! Have you specified the correct executable name in Options?", "Terraria not Running"); }); } } }
private void OnChannelMessagePlayed(object sender, ChannelMessageEventArgs e) { if (Config.Midi.IsMessagePlayable(e) && (watch.ElapsedMilliseconds >= Config.UseTime * 1000 / 60 + 2 || firstNote)) { if (Config.ChecksEnabled) { checkCount++; if (!TerrariaWindowLocator.Update(Config.ChecksEnabled && checkCount > Config.CheckFrequency)) { Pause(); Dispatcher.Invoke(() => { TriggerMessageBox.Show(this, MessageIcon.Error, "Failed to keep track of the Terraria Window!", "Tracking Error"); }); return; } if (checkCount > Config.CheckFrequency) { checkCount = 0; } if (!TerrariaWindowLocator.HasFocus) { TerrariaWindowLocator.Focus(); Thread.Sleep(100); return; } if (!TerrariaWindowLocator.IsOpen) { Pause(); Dispatcher.Invoke(() => { TriggerMessageBox.Show(this, MessageIcon.Warning, "Terraria window has been closed.", "Terraria Closed"); }); return; } clientArea = TerrariaWindowLocator.ClientArea; } firstNote = false; int note = e.Message.Data1 - 12 * (Config.Midi.GetTrackSettingsByTrackObj(e.Track).OctaveOffset + 1) + Config.Midi.NoteOffset; watch.Restart(); PlayNote(note); } }
private void OnChannelMessagePlayed(object sender, ChannelMessageEventArgs e) { if (Config.Midi.IsMessagePlayable(e) && (watch.ElapsedMilliseconds >= Config.UseTime * 1000 / 60 + 2 || firstNote || (Config.PianoMode && !Config.SkipPianoMode))) { if (Config.PianoMode) { int note = e.Message.Data1 - 12 * (Config.Midi.GetTrackSettingsByTrackObj(e.Track).OctaveOffset + 1) + Config.Midi.NoteOffset; // Shift the note into a valid octave if (Config.WrapPianoMode) { if (note < 0) { note -= ((note - 11) / 12) * 12; } if (note > 24) // Remember, there's one extra C { note -= ((note - 14) / 12) * 12; } } Config.OutputDevice.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, note + 5 * 12, 100)); firstNote = false; watch.Restart(); } else { if (Config.ChecksEnabled) { checkCount++; if (!TerrariaWindowLocator.Update(Config.ChecksEnabled && checkCount > Config.CheckFrequency)) { Pause(); Dispatcher.Invoke(() => { TriggerMessageBox.Show(this, MessageIcon.Error, "Failed to keep track of the Terraria Window!", "Tracking Error"); }); return; } if (checkCount > Config.CheckFrequency) { checkCount = 0; } if (!TerrariaWindowLocator.HasFocus) { TerrariaWindowLocator.Focus(); Thread.Sleep(100); return; } if (!TerrariaWindowLocator.IsOpen) { Pause(); Dispatcher.Invoke(() => { TriggerMessageBox.Show(this, MessageIcon.Warning, "Terraria window has been closed.", "Terraria Closed"); }); return; } clientArea = TerrariaWindowLocator.ClientArea; } firstNote = false; int note = e.Message.Data1 - 12 * (Config.Midi.GetTrackSettingsByTrackObj(e.Track).OctaveOffset + 1) + Config.Midi.NoteOffset; watch.Restart(); PlayNote(note); } } }