Exemplo n.º 1
0
 public void NoteOn(NoteOnMessage msg)
 {
     clock.Schedule(new NoteOnMessage(outputDevice, msg.Channel, msg.Note + 4, msg.Velocity,
                                      msg.BeatTime + 1));
     clock.Schedule(new NoteOnMessage(outputDevice, msg.Channel, msg.Note + 7, msg.Velocity,
                                      msg.BeatTime + 2));
 }
Exemplo n.º 2
0
        private void Decode(byte[] message)
        {
            byte status = message[0];

            switch (status & 0b1111_0000)
            {
            case Midi.Status.NoteOffBitmask:
                if (NoteOffMessage.TryDecode(message, out var noteOffMessage))
                {
                    NoteOff?.Invoke(this, in noteOffMessage);
                }
                break;

            case Midi.Status.NoteOnBitmask:
                if (NoteOnMessage.TryDecoce(message, out var noteOnMessage))
                {
                    NoteOn?.Invoke(this, in noteOnMessage);
                }
                break;

            case Midi.Status.PolyphonicKeyPressureBitmask:
                if (PolyphonicKeyPressureMessage.TryDecode(message, out var polyphonicKeyPressureMessage))
                {
                    PolyphonicKeyPressure?.Invoke(this, in polyphonicKeyPressureMessage);
                }
                break;

            case Midi.Status.ControlChangeBitmask:
                if (ControlChangeMessage.TryDecode(message, out var controlChangeMessage))
                {
                    _nrpnInterpreters[(int)controlChangeMessage.Channel].HandleControlChangeMessage(in controlChangeMessage);
                }
                break;

            case Midi.Status.ProgramChangeBitmask:
                if (ProgramChangeMessage.TryDecode(message, out var programChangeMessage))
                {
                    ProgramChange?.Invoke(this, in programChangeMessage);
                }
                break;

            case Midi.Status.ChannelPressureBitmask:
                if (ChannelPressureMessage.TryDecode(message, out var channelPressureMessage))
                {
                    ChannelPressure?.Invoke(this, in channelPressureMessage);
                }
                break;

            case Midi.Status.PitchBendChange:
                if (PitchBendMessage.TryDecode(message, out var pitchBendMessage))
                {
                    PitchBend?.Invoke(this, in pitchBendMessage);
                }
                break;

            default:
                Log.Error("Unknown message type {Bitmask}", $"{status & 0b1111_0000:X2}");
                break;
            }
        }
Exemplo n.º 3
0
 public void NoteOn(NoteOnMessage msg)
 {
     lock (this)
     {
         pitchesPressed[msg.Pitch] = true;
     }
 }
Exemplo n.º 4
0
        private void mInputDevice_NoteOn(NoteOnMessage msg)
        {
            LaunchpadButton button = GetButton(msg.Pitch);

            if (button == null)
            {
                return;
            }
            button.State = (ButtonPressState)msg.Velocity;
            if (ButtonPressed == null)
            {
                return;
            }


            var pressEventArgs = (int)msg.Pitch % 16 == 8 ? new ButtonPressEventArgs((SideButton)((int)msg.Pitch / 16), button) : new ButtonPressEventArgs((int)msg.Pitch % 16, (int)msg.Pitch / 16, button);

            if (button.State == ButtonPressState.Up)
            {
                ButtonPressed?.Invoke(this, pressEventArgs);
                ButtonUp?.Invoke(this, pressEventArgs);
            }
            else
            {
                ButtonDown?.Invoke(this, pressEventArgs);
            }
        }
Exemplo n.º 5
0
    private static void NoteOn(NoteOnMessage noteOnMessage)
    {
        var channel = noteOnMessage.Channel.Number();
        var note    = noteOnMessage.Pitch.NoteNumber();

        switch (channel)
        {
        case 10:
            // ! Tanzmaus
            switch (note)
            {
            case 65:
                // --> SP1
                // debounce
                if (Mathf.Abs(noteOnMessage.Time - LastSP1Time) < 0.04f)
                {
                    return;
                }
                LastSP1Time = noteOnMessage.Time;
                Threading.RunOnMain(RandomiseHue);
                break;
            }
            break;
        }
    }
