/// <summary> /// Creates a new InputVoiceDef containing just the argument inputChordDef, /// then calls the other InsertInRest() function with the voiceDef as argument. /// </summary> public void InsertInRest(InputChordDef inputChordDef) { List <IUniqueDef> iuds = new List <IUniqueDef>() { inputChordDef }; InputVoiceDef iVoiceDef = new InputVoiceDef(iuds); InsertInRest(iVoiceDef); }
/// <summary> /// From startMsPosition to (not including) endMsPosition, /// replace all MidiChordDefs or InputChordDefs by UniqueMidiRestDefs, then aglommerate the rests. /// </summary> public void Erase(int startMsPosition, int endMsPosition) { int beginIndex = FindIndexAtMsPosition(startMsPosition); int endIndex = FindIndexAtMsPosition(endMsPosition); for (int i = beginIndex; i < endIndex; ++i) { MidiChordDef mcd = this[i] as MidiChordDef; InputChordDef icd = this[i] as InputChordDef; IUniqueDef iud = (mcd == null) ? (IUniqueDef)icd : (IUniqueDef)mcd; if (iud != null) { RestDef umrd = new RestDef(iud.MsPosition, iud.MsDuration); RemoveAt(i); Insert(i, umrd); } } AgglomerateRests(); }
public InputChordSymbol(Voice voice, InputChordDef umcd, int absMsPosition, int minimumCrotchetDurationMS, float fontSize) : base(voice, umcd.MsDuration, absMsPosition, minimumCrotchetDurationMS, umcd.BeamContinues, fontSize) { _inputChordDef = umcd; _msDurationToNextBarline = umcd.MsDurationToNextBarline; SetNoteheadPitches(umcd.NotatedMidiPitches); if(umcd.Lyric != null) { LyricText lyricText = new LyricText(this, umcd.Lyric, FontHeight); DrawObjects.Add(lyricText); } if(umcd.Dynamic != null) { DynamicText dynamicText = new DynamicText(this, umcd.Dynamic, FontHeight); DrawObjects.Add(dynamicText); } }
/// <summary> /// Transposes the UniqueDefs from the beginIndex upto (but not including) endIndex /// by an equally increasing amount, so that the final MidiChordDef or InputChordDef is transposed by glissInterval. /// beginIndex must be less than endIndex. /// glissInterval can be negative. /// </summary> public void StepwiseGliss(int beginIndex, int endIndex, int glissInterval) { CheckIndices(beginIndex, endIndex); Debug.Assert(beginIndex < endIndex); int nNonMidiChordDefs = GetNumberOfNonMidiOrInputChordDefs(beginIndex, endIndex); int nSteps = (endIndex - beginIndex - nNonMidiChordDefs); double interval = ((double)glissInterval) / nSteps; double step = interval; for (int i = beginIndex; i < endIndex; ++i) { MidiChordDef mcd = _uniqueDefs[i] as MidiChordDef; InputChordDef icd = _uniqueDefs[i] as InputChordDef; IUniqueChordDef iucd = (mcd == null) ? (IUniqueChordDef)icd : (IUniqueChordDef)mcd; if (iucd != null) { iucd.Transpose((int)Math.Round(interval)); interval += step; } } }
/// <summary> /// Creates a new InputVoiceDef containing just the argument inputChordDef, /// then calls the other InsertInRest() function with the voiceDef as argument. /// </summary> public void InsertInRest(InputChordDef inputChordDef) { List<IUniqueDef> iuds = new List<IUniqueDef>() { inputChordDef }; InputVoiceDef iVoiceDef = new InputVoiceDef(this.MidiChannel, 0, iuds); InsertInRest(iVoiceDef); }
List<VoiceDef> CreateBar1() { List<VoiceDef> bar = new List<VoiceDef>(); byte channel = 0; foreach(Palette palette in _palettes) { TrkDef trkDef = new TrkDef(channel, new List<IUniqueDef>()); bar.Add(trkDef); WriteVoiceMidiDurationDefs1(trkDef, palette); ++channel; } InputVoiceDef inputVoiceDef = new InputVoiceDef(); VoiceDef bottomOutputVoice = bar[0]; foreach(IUniqueDef iud in bottomOutputVoice.UniqueDefs) { MidiChordDef mcd = iud as MidiChordDef; RestDef rd = iud as RestDef; if(mcd != null) { List<IUniqueDef> iuds = new List<IUniqueDef>() { (IUniqueDef)mcd }; // Note that the msPosition of the trkDef is trkDef.StartMsPosition (= iuds[0].msPosition), // which may be greater than the InputChordDef's msPosition TrkDef trkDef = new TrkDef(bottomOutputVoice.MidiChannel, iuds); // If non-null, arg2 overrides the inputControls attached to the InputNote or InputChord. TrkOn trkRef = new TrkOn(trkDef, null); List<TrkOn> trkRefs = new List<TrkOn>() { trkRef }; TrkOns trkOns = new TrkOns(trkRefs, null); byte displayPitch = (byte)(mcd.NotatedMidiPitches[0] + 36); Pressure pressure = new Pressure(0, null); Pressures pressures = new Pressures(new List<Pressure>() {pressure}, null); TrkOff trkOff = new TrkOff(trkRef.TrkMidiChannel, mcd.MsPosition, null); List<TrkOff> noteOffTrkOffs = new List<TrkOff>() { trkOff }; TrkOffs trkOffs = new TrkOffs(noteOffTrkOffs, null); InputNoteDef inputNoteDef = new InputNoteDef(displayPitch, trkOns, null, pressures, null, trkOffs, null); List<InputNoteDef> inputNoteDefs = new List<InputNoteDef>() { inputNoteDef }; // The InputChordDef's msPosition must be <= the msPosition of any of the contained trkRefs InputChordDef icd = new InputChordDef(mcd.MsPosition, mcd.MsDuration, inputNoteDefs); inputVoiceDef.UniqueDefs.Add(icd); } else if(rd != null) { RestDef newRest = new RestDef(rd.MsPosition, rd.MsDuration); inputVoiceDef.UniqueDefs.Add(newRest); } } #region set cascading inputControls on the first InputChordDef (for testing) InputChordDef inputChordDef1 = inputVoiceDef.UniqueDefs[0] as InputChordDef; // no need to check for null here. InputControls chordInputControls = new InputControls(); chordInputControls.VelocityOption = VelocityOption.overridden; chordInputControls.MinimumVelocity = 19; inputChordDef1.InputControls = chordInputControls; InputControls noteInputControls = new InputControls(); noteInputControls.VelocityOption = VelocityOption.scaled; noteInputControls.MinimumVelocity = 20; inputChordDef1.InputNoteDefs[0].InputControls = noteInputControls; #endregion bar.Add(inputVoiceDef); return bar; }
/// <summary> /// This function creates only one bar, but with VoiceDef objects. /// </summary> List<VoiceDef> CreateBar2(int bar2StartMsPos) { List<VoiceDef> bar = new List<VoiceDef>(); byte channel = 0; List<TrkDef> trkDefs = new List<TrkDef>(); foreach(Palette palette in _palettes) { bar.Add(new TrkDef(channel, new List<IUniqueDef>())); TrkDef trkDef = palette.NewTrkDef(channel); trkDef.SetMsDuration(6000); trkDefs.Add(trkDef); ++channel; } int msPosition = bar2StartMsPos; int maxBarMsPos = 0; int startMsDifference = 1500; for(int i = 0; i < trkDefs.Count; ++i) { int maxMsPos = WriteVoiceMidiDurationDefsInBar2(bar[i], trkDefs[i], msPosition, bar2StartMsPos); maxBarMsPos = maxBarMsPos > maxMsPos ? maxBarMsPos : maxMsPos; msPosition += startMsDifference; } // now add the final rest in the bar for(int i = 0; i < trkDefs.Count; ++i) { int mdsdEndPos = trkDefs[i].EndMsPosition; if(maxBarMsPos > mdsdEndPos) { RestDef rest2Def = new RestDef(mdsdEndPos, maxBarMsPos - mdsdEndPos); bar[i].UniqueDefs.Add(rest2Def); } } InputVoiceDef inputVoiceDef = new InputVoiceDef(maxBarMsPos - bar2StartMsPos); inputVoiceDef.StartMsPosition = bar2StartMsPos; int msPos = bar2StartMsPos; for(int i = 0; i < bar.Count; ++i) { TrkOn trkRef = new TrkOn((byte)i, msPos, 12, null); List<TrkOn> trkRefs = new List<TrkOn>() { trkRef }; TrkOns seqDef = new TrkOns(trkRefs, null); InputNoteDef inputNoteDef = new InputNoteDef(64, seqDef, null, null); List<InputNoteDef> inputNoteDefs = new List<InputNoteDef>(){inputNoteDef}; InputChordDef inputChordDef = new InputChordDef(msPos, startMsDifference, inputNoteDefs); inputVoiceDef.InsertInRest(inputChordDef); msPos += startMsDifference; } bar.Add(inputVoiceDef); return bar; }
private InputVoiceDef GetBar2InputVoiceDef(Seq bar2Seq) { InputVoiceDef ivd = new InputVoiceDef(0, 0, new List<IUniqueDef>()); ivd.MsPositionReContainer = bar2Seq.AbsMsPosition; foreach(Trk trk in bar2Seq.Trks) { MidiChordDef firstMidiChordDef = null; foreach(IUniqueDef iud in trk.UniqueDefs) { firstMidiChordDef = iud as MidiChordDef; if(firstMidiChordDef != null) { List<TrkRef> trkRefs = new List<TrkRef>(); trkRefs.Add(new TrkRef((byte)trk.MidiChannel, bar2Seq.AbsMsPosition + firstMidiChordDef.MsPositionReFirstUD, 12, null)); SeqRef seqRef = new SeqRef(trkRefs, null); NoteOn noteOn = new NoteOn(seqRef); List<InputNoteDef> inputNoteDefs = new List<InputNoteDef>(); inputNoteDefs.Add(new InputNoteDef((byte)65, noteOn, null)); InputChordDef icd = new InputChordDef(firstMidiChordDef.MsPositionReFirstUD, 1500, inputNoteDefs, M.Dynamic.none, null); ivd.Add(icd); break; } } } return ivd; }
private InputVoiceDef GetBar1InputVoiceDef(Seq bar1Seq) { InputVoiceDef ivd = new InputVoiceDef(0, 0, new List<IUniqueDef>()); ivd.MsPositionReContainer = bar1Seq.AbsMsPosition; Trk leadTrk = null; foreach(Trk trk in bar1Seq.Trks) { if(trk.MidiChannel == 0) { leadTrk = trk; break; } } Debug.Assert(leadTrk != null); foreach(IUniqueDef tIud in leadTrk) { RestDef tRestDef = tIud as RestDef; MidiChordDef tmcd = tIud as MidiChordDef; if(tRestDef != null) { RestDef iRestDef = new RestDef(tRestDef.MsPositionReFirstUD, tRestDef.MsDuration); ivd.Add(iRestDef); } else if(tmcd != null) { List<TrkRef> trkRefs = new List<TrkRef>(); foreach(Trk trk in bar1Seq.Trks) { trkRefs.Add(new TrkRef((byte)trk.MidiChannel, bar1Seq.AbsMsPosition + tmcd.MsPositionReFirstUD, 1, null)); } SeqRef seqRef = new SeqRef(trkRefs, null); NoteOn noteOn = new NoteOn(seqRef); List<InputNoteDef> inputNoteDefs = new List<InputNoteDef>(); foreach(byte notatedMidiPitch in tmcd.NotatedMidiPitches) { inputNoteDefs.Add(new InputNoteDef((byte)(notatedMidiPitch + 36), noteOn, null)); } InputChordDef icd = new InputChordDef(tIud.MsPositionReFirstUD, tIud.MsDuration, inputNoteDefs, M.Dynamic.none, null); ivd.Add(icd); } } return ivd; }