} //SetupVisualization void ActivateVisualizedKey(Rectangle rectangle, bool activate) { KeyboardElement el = (KeyboardElement)rectangle.Tag; var chord = KeyboardLayout.Instance.CurrentChord; if (!Keyboard.IsKeyDown(Key.LeftCtrl)) chord = null; byte volume = (byte)this.sliderOnVelocity.Value; if (Keyboard.IsKeyDown(Key.LeftShift)) volume = (byte)this.sliderOnPedalVelocity.Value; el.Activate(activate, chord, volume); } //ActivateVisualizedKey
public MainWindow() { InitializeComponent(); Icon = Main.TheApplication.Current.ApplicationIcon; SetupHelp(KeyboardLayout.Create(this)); radioIsWickiHayden.Checked += (sender, eventArgs) => { KeyboardLayout.Instance.PopulateTones(true); }; radioIsWickiHayden.Unchecked += (sender, eventArgs) => { KeyboardLayout.Instance.PopulateTones(false); }; radioIsWickiHayden.IsChecked = true; PopulateInstruments(); SetupSliders(); var presetsResetAction = SetupChordPresets(SetupChords()); buttonResetAll.Click += (sender, evenArgs) => { ResetAll(presetsResetAction); }; SetupVisualization(); int maxKey = (int)(int)KeyboardLayout.Instance.MaxKey + 1; keyStates = new BitArray(maxKey, false); this.KeyDown += (sender, evenArgs) => { KeyboardElement ke = KeyboardLayout.Instance.FindKeyboardElementByKey(evenArgs.Key); if (ke != null) { if ((int)evenArgs.Key > maxKey) { return; } if (keyStates[(int)evenArgs.Key]) { evenArgs.Handled = true; return; } //if keyStates[(int)evenArgs.Key] = true; byte velocity; if (Keyboard.IsKeyDown(Key.LeftShift)) { velocity = (byte)this.sliderOnPedalVelocity.Value; } else { velocity = (byte)this.sliderOnVelocity.Value; } var chordToUse = KeyboardLayout.Instance.CurrentChord; if (!Keyboard.IsKeyDown(Key.LeftCtrl)) { chordToUse = null; } byte volume = (byte)this.sliderOnVelocity.Value; if (Keyboard.IsKeyDown(Key.LeftShift)) { volume = (byte)this.sliderOnPedalVelocity.Value; } ke.Activate(true, chordToUse, volume); evenArgs.Handled = true; } //if }; //this.KeyDown this.KeyUp += (sender, evenArgs) => { if ((int)evenArgs.Key > maxKey) { return; } keyStates[(int)evenArgs.Key] = false; KeyboardElement ke = KeyboardLayout.Instance.FindKeyboardElementByKey(evenArgs.Key); if (ke != null) { ke.Activate(false, null, api.maxVelocity); evenArgs.Handled = true; } //if }; //this.KeyDown this.PreviewKeyDown += (sender, evenArgs) => { Key key = evenArgs.SystemKey; if (key == Key.None) { return; } string keyString = key.ToString(); ToggleButton option; if (!chordAlternateKey.TryGetValue(keyString, out option)) { return; } var wasChecked = option.IsChecked; CheckBox cb = option as CheckBox; if (cb != null) { option.IsChecked = !wasChecked; } else { option.IsChecked = true; } }; //this.PreviewKeyDown Persistence.RestoreState(this); } //MainWindow