Exemplo n.º 6
0
 private void midiPress(NoteOnMessage msg)
 {
     if (!rightLEDnotes.Contains(msg.Pitch))
     {
         if (OnLaunchpadKeyPressed != null)
         {
             OnLaunchpadKeyPressed(this, new LaunchpadKeyEventArgs(midiNoteToLed(msg.Pitch)[0], midiNoteToLed(msg.Pitch)[1]));
         }
         if (OnLaunchpadKeyUp != null && msg.Velocity == 0)
         {
             OnLaunchpadKeyUp(this, new LaunchpadKeyEventArgs(midiNoteToLed(msg.Pitch)[0], midiNoteToLed(msg.Pitch)[1]));
         }
         if (OnLaunchpadKeyDown != null && msg.Velocity == 127)
         {
             OnLaunchpadKeyDown(this, new LaunchpadKeyEventArgs(midiNoteToLed(msg.Pitch)[0], midiNoteToLed(msg.Pitch)[1]));
         }
     }
     else if (OnLaunchpadKeyPressed != null && rightLEDnotes.Contains(msg.Pitch))
     {
         OnLaunchpadCCKeyPressed(this,
                                 new LaunchpadCCKeyEventArgs(
                                     midiNoteToSideLED(msg.Pitch)
                                     )
                                 );
     }
 }
Exemplo n.º 7
0
 public static void NoteOn(NoteOnMessage msg)
 {
     lock (NoteOnlock)
     {
         logs += $"Time: {DateTime.Now.ToString("HH:mm:ss:ffffff")}  Event:NoteOn Pitch:{msg.Pitch} \r\n";
     }
 }
Exemplo n.º 8
0
 private void _callback(NoteOnMessage msg)
 {
     foreach (var listener in _listeners)
     {
         listener.OnNotePressed(msg.Pitch.PositionInOctave());
     }
 }
Exemplo n.º 9
0
        public void AddNote(NoteOnMessage msg)
        {
            if (!Visible)
            {
                return;
            }

            if (this.InvokeRequired)
            {
                Invoke(new MethodInvoker(() => AddNote(msg)));
                return;
            }

            if (noteListBox.Items.Count > 100)
            {
                noteListBox.Items.Clear();
            }

            noteListBox.Items.Add(new ListViewItem(new string[]
            {
                Enum.GetName(typeof(Pitch), msg.Pitch),
                ((int)msg.Pitch).ToString(),
                msg.Channel.Name()
            }));
        }
Exemplo n.º 10
0
        private static void Receive(IAsyncResult result)
        {
            if (connection == null || result == null)
            {
                return;
            }

            IPEndPoint source = null;

            byte[] message = connection.EndReceive(result, ref source);

            connection.BeginReceive(new AsyncCallback(Receive), connection);

            if (source.Address.Equals(localhost))
            {
                if (!portMap.ContainsKey(source))
                {
                    connection?.SendAsync(new byte[] { 244, Convert.ToByte((portMap[source] = MIDI.ConnectAbleton()).Name.Substring(18)) }, 2, source);
                }

                if (message[0] < 128)
                {
                    NoteOnMessage msg = new NoteOnMessage(Channel.Channel1, (Key)message[0], message[1]);
                    portMap[source].NoteOn(null, in msg);
                }
                else if (message[0] == 245)
                {
                    MIDI.Disconnect(portMap[source]);
                    portMap.Remove(source);
                }
            }
        }
Exemplo n.º 11
0
        public IMessage getMessage(MidiEvent midiEvent)
        {
            switch (midiEvent.CommandCode)
            {
            case MidiCommandCode.NoteOn:
                NoteEvent     noteEvent = (NoteEvent)midiEvent;
                Note          note      = new Note(noteEvent.channel, noteEvent.NoteNumber, noteEvent.Velocity);
                NoteOnMessage message   = new NoteOnMessage(note);
                return(message);

            case MidiCommandCode.NoteOff:
                NoteEvent      noteEvent = (NoteEvent)midiEvent;
                Note           note      = new Note(noteEvent.channel, noteEvent.NoteNumber, noteEvent.Velocity);
                NoteOffMessage message   = new NoteOffMessage(note);
                trackMessages.add(message);
                return(message);

            case MidiCommandCode.TimingClock:
                NoteOffMessage message = new NoteOffMessage(midiEvent.AbsoluteTime);
                trackMessages.add(message);
                return(message);

            case MidiCommandCode.MetaEvent:
                MetaEvent metaEvent = (MetaEvent)midiEvent;
                return(getMessage(metaEvent));

            default:
                return(null);    // TODO implement remaining IMessage types
            }
        }
