private ArrayList GenerateRandomPattern(int Difficulty, int Length) { //TODO Start at a random MIDI Note Number and do random walk. //Therefore Note would have to be translated in terms of number of keys by doing a Mod operation on the number of keys //Also Octave would have to slide as a sliding window according to when notes reach the edge of the octave when next note goes into next octave ArrayList NewPattern = new ArrayList(); PatternUnit TempPatternUnit; Random RandNote = new Random(); Random RandDuration = new Random(); int TempNote = -1, MinNote, MaxNote; for (int index = 0; index < Length; index++) { do { if (NewPattern.Count == 0) { TempNote = RandNote.Next(26); } MinNote = TempNote; MaxNote = TempNote; if (MinNote - Difficulty < -1) { MinNote = -1; } else { MinNote -= Difficulty; } if (MaxNote + Difficulty > 26) { MaxNote = 26; } else { MaxNote += Difficulty; } TempNote = RandNote.Next(MinNote, MaxNote); } //while (UnusedKeys.Contains(TempNote)); while (UnusedKeys.Contains(TempNote) || ((TempNote > 9 && TempNote < 13) || (TempNote > 22 && TempNote < 26))) ; //COMMENT OUT ON REAL USE ON SURFACE TempPatternUnit = new PatternUnit(TempNote, (int) Math.Pow(2.0, RandDuration.Next(1, 5))); NewPattern.Add(TempPatternUnit); Console.Write("N:{0}, D:{1} : ", TempPatternUnit.Note, TempPatternUnit.Duration); } Console.WriteLine(); PatternMetrics.Add(new PatternMetric()); ((PatternMetric)PatternMetrics[PatternMetrics.Count - 1]).PatternDifficulty = Difficulty; ((PatternMetric)PatternMetrics[PatternMetrics.Count - 1]).PatternTimePlayed = DateTime.Now; return NewPattern; }
private void HandleTimerElapsedEvent(Object Source, ElapsedEventArgs e) { //What happens when AppTimer's Elapsed Event Fire if (CurrentDuration == 0) { if (CurrentNoteIndex == Pattern.Count - 1) { ((PatternUnit)Pattern[CurrentNoteIndex]).MadeErrors = MadeErrorOnLastNote; ((PatternUnit)Pattern[CurrentNoteIndex]).NoOfErrors = NoOfErrorsOnLastNote; ((PatternUnit)Pattern[CurrentNoteIndex]).IsLate = (((PatternUnit)Pattern[CurrentNoteIndex]).ActualTime - ((PatternUnit)Pattern[CurrentNoteIndex]).CorrectTime) > LatenessThreshold; AppTimer.Enabled = false; HideVisualCue(); CalculateAccuracy(); if (DemoMode) { PatternMetrics.RemoveAt(PatternMetrics.Count - 1); DemoMode = false; if (TestMode) { StartTest(); } } else { TestMode = false; ShowTestResults(); } Console.WriteLine("Test Done : " + e.SignalTime.Minute + ":" + e.SignalTime.Second + ":" + e.SignalTime.Millisecond); return; } CurrentNoteIndex++; ((PatternUnit)Pattern[CurrentNoteIndex]).CorrectTime = DateTime.Now; if (CurrentNoteIndex > 0) { ((PatternUnit)Pattern[CurrentNoteIndex - 1]).MadeErrors = MadeErrorOnLastNote; ((PatternUnit)Pattern[CurrentNoteIndex - 1]).NoOfErrors = NoOfErrorsOnLastNote; ((PatternUnit)Pattern[CurrentNoteIndex - 1]).IsLate = (((PatternUnit)Pattern[CurrentNoteIndex - 1]).ActualTime - ((PatternUnit)Pattern[CurrentNoteIndex - 1]).CorrectTime) > LatenessThreshold; } MadeErrorOnLastNote = false; NoOfErrorsOnLastNote = 0; CurrentPatternUnit = new PatternUnit((PatternUnit)Pattern[CurrentNoteIndex]); CurrentNote = CurrentPatternUnit.Note; CurrentDuration = CurrentPatternUnit.Duration; IsPlayed = false; Console.WriteLine("CDur == 0 : CN++, Cnot, Cdur, IP = F, HiVisCu : " + e.SignalTime.Minute + ":" + e.SignalTime.Second + ":" + e.SignalTime.Millisecond); HideVisualCue(); if (CurrentNote >= 0) //Rests Should Not Trigger Visual Cue { Console.WriteLine("CNot >= 0 : ShVisCu : " + e.SignalTime.Minute + ":" + e.SignalTime.Second + ":" + e.SignalTime.Millisecond); ShowVisualCue(Buttons[CurrentNote]); } } else if (CurrentNoteIndex < 0) { Console.WriteLine("CNI < 0 : CDur = 0 : " + e.SignalTime.Minute + ":" + e.SignalTime.Second + ":" + e.SignalTime.Millisecond); CurrentDuration = 0; } else if (DemoMode) { CurrentDuration--; } else if (IsPlayed && EIdx >= 0) { ((PatternUnit)Pattern[CurrentNoteIndex]).ActualTime = LastPlayedTime; Console.WriteLine("IP == T & EIdx >=0 : CDur-- : " + e.SignalTime.Minute + ":" + e.SignalTime.Second + ":" + e.SignalTime.Millisecond); CurrentDuration--; } else if (IsPlayed) { Console.WriteLine("IP : CDur--" + e.SignalTime.Minute + ":" + e.SignalTime.Second + ":" + e.SignalTime.Millisecond); CurrentDuration--; } else if (!IsPlayed && CurrentNote == -1) { Console.WriteLine("!IP & CNot ==-1 : CDur--" + e.SignalTime.Minute + ":" + e.SignalTime.Second + ":" + e.SignalTime.Millisecond); CurrentDuration--; } else { Console.WriteLine("Else... ??? : " + e.SignalTime.Minute + ":" + e.SignalTime.Second + ":" + e.SignalTime.Millisecond); } }
public PatternUnit(PatternUnit PattrnUnit) { this.Note = PattrnUnit.Note; this.Duration = PattrnUnit.Duration; }
private ArrayList ReadPatternFromFile(string FileName) { ArrayList ReadPattern = new ArrayList(); PatternUnit TempPatternUnit; FileStream fs = new FileStream(FileName, FileMode.Open); StreamReader sr = new StreamReader(fs); string TempString; while((TempString = sr.ReadLine()).IndexOf("//") != -1) { } Tempo = Int32.Parse(TempString); while ((TempString = sr.ReadLine()).IndexOf("//") != -1) { } KeyMidiNote = Int32.Parse(TempString); while ((TempString = sr.ReadLine()).IndexOf("//") != -1) { } PatternMetrics.Add(new PatternMetric()); ((PatternMetric)PatternMetrics[PatternMetrics.Count - 1]).PatternDifficulty = Int32.Parse(TempString); ((PatternMetric)PatternMetrics[PatternMetrics.Count - 1]).PatternTimePlayed = DateTime.Now; string line = ""; while ((line = sr.ReadLine()) != null) { if (line.IndexOf("//") != -1) { continue; } string[] Pieces = line.Split(':'); int note = int.Parse(Pieces[0]); //MIDI Note Number note -= KeyMidiNote; if (note < 0) { note = -1; } else if (note > NoOfKeys) { note = NoOfKeys - 1; } int duration = int.Parse(Pieces[1]); TempPatternUnit = new PatternUnit(note, duration); ReadPattern.Add(TempPatternUnit); } sr.Close(); fs.Close(); Quarter = 1000.0 / (Tempo / 60); Half = 2 * Quarter; Whole = 2 * Half; Eighth = Quarter / 2; Sixteenth = Eighth / 2; ThirtySecondth = Sixteenth / 2; return ReadPattern; }