public PianoControl() { CreatePianoKeys(); InitializePianoKeys(); context = SynchronizationContext.Current; noteOnCallback = delegate(ChannelMessage message) { if (message.Data2 > 0 && (message.Data1 - lowNoteID) < keys.Length) { keys[message.Data1 - lowNoteID].PressPianoKey(); } else if ((message.Data1 - lowNoteID) < keys.Length) { keys[message.Data1 - lowNoteID].ReleasePianoKey(); } }; noteOffCallback = delegate(ChannelMessage message) { if (message.Data1 - lowNoteID < keys.Length) { keys[message.Data1 - lowNoteID].ReleasePianoKey(); } }; }
// Constructor public PianoControl() { this.TabStop = true; // Orientation Default value in constructor _orientation = Orientation.Vertical; _scale = 20; CreatePianoKeys(); InitializePianoKeys(); context = SynchronizationContext.Current; this.LostFocus += new EventHandler(PianoControl_LostFocus); this.GotFocus += new EventHandler(PianoControl_GotFocus); this.MouseLeave += new EventHandler(PianoControl_MouseLeave); this.DoubleBuffered = true; noteOnCallback = delegate(ChannelMessage message) { if (message.Data2 > 0) { if (Orientation == Orientation.Horizontal) { keys[message.Data1 - lowNoteID].NoteOnColor = ChannelColor(message.MidiChannel); keys[message.Data1 - lowNoteID].PressPianoKey(); } else { keys[highNoteID - message.Data1].NoteOnColor = ChannelColor(message.MidiChannel); keys[highNoteID - message.Data1].PressPianoKey(); } } else { if (Orientation == Orientation.Horizontal) { keys[message.Data1 - lowNoteID].ReleasePianoKey(); } else { keys[highNoteID - message.Data1].ReleasePianoKey(); } } }; noteOffCallback = delegate(ChannelMessage message) { if (Orientation == Orientation.Horizontal) { keys[message.Data1 - lowNoteID].ReleasePianoKey(); } else { keys[highNoteID - message.Data1].ReleasePianoKey(); } }; }
public PianoControlWPF() { InitializeComponent(); CreatePianoKeys(); //InitializePianoKeys(); context = SynchronizationContext.Current; noteOnCallback = delegate(ChannelMessage message) { if (message.Data2 > 0) { keys[message.Data1 - LowNoteID].PressPianoKey(); } else { keys[message.Data1 - LowNoteID].ReleasePianoKey(); } }; noteOffCallback = delegate(ChannelMessage message) { keys[message.Data1 - LowNoteID].ReleasePianoKey(); }; }
public PianoControl() { CreatePianoKeys(); InitializePianoKeys(); context = SynchronizationContext.Current; noteOnCallback = delegate(ChannelMessage message) { if(message.Data2 > 0) { keys[message.Data1 - lowNoteID].PressPianoKey(); } else { keys[message.Data1 - lowNoteID].ReleasePianoKey(); } }; noteOffCallback = delegate(ChannelMessage message) { keys[message.Data1 - lowNoteID].ReleasePianoKey(); }; }