Exemplo n.º 12
0
        public void TestNoteOn()
        {
            byte channel  = 0;
            byte pitch    = 60;
            byte velocity = 50;

            NoteOnMessage message = new NoteOnMessage(
                new Note(
                    channel,
                    pitch,
                    velocity
                    ),
                0
                );

            MidiMessage bytes    = message.Message;
            MidiMessage expected = new MidiMessage
            {
                Status    = (byte)(0x90 + channel),
                Data      = new byte[] { pitch, velocity },
                TimeDelta = 0
            };

            Assert.Equal(expected, bytes);
        }
Exemplo n.º 13
0
 public void NoteOn(NoteOnMessage msg)
 {
     lock (this)
     {
         _pitchesPressed[msg.Pitch] = true;
         PrintStatus();
     }
 }
Exemplo n.º 14
0
    void RecieveNoteOn(NoteOnMessage noteOnMessage)
    {
        int channel    = noteOnMessage.Channel.Number();
        int noteNumber = noteOnMessage.Pitch.NoteNumber();
        int velocity   = noteOnMessage.Velocity;

        UnityMainThreadDispatcher.Instance().Enqueue(NoteOn(noteNumber, velocity));
    }
Exemplo n.º 15
0
        private DtoMidiMessageNoteOn Map(NoteOnMessage msg)
        {
            var on = new DtoMidiMessageNoteOn();

            EnrichNoteMessage(msg, on);

            return(on);
        }
Exemplo n.º 16
0
        private void NoteOn(NoteOnMessage msg)
        {
            int note   = msg.Pitch.PositionInOctave();
            int octave = msg.Pitch.Octave();

            pitch         = note + octave * 12;
            pitch_channel = (int)msg.Channel;
        }
Exemplo n.º 17
0
    private void SendNote(Note note)
    {
        NoteOnMessage  noteOn  = new NoteOnMessage(note, TickOf(beatOffset));
        NoteOffMessage noteOff = new NoteOffMessage(note, TickOf(beatDuration));

        Debug.Log("Sending message: " + noteOn);
        Debug.Log("Sending message: " + noteOff);
        instrument.ProcessMidi(new IMessage[] { noteOn, noteOff });
    }
Exemplo n.º 18
0
 public void NoteOn(NoteOnMessage msg)
 {
     lock (this)
     {
         Console.WriteLine("NoteOn {0} {1} {2} {3} {4} ", msg.Pitch, msg.Velocity, msg.Pitch.Octave(), msg.Pitch.PositionInOctave(), (int)msg.Pitch);
         //pitchesPressed[msg.Pitch] = true;
         //PrintStatus();
     }
 }
Exemplo n.º 19
0
 // Method called when the input device receives a NoteOn message.  Updates
 // the input status label.  Respects GUI thread affinity by invoking to the
 // GUI thread if necessary.
 public void NoteOn(NoteOnMessage msg)
 {
     if (InvokeRequired)
     {
         BeginInvoke(noteOnHandler, msg);
         return;
     }
     inputStatusLabel.Text = String.Format("Note On {0}", msg.Pitch);
 }
Exemplo n.º 20
0
 private void MyNoteOn(NoteOnMessage msg)
 {
     if (msg.Velocity > 0)
     {
         OnPress((int)msg.Pitch % 16, 7 - (int)msg.Pitch / 16);
     }
     else
     {
         OnRelease((int)msg.Pitch % 16, 7 - (int)msg.Pitch / 16);
     }
 }
Exemplo n.º 21
0
 private void NoteOn(NoteOnMessage msg)
 {
     if (radioButton1.Checked) // Logitech SDK
     {
         Gmidi.palette_led((int)msg.Pitch, msg.Velocity);
     }
     else if (radioButton2.Checked)  // Razer SDK
     {
         Rmidi.palette_led((int)msg.Pitch, msg.Velocity);
     }
 }
Exemplo n.º 22
0
 private void midiPress(NoteOnMessage msg)
 {
     if (OnLaunchpadKeyPressed != null && !rightLEDnotes.Contains(msg.Pitch))
     {
         OnLaunchpadKeyPressed(this, new LaunchpadKeyEventArgs(midiNoteToLed(msg.Pitch)[0], midiNoteToLed(msg.Pitch)[1], msg.Velocity == 127 ? true : false));
     }
     else if (OnLaunchpadCCKeyPressed != null && rightLEDnotes.Contains(msg.Pitch))
     {
         OnLaunchpadCCKeyPressed(this, new LaunchpadCCKeyEventArgs(midiNoteToSideLED(msg.Pitch), msg.Velocity == 127 ? true : false));
     }
 }
