Ejemplo n.º 1
0
 private void clickhandler(MidiMessageEventArgs mmea)
 {
     if (mmea.ShortMessage != null)
     {
         PointerEngineHelper.Position2D pos = PointerEngineHelper.NoteToGridPos(mmea.ShortMessage.Note);
         per.DrawPixel(pos.x, pos.y, (int)PointerEngineHelper.BasicColors.FULL_AMBER, mmea.ShortMessage.Velocity == 127 ? false : true);
     }
 }
Ejemplo n.º 2
0
        private void OnMidiMessageReceived(object sender, MidiMessageEventArgs e)
        {
            if (this.MessageReceived != null)
            {
                this.MessageReceived(sender, e);
            }

            this.AddMessageToMonitor(e);
        }
Ejemplo n.º 3
0
        void mPluginManager_MidiInMessageReceived(object sender, MidiMessageEventArgs e)
        {
            int pitch;

            if (e.MidiMessage.IsNoteOn(out pitch))
            {
                this.BeginInvoke(new Action(() => keyDown(pitch)));
            }
            else if (e.MidiMessage.IsNoteOff(out pitch))
            {
                this.BeginInvoke(new Action(() => keyUp(pitch)));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Simulates a button being released.
        /// </summary>
        public void PadUp(int x, int y)
        {
            var e = new MidiMessageEventArgs();

            //e.Message = LaunchPadXY.GetMidiMessage(x, y, false);
            e.Message = new MidiMessage();
            XYMapper.ConvertXY(x, y, out e.Message.Type, out e.Message.Value);
            e.Message.Velocity = 0;

            e.Driver = Driver;
            e.Device = this;
            if (Input != null)
            {
                Input(this, e);
            }
        }
Ejemplo n.º 5
0
        private void InDevice_MessageReceived(object sender, MidiMessageEventArgs e)
        {
            if (this.textBoxMsg.Text.Length > 32000)
            {
                this.textBoxMsg.Clear();
            }

            if (e.IsShortMessage)
            {
                if (this.checkBoxHex.Checked)
                {
                    this.textBoxMsg.AppendText(String.Format("{0} : {1}\r\n", e.ShortMessage.ID, e.ShortMessage.ToString("{T}\t{A} {H}")));
                }
                else
                {
                    this.textBoxMsg.AppendText(String.Format("{0} : {1}\r\n", e.ShortMessage.ID, e.ShortMessage.ToString("G")));
                }
            }
            else if (e.IsSysExMessage)
            {
                this.textBoxMsg.AppendText(String.Format("{0} : {1}\r\n", e.SysExMessage.ID, e.SysExMessage.ToString()));
            }
            else if (e.EventType == MidiMessageEventType.Opened)
            {
                this.textBoxMsg.AppendText(String.Format("Midi device {0} opened.\r\n", e.DeviceID));
            }
            else if (e.EventType == MidiMessageEventType.Closed)
            {
                this.textBoxMsg.AppendText(String.Format("Midi device {0} closed.\r\n", e.DeviceID));
            }
            else if (e.EventType == MidiMessageEventType.Started)
            {
                this.textBoxMsg.AppendText(String.Format("Midi device {0} started.\r\n", e.DeviceID));
            }
            else if (e.EventType == MidiMessageEventType.Stopped)
            {
                this.textBoxMsg.AppendText(String.Format("Midi device {0} stopped.\r\n", e.DeviceID));
            }
        }
Ejemplo n.º 6
0
        private void AddMessageToMonitor(MidiMessageEventArgs e)
        {
            string message = e.ToString();

            if (e.IsShortMessage)
            {
                message = string.Format(
                    "[{0:D2}:{1:D2}:{2:D3}] - {3} | {4} | Channel: {5} | Velocity: {6}",
                    e.ShortMessage.Timespan.Minutes,
                    e.ShortMessage.Timespan.Seconds,
                    e.ShortMessage.Timespan.Milliseconds,
                    e.ShortMessage.StatusType,
                    e.ShortMessage.Note,
                    e.ShortMessage.Channel,
                    e.ShortMessage.Velocity);
            }
            else if (e.IsSysExMessage)
            {
                message = e.SysExMessage.ToString();
            }
            else if (e.EventType == MidiMessageEventType.Opened)
            {
                message = string.Format("Midi device {0} opened.", e.DeviceID);
            }
            else if (e.EventType == MidiMessageEventType.Closed)
            {
                message = string.Format("Midi device {0} closed.", e.DeviceID);
            }
            else if (e.EventType == MidiMessageEventType.Started)
            {
                message = string.Format("Midi device {0} started.", e.DeviceID);
            }
            else if (e.EventType == MidiMessageEventType.Stopped)
            {
                message = string.Format("Midi device {0} stopped.", e.DeviceID);
            }

            this.AddMessageToMonitor(message);
        }
        private void MidiMessageReceived(object sender, MidiMessageEventArgs e)
        {
            if (!e.IsShortMessage)
            {
                return;
            }

            if (this.detectedNote == 0)
            {
                if (e.ShortMessage.StatusType == MIDIStatus.NoteOn)
                {
                    this.detectedNote    = e.ShortMessage.Note;
                    this.detectedChannel = e.ShortMessage.Channel;

                    if (!this.midiViewModel.WaitForNoteOff)
                    {
                        this.OnNoteDetected();
                        return;
                    }

                    this.Status = string.Format(
                        "Detected note {0} on channel {1}.{2}Waiting for note off event..",
                        this.detectedNote,
                        this.detectedChannel,
                        Environment.NewLine);
                }

                return;
            }

            if (e.ShortMessage.StatusType == MIDIStatus.NoteOff &&
                e.ShortMessage.Note == this.detectedNote &&
                e.ShortMessage.Channel == this.detectedChannel)
            {
                this.detectedNoteOffValue = e.ShortMessage.Velocity;
                this.OnNoteDetected();
            }
        }
Ejemplo n.º 8
0
        private void InDevice_MessageRecieved(object sender, MidiMessageEventArgs e)
        { // parse incoming midi message, find correct note from dictionary, get note integer and see if user is right or wrong
            if (e.IsShortMessage)
            {
                string   rawMidi    = e.ShortMessage.ToString();
                string[] parsedMidi = rawMidi.Split();
                string   midiKey    = parsedMidi[4].Substring(4, 2);

                if (parsedMidi[3] == "NoteOn")
                {
                    string trebleMidiNoteName = "";

                    foreach (KeyValuePair <string, string> name in trebleMidiNamesNoteNames)
                    {
                        if (name.Value == midiKey)
                        {
                            trebleMidiNoteName = name.Key;
                        }
                    }

                    string bassMidiNoteName = "";

                    foreach (KeyValuePair <string, string> name in bassMidiNamesNoteNames)
                    {
                        if (name.Value == midiKey)
                        {
                            bassMidiNoteName = name.Key;
                        }
                    }

                    int trebleMidiKeyInt = 0;

                    foreach (KeyValuePair <int, string> note in numberedNoteNames)
                    {
                        if (note.Value == trebleMidiNoteName)
                        {
                            trebleMidiKeyInt = note.Key;
                        }
                    }

                    int bassMidiKeyInt = 0;

                    foreach (KeyValuePair <int, string> note in numberedNoteNames)
                    {
                        if (note.Value == bassMidiNoteName)
                        {
                            bassMidiKeyInt = note.Key;
                        }
                    }

                    if ((trebleMidiKeyInt == userKeyListObject.CurrentRandomKey) ||
                        (bassMidiKeyInt == userKeyListObject.CurrentRandomKey))
                    {
                        UserAnswerRight();
                    }
                    else
                    {
                        UserAnswerWrong();
                    }
                }
            }

            // to handle additional midi messages if needed
            else if (e.IsSysExMessage)
            {
            }
            else if (e.EventType == MidiMessageEventType.Opened)
            {
            }
            else if (e.EventType == MidiMessageEventType.Closed)
            {
            }
            else if (e.EventType == MidiMessageEventType.Started)
            {
            }
            else if (e.EventType == MidiMessageEventType.Stopped)
            {
            }
        }
Ejemplo n.º 9
0
 public void EventHandler(Object o, MidiMessageEventArgs mmea)
 {
     this.callbackHandler(mmea);
 }
Ejemplo n.º 10
0
        private void OnMidiMessageReceived(object sender, MidiMessageEventArgs e)
        {
            this.OnPropertyChanged("NoteHistory");
            if (!e.IsShortMessage)
            {
                return;
            }

            byte velocity        = e.ShortMessage.Velocity;
            bool isControlChange = e.ShortMessage.StatusType == MIDIStatus.ControlChange;
            bool isPitchBend     = e.ShortMessage.StatusType == MIDIStatus.PitchBend;
            bool isNoteOn        = e.ShortMessage.StatusType == MIDIStatus.NoteOn;
            bool isNoteOff       = e.ShortMessage.StatusType == MIDIStatus.NoteOff;

            if (isControlChange && this.controllerMonitor is IHiHatPedalMonitor)
            {
                byte controller = e.ShortMessage.Controller;
                bool isMSB      = controller == 4;
                bool isLSB      = controller == 36;

                if (isMSB || (isLSB && velocity == 0))
                {
                    var pedalMonitor = this.controllerMonitor as IHiHatPedalMonitor;
                    pedalMonitor.HiHatPedalVelocity = velocity;
                }
            }

            if (isPitchBend && this.controllerMonitor is IPitchBendMonitor)
            {
                var pitchMonitor = this.controllerMonitor as IPitchBendMonitor;
                pitchMonitor.PitchWheelValue = (float)Math.Round((e.ShortMessage.PitchBend - 8192) / 8192.0f, 2);
            }

            if (!isNoteOn && !isNoteOff)
            {
                return;
            }

            if (this.controllerMonitor is INoteHighlighter)
            {
                var noteHighlighter = this.controllerMonitor as INoteHighlighter;
                noteHighlighter.HighlightNote(
                    e.ShortMessage.Note,
                    isNoteOn,
                    e.ShortMessage.Velocity);
                return;
            }

            if (this.controllerMonitor is IButtonHighlighter)
            {
                var buttonHighlighter = this.controllerMonitor as IButtonHighlighter;
                var buttons           = buttonHighlighter.MonitorButtons.Where(
                    button => button.ProfileButton.Note == e.ShortMessage.Note &&
                    button.ProfileButton.Channel == e.ShortMessage.Channel);

                foreach (var button in buttons)
                {
                    buttonHighlighter.Highlight(
                        button.ProfileButton.Name,
                        isNoteOn,
                        e.ShortMessage.Velocity);
                }

                if (isNoteOn && !this.WaitForNoteOff)
                {
                    var task = Task.Run(async delegate
                    {
                        await Task.Delay(MidiViewModel.UnhighlightDelayInMilliseconds);
                        foreach (var button in buttons)
                        {
                            buttonHighlighter.Highlight(button.ProfileButton.Name, false, 0);
                        }
                    });
                }
            }
        }