public void ProcessKeyDown(System.Windows.Forms.KeyEventArgs args)
        {
            int kc = args.KeyValue;

            // Does this button matter? If not, never mind.
            if (!buttons.ContainsKey(kc))
            {
                return;
            }
            PianoButton b = buttons[kc];

            // Is this key already pressed? Nevermind then.
            if (b.pressed)
            {
                return;
            }

            // Light 'em up
            LightUp(b.octave, b.letter, b.black);

            // Play sound
            songPlayer.PlayNote(new Note(
                                    Note.GetNoteLetterFromLetter(b.letter),
                                    b.octave,
                                    b.black,
                                    ComponentLength.FULL,
                                    0
                                    ));

            // Set this button to be pressed
            b.pressed = true;

            // Register the key press
            songProgress.Register(b);
        }
Beispiel #2
0
        static void HandleChannelMessageReceived(object sender, ChannelMessageEventArgs e)
        {
            Console.WriteLine("{0}\t\t{1}\t{2}\t{3}", e.Message.Command, e.Message.MidiChannel, e.Message.Data1, e.Message.Data2);

            var  note             = (sbyte)e.Message.Data1;
            byte volumeOrVelocity = (byte)((e.Message.Data2 / 127f) * Engine.GetMaxVolume());

            if (e.Message.Command == ChannelCommand.Controller && e.Message.Data1 == 7) // Volume
            {
                track.Volume = volumeOrVelocity;
            }
            else if ((e.Message.Command == ChannelCommand.NoteOn && e.Message.Data2 == 0) || e.Message.Command == ChannelCommand.NoteOff) // Note off
            {
                SoundMixer.ReleaseChannels(16, note);
            }
            else if (e.Message.Command == ChannelCommand.NoteOn) // Note on
            {
                // Has some input lag
                SongPlayer.PlayNote(track, note, Config.MIDIKeyboardFixedVelocity ? Engine.GetMaxVolume() : volumeOrVelocity, -1);
            }
        }