Exemplo n.º 23
0
 private void InDevOnNoteOn(NoteOnMessage msg)
 {
     if (msg.Velocity == 0)
     {
         ButtonReleased?.Invoke(new ButtonReleasedEventArgs(PitchToButton(msg.Pitch)));
     }
     else
     {
         ButtonPressed?.Invoke(new ButtonPressedEventArgs(PitchToButton(msg.Pitch)));
     }
 }
Exemplo n.º 24
0
 void RouteNoteOns(NoteOnMessage noteOnMessage)
 {
     if (noteOnMessage.Channel.Number() == 1)
     {
         switch (noteOnMessage.Pitch.NoteNumber())
         {
         case 42:
             //UnityMainThreadDispatcher.Instance().Enqueue(ReverseColors);
             break;
         }
     }
 }
Exemplo n.º 25
0
 public void NoteOn(NoteOnMessage msg)
 {
     if (msg.Velocity < 128)
     {
         Gmidi.palette_led(Convert.ToInt32(msg.Pitch), msg.Velocity);
         pictureBox4.BackColor = Color.FromArgb(163, 133, 0);
     }
     else
     {
         Gmidi.palette_led(Convert.ToInt32(msg.Pitch), 0);
         pictureBox4.BackColor = Color.FromArgb(63, 33, 0);
     }
 }
Exemplo n.º 26
0
        //- midi processing ---------------------------------------------------

        public void handleMidiMessage(byte[] msgData)
        {
            Message msg = Message.getMessage(msgData);

            if (!holdOn)            //tracking note on msgs when hold is off
            {
                if (msg is NoteOnMessage)
                {
                    NoteOnMessage noteOn = (NoteOnMessage)msg;
                    keysdown[noteOn.noteNumber] = true;
                }
                else if (msg is NoteOffMessage)
                {
                    NoteOffMessage noteOff = (NoteOffMessage)msg;
                    keysdown[noteOff.noteNumber] = false;
                }
                modifier.sendMidiMsg(msg.getDataBytes());
            }
            else
            {
                if (msg is NoteOnMessage)
                {
                    NoteOnMessage noteOn   = (NoteOnMessage)msg;
                    int           baseNote = noteOn.noteNumber;
                    modifier.sendMidiMsg(msg.getDataBytes());
                    foreach (int interval in chordNotes)
                    {
                        NoteOnMessage newnote = (NoteOnMessage)noteOn.copy();
                        newnote.noteNumber += interval;
                        Console.WriteLine("new note number " + newnote.noteNumber);
                        modifier.sendMidiMsg(newnote.getDataBytes());
                    }
                }
                else if (msg is NoteOffMessage)
                {
                    NoteOffMessage noteOff = (NoteOffMessage)msg;
                    modifier.sendMidiMsg(msg.getDataBytes());
                    foreach (int interval in chordNotes)
                    {
                        NoteOffMessage newnote = (NoteOffMessage)noteOff.copy();
                        newnote.noteNumber += interval;
                        modifier.sendMidiMsg(newnote.getDataBytes());
                    }
                }
                else
                {
                    modifier.sendMidiMsg(msg.getDataBytes());
                }
            }
        }
Exemplo n.º 27
0
 void NoteStateChange(NoteOnMessage msg)
 {
     if (!m_Pitches.Contains(msg.Pitch))
     {
         int vel = useVelocity ? ( int )((msg.Velocity / 127f) * 0xF) : 0xF;
         keyboard.SetNoteOn(PitchToNote(msg.Pitch), msg.Pitch.Octave(), vel);
         m_Pitches.Add(msg.Pitch);
     }
     else
     {
         keyboard.SetNoteOff(PitchToNote(msg.Pitch), msg.Pitch.Octave( ));
         m_Pitches.Remove(msg.Pitch);
     }
 }
