示例#1
0
 public void KeyboardPress(int pitch)
 {
     if (pitch > 84 || pitch < 48)
     {
         return;
     }
     if (Settings.Default.IsEightKeyLayout)
     {
         this.KeyboardPress(KeyBinding.GetNoteToCtrlKey(pitch), KeyBinding.GetNoteToKey(pitch));
     }
     else if (this.isBackGroundKey)
     {
         this.bkKeyController.BackgroundKeyPress(KeyBinding.GetNoteToKey(pitch));
     }
     else
     {
         this.KeyboardPress(KeyBinding.GetNoteToKey(pitch));
     }
     ParameterController.GetInstance().NetSyncQueue.Enqueue(new Daigassou.Utils.TimedNote()
     {
         Note      = pitch - 24,
         StartTime = DateTime.Now
     });
     if (ParameterController.GetInstance().isEnsembleSync)
     {
         Log.overlayLog($"{pitch} pressed");
     }
     if (initFlag)
     {
         Log.overlayLog($"{pitch} note on");
         initFlag = false;
     }
 }
示例#2
0
        private void MessageReceived(string connection, long epoch, byte[] message)
        {
            var res = Parse(message);


            if (res.header.MessageType == ParameterController.countDownPacket)//CountDown
            {
                var countDownTime = res.data[36];
                var unixTime      = BitConverter.ToUInt32(res.data, 24);
                var nameBytes     = new byte[18];
                Array.Copy(res.data, 41, nameBytes, 0, 18);
                var name = Encoding.UTF8.GetString(nameBytes) ?? "";
                Play?.Invoke(this, new PlayEvent(0, Convert.ToInt32(unixTime + countDownTime), name));
            }


            if (res.header.MessageType == ParameterController.partyStopPacket || res.header.MessageType == ParameterController.ensembleStopPacket) //Stop
            {
                Play?.Invoke(this, new PlayEvent(1, 0, " "));
            }
            if (res.header.MessageType == ParameterController.ensembleStartPacket)//ensemble start
            {
                var unixTime = BitConverter.ToUInt32(res.data, 24);
                ParameterController.GetInstance().isEnsembleSync = true;
                Play?.Invoke(this, new PlayEvent(0, Convert.ToInt32(unixTime + 6), " "));
            }
            if (res.header.MessageType == ParameterController.ensemblePacket)//ensemble mode
            {
                if (ParameterController.GetInstance().isEnsembleSync)
                {
                    ParameterController.GetInstance().AnalyzeEnsembleNotes(res.data);
                }
                ParameterController.GetInstance().isEnsembleSync = false;
            }
        }
示例#3
0
        private void MessageSent(long epoch, byte[] message, int set, FFXIVNetworkMonitor.ConnectionType connectionType)
        {
            var res = Parse(message);

            var item = new PacketEntry
            {
                IsVisible    = true,
                ActorControl = -1,
                Data         = message,
                Message      = res.header.MessageType.ToString("X4"),
                Direction    = "C",
                Category     = set.ToString(),
                // Timestamp = Util.UnixTimeStampToDateTime(res.header.Seconds).ToString(@"MM\/dd\/yyyy HH:mm:ss"),
                Size           = res.header.MessageLength.ToString(),
                Set            = set,
                RouteID        = res.header.RouteID.ToString(),
                PacketUnixTime = res.header.Seconds,
                // SystemMsTime = Millis(),
                Connection = connectionType
            };

            if (res.header.MessageType == 0x018B) //Bard Performance
            {
                var length = res.data[32];
                var notes  = new byte[length];
                Array.Copy(res.data, 33, notes, 0, length);
                Log.B(notes, true);//TODO: Time analyze
                ParameterController.GetInstance().AnalyzeNotes(notes);
            }
        }
