private void Form1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e) { keysDown.Remove(e.KeyCode); //Console.WriteLine(e.KeyCode); int note = keyToMidi(e.KeyCode); endNote(note, 0); //currentDurationValue = 0; // this is not necessary anymore as the decay is based on the previous note // when the note is released we calculate the decay to create the inputs to the rhythm ANNs if (modulesOn) { noteOn = false; decays.Enqueue(1d / ticksCounter); // when note ends add to the recording queue if (ticksCounter != 0) { recordedPitches.Enqueue(note % 12); recordedDurations.Enqueue(MusicEnvironment.ticksToDuration(ticksCounter)); // only hold a specified amount of notes in the recording while (recordedDurations.Count > MAX_AMOUNT) { recordedDurations.Dequeue(); } while (recordedPitches.Count > MAX_AMOUNT) { recordedPitches.Dequeue(); } UpdatePhraseLabels(); } } }
private void calculateOutputs(object sender, EventArgs e) { if (noteOn) { ticksCounter += 1; } if (currentDurationValue == 0 && decays.Count != 0) { decayForNote = decays.Dequeue(); currentDurationValue = 1; } //decay duration value currentDurationValue -= decayForNote; // WARN this decay is calculated from the previous note the human played if (currentDurationValue < 0) { currentDurationValue = 0; } //Console.WriteLine(ticksCounter + "\t" + currentDurationValue); if (modulesOn) { double rhythm1o = rhythm1.calculateOutput(new double[] { currentDurationValue, 0.5 }); double rhythm2o = rhythm2.calculateOutput(new double[] { currentDurationValue, rhythm1o }); int pitch1o = MusicEnvironment.convertToMidiClass(pitch1.calculateOutput(new double[] { currentPitch, 0.5 })); int pitch2o = MusicEnvironment.convertToMidiClass(pitch2.calculateOutput(new double[] { currentPitch, pitch1o })); //if new rhythm value is higher than previous one start new note end end previous note in case there was one //if (module1Duration < rhythm1o && !module1rhythmpeak) if (smoothening1.isPeak(rhythm1o) == 1) { endNote(module1Pitch, 1); startNote(pitch1o + 72, 1); module1Pitch = pitch1o + 72; } module1Duration = rhythm1o; //if (module2Duration < rhythm2o && !module2rhythmpeak) if (smoothening2.isPeak(rhythm1o) == 1) { endNote(module2Pitch, 2); startNote(pitch2o + 48, 2); } module2Duration = rhythm2o; //if under threshold consider note over if (module1Duration < 0.05) { endNote(module1Pitch, 1); } if (module2Duration < 0.05) { endNote(module2Pitch, 2); } } }
public void setNewFitness() { // tell the thread to copy the champion file when it is not writing it evoObject.copyChampionFile(); // set networks to champion of previous fitness initializeNetworks(); // change the fitness target so evolution will take a different direction if (recordedDurations.Count == MAX_AMOUNT) { MusicEnvironment.setTargetPhrase(recordedDurations.ToArray(), recordedPitches.ToArray()); } //UpdateMessage("Changed fitness target."); }