private void CreateSliders(int channel, MidiChordSliderDefs sliderDefs, int msDuration) { if (sliderDefs.ModulationWheelMsbs != null && sliderDefs.ModulationWheelMsbs.Count > 0) { this._modulationWheelSlider = new MidiModulationWheelSlider(sliderDefs.ModulationWheelMsbs, channel, msDuration); } if (sliderDefs.PanMsbs != null && sliderDefs.PanMsbs.Count > 0) { this._panSlider = new MidiPanSlider(sliderDefs.PanMsbs, channel, msDuration); } if (sliderDefs.PitchWheelMsbs != null && sliderDefs.PitchWheelMsbs.Count > 0) { this._pitchWheelSlider = new MidiPitchWheelSlider(sliderDefs.PitchWheelMsbs, channel, msDuration); } if (sliderDefs.ExpressionMsbs != null && sliderDefs.ExpressionMsbs.Count > 0) { this._expressionSlider = new MidiExpressionSlider(sliderDefs.ExpressionMsbs, channel, msDuration); } }
/// <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); }