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 Measure(KeySignature keySig, TimeSignature timeSig, List <MeasureSegment> contents)
 {
     _keySig  = keySig;
     _timeSig = timeSig;
     Contents = contents;
 }
Beispiel #3
0
        private static Dictionary <string, object> getParameters()
        {
            var parameters = new Dictionary <string, object>();

            bool titleFound = false;

            while (!titleFound)
            {
                Console.WriteLine("Enter a title for your piece:");
                string titleInput = Console.ReadLine();
                if (!String.IsNullOrEmpty(titleInput))
                {
                    parameters.Add("title", titleInput);
                    titleFound = true;
                }
                else
                {
                    Console.WriteLine("Title must contain at least one character.");
                }
            }

            bool numMeasuresFound = false;

            while (!numMeasuresFound)
            {
                Console.WriteLine("Enter the number of measures in your piece:");
                string numMeasuresInput = Console.ReadLine();
                int    numMeasures;
                if (int.TryParse(numMeasuresInput, out numMeasures))
                {
                    if (numMeasures >= 1)
                    {
                        parameters.Add("measures", numMeasures);
                        numMeasuresFound = true;
                    }
                    else
                    {
                        Console.WriteLine("Piece must contain at least one measure.");
                    }
                }
                else
                {
                    Console.WriteLine("Input must be an integer.");
                }
            }

            bool keySigFound = false;

            while (!keySigFound)
            {
                Console.WriteLine("Enter a key signature (e.g., C minor, F# Major, Ab minor, etc):");
                string keySigInput = Console.ReadLine();
                var    newKeySig   = KeySignature.Parse(keySigInput);
                if (newKeySig != null)
                {
                    parameters.Add("key", newKeySig);
                    keySigFound = true;
                }
            }

            bool timeSigFound = false;

            while (!timeSigFound)
            {
                Console.WriteLine("Enter a time signature for your piece (e.g., 2/4, 6/8, etc):");
                string timeSigInput = Console.ReadLine();
                var    newTimeSig   = TimeSignature.Parse(timeSigInput);
                if (newTimeSig != null)
                {
                    parameters.Add("time", newTimeSig);
                    timeSigFound = true;
                }
            }

            return(parameters);
        }