static void Main3(string[] args) { RhythmPatternBase pattern = new RhytmPatternComposite("AAAA", RhythmMaker.CreateRhytmPattern()); int tempo = 60; foreach (var fract in pattern.Notes()) { midiOut.Send(MidiMessage.StartNote(48, 100, 1).RawData); Console.Write(fract + " "); Thread.Sleep(60 * 1000 * fract.p / fract.q / tempo); } }
static public RhythmPatternBase CreateRhytmPattern(int beatsPerMeasure = 3, int minLenght = 15) { HashSet <RhythmPatternBase> patterns = new HashSet <RhythmPatternBase>(); for (int i = 0; i < 5; i++) { patterns.Add(new RhythmPattern(beatsPerMeasure, 2, rand)); } while (true) { string st = RhytmPatternComposite.sts[rand.Next(RhytmPatternComposite.sts.Length)]; RhythmPatternBase pattern1, pattern2; FindTwoOfSameLength(patterns.ToArray(), out pattern1, out pattern2); RhythmPatternBase patternNew = new RhytmPatternComposite(st, pattern1, pattern2); Console.WriteLine($"{st} = {patternNew.MeasuresCount}"); if (patternNew.MeasuresCount >= minLenght) { return(patternNew); } patterns.Add(patternNew); } }