internal void GetBeforeInterlude3(Clytemnestra clytemnestra, TrkDef wind1, TrkDef furies2, Palette cheepsPalette) { int[] cheepIndices = { 4, 8, 2, 6, 10, 0, 1, 3, 5, 7, 9, 11 }; int[] transpositions = { 2, 1, 3, 0, 4, -3, 5, 10, 6, 9, 7, 8 }; double[] velocityfactors = { 0.32, 0.31, 0.34, 0.3, 0.35, 0.37, 0.36, 0.43, 0.37, 0.42, 0.39, 0.4 }; int[] msPositions = { furies2[8].MsPosition + 200, furies2[12].MsPosition + 100, furies2[24].MsPosition + 300, furies2[30].MsPosition + 400, furies2[40].MsPosition + 500, clytemnestra[122].MsPosition, clytemnestra[132].MsPosition + 110, clytemnestra[141].MsPosition + 220, clytemnestra[150].MsPosition + 330, clytemnestra[158].MsPosition + 440, clytemnestra[164].MsPosition + 550, clytemnestra[173].MsPosition, }; for (int i = 0; i < cheepsPalette.Count; ++i) { MidiChordDef cheep = cheepsPalette.UniqueDurationDef(cheepIndices[i]) as MidiChordDef; Debug.Assert(cheep != null); cheep.MsPosition = msPositions[i]; cheep.MsDuration *= 2; cheep.AdjustVelocities(velocityfactors[i]); cheep.Transpose(transpositions[i]); InsertInRest(cheep); } AlignObjectAtIndex(11, 12, 13, clytemnestra[123].MsPosition); AlignObjectAtIndex(21, 22, 23, clytemnestra[168].MsPosition); }
/// <summary> /// Steals the ticks from furies 3, then agglommerates the remaining rests in furies3... /// </summary> private void GetFuries2Interlude2(Clytemnestra clytemnestra, TrkDef wind1, TrkDef furies3) { List <int> furies3TickIndices = new List <int>() { 66, 70, 74, 81, 85, 89, 93, 96, 100, 104, 109, 113, 117, 122, 126, 130, 135, 139, 143, 148, 152 }; for (int i = 0; i < furies3TickIndices.Count; ++i) { int f3Index = furies3TickIndices[i]; MidiChordDef ticksChord = furies3[f3Index] as MidiChordDef; Debug.Assert(ticksChord != null); RestDef ticksRest = new RestDef(ticksChord.MsPosition, ticksChord.MsDuration); furies3.Replace(f3Index, ticksRest); InsertInRest(ticksChord); } MidiChordDef lastTicksBeforeVerse3 = (MidiChordDef)((MidiChordDef)this[39]).DeepClone(); lastTicksBeforeVerse3.MsPosition = furies3[155].MsPosition + furies3[155].MsDuration; lastTicksBeforeVerse3.MsDuration = clytemnestra[117].MsPosition - lastTicksBeforeVerse3.MsPosition; lastTicksBeforeVerse3.Transpose(10); InsertInRest(lastTicksBeforeVerse3); furies3.AgglomerateRests(); }
/// <summary> /// There is currently still one bar per system. /// </summary> protected void ReplaceConsecutiveRestsInBars(List <List <VoiceDef> > voicesPerStaffPerSystem) { foreach (List <VoiceDef> voicesPerStaff in voicesPerStaffPerSystem) { foreach (VoiceDef voice in voicesPerStaff) { // contains lists of consecutive rest indices List <List <int> > restsToReplace = new List <List <int> >(); #region find the consecutive rests List <int> consecRestIndices = new List <int>(); for (int i = 0; i < voice.UniqueDefs.Count - 1; i++) { MidiChordDef mcd1 = voice.UniqueDefs[i] as MidiChordDef; MidiChordDef mcd2 = voice.UniqueDefs[i + 1] as MidiChordDef; if (mcd1 == null && mcd2 == null) { if (!consecRestIndices.Contains(i)) { consecRestIndices.Add(i); } consecRestIndices.Add(i + 1); } else { if (consecRestIndices != null && consecRestIndices.Count > 0) { restsToReplace.Add(consecRestIndices); consecRestIndices = new List <int>(); } } if (i == voice.UniqueDefs.Count - 2 && consecRestIndices.Count > 0) { restsToReplace.Add(consecRestIndices); } } #endregion #region replace the consecutive rests if (restsToReplace.Count > 0) { for (int i = restsToReplace.Count - 1; i >= 0; i--) { List <int> indToReplace = restsToReplace[i]; int msDuration = 0; int msPosition = voice.UniqueDefs[indToReplace[0]].MsPosition; for (int j = indToReplace.Count - 1; j >= 0; j--) { IUniqueDef iumdd = voice.UniqueDefs[indToReplace[j]]; Debug.Assert(iumdd.MsDuration > 0); msDuration += iumdd.MsDuration; voice.UniqueDefs.RemoveAt(indToReplace[j]); } RestDef replacementLmdd = new RestDef(msPosition, msDuration); voice.UniqueDefs.Insert(indToReplace[0], replacementLmdd); } } #endregion } } }
private List <IUniqueDef> GetTicksSequence(Palette ticksPalette) { List <IUniqueDef> ticksSequence = new List <IUniqueDef>(); int msPosition = 0; int[] transpositions = { 12, 14, 17 }; for (int i = 0; i < 3; ++i) { int[] contour = K.Contour(7, 4, 10 - i); for (int j = 6; j >= 0; --j) { IUniqueDef ticks = ticksPalette.UniqueDurationDef(contour[j] - 1); ticks.MsPosition = msPosition; msPosition += ticks.MsDuration; MidiChordDef iumdd = ticks as MidiChordDef; if (iumdd != null) { iumdd.Transpose(transpositions[i] + contour[j]); iumdd.AdjustVelocities(0.6); } ticksSequence.Add(ticks); } } return(ticksSequence); }
/// <summary> /// Old constructor, currently not used (03.05.2020), but retained for future inspection /// </summary> public OutputChordSymbol(Voice voice, MidiChordDef umcd, int absMsPosition, PageFormat pageFormat) : base(voice, umcd.MsDuration, absMsPosition, pageFormat.MinimumCrotchetDuration, pageFormat.MusicFontHeight) { M.Assert(false); // 03.05.2020: don't use this constructor (to be inspected once work on midi info begins). _midiChordDef = umcd; _msDurationToNextBarline = umcd.MsDurationToNextBarline; SetNoteheadPitchesAndVelocities(umcd.NotatedMidiPitches, umcd.NotatedMidiVelocities); if (!String.IsNullOrEmpty(umcd.OrnamentText)) { string ornamentString = null; if (Char.IsDigit(umcd.OrnamentText[0])) { // if umcd.OrnamentText is null or empty, there will be no ornamentString DrawObject ornamentString = String.Concat('~', umcd.OrnamentText); } else { ornamentString = umcd.OrnamentText; } OrnamentText ornamentText = new OrnamentText(this, ornamentString, pageFormat.OrnamentFontHeight); DrawObjects.Add(ornamentText); } if (umcd.Lyric != null) { LyricText lyric = new LyricText(this, umcd.Lyric, FontHeight); DrawObjects.Add(lyric); } }
internal void GetChirpsInInterlude2AndVerse3(TrkDef furies1, TrkDef furies2, Clytemnestra clytemnestra, TrkDef wind1, Palette chirpsPalette) { int[] chirpIndices = { 4, 8, 2, 6, 10, 0 }; int[] transpositions = { 2, 1, 3, 0, 4, 5 }; //double[] velocityfactors = { 0.3, 0.31, 0.32, 0.34, 0.35, 0.36, 0.37, 0.39, 0.4, 0.42, 0.43, 0.45 }; double[] velocityfactors = { 0.32, 0.34, 0.36, 0.38, 0.40, 0.42 }; int[] msPositions = { this[112].MsPosition + 200, this[129].MsPosition + 500, clytemnestra[118].MsPosition, clytemnestra[138].MsPosition + 250, clytemnestra[151].MsPosition, furies2[57].MsPosition }; for (int i = 5; i >= 0; --i) { MidiChordDef cheep = chirpsPalette.MidiChordDef(chirpIndices[i]); cheep.MsPosition = msPositions[i]; cheep.AdjustVelocities(velocityfactors[i]); cheep.Transpose(transpositions[i]); InsertInRest(cheep); } AlignObjectAtIndex(25, 30, 31, clytemnestra[65].MsPosition); AlignObjectAtIndex(140, 141, 142, clytemnestra[119].MsPosition); AlignObjectAtIndex(142, 143, 144, clytemnestra[140].MsPosition); AlignObjectAtIndex(144, 145, 146, clytemnestra[152].MsPosition); AlignObjectAtIndex(146, 147, 148, furies1[23].MsPosition); AgglomerateRestOrChordAt(114); }
/// <summary> /// Sets Clytamnestra's _uniqueMidiDurationDefs for the whole piece including rests. /// Barline positions are set later. /// </summary> private void SetUniqueMidiDurationDefs(TrkDef wind3) { Debug.Assert(_momentDefsListPerVerse.Count == 5); List <int> verseMsPositions = new List <int>(); verseMsPositions.Add(wind3[8].MsPosition); verseMsPositions.Add(wind3[20].MsPosition); verseMsPositions.Add(wind3[33].MsPosition); verseMsPositions.Add(wind3[49].MsPosition); verseMsPositions.Add(wind3[70].MsPosition); int currentVerseMsPosition = 0; int currentEndMsPosition = 0; IUniqueDef interludeRestDef = null; for (int verseIndex = 0; verseIndex < 5; ++verseIndex) { currentVerseMsPosition = verseMsPositions[verseIndex]; interludeRestDef = new RestDef(currentEndMsPosition, currentVerseMsPosition - currentEndMsPosition); _uniqueDefs.Add(interludeRestDef); List <MomentDef> momentDefs = _momentDefsListPerVerse[verseIndex]; for (int momentDefIndex = 0; momentDefIndex < momentDefs.Count; ++momentDefIndex) { MomentDef momentDef = momentDefs[momentDefIndex]; momentDef.MsPosition += currentVerseMsPosition; int restWidth = momentDef.MsWidth - momentDef.MaximumMsDuration; IUniqueDef lmrd = null; if (restWidth > 0) { momentDef.MsWidth -= restWidth; lmrd = new RestDef(momentDef.MsPosition + momentDef.MsWidth, restWidth); Debug.Assert(lmrd.MsDuration > 0); } MidiChordDef mcd = momentDef.MidiChordDefs[0]; IUniqueDef lmcd = mcd.DeepClone(); lmcd.MsPosition = momentDef.MsPosition; lmcd.MsDuration = momentDef.MsWidth; Debug.Assert(lmcd.MsDuration > 0); _uniqueDefs.Add(lmcd); if (lmrd != null) { _uniqueDefs.Add(lmrd); } currentEndMsPosition = _uniqueDefs[_uniqueDefs.Count - 1].MsPosition + _uniqueDefs[_uniqueDefs.Count - 1].MsDuration; } } interludeRestDef = new RestDef(currentEndMsPosition, wind3.EndMsPosition - currentEndMsPosition); _uniqueDefs.Add(interludeRestDef); }
/// <summary> /// Returns a dictionary containing the current transposition per msPosition /// ( Dictionary[msPositon, transposition] ) /// </summary> /// <returns></returns> public Dictionary <int, int> SetFinalMelody(Krystal mod7krys, Krystal mod12krys) { int f4Interlude4Index = 42; int f4PostludeIndex = 59; int f4finalPhaseIndex = 73; List <int> mod7Values = mod7krys.GetValues(1)[0]; List <int> mod12Values = mod12krys.GetValues(1)[0]; // circle of fifths hierarchy (mod 12): 0 7 4 2 10 9 3 4 8 11 1 6 // rearranged for mod7krys hierarchy (4536271) int[] transpositionArray1 = { 3, -2, 4, 0, 4, 2, -3 }; // 7 changed to 4 (was too high!) // circle of fifths hierarchy centred on 0: int[] transpositionArray2 = { 0, 4, 4, 2, -2, -3, 3, 4, -4, -1, 1, 6 }; // 7 changed to 4 (was too high!) // widened int[] transpositionArray3 = { 0, 9, 4, 4, -2, -5, 6, 8, -7, -2, 2, 11 }; Dictionary <int, int> msPosTranspositionDict = new Dictionary <int, int>(); int transposition; int valueIndex = 0; for (int i = f4Interlude4Index; i < f4PostludeIndex; ++i) { MidiChordDef umcd = this[i] as MidiChordDef; if (umcd != null) { transposition = transpositionArray1[mod7Values[valueIndex++] - 1]; umcd.Transpose(transposition); msPosTranspositionDict.Add(umcd.MsPosition, transposition); } } valueIndex = 0; for (int i = f4PostludeIndex; i < f4finalPhaseIndex; ++i) { MidiChordDef umcd = this[i] as MidiChordDef; if (umcd != null) { transposition = transpositionArray2[mod12Values[valueIndex++] - 1]; umcd.Transpose(transposition); msPosTranspositionDict.Add(umcd.MsPosition, transposition); } } valueIndex = 0; for (int i = f4finalPhaseIndex; i < this.Count; ++i) { MidiChordDef umcd = this[i] as MidiChordDef; if (umcd != null) { transposition = transpositionArray3[mod12Values[valueIndex++] - 1]; umcd.Transpose(transposition); msPosTranspositionDict.Add(umcd.MsPosition, transposition); } } return(msPosTranspositionDict); }
/// <summary> /// Returns a MidiChordDef if the object at index is a MidiChordDef, /// otherwise throws an exception. /// </summary> public MidiChordDef MidiChordDef(int index) { MidiChordDef midiChordDef = _durationDefs[index].DeepClone() as MidiChordDef; if (midiChordDef == null) { throw new ApplicationException("The indexed object was not a MidiChordDef."); } return(midiChordDef); }
/// <summary> /// A temporary measure while composing /// </summary> public override void SetLyricsToIndex() { for (int index = 0; index < _uniqueDefs.Count; ++index) { MidiChordDef lmcd = _uniqueDefs[index] as MidiChordDef; if (lmcd != null) { lmcd.Lyric = index.ToString() + lmcd.Lyric; } } }
public MidiChord(int channel, MidiChordDef midiChordDef, OutputDevice midiOutputDevice) : base(channel, 0, midiChordDef.MsDuration) { _midiOutputDevice = midiOutputDevice; List <BasicMidiChordDef> basicMidiChordDefs = midiChordDef.BasicMidiChordDefs; Debug.Assert(basicMidiChordDefs.Count > 0); List <int> realBasicMidiChordDurations = MidiChordDef.GetIntDurations(MsDuration, midiChordDef.BasicChordDurations, basicMidiChordDefs.Count); var notesToStop = new SortedSet <byte>(); int i = 0; foreach (BasicMidiChordDef basicMidiChordDef in midiChordDef.BasicMidiChordDefs) { this._basicMidiChords.Add(new BasicMidiChord(channel, this, basicMidiChordDef, realBasicMidiChordDurations[i++])); if (basicMidiChordDef.HasChordOff) { foreach (byte note in basicMidiChordDef.Pitches) { if (!notesToStop.Contains(note)) { notesToStop.Add(note); } } } } if (midiChordDef.Bank != null) { _bank = new BankControl(channel, (byte)midiChordDef.Bank); } if (midiChordDef.Patch != null) { _patch = new PatchControl(channel, (byte)midiChordDef.Patch); } // Moritz currently never repeats MidiChords, so the _repeat field is unnecessary. // However: the value of midiChordDef.Repeat is saved in SVG-MIDI files, // and may be used by the web AssistantPerformer. //_repeat = midiChordDef.Repeat; if (midiChordDef.PitchWheelDeviation != null) { _pitchWheelDeviation = new PitchWheelDeviation(channel, (byte)midiChordDef.PitchWheelDeviation); } if (midiChordDef.MidiChordSliderDefs != null) { CreateSliders(channel, midiChordDef.MidiChordSliderDefs, MsDuration); } SetMessagesDict(); }
public override NoteObject GetNoteObject(Voice voice, IUniqueDef iud, bool firstDefInVoice, ref byte currentVelocity, float musicFontHeight) { NoteObject noteObject = null; CautionaryChordDef cautionaryChordDef = iud as CautionaryChordDef; MidiChordDef midiChordDef = iud as MidiChordDef; InputChordDef inputChordDef = iud as InputChordDef; RestDef restDef = iud as RestDef; ClefChangeDef clefChangeDef = iud as ClefChangeDef; PageFormat pageFormat = voice.Staff.SVGSystem.Score.PageFormat; float cautionaryFontHeight = pageFormat.CautionaryNoteheadsFontHeight; int minimumCrotchetDuration = pageFormat.MinimumCrotchetDuration; if (cautionaryChordDef != null && firstDefInVoice) { CautionaryChordSymbol cautionaryChordSymbol = new CautionaryChordSymbol(voice, cautionaryChordDef, cautionaryFontHeight); noteObject = cautionaryChordSymbol; } else if (midiChordDef != null) { OutputChordSymbol outputChordSymbol = new OutputChordSymbol(voice, midiChordDef, minimumCrotchetDuration, musicFontHeight); if (midiChordDef.MidiVelocity != currentVelocity) { outputChordSymbol.AddDynamic(midiChordDef.MidiVelocity, currentVelocity); currentVelocity = midiChordDef.MidiVelocity; } noteObject = outputChordSymbol; } else if (inputChordDef != null) { InputChordSymbol inputChordSymbol = new InputChordSymbol(voice, inputChordDef, minimumCrotchetDuration, musicFontHeight); noteObject = inputChordSymbol; } else if (restDef != null) { RestSymbol restSymbol = new RestSymbol(voice, iud, minimumCrotchetDuration, musicFontHeight); noteObject = restSymbol; } else if (clefChangeDef != null) { ClefChangeSymbol clefChangeSymbol = new ClefChangeSymbol(voice, clefChangeDef.ClefType, cautionaryFontHeight, ((IUniqueDef)iud).MsPosition); noteObject = clefChangeSymbol; } return(noteObject); }
public OutputChordSymbol(Voice voice, MidiChordDef umcd, int minimumCrotchetDurationMS, float fontSize) : base(voice, umcd.MsDuration, umcd.MsPosition, minimumCrotchetDurationMS, fontSize) { _midiChordDef = umcd; _msDurationToNextBarline = umcd.MsDurationToNextBarline; SetNoteheadPitches(umcd.NotatedMidiPitches); if (umcd.OrnamentNumberSymbol != 0) { OrnamentText ornamentText = new OrnamentText(this, "~" + umcd.OrnamentNumberSymbol.ToString(), FontHeight); DrawObjects.Add(ornamentText); } if (umcd.Lyric != null) { LyricText lyric = new LyricText(this, umcd.Lyric, FontHeight); DrawObjects.Add(lyric); } }
private void AddGrowlsToInterlude2AndVerse3(Clytemnestra clytemnestra, Palette growlsPalette) { int[] growlIndices = { 0, 2, 5, 1 }; //int[] transpositions = { 0,0,0,0 }; //double[] velocityfactors = { 1,1,1,1 }; int[] msPositions = { this[24].MsPosition + 200, this[26].MsPosition + 200, this[30].MsPosition + 200, this[32].MsPosition + 200, }; int[] msDurations = { this[24].MsDuration / 2, this[26].MsDuration / 2, this[30].MsDuration / 2, this[32].MsDuration / 2 }; for (int i = 3; i >= 0; --i) { MidiChordDef growl = growlsPalette.UniqueDurationDef(growlIndices[i]) as MidiChordDef; Debug.Assert(growl != null); growl.MsPosition = msPositions[i]; growl.MsDuration = msDurations[i]; //growl.AdjustVelocities(velocityfactors[i]); //growl.Transpose(transpositions[i]); InsertInRest(growl); } AgglomerateRestOrChordAt(40); AlignObjectAtIndex(34, 35, 36, clytemnestra[140].MsPosition); AlignObjectAtIndex(35, 36, 37, clytemnestra[141].MsPosition); AlignObjectAtIndex(38, 39, 40, clytemnestra[162].MsPosition); }
private void AddFuries2ChirpsForInterlude2AndVerse3(Clytemnestra clytemnestra, TrkDef wind1, Palette chirpsPalette) { int[] chirpIndices = { 4, 6, 10, 0, 1, 3, 5, 7, 9, 11 }; int[] transpositions = { 2, 0, 4, 11, 5, 10, 6, 9, 7, 8 }; double[] velocityfactors = { 0.32, 0.3, 0.35, 0.45, 0.36, 0.43, 0.37, 0.42, 0.39, 0.4 }; IUniqueDef c3 = chirpsPalette.UniqueDurationDef(chirpIndices[3]); IUniqueDef c7 = chirpsPalette.UniqueDurationDef(chirpIndices[7]); int[] msPositions = { this[2].MsPosition, this[6].MsPosition, this[16].MsPosition, this[26].MsPosition, this[26].MsPosition + c3.MsDuration, clytemnestra[129].MsPosition, clytemnestra[143].MsPosition + 110, clytemnestra[156].MsPosition + 220, clytemnestra[156].MsPosition + 220 + c7.MsDuration, clytemnestra[168].MsPosition + 330, }; for (int i = 9; i >= 0; --i) { MidiChordDef cheep = chirpsPalette.MidiChordDef(chirpIndices[i]); cheep.MsPosition = msPositions[i]; //cheep.MsDuration *= 2; cheep.AdjustVelocities(velocityfactors[i]); cheep.Transpose(transpositions[i]); InsertInRest(cheep); } AlignObjectAtIndex(50, 51, 52, clytemnestra[130].MsPosition); AlignObjectAtIndex(55, 56, 57, clytemnestra[159].MsPosition); AgglomerateRestOrChordAt(31); }
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(); } } }
private void AdjustWindPitchWheelDeviations(TrkDef wind) { byte versePwdValue = 3; double windStartPwdValue = 6, windEndPwdValue = 28; double pwdfactor = Math.Pow(windEndPwdValue / windStartPwdValue, (double)1 / 5); // 5th root of windEndPwdValue/windStartPwdValue -- the last pwd should be windEndPwdValue MidiChordDef umcd = null; for (int i = 0; i < wind.Count; ++i) { if (i < 8) //prelude { umcd = wind[i] as MidiChordDef; if (umcd != null) { umcd.PitchWheelDeviation = M.MidiValue((int)windStartPwdValue); } } else if (i < 15) // verse 1 { umcd = wind[i] as MidiChordDef; if (umcd != null) { umcd.PitchWheelDeviation = versePwdValue; } } else if (i < 20) // interlude 1 { umcd = wind[i] as MidiChordDef; if (umcd != null) { umcd.PitchWheelDeviation = M.MidiValue((int)(windStartPwdValue * pwdfactor)); } } else if (i < 24) // verse 2 { umcd = wind[i] as MidiChordDef; if (umcd != null) { umcd.PitchWheelDeviation = versePwdValue; } } else if (i < 33) // interlude 2 { umcd = wind[i] as MidiChordDef; if (umcd != null) { umcd.PitchWheelDeviation = M.MidiValue((int)(windStartPwdValue * (Math.Pow(pwdfactor, 2)))); } } else if (i < 39) // verse 3 { umcd = wind[i] as MidiChordDef; if (umcd != null) { umcd.PitchWheelDeviation = versePwdValue; } } else if (i < 49) // interlude 3 { umcd = wind[i] as MidiChordDef; if (umcd != null) { umcd.PitchWheelDeviation = M.MidiValue((int)(windStartPwdValue * (Math.Pow(pwdfactor, 3)))); } } else if (i < 57) // verse 4 { umcd = wind[i] as MidiChordDef; if (umcd != null) { umcd.PitchWheelDeviation = versePwdValue; } } else if (i < 70) // interlude 4 { umcd = wind[i] as MidiChordDef; if (umcd != null) { umcd.PitchWheelDeviation = M.MidiValue((int)(windStartPwdValue * (Math.Pow(pwdfactor, 4)))); } } else if (i < 74) // verse 5 { umcd = wind[i] as MidiChordDef; if (umcd != null) { umcd.PitchWheelDeviation = versePwdValue; } } else // postlude { umcd = wind[i] as MidiChordDef; if (umcd != null) { umcd.PitchWheelDeviation = M.MidiValue((int)(windStartPwdValue * (Math.Pow(pwdfactor, 5)))); } } } }
/// <summary> /// Sets _momentDefsListPerVerse to contain a list of MomentDefs for each verse. /// Each MomentDef is positioned with respect to the beginning of its verse, and contains /// a single MidiChordDef in its MidiChordDefs list. /// </summary> private void SetMomentDefsListPerVerse() { _momentDefsListPerVerse = new List <List <MomentDef> >(); List <List <int> > momentDefMsWidthPerVerse = MomentDefMsWidthPerVerse; List <List <int> > midiChordDefMsDurPerVerse = MidiChordDefMsDurationsPerVerse; CheckWidths(momentDefMsWidthPerVerse, midiChordDefMsDurPerVerse); List <List <string> > lyricsPerVerse = LyricsPerVerse; List <byte> verseVelocities = new List <byte>() { (byte)64, (byte)75, (byte)90, (byte)105, (byte)120 }; for (int verseIndex = 0; verseIndex < 5; ++verseIndex) { int momentMsPos = 0; List <int> momentMsWidth = momentDefMsWidthPerVerse[verseIndex]; List <int> midiChordMsDur = midiChordDefMsDurPerVerse[verseIndex]; List <string> lyrics = lyricsPerVerse[verseIndex]; List <MomentDef> momentDefs = new List <MomentDef>(); _momentDefsListPerVerse.Add(momentDefs); byte patch = (byte)(123 + verseIndex); // top 5 patches in bank 0 List <byte> velocity = new List <byte>() { verseVelocities[verseIndex] }; for (int syllableIndex = 0; syllableIndex < momentMsWidth.Count; ++syllableIndex) { Debug.Assert(midiChordMsDur[syllableIndex] <= momentMsWidth[syllableIndex]); MomentDef momentDef = new MomentDef(momentMsPos); momentDef.MsWidth = momentMsWidth[syllableIndex]; momentDefs.Add(momentDef); List <byte> pitch = new List <byte>() { (byte)syllableIndex }; // the syllables are organised like this in the soundfont. int msDuration = midiChordMsDur[syllableIndex]; #region MidiChordDef lmcd = new MidiChordDef(); lmcd.HasChordOff = true; // Bank, and Patch are added to *every* chord so that performances can start anywhere. // If the Assistant Performer is clever enough, repeated controls are not actually sent. lmcd.Bank = (byte)(0); lmcd.Patch = patch; lmcd.Lyric = lyrics[syllableIndex]; // the following determine what is actually heard List <byte> expressionMsbs = new List <byte>() { (byte)65 }; lmcd.MidiChordSliderDefs = new MidiChordSliderDefs(null, null, null, expressionMsbs); lmcd.BasicMidiChordDefs.Add(new BasicMidiChordDef(msDuration, 0, patch, true, pitch, velocity)); lmcd.MsDuration = msDuration; // these two attributes determine the symbols in the score. lmcd.NotatedMidiPitches = new List <byte>() { 67 }; // display middle G, even though "pitch" is different. lmcd.MidiVelocity = velocity[0]; // determines the visible dynamic symbol #endregion momentDef.MidiChordDefs.Add(lmcd); momentMsPos += momentDef.MsWidth; } } }
/// <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); }
private void GetSnores(int firstRestMsDuration, Clytemnestra clytemnestra, TrkDef wind1, Palette snoresPalette) { List <IUniqueDef> snores = new List <IUniqueDef>(); int msPosition = 0; IUniqueDef firstRest = new RestDef(msPosition, firstRestMsDuration); snores.Add(firstRest); msPosition += firstRestMsDuration; #region prelude + verse1 int[] transpositions1 = { 0, 0, 0, 0, 0, 1, 0 }; for (int i = 0; i < 7; ++i) { IUniqueDef snore = snoresPalette.UniqueDurationDef(i); snore.MsPosition = msPosition; msPosition += snore.MsDuration; MidiChordDef iumdd = snore as MidiChordDef; if (iumdd != null) { iumdd.Transpose(transpositions1[i]); iumdd.PitchWheelDeviation = 3; } snores.Add(snore); RestDef rest = new RestDef(msPosition, 2500); msPosition += rest.MsDuration; snores.Add(rest); } #endregion double factor; double msDuration; double restDuration; int[] transpositions2 = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 }; double[] factors = { 0.93, 0.865, 0.804, 0.748, 0.696, 0.647, 0.602, 0.56, 0.52, 0.484 }; for (int i = 0; i < 10; ++i) { IUniqueDef snore = snoresPalette.UniqueDurationDef(i / 2); snore.MsPosition = msPosition; factor = factors[i]; msDuration = snore.MsDuration * factor; snore.MsDuration = (int)msDuration; msPosition += snore.MsDuration; MidiChordDef iumdd = snore as MidiChordDef; if (iumdd != null) { iumdd.Transpose(transpositions2[i]); iumdd.PitchWheelDeviation = 20; } //iumdd.MidiVelocity = (byte)((double)snore.MidiVelocity * factor * factor); snores.Add(snore); restDuration = 2500 / factor; RestDef rest = new RestDef(msPosition, (int)restDuration); msPosition += rest.MsDuration; snores.Add(rest); } snores[snores.Count - 1].MsDuration = clytemnestra.EndMsPosition - snores[snores.Count - 1].MsPosition; this._uniqueDefs = snores; AdjustVelocitiesHairpin(13, Count, 0.25); #region alignments before Interlude3 AlignObjectAtIndex(7, 8, 9, clytemnestra[3].MsPosition); AlignObjectAtIndex(8, 9, 10, clytemnestra[7].MsPosition); AlignObjectAtIndex(9, 10, 11, clytemnestra[16].MsPosition); AlignObjectAtIndex(10, 11, 12, clytemnestra[24].MsPosition); AlignObjectAtIndex(11, 12, 13, clytemnestra[39].MsPosition); AlignObjectAtIndex(12, 13, 14, clytemnestra[42].MsPosition); AlignObjectAtIndex(14, 34, Count, wind1[38].MsPosition); // rest at start of Interlude3 #endregion RemoveScorePitchWheelCommands(0, 13); // pitchwheeldeviation is 20 for R2M }
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); }