コード例 #1
0
        private void HandlePlayingCompleted(object sender, EventArgs e)
        {
            var           cArray   = new string(' ', 88).ToCharArray();
            List <string> noteList = new List <string>();
            List <string> fretList = new List <string>();
            var           count    = messageList.Count;

            foreach (var message in messageList)
            {
                if (message.MidiChannel == 1)
                {
                    var noteId = message.Data1 - LowNoteID;

                    string s = string.Format("{0}: {1}", message.Ticks.ToString("000000000"), new string(cArray));

                    noteList.Add(s);
                }
            }

            //Calculate diffs
            MessageDto currentMessageNoteOn  = null;
            MessageDto previousMessageNoteOn = null;

            count = messageList.Count();
            for (var i = 0; i < count; i++)
            {
                var message = messageList[i];
                if (message.ChannelCommand == ChannelCommand.NoteOn &&
                    message.Data2 > 0)
                {
                    if (currentMessageNoteOn != null)
                    {
                        previousMessageNoteOn = currentMessageNoteOn;
                    }

                    currentMessageNoteOn = messageList[i];

                    if (previousMessageNoteOn == null)
                    {
                        currentMessageNoteOn.FretPosition = 3; //first note must fall at the middle of the fret
                    }
                    else
                    {
                        currentMessageNoteOn.NoteDiffToPrevious = currentMessageNoteOn.Data1 - previousMessageNoteOn.Data1;
                        previousMessageNoteOn.NoteDiffToNext    = previousMessageNoteOn.Data1 - currentMessageNoteOn.Data1;
                        currentMessageNoteOn.TickDiffToPrevious = (int)(currentMessageNoteOn.Ticks - previousMessageNoteOn.Ticks);
                        previousMessageNoteOn.TickDiffToNext    = (int)(previousMessageNoteOn.Ticks - currentMessageNoteOn.Ticks);

                        if (currentMessageNoteOn.Data1 == previousMessageNoteOn.Data1)
                        {
                            currentMessageNoteOn.FretPosition = previousMessageNoteOn.FretPosition; //keep the same fret position as the previous note
                        }
                        else if (currentMessageNoteOn.Data1 > previousMessageNoteOn.Data1)
                        {
                            currentMessageNoteOn.FretPosition = previousMessageNoteOn.FretPosition + 1; //one fret to the right
                        }
                        else if (currentMessageNoteOn.Data1 < previousMessageNoteOn.Data1)
                        {
                            currentMessageNoteOn.FretPosition = previousMessageNoteOn.FretPosition - 1; //one fret to the left
                        }
                    }
                }
            }


            //var fret = "||";
            //var id = 0;

            //count = messageList.Count;
            //foreach (var message in messageList)
            //{
            //    if (message.MidiChannel == 1)
            //    {
            //        var noteId = message.Data1 - LowNoteID;

            //        if (message.ChannelCommand == ChannelCommand.NoteOn)
            //        {
            //            if (message.Data2 > 0)
            //            {
            //                string s = string.Format("{0}: {1}", message.FretPosition, new string(cArray));
            //            }
            //        }
            //    }

            //    sequence1.LoadAsync(fileName);
            //}
        }
コード例 #2
0
        private void HandlePlayingCompleted(object sender, EventArgs e)
        {
            if (Status == PlayStatus.Paused)
            {
                return;
            }

            var           cArray   = new string(' ', 88).ToCharArray();
            List <string> noteList = new List <string>();
            List <string> fretList = new List <string>();
            var           count    = messageList.Count;

            foreach (var message in messageList)
            {
                if (message.MidiChannel == 1)
                {
                    var noteId = message.Data1 - LowNoteID;

                    string s = string.Format("{0}: {1}", message.Ticks.ToString("000000000"), new string(cArray));

                    noteList.Add(s);
                }
            }

            //Calculate diffs
            MessageDto currentMessageNoteOn  = null;
            MessageDto previousMessageNoteOn = null;

            count = messageList.Count();
            for (var i = 0; i < count; i++)
            {
                var message = messageList[i];
                if (message.ChannelCommand == ChannelCommand.NoteOn &&
                    message.Data2 > 0)
                {
                    if (currentMessageNoteOn != null)
                    {
                        previousMessageNoteOn = currentMessageNoteOn;
                    }

                    currentMessageNoteOn = messageList[i];

                    if (previousMessageNoteOn == null)
                    {
                        currentMessageNoteOn.FretPosition = 3; //first note must fall at the middle of the fret
                    }
                    else
                    {
                        currentMessageNoteOn.NoteDiffToPrevious = currentMessageNoteOn.Data1 - previousMessageNoteOn.Data1;
                        previousMessageNoteOn.NoteDiffToNext    = previousMessageNoteOn.Data1 - currentMessageNoteOn.Data1;
                        currentMessageNoteOn.TickDiffToPrevious = (int)(currentMessageNoteOn.Ticks - previousMessageNoteOn.Ticks);
                        previousMessageNoteOn.TickDiffToNext    = (int)(previousMessageNoteOn.Ticks - currentMessageNoteOn.Ticks);

                        if (currentMessageNoteOn.Data1 == previousMessageNoteOn.Data1)
                        {
                            currentMessageNoteOn.FretPosition = previousMessageNoteOn.FretPosition; //keep the same fret position as the previous note
                        }
                        else if (currentMessageNoteOn.Data1 > previousMessageNoteOn.Data1)
                        {
                            currentMessageNoteOn.FretPosition = previousMessageNoteOn.FretPosition + 1; //one fret to the right
                        }
                        else if (currentMessageNoteOn.Data1 < previousMessageNoteOn.Data1)
                        {
                            currentMessageNoteOn.FretPosition = previousMessageNoteOn.FretPosition - 1; //one fret to the left
                        }
                    }
                }
            }
            Status = PlayStatus.Paused;
            if (playingList.Count == 0)
            {
                return;
            }
            switch (mode)
            {
            case PlayMode.Order:
                index = (index + 1) % this.playingList.Count;
                break;

            case PlayMode.Random:
                index = new Random().Next(this.playingList.Count + 1);
                break;

            case PlayMode.Repeat:
                break;
            }

            this.Dispatcher.Invoke((Action <string>)open, this.playingList[index]);
        }