private void MidiEventDemoButton_Click(object sender, EventArgs e) { if(M.HasError(_allTextBoxes)) { DoErrorMessage("Can't play because there is an error in one or more of the fields."); } else { Button midiEventDemoButton = sender as Button; DurationDef durationDef = GetDurationDef(); MidiChordDef midiChordDef = durationDef as MidiChordDef; RestDef restDef = durationDef as RestDef; if(midiChordDef != null) { int midiChannel = 0; Sanford.Multimedia.Midi.OutputDevice outputDevice = M.Preferences.CurrentMultimediaMidiOutputDevice; if(_paletteForm.IsPercussionPalette) { midiChannel = 9; outputDevice = M.Preferences.GetMidiOutputDevice("Microsoft GS Wavetable Synth"); } MidiChord midiChord = new MidiChord(midiChannel, midiChordDef, outputDevice); midiChord.Send(); //sends in this thread (blocks the current thread -- keeping the button selected) } else { midiEventDemoButton.Hide(); Refresh(); // shows "rest" behind button Debug.Assert(restDef != null); Thread.Sleep(restDef.MsDuration); midiEventDemoButton.Show(); Refresh(); } } }
private void MidiEventDemoButton_Click(object sender, EventArgs e) { Button button = sender as Button; if(button != null) { PaletteForm paletteForm = this._paletteForm as PaletteForm; Palette palette = null; IUniqueDef iud = null; OutputDevice outputDevice = M.Preferences.GetMidiOutputDevice(M.Preferences.PreferredOutputDevice); int midiChannel = 0; int index = int.Parse(button.Text) - 1; if(index >= 0 && index < _midiEventDemoButtons.Count) { if(paletteForm != null) { palette = new Palette(paletteForm); if(palette.IsPercussionPalette) { outputDevice = M.Preferences.GetMidiOutputDevice("Microsoft GS Wavetable Synth"); midiChannel = 9; } } iud = palette.UniqueDurationDef(index); if(iud is RestDef) { _midiEventDemoButtons[index].Hide(); this._restLabels[0].Select(); // just to deselect everything Refresh(); // shows "rest" behind button Thread.Sleep(iud.MsDuration); _midiEventDemoButtons[index].Show(); Refresh(); } else { _midiEventDemoButtons[index].Select(); Refresh(); MidiChordDef midiChordDef = iud as MidiChordDef; Debug.Assert(midiChordDef != null); MidiChord midiChord = new MidiChord(midiChannel, midiChordDef, outputDevice); midiChord.Send(); //sends in this thread (blocks the current thread -- keeping the button selected) } } } }