private void scoreScrollViewer_Drop(object sender, DragEventArgs e) { try { Genome gen = e.Data.GetData("Object") as Genome; if (gen != null && !playbackThread.IsBusy) { string str = e.Data.GetData("String") as string; string tempo = str.Substring(str.IndexOf("|") + 1); string ksa = str.Remove(str.IndexOf("|")); Octave[] octaves = e.Data.GetData("MusicNoteLib.Octave[]") as Octave[]; DurationCFugue durCF = (DurationCFugue)(e.Data.GetData("MusicNoteLib.DurationCFugue")); byte[] barIter = e.Data.GetData("byte[]") as byte[]; // If there's an empty bar currently mode-1-selected, replace it with the bar that's being dropped. if (geneticSong != null && selectIndex != -1 && geneticSong.IsEmpty(selectIndex) == true) { FillEmptyBar(gen, ksa, octaves, durCF, barIter, tempo); } // Else, append to the song the bar that's being dropped. else { AddBar(gen, ksa, octaves, durCF, barIter, tempo); } MarkSavedScore(true); } } catch (Exception) { } }
public void AddGenome(string tempo, Genome gen, byte[] octaves, DurationCFugue durCF, byte[] barIter, int pos) { // If the genome represents a non-empty bar, it is to be appended to the song. if (pos == -1) { tempos.Add(Convert.ToInt32(tempo)); songOctaves.Add(octaves); songDurations.Add(durCF); songBarIters.Add(barIter); songGenomes.Add(gen); AddToParts(tempo, gen); } // Else, it is to be inserted in its right place. else { tempos.Insert(pos, Convert.ToInt32(tempo)); songOctaves.Insert(pos, octaves); songDurations.Insert(pos, durCF); songBarIters.Insert(pos, barIter); songGenomes.Insert(pos, gen); part1 = "V0 "; part2 = "V1 "; for (int i = 0; i < songGenomes.Count; i++) { AddToParts(tempos[i].ToString(), songGenomes[i]); } } }
public static double GetRestTopMargin(double restHeight, DurationCFugue duration, byte partIndex) { double res = GetElementTopMargin(F6[partIndex], restHeight, partIndex); switch (duration) { case DurationCFugue.s: res += stepLedgerLine / 2; break; case DurationCFugue.i: res += stepLedgerLine * elemPosFactor; break; case DurationCFugue.q: res += stepLedgerLine / 2 * elemPosFactor; break; case DurationCFugue.h: res = res - stepLedgerLine * elemPosFactor + stepLedgerLine - 1; break; case DurationCFugue.w: res = res - stepLedgerLine * elemPosFactor - 1; break; } return(res); }
/// <summary> /// Loads the information associated with the list of genomes contained in a field opened by the user. /// </summary> /// <param name="genomeList"></param> /// <param name="fieldParams"></param> /// <returns> The list of genomes from a user-opened field.</returns> public List <Genome> OpenFieldGenomes(List <List <string[]> > genomeList, List <string> fieldParams) { byte[] barIterate = { Parameters.barIterate[0], Parameters.barIterate[1] }; byte[] octaves = { Parameters.octavesByteValues[0], Parameters.octavesByteValues[1] }; byte ksIndex = Parameters.keySignatureIndex; DurationCFugue duration = Parameters.Duration; List <Genome> list = new List <Genome>(); byte numParts = Parameters.NumParts; try { Parameters.keySignatureIndex = Convert.ToByte(Controller.StringToEnum <KeySignature>(fieldParams[0] + "Maj")); Parameters.octavesByteValues[0] = Convert.ToByte(Controller.StringToEnum <Octave>(fieldParams[2])); Parameters.octavesByteValues[1] = Convert.ToByte(Controller.StringToEnum <Octave>(fieldParams[3])); Parameters.barIterate[0] = Convert.ToByte(fieldParams[4]); Parameters.barIterate[1] = Convert.ToByte(fieldParams[5]); Parameters.Duration = Controller.StringToEnum <DurationCFugue>(fieldParams[6]); int k; foreach (List <string[]> x in genomeList) { k = 0; Genome g = new Genome(); for (int i = 0; i < numParts; i++) { g.rhythmChromosome.Add(x[0 + k]); int[] array = new int[16]; for (int j = 0; j < x[1 + k].Length; j++) { array[j] = Convert.ToInt32(x[1 + k][j]); } g.pitchChromosome.Add(array); byte[] array1 = new byte[16]; for (int j = 0; j < x[2 + k].Length; j++) { array1[j] = Convert.ToByte(x[2 + k][j]); } g.velocityChromosome.Add(array1); k += 3; } g.GenotypeDecode(); list.Add(g); } } catch (Exception) { throw new Exception("The file you're trying to open is corrupted."); } Parameters.barIterate[0] = barIterate[0]; Parameters.barIterate[1] = barIterate[1]; Parameters.octavesByteValues[0] = octaves[0]; Parameters.octavesByteValues[1] = octaves[1]; Parameters.keySignatureIndex = ksIndex; Parameters.Duration = duration; return(list); }
private void DrawRestForEachPart(string cFugueDuration, bool hasDot) { DurationCFugue cFugueFinalDur = LayoutController.StringToEnum <DurationCFugue>(cFugueDuration); // First part score. DrawRest(cFugueFinalDur, hasDot, 0); // Second part score. DrawRest(cFugueFinalDur, hasDot, 1); }
/// <summary> /// Extracts the CFugue (as data type) duration given the specified CFugue duration string for each note in tie. /// </summary> /// <param name="cFugueDuration"></param> /// <returns></returns> private DurationCFugue[] GetCFugueDurationsInTie(string cFugueDurationNote1, string cFugueDurationNote2) { DurationCFugue[] cFugueDurationResult = new DurationCFugue[2]; cFugueDurationResult[0] = LayoutController.StringToEnum <DurationCFugue>(cFugueDurationNote1); cFugueDurationResult[1] = LayoutController.StringToEnum <DurationCFugue>(cFugueDurationNote2); return(cFugueDurationResult); }
/// <summary> /// Draws extra ledger line(s) when the specified note falls above/below the staff. /// </summary> /// <param name="notePos"></param> /// <param name="note"></param> /// <param name="octave"></param> /// <param name="duration"></param> /// <param name="noteLeft"></param> /// <param name="partIndex"></param> private void DrawExtraLedgerLines(double notePos, Note note, Octave octave, DurationCFugue duration, double noteLeftMargin, int verticalOffset, byte partIndex) { double x1 = noteLeftMargin - 4; double x2 = noteLeftMargin + LayoutController.ElementWidth["N" + duration]; double y = notePos + verticalOffset * LayoutController.stepLedgerLine / 2; DrawLine(x1, x2, y, partIndex); Clef clef = Parameters.Clefs[partIndex]; // Now add the extra lines. if (octave == Octave.Octave3 && note == Note.C) { y = LayoutController.GetNotePos(Note.E, Octave.Octave3, clef, partIndex); DrawLine(x1, x2, y, partIndex); } else if (octave == Octave.Octave7) { if (note == Note.C || note == Note.D) { y = LayoutController.GetNotePos(Note.A, Octave.Octave6, clef, partIndex); DrawLine(x1, x2, y, partIndex); } else if (note == Note.E || note == Note.F) { y = LayoutController.GetNotePos(Note.A, Octave.Octave6, clef, partIndex); DrawLine(x1, x2, y, partIndex); y = LayoutController.GetNotePos(Note.C, Octave.Octave7, clef, partIndex); DrawLine(x1, x2, y, partIndex); } else if (note == Note.G || note == Note.A) { y = LayoutController.GetNotePos(Note.A, Octave.Octave6, clef, partIndex); DrawLine(x1, x2, y, partIndex); y = LayoutController.GetNotePos(Note.C, Octave.Octave7, clef, partIndex); DrawLine(x1, x2, y, partIndex); y = LayoutController.GetNotePos(Note.E, Octave.Octave7, clef, partIndex); DrawLine(x1, x2, y, partIndex); } else { y = LayoutController.GetNotePos(Note.A, Octave.Octave6, clef, partIndex); DrawLine(x1, x2, y, partIndex); y = LayoutController.GetNotePos(Note.C, Octave.Octave7, clef, partIndex); DrawLine(x1, x2, y, partIndex); y = LayoutController.GetNotePos(Note.E, Octave.Octave7, clef, partIndex); DrawLine(x1, x2, y, partIndex); y = LayoutController.GetNotePos(Note.G, Octave.Octave7, clef, partIndex); DrawLine(x1, x2, y, partIndex); } } }
/// <summary> /// Returns an image resource that is used to represent a specific rest duration. /// </summary> /// <param name="Duration"></param> /// <param name="Dot"></param> /// <returns></returns> public static BitmapImage GetRest(DurationCFugue Duration, bool Dot) { var result = from imageSource in RestVisuals where (imageSource.Duration == Duration) && (imageSource.Dot == Dot) select imageSource.Output; BitmapImage bmp = new BitmapImage(); bmp.BeginInit(); bmp.UriSource = result.First <Uri>(); bmp.EndInit(); return(bmp); }
public void FillEmptyBar(string tempo, Genome gen, byte[] octaves, DurationCFugue durCF, byte[] barIter, int pos) { tempos[pos] = Convert.ToInt32(tempo); songOctaves[pos] = octaves; songDurations[pos] = durCF; songBarIters[pos] = barIter; songGenomes[pos] = gen; part1 = "V0 "; part2 = "V1 "; for (int i = 0; i < songGenomes.Count; i++) { AddToParts(tempos[i].ToString(), songGenomes[i]); } }
private void DrawRest(DurationCFugue duration, bool dot, byte partIndex) { Image image = new Image(); image.HorizontalAlignment = HorizontalAlignment.Left; image.Source = LayoutController.GetRest(duration, dot); image.Height = LayoutController.ElementHeight["R" + duration]; double top = LayoutController.GetRestTopMargin(image.Height, duration, partIndex); image.Margin = new Thickness(leftMargin, top, 0, 0); staffGrid.Children.Add(image); Grid.SetRow(image, partIndex); }
private void AddBar(Genome genome, string ksa, Octave[] octaves, DurationCFugue durCF, byte[] barIter, string tempo) { if (barCount == 0) { keySignature = ksa; Clefs[0] = Scales.GetClef(octaves[0]); Clefs[1] = Scales.GetClef(octaves[1]); Tempo = ""; geneticSong = new GeneticSong(keySignature); } if (keySignature == ksa) { byte[] oct = { (byte)octaves[0], (byte)octaves[1] }; int barPosition = GetBarPosition(); geneticSong.AddGenome(tempo, genome, oct, durCF, barIter, barPosition); if (pause == true) { addBarOnPause = true; } // If the new bar is the first one in the next row. if (barCount % individPerRow == 0) { StartNewRow(ksa); } ScoreStaffs ss = CreateScoreStaffsBar(genome, tempo, barPosition); if (addEmptyBar == false) { scores.Add(ss); scoreWrapPanel.Children.Add(ss); } else { AddBlankBar(ss, barPosition); } barCount++; addEmptyBar = false; Tempo = tempo; } else { MessageBox.Show("Key signatures must match!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void FillEmptyBar(Genome gen, string keysignature, Octave[] octaves, DurationCFugue durCF, byte[] barIter, string tempo) { ScoreStaffs ss; int ind = scoreWrapPanel.Children.IndexOf(scores[startIndex]); ss = ((ScoreStaffs)scoreWrapPanel.Children[ind]); ss.staffGrid.Children.RemoveRange(ss.staffGrid.Children.Count - 7, 7); ss.setContent(gen); ss.AddTempoInfo(tempo); ss.AddIndexTag(startIndex + 1); byte[] oct = { (byte)octaves[0], (byte)octaves[1] }; geneticSong.FillEmptyBar(tempo, gen, oct, durCF, barIter, startIndex); }
private void DrawNoteForEachPart(string noteWordPart0, string noteWordPart1, bool hasDot, string cFugueFinalDuration) { Octave[] actualOctave = GetActualOctaves(noteWordPart0, noteWordPart1); string[] note = GetNotes(noteWordPart0, noteWordPart1); // A clean note is a note without accidentals. Note[] cleanNote = GetCleanNotes(note, actualOctave); char[] orientation = GetOrientations(cleanNote, actualOctave); string[] hasAcc = GetAccidentals(note[0], note[1]); DurationCFugue cFugueDuration = LayoutController.StringToEnum <DurationCFugue>(cFugueFinalDuration); // First part score. DrawNote(cleanNote[0], cFugueDuration, hasDot, actualOctave, orientation[0], hasAcc[0], false, 0); // Second part score. DrawNote(cleanNote[1], cFugueDuration, hasDot, actualOctave, orientation[1], hasAcc[1], false, 1); }
private void AddEmptyBar_Click(object sender, RoutedEventArgs e) { try { if (!playbackThread.IsBusy) { addEmptyBar = true; Genome gen = new Genome(0); Octave[] octaves = { Octave.Octave5, Octave.Octave5 }; DurationCFugue dur = DurationCFugue.s; byte[] iter = { 1, 1 }; string tempo = "120"; AddBar(gen, keySignature, octaves, dur, iter, tempo); MarkSavedScore(true); } } catch (Exception) { } }
private void DrawNote(Note note, DurationCFugue duration, bool dot, Octave[] actOctave, char orientation, string hasAcc, bool hasTie, byte partIndex) { double height = LayoutController.ElementHeight["N" + duration]; Octave actualOctave = actOctave[partIndex]; double notePos = LayoutController.GetNotePos(note, actualOctave, Parameters.Clefs[partIndex], partIndex); double top = LayoutController.GetNoteTopMargin(notePos, height, orientation, partIndex); double noteLeftMargin = leftMargin; if (hasAcc != "") { DrawAccidental(notePos, hasAcc, orientation, partIndex); noteLeftMargin += LayoutController.accidentalOffset; } if (hasTie) { double notePosOffset = notePos + LayoutController.GetTieOffset(note, actualOctave, partIndex); DrawTie(layoutInterval + 2 * unitElementWidth, noteLeftMargin - layoutInterval - unitElementWidth, notePosOffset, orientation, partIndex); } Image image = new Image(); image.HorizontalAlignment = HorizontalAlignment.Left; image.Source = LayoutController.GetNote(duration, dot, orientation); image.Height = height; image.Margin = new Thickness(noteLeftMargin, top, 0, 0); staffGrid.Children.Add(image); Grid.SetRow(image, partIndex); string has = LayoutController.HasLine(note, actualOctave); if (has != "") { DrawExtraLedgerLines(notePos, note, actualOctave, duration, noteLeftMargin, Convert.ToInt32(has), partIndex); } }