示例#4
0
        private void StartKeyPlayback(int interval)
        {
            kc.isPlayingFlag = false;
            kc.isRunningFlag = false;
            kc.pauseOffset   = 0;
            ParameterController.GetInstance().Pitch = 0;
            if (Path.GetExtension(midFileDiag.FileName) != ".mid" && Path.GetExtension(midFileDiag.FileName) != ".midi")
            {
                Log.overlayLog($"错误:没有Midi文件");
                MessageBox.Show(new Form()
                {
                    TopMost = true
                }, "没有midi你演奏个锤锤?", "喵喵喵?", MessageBoxButtons.OK, MessageBoxIcon.Question);
                return;
            }

            if (_runningTask == null ||
                _runningTask.ThreadState != System.Threading.ThreadState.Running &&
                _runningTask.ThreadState != System.Threading.ThreadState.Suspended)
            {
                _runningTask?.Abort();

                this.kc.isPlayingFlag  = true;
                btnSyncReady.BackColor = Color.Aquamarine;
                btnSyncReady.Text      = "中断演奏";
                var Interval = interval < 1000 ? 1000 : interval;
                var sub      = (long)(1000 - interval);

                //timer1.Start();
                var sw = new Stopwatch();
                sw.Start();
                Log.overlayLog($"文件名:{Path.GetFileName(midFileDiag.FileName)}");
                Log.overlayLog($"定时:{Interval}毫秒后演奏");

                OpenFile(midFileDiag.FileName);
                lyricPoster.LrcStart(midFileDiag.FileName.Replace(".mid", ".mml").Replace(".mml", ".lrc"), interval);
                mtk.GetTrackManagers();
                keyPlayLists = mtk.ArrangeKeyPlaysNew((double)(mtk.GetBpm() / nudBpm.Value));
                //File.WriteAllText($"1.txt", JsonConvert.SerializeObject(keyPlayLists));
                if (interval < 0)
                {
                    var keyPlay = keyPlayLists.Where((x) => x.TimeMs > sub);
                    keyPlayLists = new Queue <KeyPlayList>();
                    foreach (KeyPlayList kp in keyPlay)
                    {
                        kp.TimeMs -= sub;
                        keyPlayLists.Enqueue(kp);
                    }
                }
                sw.Stop();

                _runningFlag          = true;
                cts                   = new CancellationTokenSource();
                _runningTask          = createPerformanceTask(cts.Token, interval - (int)sw.ElapsedMilliseconds);//minus bug?
                _runningTask.Priority = ThreadPriority.Highest;
            }
        }
示例#5
0
        private Thread createPerformanceTask(CancellationToken token, int startOffset)
        {
            ParameterController.GetInstance().InternalOffset = (int)numericUpDown2.Value;
            ParameterController.GetInstance().Offset         = 0;
            Thread thread = new Thread(
                () => {
                kc.KeyPlayBack(keyPlayLists, 1, cts.Token, startOffset);
                _runningFlag = false;
            }
                );

            thread.Start();
            return(thread);
        }
示例#6
0
        public void KeyPlayBack(
            Queue <KeyPlayList> keyQueue,
            double speed,
            CancellationToken token,
            int startOffset)
        {
            this.isRunningFlag = true;
            initFlag           = true;
            this.UpdateKeyMap();
            double?   timeMs    = keyQueue.LastOrDefault <KeyPlayList>()?.TimeMs;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            while (keyQueue.Any <KeyPlayList>())
            {
                KeyPlayList keyPlayList = keyQueue.Dequeue();
                double      num1        = (double)startOffset + keyPlayList.TimeMs * speed;
                while (true)
                {
                    if (!this.isPlayingFlag || num1 + (double)ParameterController.GetInstance().Offset + (double)this.pauseOffset > (double)stopwatch.ElapsedMilliseconds)
                    {
                        Thread.Sleep(1);
                    }
                    else
                    {
                        break;
                    }
                }
                if (keyPlayList.Ev == KeyPlayList.NoteEvent.NoteOn)
                {
                    this.KeyboardPress(keyPlayList.Pitch + ParameterController.GetInstance().Pitch);
                }
                else
                {
                    this.KeyboardRelease(keyPlayList.Pitch + ParameterController.GetInstance().Pitch);
                }
                double num2     = keyPlayList.TimeMs * 100.0;
                double?nullable = timeMs;
                Daigassou.Utils.Log.overlayProcess(((int)(nullable.HasValue ? new double?(num2 / nullable.GetValueOrDefault()) : new double?()).Value).ToString());
            }
            Daigassou.Utils.Log.overlayLog("演奏:演奏结束");
            if (stopHandler != null)
            {
                stopHandler.BeginInvoke(null, null);
            }
            this.ResetKey();
        }
示例#7
0
        private Thread createPerformanceTaskOriginal(CancellationToken token, double speed)
        {
            ParameterController.GetInstance().InternalOffset = (int)numericUpDown2.Value;
            ParameterController.GetInstance().Offset         = 0;

            Thread thread = new Thread(
                () => {
                KeyboardUtilities.kc = kc;
                kc.isRunningFlag     = true;
                mtk.PlaybackWithoutAnalysis(speed, P_EventPlayed, cts.Token);

                _runningFlag = false;
            }
                );

            thread.Start();
            return(thread);
        }
