コード例 #1
0
        private async Task startWordExposition() // starts colored words exposition - classic Stroop
        {
            cts = new CancellationTokenSource();
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                await Task.Delay(currentTest.ProgramInUse.IntervalTime, cts.Token); // first interval before exposition begins

                if (currentTest.ProgramInUse.AudioCapture)
                {
                    startRecordingAudio();
                }

                // exposition loop
                for (int counter = 1; counter <= currentTest.ProgramInUse.NumExpositions && runExposition; counter++)
                {
                    subtitleLabel.Visible = false;
                    wordLabel.Visible     = false;
                    await intervalOrFixPoint(currentTest.ProgramInUse, cts.Token);

                    drawWord();

                    wordLabel.Text      = currentStimulus;
                    wordLabel.ForeColor = ColorTranslator.FromHtml(currentColor);

                    elapsedTime = stopwatch.ElapsedMilliseconds;    // grava tempo decorrido
                    SendKeys.SendWait(currentTest.Mark.ToString()); //sending event to neuronspectrum

                    showSubtitle();

                    wordLabel.Visible = true;

                    currentTest.writeLineOutputResult(currentStimulus, currentColor, counter,
                                                      outputContent, elapsedTime, currentAudio
                                                      );

                    await Task.Delay(currentTest.ProgramInUse.ExpositionTime, cts.Token);
                }

                if (currentTest.ProgramInUse.AudioCapture)
                {
                    stopRecordingAudio();
                }
            }
            catch (TaskCanceledException)
            {
                if (currentTest.ProgramInUse.AudioCapture)
                {
                    stopRecordingAudio();
                }
                finishExposition();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        private async Task startWordExposition() // starts colored words exposition - classic Stroop
        {
            cts = new CancellationTokenSource();
            try
            {
                response_label.ForeColor = Color.Black;
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                await Task.Delay(currentTest.ProgramInUse.IntervalTime, cts.Token); // first interval before exposition begins

                //Write to file to indicate beginning of task
                FormMain.writer.WriteLine(FormMain.GetTimestamp(DateTime.UtcNow) + ",0,0,0,0");

                // exposition loop
                for (int counter = 1; counter <= currentTest.ProgramInUse.NumExpositions && runExposition; counter++)
                {
                    button_clicked = false;
                    //response_label.Visible = false;
                    // new cancellation token for skipping this word after button clicked
                    cts = new CancellationTokenSource();
                    subtitleLabel.Visible = false;
                    wordLabel.Visible     = false;
                    //await intervalOrFixPoint(currentTest.ProgramInUse, cts.Token);

                    drawWord();
                    button1.Visible = true;
                    button2.Visible = true;

                    wordLabel.Text      = currentStimulus;
                    wordLabel.ForeColor = ColorTranslator.FromHtml(currentColor);
                    elapsedTime         = stopwatch.ElapsedMilliseconds; // Writes elapsed time

                    /*
                     * // quit after 3 minutes
                     * if (elapsedTime > 180000) {
                     *  FormMain.writer.WriteLine(FormMain.GetTimestamp(DateTime.UtcNow) + ",0,0,0,0");
                     *  throw new TaskCanceledException();
                     * }
                     */

                    SendKeys.SendWait(currentTest.Mark.ToString()); //sending event to neuronspectrum
                    showSubtitle();
                    wordLabel.Visible = true;
                    currentTest.writeLineOutputResult(currentStimulus, currentColor, counter,
                                                      outputContent, elapsedTime, currentAudio, score
                                                      );

                    try
                    {
                        await Task.Delay(currentTest.ProgramInUse.ExpositionTime, cts.Token);

                        // Response label = "Missed" if no keys were pressed
                        if (button_clicked == false)
                        {
                            response = false;
                            changeResponseLabelColor(response);
                            response_label.Text = "Missed";
                        }
                    }
                    catch (TaskCanceledException e) {
                        FormMain.writer.WriteLine(FormMain.GetTimestamp(DateTime.UtcNow) + ",0,0,0,0");
                        button_clicked = false;
                        continue;
                    }
                }
            }
            catch (TaskCanceledException)
            {
                finishExposition();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #3
0
        private async Task startWordExposition() // starts colored words exposition - classic Stroop
        {
            cts = new CancellationTokenSource();
            string        audioDetail = "false";
            int           textArrayCounter = 0, colorArrayCounter = 0, audioCounter = 0, subtitleCounter = 0;
            List <string> outputContent = new List <string>();


            try
            {
                // reading list files
                // string array receives lists itens from lists file
                string[] labelText  = currentTest.ProgramInUse.getWordListFile().ListContent.ToArray();
                string[] labelColor = currentTest.ProgramInUse.getColorListFile().ListContent.ToArray();

                string[] subtitlesArray = configureSubtitle();
                string[] audioDirs      = null;
                if (currentTest.ProgramInUse.getAudioListFile() != null) // if there is an audioFile to be played, string array receives audioList itens from list file
                {
                    audioDirs = currentTest.ProgramInUse.getAudioListFile().ListContent.ToArray();
                }

                if (currentTest.ProgramInUse.ExpositionRandom) // if the presentation is random, shuffles arrays
                {
                    labelText  = ExpositionController.ShuffleArray(labelText, currentTest.ProgramInUse.NumExpositions, 1);
                    labelColor = ExpositionController.ShuffleArray(labelColor, currentTest.ProgramInUse.NumExpositions, 5);
                    if (audioDirs != null)
                    {
                        audioDirs = ExpositionController.ShuffleArray(audioDirs, currentTest.ProgramInUse.NumExpositions, 6);
                    }
                }


                if (!Validations.allHexPattern(labelColor))
                {
                    throw new Exception("A lista de cores '" + currentTest.ProgramInUse.getColorListFile().ListName + "' contém valores inválidos!\n A lista de" +
                                        "cores deve conter apenas valores hexadecimais (ex: #000000)");
                }

                // presenting test instructions:
                await showInstructions(currentTest.ProgramInUse, cts.Token);

                textArrayCounter  = 0;       // counters to zero
                colorArrayCounter = 0;
                elapsedTime       = 0;       // elapsed time to zero
                subtitleCounter   = 0;
                changeBackgroundColor(true); // changes background color, if there is one defined
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                await Task.Delay(currentTest.ProgramInUse.IntervalTime, cts.Token); // first interval before exposition begins

                if (currentTest.ProgramInUse.AudioCapture && currentTest.ProgramInUse.ExpositionType != "txtaud")
                {
                    startRecordingAudio();
                }

                // exposition loop
                for (int counter = 1; counter <= currentTest.ProgramInUse.NumExpositions && runExposition; counter++)
                {
                    subtitleLabel.Visible = false;
                    wordLabel.Visible     = false;
                    await intervalOrFixPoint(currentTest.ProgramInUse, cts.Token);

                    string textCurrent  = labelText[textArrayCounter];
                    string colorCurrent = labelColor[colorArrayCounter];

                    if (textArrayCounter == labelText.Count() - 1)
                    {
                        textArrayCounter = 0;
                    }
                    else
                    {
                        textArrayCounter++;
                    }

                    if (colorArrayCounter == labelColor.Count() - 1)
                    {
                        colorArrayCounter = 0;
                    }
                    else
                    {
                        colorArrayCounter++;
                    }

                    wordLabel.Text      = textCurrent;
                    wordLabel.ForeColor = ColorTranslator.FromHtml(colorCurrent);

                    if (currentTest.ProgramInUse.getAudioListFile() != null &&
                        currentTest.ProgramInUse.ExpositionType == "txtaud") // reproduz audio
                    {
                        if (audioCounter == audioDirs.Length)
                        {
                            audioCounter = 0;
                        }
                        else
                        {
                            /* do nothing */
                        }
                        audioDetail          = audioDirs[audioCounter];
                        Player.SoundLocation = audioDetail;
                        audioCounter++;
                        Player.Play();
                    }
                    else
                    {
                        /* do nothing */
                    }

                    elapsedTime = stopwatch.ElapsedMilliseconds;    // grava tempo decorrido
                    SendKeys.SendWait(currentTest.Mark.ToString()); //sending event to neuronspectrum

                    if (currentTest.ProgramInUse.SubtitleShow)
                    {
                        subtitleCounter = showSubtitle(subtitleCounter, subtitlesArray);
                    }
                    wordLabel.Visible = true;

                    currentTest.writeLineOutputResult(currentTest.ProgramInUse, textCurrent, colorCurrent, counter,
                                                      outputContent, elapsedTime, currentTest.ProgramInUse.ExpositionType, audioDetail
                                                      );

                    await Task.Delay(currentTest.ProgramInUse.ExpositionTime, cts.Token);
                }
                wordLabel.Visible     = false;
                subtitleLabel.Visible = false;
                await Task.Delay(currentTest.ProgramInUse.IntervalTime, cts.Token);

                // beginAudio
                if (currentTest.ProgramInUse.AudioCapture && currentTest.ProgramInUse.ExpositionType != "txtaud" && currentTest.ProgramInUse.ExpositionType != "imgaud")
                {
                    stopRecordingAudio();
                }
                // endAudio
                changeBackgroundColor(false); // retorna à cor de fundo padrão

                StroopProgram.writeOutputFile(outputFile, string.Join("\n", outputContent.ToArray()));
                this.DialogResult = DialogResult.OK;
                Close(); // finaliza exposição após execução
            }
            catch (TaskCanceledException)
            {
                StroopProgram.writeOutputFile(outputFile, string.Join("\n", outputContent.ToArray()));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            cts = null;
        }