Exemplo n.º 1
0
        public Melody GenerateMajChords(IEnumerable <NoteKey> possibleNotes, int noteCount)
        {
            var random = new Random();
            var notes  = possibleNotes.ToArray();

            var result = new []
            {
                new List <Note>(),
                new List <Note>(),
                new List <Note>()
            };

            for (int i = 0; i < noteCount; i++)
            {
                var key   = notes[random.Next(notes.Length)];
                var chord = Chord.Maj(key);
                Console.WriteLine(string.Join(", ", chord.Keys.Select(k => k.ToString())));
                var duration = durationGenerator.GetNext();
                var j        = 0;
                foreach (var chordKey in chord.Keys)
                {
                    var frequency = NoteFrequencies.Get(chordKey);

                    var note = new Note(frequency, duration);

                    result[j].Add(note);
                    j++;
                }
            }

            return(new Melody(result.Select(r => r.ToArray()).ToArray()));
        }
Exemplo n.º 2
0
        public Melody Generate(IEnumerable <NoteKey> possibleNotes, int noteCount)
        {
            var random = new Random();
            var notes  = possibleNotes.ToArray();

            var result = new List <Note>();

            for (int i = 0; i < noteCount; i++)
            {
                var key       = notes[random.Next(notes.Length)];
                var frequency = NoteFrequencies.Get(key);
                var duration  = durationGenerator.GetNext();

                var note = new Note(frequency, duration);

                result.Add(note);
            }

            return(new Melody(new [] { result.ToArray() }));
        }
Exemplo n.º 3
0
 public Melody(Chord chord) : this(
         chord.Keys.Select(k => new[] { new Note(NoteFrequencies.Get(k), NoteDuration.Whole) }))
 {
 }