Esempio n. 1
0
        private async Task startImageExposition() // inicia exposição de imagem
        {
            cts = new CancellationTokenSource();
            int j, subtitleCounter = 0;
            int arrayCounter = 0;

            string[] labelText       = null, imageDirs = null, audioDirs = null, subtitlesArray = null;
            string   actualImagePath = "";
            string   audioDetail     = "false";

            try
            {
                BackColor           = Color.White;
                wordLabel.ForeColor = Color.Red;


                if (programInUse.ExpandImage)
                {
                    imgPictureBox.Dock = DockStyle.Fill;
                }
                else
                {
                    imgPictureBox.Dock = DockStyle.None;
                }

                imageDirs = StroopProgram.readDirListFile(path + "/lst/" + programInUse.ImagesListFile); // auxiliar recebe o vetor original
                if (programInUse.ExpositionRandom)                                                       // se exposição aleatória, randomiza itens de acordo com o numero de estimulos
                {
                    imageDirs = ExpositionController.shuffleArray(imageDirs, programInUse.NumExpositions, 3);
                }

                subtitlesArray = configureSubtitle();


                if (programInUse.AudioListFile != "false")
                {
                    audioDirs = StroopProgram.readDirListFile(path + "/lst/" + programInUse.AudioListFile);
                    if (programInUse.ExpositionRandom)
                    {
                        audioDirs = ExpositionController.shuffleArray(audioDirs, programInUse.NumExpositions, 6);
                    }
                }
                if (programInUse.WordsListFile.ToLower() != "false")
                {
                    labelText = StrList.readListFile(path + "/lst/" + programInUse.WordsListFile);
                }

                await showInstructions(programInUse, cts.Token); // Apresenta instruções se houver

                outputContent = new List <string>();

                while (true)
                {
                    changeBackgroundColor(programInUse, true); // muda cor de fundo se houver parametro
                    imgPictureBox.BackColor = BackColor;

                    elapsedTime  = 0; // zera tempo em milissegundos decorrido
                    j            = 0; subtitleCounter = 0;
                    arrayCounter = 0;
                    var       audioCounter = 0;
                    Stopwatch stopwatch    = new Stopwatch();
                    stopwatch.Start();
                    await Task.Delay(programInUse.IntervalTime, cts.Token);

                    string printCount = "";
                    // beginAudio
                    if (programInUse.AudioCapture)
                    {
                        startRecordingAudio();
                    }                                                         // inicia gravação áudio
                    // endAudio

                    if (programInUse.ExpositionType == "imgtxt")
                    {
                        for (int counter = 0; counter < programInUse.NumExpositions; counter++) // AQUI ver estimulo -> palavra ou imagem como um só e ter intervalo separado
                        {
                            if (counter < 10)                                                   // contador p/ arquivo de audio
                            {
                                printCount = "0" + counter.ToString();
                            }
                            else
                            {
                                printCount = counter.ToString();
                            }


                            imgPictureBox.Visible = false;
                            wordLabel.Visible     = false;
                            subtitleLabel.Visible = false;
                            await intervalOrFixPoint(programInUse, cts.Token);

                            if (arrayCounter == imageDirs.Count())
                            {
                                arrayCounter = 0;
                            }
                            if (programInUse.RotateImage != 0)
                            {
                                imgPictureBox.Image = RotateImage(imageDirs[arrayCounter], programInUse.RotateImage);
                            }
                            else
                            {
                                imgPictureBox.Image = Image.FromFile(imageDirs[arrayCounter]);
                            }

                            elapsedTime = stopwatch.ElapsedMilliseconds; // grava tempo decorrido
                            SendKeys.SendWait("=");
                            imgPictureBox.Visible = true;
                            if (programInUse.SubtitleShow)
                            {
                                subtitleCounter = showSubtitle(subtitleCounter, subtitlesArray);
                            }
                            wordLabel.Visible = false;
                            actualImagePath   = Path.GetFileName(imageDirs[arrayCounter].ToString());
                            arrayCounter++;


                            StroopProgram.writeLineOutput(programInUse, actualImagePath, "false", counter + 1, outputContent, elapsedTime, "img", audioDetail);

                            await Task.Delay(programInUse.ExpositionTime, cts.Token);

                            imgPictureBox.Visible = false;
                            wordLabel.Visible     = false;

                            await Task.Delay(programInUse.DelayTime, cts.Token);

                            if (programInUse.WordsListFile.ToLower() != "false") // se tiver palavras intercala elas com a imagem
                            {
                                if (j == labelText.Count() - 1)
                                {
                                    j = 0;
                                }
                                wordLabel.Text = labelText[j];


                                elapsedTime = stopwatch.ElapsedMilliseconds; // grava tempo decorrido
                                SendKeys.SendWait("=");
                                imgPictureBox.Visible = false;
                                subtitleLabel.Visible = false;
                                wordLabel.ForeColor   = ColorTranslator.FromHtml(programInUse.WordColor);
                                wordLabel.Visible     = true;
                                if (programInUse.SubtitleShow)
                                {
                                    subtitleCounter = showSubtitle(subtitleCounter, subtitlesArray);
                                }
                                actualImagePath = wordLabel.Text;
                                j++;

                                StroopProgram.writeLineOutput(programInUse, actualImagePath, "false", counter + 1, outputContent, elapsedTime, "txt", audioDetail);

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

                            await Task.Delay(programInUse.IntervalTime, cts.Token);
                        }
                    }
                    else
                    {
                        for (int counter = 0; counter < programInUse.NumExpositions; counter++) // AQUI ver estinulo -> palavra ou imagem como um só e ter intervalo separado
                        {
                            imgPictureBox.Visible = false;
                            wordLabel.Visible     = false;
                            subtitleLabel.Visible = false;
                            await intervalOrFixPoint(programInUse, cts.Token);


                            if (arrayCounter == imageDirs.Count())
                            {
                                arrayCounter = 0;
                            }
                            if (programInUse.RotateImage != 0)
                            {
                                imgPictureBox.Image = RotateImage(imageDirs[arrayCounter], programInUse.RotateImage);
                            }
                            else
                            {
                                imgPictureBox.Image = Image.FromFile(imageDirs[arrayCounter]);
                            }

                            if (programInUse.AudioListFile.ToLower() != "false" && programInUse.ExpositionType == "imgaud")
                            {
                                if (audioCounter == audioDirs.Length)
                                {
                                    audioCounter = 0;
                                }
                                audioDetail          = audioDirs[audioCounter];
                                Player.SoundLocation = audioDetail;
                                audioCounter++;
                                Player.Play();
                            }

                            elapsedTime = stopwatch.ElapsedMilliseconds; // grava tempo decorrido
                            SendKeys.SendWait("=");

                            imgPictureBox.Visible = true;

                            if (programInUse.SubtitleShow)
                            {
                                subtitleCounter = showSubtitle(subtitleCounter, subtitlesArray);
                            }

                            StroopProgram.writeLineOutput(programInUse, Path.GetFileName(imageDirs[arrayCounter].ToString()), "false", counter + 1, outputContent, elapsedTime, programInUse.ExpositionType, Path.GetFileNameWithoutExtension(audioDetail));

                            arrayCounter++;
                            await Task.Delay(programInUse.ExpositionTime, cts.Token);
                        }
                    }

                    imgPictureBox.Visible = false;
                    wordLabel.Visible     = false;
                    subtitleLabel.Visible = false;


                    await Task.Delay(programInUse.IntervalTime, cts.Token);

                    // beginAudio
                    if (programInUse.AudioCapture)
                    {
                        stopRecordingAudio();
                    }                                           // para gravação áudio
                    // endAudio
                    changeBackgroundColor(programInUse, false); // retorna à cor de fundo padrão

                    break;

                    /*
                     * DialogResult dialogResult = MessageBox.Show("Deseja repetir o teste?", "", MessageBoxButtons.YesNo); // pergunta se deseja repetir o programa
                     *
                     * if (dialogResult == DialogResult.Yes) { MessageBox.Show("O teste será repetido!"); } // se deseja repetir o programa mantém o laço while
                     * if (dialogResult == DialogResult.No) { break; } // se não deseja repetir quebra o laço
                     */
                }
                imgPictureBox.Dock  = DockStyle.None;
                wordLabel.Font      = new Font(wordLabel.Font.FontFamily, 160);
                wordLabel.ForeColor = Color.Black;
                StroopProgram.writeOutputFile(outputFile, string.Join("\n", outputContent.ToArray()));
                Close();
            }
            catch (TaskCanceledException)
            {
                StroopProgram.writeOutputFile(outputFile, string.Join("\n", outputContent.ToArray()));
                if (programInUse.AudioCapture)
                {
                    stopRecordingAudio();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            cts = null;
        }
Esempio n. 2
0
        private async Task startWordExposition() // starts colored words exposition - classic Stroop
        {
            cts = new CancellationTokenSource();
            string textCurrent = null, colorCurrent = null, audioDetail = "false";

            string[]      labelText = null, labelColor = null, audioDirs = null, subtitlesArray = null;
            int           textArrayCounter = 0, colorArrayCounter = 0, audioCounter = 0, subtitleCounter = 0;
            List <string> outputContent = new List <string>();

            var interval   = Task.Run(async delegate { await Task.Delay(programInUse.IntervalTime, cts.Token); });
            var exposition = Task.Run(async delegate { await Task.Delay(programInUse.ExpositionTime, cts.Token); });

            try
            {
                // reading list files:
                labelText      = StrList.readListFile(path + "/lst/" + programInUse.WordsListFile);  // string array receives wordsList itens from list file
                labelColor     = StrList.readListFile(path + "/lst/" + programInUse.ColorsListFile); // string array receives colorsList itens from list file
                subtitlesArray = configureSubtitle();
                if (programInUse.ExpositionRandom)                                                   // if the presentation is random, shuffles arrays
                {
                    labelText  = ExpositionController.shuffleArray(labelText, programInUse.NumExpositions, 1);
                    labelColor = ExpositionController.shuffleArray(labelColor, programInUse.NumExpositions, 5);
                }
                if (programInUse.AudioListFile != "false") // if there is an audioFile to be played, string array receives audioList itens from list file
                {
                    audioDirs = StroopProgram.readDirListFile(path + "/lst/" + programInUse.AudioListFile);
                    if (programInUse.ExpositionRandom)
                    {
                        audioDirs = ExpositionController.shuffleArray(audioDirs, programInUse.NumExpositions, 6);
                    }                                                                                                                                // if the presentation is random, shuffles array
                }
                if (!Validations.allHexPattern(labelColor))
                {
                    throw new Exception("A lista de cores '" + programInUse.ColorsListFile + "' contém valores inválidos!\n A lista de" +
                                        "cores deve conter apenas valores hexadecimais (ex: #000000)");
                }

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

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

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

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

                        if (counter < 10)// contador p/ arquivo de audio
                        {
                            printCount = "0" + counter.ToString();
                        }
                        else
                        {
                            printCount = counter.ToString();
                        }

                        textCurrent  = labelText[textArrayCounter];
                        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 (programInUse.AudioListFile.ToLower() != "false" && programInUse.ExpositionType == "txtaud") // reproduz audio
                        {
                            if (audioCounter == audioDirs.Length)
                            {
                                audioCounter = 0;
                            }
                            audioDetail          = audioDirs[audioCounter];
                            Player.SoundLocation = audioDetail;
                            audioCounter++;
                            Player.Play();
                        }

                        elapsedTime = stopwatch.ElapsedMilliseconds; // grava tempo decorrido
                        SendKeys.SendWait("=");
                        if (programInUse.SubtitleShow)
                        {
                            subtitleCounter = showSubtitle(subtitleCounter, subtitlesArray);
                        }
                        wordLabel.Visible = true;



                        StroopProgram.writeLineOutput(programInUse, textCurrent, colorCurrent, counter, outputContent, elapsedTime, programInUse.ExpositionType, audioDetail);

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

                    // beginAudio
                    if (programInUse.AudioCapture && programInUse.ExpositionType != "txtaud")
                    {
                        stopRecordingAudio();
                    }                                           // para gravação áudio
                    // endAudio
                    changeBackgroundColor(programInUse, false); // retorna à cor de fundo padrão

                    break;

                    /*
                     * DialogResult dialogResult = MessageBox.Show("Deseja repetir o teste?", "", MessageBoxButtons.YesNo); // pergunta se deseja repetir o programa
                     * if (dialogResult == DialogResult.Yes) { MessageBox.Show("O teste será repetido!"); } // se deseja repetir o programa mantém o laço while
                     * if (dialogResult == DialogResult.No) { break; } // se não deseja repetir quebra o laço
                     */
                }
                StroopProgram.writeOutputFile(outputFile, string.Join("\n", outputContent.ToArray()));
                Close(); // finaliza exposição após execução
            }
            catch (TaskCanceledException)
            {
                StroopProgram.writeOutputFile(outputFile, string.Join("\n", outputContent.ToArray()));
                if (programInUse.AudioCapture)
                {
                    stopRecordingAudio();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            cts = null;
        }