//============= 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);
     }
 }
示例#3
0
        private void OnGlobalKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (!loaded || keybindReaderMidi.IsReading)
            {
                return;
            }
            bool isActive = IsActive;
            var  focus    = FocusManager.GetFocusedElement(this);

            if (focus is TextBox || focus is IntSpinner)
            {
                return;
            }
            foreach (Window window in OwnedWindows)
            {
                focus = FocusManager.GetFocusedElement(window);
                if (focus is TextBox || focus is IntSpinner)
                {
                    return;
                }
                if (window.IsActive)
                {
                    isActive = true;
                }
            }

            if (e.KeyCode == Keys.Enter && TerrariaWindowLocator.CheckIfFocused() && Config.DisableMountWhenTalking)
            {
                talking = !talking;
                checkBoxTalking.IsChecked = talking;
            }

            if (Config.HasMidi)
            {
                if (Config.Keybinds.Play.IsDown(e) && (Config.PlaybackNoFocus || isActive || TerrariaWindowLocator.CheckIfFocused()))
                {
                    if (server != null)
                    {
                        HostStartPlay();
                    }
                    else
                    {
                        Play();
                    }
                }
                else if (Config.Keybinds.Pause.IsDown(e) && (Config.PlaybackNoFocus || isActive || TerrariaWindowLocator.CheckIfFocused()))
                {
                    if (server != null)
                    {
                        HostStop();
                    }
                    else
                    {
                        Pause();
                    }
                }
                else if (Config.Keybinds.Stop.IsDown(e))
                {
                    if (server != null)
                    {
                        HostStop();
                    }
                    else
                    {
                        Stop();
                    }
                }
            }
            if (Config.Keybinds.Mount.IsDown(e) && TerrariaWindowLocator.CheckIfFocused() && !talking)
            {
                mounted = !mounted;
                checkBoxMounted.IsChecked = mounted;
            }
            for (int i = 0; i < Config.Midis.Count; i++)
            {
                if (Config.MidiIndex != i && Config.Midis[i].Keybind.IsDown(e) && (Config.PlaybackNoFocus || isActive || TerrariaWindowLocator.CheckIfFocused()))
                {
                    Stop();

                    loaded                  = false;
                    Config.MidiIndex        = i;
                    listMidis.SelectedIndex = i;
                    loaded                  = true;
                    UpdateMidi();
                }
            }
            if (Config.Keybinds.Close.IsDown(e) && (Config.CloseNoFocus || isActive || TerrariaWindowLocator.CheckIfFocused()))
            {
                Close();
            }
        }
示例#4
0
 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);
         }
     }
 }
示例#5
0
        private void OnGlobalKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (!loaded || keybindReaderMidi.IsReading)
            {
                return;
            }

            if (Config.HasMidi)
            {
                if (Config.Keybinds.Play.IsDown(e) && (Config.PlaybackNoFocus || IsActive || TerrariaWindowLocator.CheckIfFocused()))
                {
                    if (server != null)
                    {
                        HostStartPlay();
                    }
                    else
                    {
                        Play();
                    }
                }
                else if (Config.Keybinds.Pause.IsDown(e) && (Config.PlaybackNoFocus || IsActive || TerrariaWindowLocator.CheckIfFocused()))
                {
                    if (server != null)
                    {
                        HostStop();
                    }
                    else
                    {
                        Pause();
                    }
                }
                else if (Config.Keybinds.Stop.IsDown(e))
                {
                    if (server != null)
                    {
                        HostStop();
                    }
                    else
                    {
                        Stop();
                    }
                }
            }
            if (Config.Keybinds.Mount.IsDown(e) && TerrariaWindowLocator.CheckIfFocused())
            {
                mounted = !mounted;
                checkBoxMounted.IsChecked = mounted;
            }
            for (int i = 0; i < Config.Midis.Count; i++)
            {
                if (Config.Midis[i].Keybind.IsDown(e) && (Config.PlaybackNoFocus || IsActive || TerrariaWindowLocator.CheckIfFocused()))
                {
                    Stop();

                    loaded                  = false;
                    Config.MidiIndex        = i;
                    listMidis.SelectedIndex = i;
                    loaded                  = true;
                    UpdateMidi();
                }
            }
            if (Config.Keybinds.Close.IsDown(e) && (Config.CloseNoFocus || IsActive || TerrariaWindowLocator.CheckIfFocused()))
            {
                Close();
            }
        }