示例#8
0
        public void ResetKey()
        {
            this.isPlayingFlag = false;
            this.isRunningFlag = false;
            this.pauseOffset   = 0;
            this.KeyboardRelease(Keys.ControlKey);
            Thread.Sleep(1);
            this.KeyboardRelease(Keys.ShiftKey);
            Thread.Sleep(1);
            this.KeyboardRelease(Keys.Menu);
            Thread.Sleep(1);
            for (int note = 48; note < 84; ++note)
            {
                this.KeyboardRelease(KeyBinding.GetNoteToKey(note));
                Thread.Sleep(1);
            }

            ParameterController.GetInstance().Pitch = 0;
        }
示例#9
0
 private void radioButton3_CheckedChanged(object sender, EventArgs e)
 {
     ParameterController.GetInstance().Pitch = EnumPitchOffset.OctaveHigher - mtk.Offset;
     mtk.Offset = EnumPitchOffset.OctaveHigher;
     Log.overlayLog($"[移调] 当前 {ParameterController.GetInstance().Pitch}");
 }
示例#10
0
 private void PitchDown_HotKeyPressed(object sender, GlobalHotKeyEventArgs e)
 {
     ParameterController.GetInstance().Pitch -= 1;
     Log.overlayLog($"快捷键:向下移调 当前 {ParameterController.GetInstance().Pitch}");
 }
示例#11
0
        private void StartKeyPlayback(int interval)
        {
            kc.isPlayingFlag = false;
            kc.isRunningFlag = false;
            kc.pauseOffset   = 0;
            ParameterController.GetInstance().Pitch = 0;
            if (midFileDiag.FileName == string.Empty)
            {
                Log.overlayLog($"错误:没有Midi文件");
                MessageBox.Show(new Form()
                {
                    TopMost = true
                }, "没有midi你演奏个锤锤?", "喵喵喵?", MessageBoxButtons.OK, MessageBoxIcon.Question);
                return;
            }

            if (_runningTask == null ||
                _runningTask.ThreadState != System.Threading.ThreadState.Running &&
                _runningTask.ThreadState != System.Threading.ThreadState.Suspended)
            {
                _runningTask?.Abort();

                this.kc.isPlayingFlag  = true;
                btnSyncReady.BackColor = Color.Aquamarine;
                btnSyncReady.Text      = "中断演奏";
                var Interval = interval < 1000 ? 1000 : interval;
                var sub      = (long)(1000 - interval);
                int bpm      = 120;
                //timer1.Start();
                var sw = new Stopwatch();
                sw.Start();
                Log.overlayLog($"文件名:{Path.GetFileName(midFileDiag.FileName)}");
                Log.overlayLog($"定时:{Interval}毫秒后演奏");
                if (ParameterController.GetInstance().isEnsembleSync)
                {
                    System.Threading.Timer timer1 = new System.Threading.Timer((TimerCallback)(x => this.kc.KeyboardPress(48)), new object(), Interval - 4000, 0);
                    System.Threading.Timer timer2 = new System.Threading.Timer((TimerCallback)(x => this.kc.KeyboardRelease(48)), new object(), Interval - 3950, 0);
                    Log.overlayLog($"定时:同步音按下");
                }
                if (netMidiFlag)
                {
                    keyPlayLists = mtk.netmidi?.Tracks[trackComboBox.SelectedIndex].notes;
                    bpm          = mtk.netmidi.BPM;
                }
                else
                {
                    OpenFile(midFileDiag.FileName);
                    bpm = mtk.GetBpm();
                    mtk.GetTrackManagers();
                    keyPlayLists = mtk.ArrangeKeyPlaysNew((double)(bpm / nudBpm.Value));
                }


                lyricPoster.LrcStart(midFileDiag.FileName.Replace(".mid", ".mml").Replace(".mml", ".lrc"), interval);
                File.WriteAllText($"1.txt", JsonConvert.SerializeObject(keyPlayLists));
                if (interval < 0)
                {
                    var keyPlay = keyPlayLists.Where((x) => x.TimeMs > sub);
                    keyPlayLists = new Queue <KeyPlayList>();
                    foreach (KeyPlayList kp in keyPlay)
                    {
                        kp.TimeMs -= sub;
                        keyPlayLists.Enqueue(kp);
                    }
                }
                sw.Stop();

                _runningFlag = true;
                cts          = new CancellationTokenSource();
                if (Settings.Default.isUsingAnalysis || netMidiFlag == true)
                {
                    _runningTask = createPerformanceTask(cts.Token, interval - (int)sw.ElapsedMilliseconds);//minus bug?
                }
                else
                {
                    _runningTask = createPerformanceTaskOriginal(cts.Token, (double)(nudBpm.Value / bpm));
                }
                _runningTask.Priority = ThreadPriority.Highest;
            }
        }