public Measure(KeySignature keySig, TimeSignature timeSig) { _keySig = keySig; _timeSig = timeSig; Contents = new List <MeasureSegment>(); while (CurrentLength < MeasureLength) { var newAddition = new MeasureSegment(); if (_random.NextDouble() < .8) { newAddition = new Note(_keySig); } else { newAddition = new Rest(); } if (newAddition.Duration + CurrentLength <= MeasureLength) { Contents.Add(newAddition); } } }
public static Piece GenerateManually() { Dictionary <string, object> parameters = getParameters(); Console.Clear(); var numMeasures = (int)parameters["measures"]; var measures = new List <Measure>(); int currentMeasureNum = 0; int cursorPosition = 7; bool measureDeleted = false; bool showInstructions = true; bool showDescription = false; bool stillEditing = true; Piece tempPiece = new Piece((string)parameters["title"], currentMeasureNum, (KeySignature)parameters["key"], (TimeSignature)parameters["time"], measures); while (currentMeasureNum < numMeasures && stillEditing) { // Recreate piece each time a measure is added or deleted: tempPiece = new Piece((string)parameters["title"], currentMeasureNum, (KeySignature)parameters["key"], (TimeSignature)parameters["time"], measures); // If measure was deleted, do not add a new measure (instead revisit previous measure): if (measureDeleted == false) { tempPiece.Measures.Add(new Measure(tempPiece.KeySig, tempPiece.TimeSig, new List <MeasureSegment>())); } // Create reference of current measure: var tempMeasure = tempPiece.Measures[currentMeasureNum]; // Reset measure deleted bool: measureDeleted = false; while (tempMeasure.CurrentLength < tempMeasure.MeasureLength && !measureDeleted && stillEditing) { if (showDescription) { tempPiece.PrintInfo(); tempPiece.ListNotes(); } var printer = new StaffPrinter(tempPiece); printer.Print(cursorPosition); printInstructions(showInstructions); var editInput = Console.ReadKey(); // Up and down arrows move cursor so that a different line is selected: if (editInput.Key == ConsoleKey.UpArrow) { cursorPosition -= 1; } else if (editInput.Key == ConsoleKey.DownArrow) { cursorPosition += 1; } else if (editInput.Key == ConsoleKey.Enter) { tempMeasure.Append(cursorPosition); } else if (editInput.Key == ConsoleKey.Backspace) { if (tempMeasure.Contents.Count > 0) { tempMeasure.Unappend(); } // If this is empty and it is the first measure, warn user: else if (currentMeasureNum == 0) { Console.WriteLine("There is nothing left to delete!"); Console.ReadKey(); } // If this is empty and it is NOT the first measure, unappend from previous, // delete this measure, and change current measure number to previous: else { tempPiece.Measures.RemoveAt(tempPiece.Measures.Count - 1); tempPiece.Measures[currentMeasureNum - 1].Unappend(); // subtract two, because current measure number will be incremented at end of loop: currentMeasureNum -= 2; measureDeleted = true; } } else if (editInput.Key == ConsoleKey.I) { showInstructions = !showInstructions; } else if (editInput.Key == ConsoleKey.D) { showDescription = !showDescription; } else if (editInput.Key == ConsoleKey.L) { MeasureSegment.ShowStaffSymbolLegend(); } else if (editInput.Key == ConsoleKey.S) { if (tempPiece.SaveToJson()) { stillEditing = false; } } else if (editInput.Key == ConsoleKey.Escape) { tempPiece.SavePrompt(); stillEditing = false; } Console.Clear(); } currentMeasureNum++; } return(tempPiece); }