Exemplo n.º 28
0
        public void NoteOn(NoteOnMessage msg)
        {
            // Find the per-device/channel mappings for the message's Device/Channel.  If there's none, nothing to do.
            String deviceKey = Mapping.PerDeviceChannelMapping.createKey(msg.Device.Name, (int)msg.Channel);

            if (!m_perDeviceChannelMappings.ContainsKey(deviceKey))
            {
                return;
            }
            Mapping.PerDeviceChannelMapping perDeviceChannelMapping = m_perDeviceChannelMappings[deviceKey];

            // Iterate over the NoteMappings for this device/channel
            foreach (NoteMapping mapping in perDeviceChannelMapping.noteMappings)
            {
                // See if the note received is in range for the NoteMapping currently under consideration
                if (msg.Pitch >= (Pitch)mapping.lowestNote && msg.Pitch <= (Pitch)mapping.highestNote)
                {
                    // It is.
                    // Create mapped note record
                    MappedNote mappedNoteRecord = new MappedNote();
                    mappedNoteRecord.sourceDeviceName = msg.Device.Name;
                    mappedNoteRecord.sourceChannel    = msg.Channel;
                    mappedNoteRecord.origNote         = msg.Pitch;
                    SoundGenerator soundGenerator = mapping.soundGenerator;
                    mappedNoteRecord.mappedDevice  = soundGenerator.device;
                    mappedNoteRecord.mappedChannel = (Channel)mapping.soundGeneratorPhysicalChannel;
                    mappedNoteRecord.mappedNote    = msg.Pitch + mapping.pitchOffset + masterTranspose;

                    if (mappedNoteRecord.mappedNote < 0 || mappedNoteRecord.mappedNote > (Pitch)127)
                    {
                        continue;
                    }

                    // See if this note is already sounding.  Look it up based on it's unmapped device, channel and note#.
                    MappedNote matchingMappedNoteAlreadySounding = FindMappedNote(mappedNoteRecord);
                    if (matchingMappedNoteAlreadySounding != null)
                    {
                        matchingMappedNoteAlreadySounding.mappedDevice.SendNoteOff(matchingMappedNoteAlreadySounding.mappedChannel, matchingMappedNoteAlreadySounding.mappedNote, 127);
                        m_mappedNotesList.Remove(matchingMappedNoteAlreadySounding);
                    }

                    // Now, play the new mapping of the source note.
                    mappedNoteRecord.mappedDevice.SendNoteOn(mappedNoteRecord.mappedChannel, mappedNoteRecord.mappedNote, msg.Velocity);

                    // And add it to the dictionary of sounding notes.
                    m_mappedNotesList.Add(mappedNoteRecord);
                }
            }
        }
Exemplo n.º 29
0
        static void NoteInput(NoteOnMessage msg)
        {
            int noteX = -1, noteY = -1;

            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    if (pitches[x, y] == msg.Pitch)
                    {
                        noteX = x;
                        noteY = y;
                    }
                }
            }

            if (noteX == -1 || noteY == -1)
            {
                return;
            }

            int panelX   = noteX / 2;
            int panelY   = noteY / 2;
            int panelNum = panelX + panelY * 4;

            isNotePressed[msg.Pitch] = !isNotePressed[msg.Pitch];
            bool isDown = isNotePressed[msg.Pitch];

            if (isNotePressed[msg.Pitch])
            {
                isPanelPressed[panelX, panelY]++;
            }
            else
            {
                isPanelPressed[panelX, panelY]--;
            }

            if (isPanelPressed[panelX, panelY] == 0 && !isDown)
            {
                Console.WriteLine($"PANEL - \t({panelX}, {panelY}) up");
            }
            else if (isPanelPressed[panelX, panelY] == 1 && isDown)
            {
                Console.WriteLine($"PANEL - \t({panelX}, {panelY}) down");
            }
            //Console.WriteLine($"VALUE - \t({panelX}, {panelY}) {isPanelPressed[panelX, panelY]}");
            //Console.WriteLine($"NOTE  - \t({noteX}, {noteY}) {(isNotePressed[msg.Pitch] ? "down" : "up")}");
        }
Exemplo n.º 30
0
        private void MidiDevice_NoteOn(NoteOnMessage msg)
        {
            if (msg.Pitch == Pitch.FNeg1 && msg.Velocity < 72)
            {
                return; // Filters out fader notes
            }

            var buttonCode = ButtonMap.ToButton(_midiOutDevice, msg.Pitch.ToString(), msg.Velocity);

            if (buttonCode == ButtonMap.ButtonCode.UNDEFINED)
            {
                return;
            }

            OnButtonPressed(buttonCode);
        }