/// <summary> /// Returns either a new RestDef or a new MidiChordDef /// In both cases, MsPosition is set to zero, Lyric is set to null. /// </summary> private DurationDef GetDurationDef() { DurationDef rval = null; if (this.ChordDensityTextBox.Text == "0") { int msDuration = 0; try { msDuration = int.Parse(this.DurationTextBox.Text); } catch { Debug.Assert(false); } Debug.Assert(msDuration > 0); rval = new RestDef(0, msDuration); } else { Palette palette = new Palette(this); rval = palette.MidiChordDef(0); } return(rval); }
public Palette(PaletteForm paletteForm) { BasicChordFormSettings bcfs = new BasicChordFormSettings(); bcfs.Durations = M.StringToIntList(paletteForm.BasicChordControl.DurationsTextBox.Text, ','); bcfs.Velocities = M.StringToByteList(paletteForm.BasicChordControl.VelocitiesTextBox.Text, ','); bcfs.MidiPitches = M.StringToByteList(paletteForm.BasicChordControl.MidiPitchesTextBox.Text, ','); bcfs.ChordOffs = M.StringToBoolList(paletteForm.BasicChordControl.ChordOffsTextBox.Text, ','); bcfs.ChordDensities = M.StringToByteList(paletteForm.BasicChordControl.ChordDensitiesTextBox.Text, ','); bcfs.Inversions = paletteForm.GetLinearInversions(paletteForm.BasicChordControl.RootInversionTextBox.Text); bcfs.InversionIndices = M.StringToIntList(paletteForm.BasicChordControl.InversionIndicesTextBox.Text, ','); bcfs.VerticalVelocityFactors = M.StringToFloatList(paletteForm.BasicChordControl.VerticalVelocityFactorsTextBox.Text, ','); _basicChordMidiSettings = new BasicChordMidiSettings(bcfs); _bankIndices = M.StringToByteList(paletteForm.BankIndicesTextBox.Text, ','); _patchIndices = M.StringToByteList(paletteForm.PatchIndicesTextBox.Text, ','); _pitchwheelDeviations = M.StringToByteList(paletteForm.PitchwheelDeviationsTextBox.Text, ','); _pitchwheelEnvelopes = M.StringToByteLists(paletteForm.PitchwheelEnvelopesTextBox.Text); _panEnvelopes = M.StringToByteLists(paletteForm.PanEnvelopesTextBox.Text); _modulationWheelEnvelopes = M.StringToByteLists(paletteForm.ModulationWheelEnvelopesTextBox.Text); _expressionEnvelopes = M.StringToByteLists(paletteForm.ExpressionEnvelopesTextBox.Text); _ornamentNumbers = M.StringToIntList(paletteForm.OrnamentNumbersTextBox.Text, ','); _ornamentMinMsDurations = M.StringToIntList(paletteForm.MinMsDurationsTextBox.Text, ','); _ornamentSettings = null; if (paletteForm.OrnamentsForm != null) { _ornamentSettings = new OrnamentSettings(paletteForm); } for (int chordIndex = 0; chordIndex < _basicChordMidiSettings.Durations.Count; ++chordIndex) { DurationDef dd = GetDurationDef(chordIndex); _durationDefs.Add(dd); } _isPercussionPalette = paletteForm.IsPercussionPalette; }
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; 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(); } } }
/// <summary> /// Returns either a new RestDef or a new MidiChordDef /// In both cases, MsPosition is set to zero, Lyric is set to null. /// </summary> private DurationDef GetDurationDef(int index) { DurationDef rval = null; BasicChordMidiSettings bcms = _basicChordMidiSettings; if (bcms.MidiPitches[index].Count == 0) { /// RestDefs are immutable, and have no MsPosition property. /// UniqueRestDefs are mutable RestDefs with both MsPositon and MsDuration properties. int restMsDuration = bcms.Durations[index]; rval = new RestDef(0, restMsDuration); } else { /// Create a new MidiChordDef (with msPosition=0, lyric=null) bool hasChordOff = BoolOrDefaultValue(bcms.ChordOffs, index, M.DefaultHasChordOff); // true int duration = bcms.Durations[index]; List <byte> rootMidiPitches = bcms.MidiPitches[index]; List <byte> rootMidiVelocities = bcms.Velocities[index]; byte? bankIndex = ByteOrNull(_bankIndices, index); byte? patchIndex = ByteOrNull(_patchIndices, index); byte pitchwheelDeviation = ByteOrDefaultValue(_pitchwheelDeviations, index, M.DefaultPitchWheelDeviation); // 2 List <byte> pitchwheelEnvelope = ListByte(_pitchwheelEnvelopes, index); List <byte> panEnvelope = ListByte(_panEnvelopes, index); List <byte> modulationWheelEnvelope = ListByte(_modulationWheelEnvelopes, index); List <byte> expressionEnvelope = ListByte(_expressionEnvelopes, index); MidiChordSliderDefs midiChordSliderDefs = new MidiChordSliderDefs(pitchwheelEnvelope, panEnvelope, modulationWheelEnvelope, expressionEnvelope); OrnamentSettings os = _ornamentSettings; List <BasicMidiChordDef> basicMidiChordDefs = new List <BasicMidiChordDef>(); int ornamentNumber; if (os == null || _ornamentNumbers[index] == 0) { ornamentNumber = 0; BasicMidiChordDef bmcd = new BasicMidiChordDef(duration, bankIndex, patchIndex, hasChordOff, rootMidiPitches, rootMidiVelocities); basicMidiChordDefs.Add(bmcd); } else { ornamentNumber = _ornamentNumbers[index]; int ornamentMinMsDuration = IntOrDefaultValue(_ornamentMinMsDurations, index, M.DefaultOrnamentMinimumDuration); // 1 List <int> ornamentValues = os.OrnamentValues[_ornamentNumbers[index] - 1]; for (int i = 0; i < ornamentValues.Count; ++i) { int oIndex = ornamentValues[i] - 1; bool oHasChordOff = BoolOrDefaultValue(os.BasicChordMidiSettings.ChordOffs, oIndex, M.DefaultHasChordOff); int oDuration = os.BasicChordMidiSettings.Durations[oIndex]; List <byte> oMidiPitches = os.BasicChordMidiSettings.MidiPitches[oIndex]; List <byte> oVelocities = os.BasicChordMidiSettings.Velocities[oIndex]; byte? oBank = ByteOrNull(os.BankIndices, oIndex); byte? oPatch = ByteOrNull(os.PatchIndices, oIndex); BasicMidiChordDef bmcd = new BasicMidiChordDef(oDuration, oBank, oPatch, oHasChordOff, oMidiPitches, oVelocities); basicMidiChordDefs.Add(bmcd); } // The basicMidiChordDefs currently contain the values from the ornaments form. // All oBank and oPatch values will be null if the corresponding field in the ornament form was empty. // The durations, pitches and velocities are relative to the main palette's values. RemoveDuplicateBankAndPatchValues(basicMidiChordDefs); if (basicMidiChordDefs[0].BankIndex == null) { basicMidiChordDefs[0].BankIndex = bankIndex; // can be null } if (basicMidiChordDefs[0].PatchIndex == null) { basicMidiChordDefs[0].PatchIndex = patchIndex; } Debug.Assert(basicMidiChordDefs[0].PatchIndex != null); basicMidiChordDefs = Moritz.Spec.MidiChordDef.FitToDuration(basicMidiChordDefs, duration, ornamentMinMsDuration); foreach (BasicMidiChordDef b in basicMidiChordDefs) { List <byte> combinedPitches = new List <byte>(); foreach (byte pitch in b.Pitches) { foreach (byte rootMidiPitch in rootMidiPitches) { combinedPitches.Add(M.MidiValue(rootMidiPitch + pitch)); } } b.Pitches = combinedPitches; List <byte> combinedVelocities = new List <byte>(); foreach (byte velocity in b.Velocities) { foreach (byte rootMidiVelocity in rootMidiVelocities) { combinedVelocities.Add(M.MidiValue(rootMidiVelocity + velocity)); } } b.Velocities = combinedVelocities; } } rval = new MidiChordDef( duration, pitchwheelDeviation, hasChordOff, rootMidiPitches, ornamentNumber, midiChordSliderDefs, basicMidiChordDefs); } return(rval); }